From e01db2c3f588e0be1561a5f58a2b6e2c35198199 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 17:07:01 +0200 Subject: [PATCH 1/2] [mod] tools:update-plankton [upd] plankton --- lib/plankton/plankton.d.ts | 772 ++++++++---- lib/plankton/plankton.js | 2435 +++++++++++++++++++++--------------- tools/update-plankton | 12 +- 3 files changed, 1899 insertions(+), 1320 deletions(-) diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 1407ed5..8aeff70 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -224,6 +224,12 @@ declare namespace lib_plankton.base { /** */ function object_merge(core: Record, mantle: Record): Record; + /** + */ + function buffer_show(buffer: Buffer, { "block_size": option_block_size, "break_char": option_break_char, }?: { + block_size?: int; + break_char?: string; + }): string; } declare module lib_plankton.pod { /** @@ -579,36 +585,6 @@ declare namespace lib_plankton.call { */ function promise_delay(promise: type_promise, delay: int): type_promise; } -declare namespace lib_plankton.call { - /** - */ - class CancellablePromise extends Promise { - /** - */ - private cancelled; - /** - */ - private interval; - /** - */ - private subject; - /** - */ - constructor(executor: ((resolve: any, reject: any) => void)); - /** - */ - private clear; - /** - */ - then(onfulfilled?: ((value: type_result) => (type_next_resolved | PromiseLike)), onrejected?: ((reason: any) => (type_next_rejected | PromiseLike))): Promise; - /** - */ - catch(x: any): Promise; - /** - */ - cancel(): void; - } -} /** * initializer might be obsolete, since promises are reusable after having been resolved or rejected */ @@ -772,25 +748,25 @@ declare namespace lib_plankton.call { * @param {Object} args * @author fenris */ - function args2list(args: any): Array; + export function args2list(args: any): Array; /** * just the empty function; useful for some callbacks etc. * * @author fenris */ - function nothing(): void; + export function nothing(): void; /** * just the identity; useful for some callbacks etc.; defined as function instead of const for using type parameters * * @author fenris */ - function id(x: type_value): type_value; + export function id(x: type_value): type_value; /** * just the identity; useful for some callbacks etc. * * @author fenris */ - function const_(x: type_value): ((y: any) => type_value); + export function const_(x: type_value): ((y: any) => type_value); /** * composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions) * @@ -798,7 +774,7 @@ declare namespace lib_plankton.call { * @param {function} function_g * @author fenris */ - function compose(function_f: ((type_x: any) => type_y), function_g: ((type_y: any) => type_z)): ((value: type_x) => type_z); + export function compose(function_f: ((type_x: any) => type_y), function_g: ((type_y: any) => type_z)): ((value: type_x) => type_z); /** * transforms a function with sequential input to a function with leveled input; example: add(2,3) = curryfy(add)(2)(3) * @@ -806,27 +782,46 @@ declare namespace lib_plankton.call { * @return {function} the currified version of the in put function * @author fenris */ - function curryfy(f: Function): Function; + export function curryfy(f: Function): Function; /** * @author fenris */ - function convey(value: any, functions: Array): any; + export function convey(value: any, functions: Array): any; + /** + */ + class class_value_wrapper { + /** + */ + private value; + /** + */ + constructor(value: type_value); + /** + */ + convey(function_: ((value: type_value) => type_value_result)): class_value_wrapper; + /** + */ + cull(): type_value; + } + /** + */ + export function wrap(value: type_value): class_value_wrapper; /** * @author fenris */ - function timeout(procedure: (() => void), delay_in_seconds: float): int; + export function timeout(procedure: (() => void), delay_in_seconds: float): int; /** * Promise version of "setTimeout" * * @author fenris */ - function defer(seconds: float, action: (() => type_result)): Promise; + export function defer(seconds: float, action: (() => type_result)): Promise; /** * a definition for a value being "defined" * * @author neuc */ - function is_def(obj: type_value, options?: { + export function is_def(obj: type_value, options?: { null_is_valid?: boolean; }): boolean; /** @@ -834,7 +829,7 @@ declare namespace lib_plankton.call { * * @author neuc */ - function def_val(value: any, default_value: any, options?: { + export function def_val(value: any, default_value: any, options?: { type?: (null | string); null_is_valid?: boolean; }): any; @@ -845,7 +840,7 @@ declare namespace lib_plankton.call { * @return {function} * @author fenris */ - function attribute(name: string): ((object: type_object) => type_attribute); + export function attribute(name: string): ((object: type_object) => type_attribute); /** * provides a method of a class as a regular function; useful for processing lists of objects * @@ -853,26 +848,36 @@ declare namespace lib_plankton.call { * @return {function} * @author fenris */ - function method(name: string): ((object: type_object) => type_output); + export function method(name: string): ((object: type_object) => type_output); /** * @author fenris */ - type type_coproduct = { + export type type_coproduct = { kind: string; data?: any; }; /** * @author fenris */ - function distinguish(coproduct: type_coproduct, handlers: Record type_output)>, options?: { + export function distinguish(coproduct: type_coproduct, handlers: Record type_output)>, options?: { fallback?: (null | ((coproduct?: type_coproduct) => type_output)); }): type_output; /** */ - function try_catch_wrap(get_value: (() => type_value)): { + export function try_catch_wrap(get_value: (() => type_value)): { value: (null | type_value); error: (null | any); }; + /** + */ + export function try_catch_wrap_async(get_value: (() => Promise)): Promise<{ + value: (null | type_value); + error: (null | any); + }>; + /** + */ + export function sleep(seconds: float): Promise; + export {}; } declare namespace lib_plankton.file { /** @@ -920,126 +925,265 @@ declare namespace lib_plankton.log { warning = 3, error = 4 } - /** - */ - function level_order(level1: enum_level, level2: enum_level): boolean; - /** - */ - function level_show(level: enum_level): string; /** */ type type_entry = { level: enum_level; incident: string; - details: Record; + tags: Array; + details: any; }; + /** + */ + type type_channel_description = lib_plankton.call.type_coproduct; + /** + */ + type type_channel_logic = { + send: ((entry: type_entry) => void); + }; + /** + */ + type type_logger_data = Array; + /** + */ + type type_logger_logic = Array; + /** + */ + type type_format_definition = ({ + kind: "jsonl"; + data: { + structured: boolean; + }; + } | { + kind: "human_readable"; + data: {}; + }); +} +declare namespace lib_plankton.log { + /** + */ + function level_order(level1: enum_level, level2: enum_level): boolean; + /** + */ + function level_show(level: enum_level, { "abbreviated": option_abbreviated, }?: { + abbreviated?: boolean; + }): string; + /** + */ + function level_decode(level_string: string): enum_level; +} +declare namespace lib_plankton.log { + /** + * @todo use label + */ + function get_logger_logic(logger_data: type_logger_data): type_logger_logic; + /** + */ + function format_entry(format_definition: type_format_definition, entry: type_entry): string; + /** + */ + function parse_format_definition(format_definition_raw: any): type_format_definition; +} +declare namespace lib_plankton.log.channel.filtered { + /** + */ + type type_predicate = ((entry: type_entry) => boolean); + /** + */ + type type_subject = { + /** + * @todo check if it has to be logic + */ + core: type_channel_logic; + predicate: type_predicate; + }; + /** + */ + function predicate_incident(substring: string): type_predicate; + /** + */ + function predicate_level(threshold: enum_level): type_predicate; + /** + */ + function predicate_tag(tag: string): type_predicate; + /** + * combines other predicates in disjunctive normal form + */ + function predicate_complex(definition: Array>): type_predicate; + /** + */ + function send(subject: type_subject, entry: type_entry): void; + /** + */ + function logic(subject: type_subject): type_channel_logic; +} +declare namespace lib_plankton.log.channel.minlevel { + /** + */ + type type_subject = { + /** + * @todo check if it has to be logic + */ + core: type_channel_logic; + threshold: enum_level; + }; + /** + */ + function send(subject: type_subject, entry: type_entry): void; + /** + */ + function logic(subject: type_subject): type_channel_logic; } /** - * @deprecated - * @todo remove + * output for writing log entries to web console */ -declare namespace lib_plankton.log { - function level_push(level: int): void; - function level_pop(): void; - function indent_push(indent: int): void; - function indent_pop(): void; - function indent_inc(): void; - function indent_dec(): void; +declare namespace lib_plankton.log.channel.console_ { /** - * @author fenris */ - function write({ "message": message, "type": type, "prefix": prefix, "level": level, "indent": indent, }: { - message?: string; - type?: string; - prefix?: string; - level?: int; - indent?: int; + type type_subject = {}; + /** + * @todo tags + */ + function send(subject: type_subject, entry: type_entry): void; + /** + */ + function logic(subject: type_subject): type_channel_logic; +} +declare namespace lib_plankton.log { + /** + */ + function get_channel_logic(channel_description: type_channel_description): type_channel_logic; +} +declare namespace lib_plankton.log { + /** + */ + function default_logger(): type_logger_data; +} +declare namespace lib_plankton.log { + /** + */ + function set_main_logger(logger_data: type_logger_data): void; + /** + * consumes a log entry, i.e. sends it to all channels + */ + function send_(logger: type_logger_logic, entry: type_entry): void; + /** + * [convenience] + * + * @todo rename to "send" + */ + function debug_(logger: type_logger_logic, incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; }): void; -} -declare namespace lib_plankton.log { /** + * [convenience] + * + * @todo rename to "info" */ - abstract class class_channel { - /** - */ - abstract add(entry: type_entry): void; - } -} -declare namespace lib_plankton.log { + function info_(logger: type_logger_logic, incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** - * output for writing log entries to web console + * [convenience] + * + * @todo rename to "notice" */ - class class_channel_console extends class_channel { - /** - */ - add(entry: type_entry): void; - } -} -declare namespace lib_plankton.log { + function notice_(logger: type_logger_logic, incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** - * decorator for filtering out log entries below a certain level threshold + * [convenience] + * + * @todo rename to "warning" */ - class class_channel_minlevel extends class_channel { - /** - */ - private core; - /** - */ - private threshold; - /** - */ - constructor(core: class_channel, threshold: enum_level); - /** - */ - add(entry: type_entry): void; - } -} -declare namespace lib_plankton.log { + function warning_(logger: type_logger_logic, incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** + * [convenience] + * + * @todo rename to "error" */ - function channel_make(description: { - kind: string; - data?: { - [key: string]: any; - }; - }): class_channel; + function error_(logger: type_logger_logic, incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** + * [convenience] */ - type type_configuration = Array; + function _send(entry: type_entry): void; /** + * [convenience] */ - function conf_default(): type_configuration; -} -declare namespace lib_plankton.log { + function _debug(incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** - * pushes a new configuration on the stack and activates it + * [convenience] */ - function conf_push(channels: type_configuration): void; + function _info(incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** - * pops the current active configuration from the stack + * [convenience] */ - function conf_pop(): void; + function _notice(incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** - * consumes a log entry, i.e. sends it to the currently active outputs + * [convenience] */ - function add(entry: type_entry): void; + function _warning(incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** + * [convenience] */ - function debug(incident: string, details?: Record): void; + function _error(incident: string, { "tags": option_tags, "details": option_details, }?: { + tags?: Array; + details?: any; + }): void; /** + * [convenience] + * + * @deprecated use ._debug instead! */ - function info(incident: string, details?: Record): void; + function debug(incident: string, details?: any, tags?: Array): void; /** + * [convenience] + * + * @deprecated use ._info instead! */ - function notice(incident: string, details?: Record): void; + function info(incident: string, details?: any, tags?: Array): void; /** + * [convenience] + * + * @deprecated use ._notice instead! */ - function warning(incident: string, details?: Record): void; + function notice(incident: string, details?: any, tags?: Array): void; /** + * [convenience] + * + * @deprecated use ._warning instead! */ - function error(incident: string, details?: Record): void; -} -declare namespace lib_plankton.log { + function warning(incident: string, details?: any, tags?: Array): void; + /** + * [convenience] + * + * @deprecated use ._error instead! + */ + function error(incident: string, details?: any, tags?: Array): void; } declare namespace lib_plankton.object { /** @@ -1300,7 +1444,7 @@ declare namespace lib_plankton.conf { */ type type_schema = ({ enum?: Array; - default?: any; + default?: (null | any); description?: string; } | { type: "null"; @@ -1309,32 +1453,32 @@ declare namespace lib_plankton.conf { type: "boolean"; nullable?: boolean; enum?: Array; - default?: boolean; + default?: (null | boolean); description?: string; } | { type: "integer"; nullable?: boolean; enum?: Array; - default?: int; + default?: (null | int); description?: string; } | { type: "number"; nullable?: boolean; enum?: Array; - default?: number; + default?: (null | number); description?: string; } | { type: "string"; nullable?: boolean; enum?: Array; - default?: string; + default?: (null | string); description?: string; } | { type: "array"; nullable?: boolean; items: type_schema; enum?: Array>; - default?: Array; + default?: (null | Array); description?: string; } | { type: "object"; @@ -1343,7 +1487,7 @@ declare namespace lib_plankton.conf { required?: Array; additionalProperties?: (false | type_schema); enum?: Array>; - default?: Record; + default?: (Record | null); description?: string; } | { anyOf: Array; @@ -1355,6 +1499,12 @@ declare namespace lib_plankton.conf { } | { not: type_schema; }); + /** + */ + type type_sheet = { + version: (null | string); + content: type_content; + }; /** */ type type_report = { @@ -1367,15 +1517,24 @@ declare namespace lib_plankton.conf { reports: Array; result: lib_plankton.pod.type_pod; }; + /** + */ + type type_migration = (null | { + target: string; + function: ((content: type_from) => type_to); + }); } declare namespace lib_plankton.conf { /** - * @todo versioning */ - function refine(schema: type_schema, value_raw: any): type_result; + function refine(schema: type_schema, content: any): type_result; + /** + * @deprecated + */ + function load(schema: type_schema, path: (null | string)): Promise; /** */ - function load(schema: type_schema, path: (null | string)): Promise; + function load_versioned(path: string, get_schema: ((version: string) => type_schema), migrations: Record>): Promise>; } declare var plain_text_to_html: (text: string) => string; /** @@ -1413,7 +1572,7 @@ declare namespace lib_plankton.string { * @return {Array} * @author fenris */ - function split(chain: string, separator?: string): Array; + function split(chain: string, separator: string): Array; /** * @author neu3no */ @@ -1499,6 +1658,9 @@ declare namespace lib_plankton.string { /** */ function slice(str: string, size: int): Array; + /** + */ + function capitalize(str: string): string; } /** * @deprecated @@ -2137,13 +2299,11 @@ declare namespace lib_plankton.complex { */ function npow(x: type_complex, n: int): type_complex; /** - * ermittelt die natürliche Potenz einer komplexen Zahl + * ermittelt den Wert der natürlichen Exponential-Funktion * * @author fenris - * @deprecated use "npow" instead - * @todo remove */ - function exp(x: type_complex, n: int): type_complex; + function exp(x: type_complex): type_complex; /** * ermittelt die Potenz zweier komplexer Zahlen * @@ -2260,7 +2420,7 @@ declare namespace lib_plankton.complex { /** * @author fenris */ - exp(n: int): class_complex; + exp(): class_complex; /** * @author fenris */ @@ -2703,82 +2863,51 @@ declare namespace lib_plankton.color { value?: float; }): type_color; } -/** - * @author fenris - */ -declare namespace lib_plankton.xml { +declare namespace lib_plankton.http_base { /** - * @author fenris */ - abstract class class_node { - /** - * @author fenris - */ - abstract compile(depth?: int): string; - } + type type_request = { + scheme: ("http" | "https"); + host: (null | string); + path: string; + version: string; + method: type_method; + query: (null | string); + headers: Record; + body: (null | Buffer); + }; /** - * @author fenris */ - class class_node_text extends class_node { - /** - * @author fenris - */ - protected content: string; - /** - * @author fenris - */ - constructor(content: string); - /** - * @author fenris - */ - compile(depth?: int): string; - } + type type_response = { + version: (null | string); + status_code: type_status_code; + headers: Record; + body: (null | Buffer); + }; +} +declare namespace lib_plankton.http_base { /** - * @author fenris */ - class class_node_comment extends class_node { - /** - * @author fenris - */ - protected content: string; - /** - * @author fenris - */ - constructor(content: string); - /** - * @author fenris - */ - compile(depth?: int): string; - } + function encode_request(encode_method: ((method: type_method) => string), request: type_request): string; /** - * @author fenris */ - class class_node_complex extends class_node { - /** - * @author fenris - */ - protected name: string; - /** - * @author fenris - */ - protected attributes: { - [key: string]: string; - }; - /** - * @author fenris - */ - protected children: Array; - /** - * @author fenris - */ - constructor(name: string, attributes?: { - [key: string]: string; - }, children?: any[]); - /** - * @author fenris - */ - compile(depth?: int): string; - } + function decode_request(decode_method: ((method_raw: string) => type_method), has_body: ((method: type_method) => boolean), request_raw: string): type_request; + /** + */ + function encode_response(encode_status_code: ((status_code: type_status_code) => string), get_status_text: ((status_code: type_status_code) => string), response: type_response): string; + /** + */ + function decode_response(decode_status_code: ((status_code_raw: string) => type_status_code), response_raw: string): type_response; + /** + * executes an HTTP request + * + * @todo define type_signal + */ + function call(has_body: ((method: type_method) => boolean), encode_method: ((method: type_method) => string), decode_status_code: ((status_code_raw: string) => type_status_code), request: type_request, { "timeout": option_timeout, "follow_redirects": option_follow_redirects, "implementation": option_implementation, }?: { + timeout?: (null | float); + follow_redirects?: boolean; + implementation?: ("fetch" | "http_module"); + }): Promise>; } declare namespace lib_plankton.http { /** @@ -2794,33 +2923,85 @@ declare namespace lib_plankton.http { patch = "patch" } /** - * @author fenris */ - type type_request = { - scheme: ("http" | "https"); - host: (null | string); - path: string; - version: string; - method: enum_method; - query: (null | string); - headers: Record; - body: (null | Buffer); - }; + enum enum_status_code { + continue_ = 100, + switching_protocols = 101, + early_hints = 103, + ok = 200, + created = 201, + accepted = 202, + non_authoritative_information = 203, + no_content = 204, + reset_content = 205, + partial_coentent = 206, + multiple_choices = 300, + moved_permanently = 301, + found = 302, + see_other = 303, + not_modified = 304, + temporary_redirect = 307, + permanent_redirect = 308, + bad_request = 400, + unauthorized = 401, + payment_required = 402, + forbidden = 403, + not_found = 404, + method_not_allowed = 405, + not_acceptable = 406, + proxy_authentication_required = 407, + request_timeout = 408, + conflict = 409, + gone = 410, + length_required = 411, + precondition_failed = 412, + payload_too_large = 413, + uri_too_long = 414, + unsupported_media_type = 415, + range_not_satisfiable = 416, + expectation_failed = 417, + i_m_a_teapot = 418, + unprocessable_entity = 422, + too_early = 425, + upgrade_required = 426, + precondition_required = 428, + too_many_requests = 429, + request_header_fields_too_large = 431, + unavailable_for_legal_reasons = 451, + internal_server_error = 500, + not_implemented = 501, + bad_gateway = 502, + service_unavailable = 503, + gateway_timeout = 504, + http_version_not_supported = 505, + variant_also_negotiates = 506, + insufficient_storage = 507, + loop_detected = 508, + not_extended = 510, + network_authentication = 511 + } /** * @author fenris */ - type type_response = { - version: (null | string); - status_code: int; - headers: Record; - body: Buffer; - }; + type type_request = lib_plankton.http_base.type_request; + /** + * @author fenris + */ + type type_response = lib_plankton.http_base.type_response; } declare namespace lib_plankton.http { /** * @author fenris */ function encode_method(method: enum_method): string; + /** + * @author fenris + */ + function decode_method(method_raw: string): enum_method; + /** + * @author fenris + */ + function has_body(method: enum_method): boolean; /** * @author fenris */ @@ -2842,52 +3023,12 @@ declare namespace lib_plankton.http { * * @todo define type_signal */ - function call(request: type_request, options?: { + function call(request: type_request, { "timeout": option_timeout, "follow_redirects": option_follow_redirects, "implementation": option_implementation, }?: { timeout?: (null | float); follow_redirects?: boolean; implementation?: ("fetch" | "http_module"); }): Promise; } -declare namespace lib_plankton.http { - /** - * @author fenris - */ - class class_http_request implements lib_plankton.code.interface_code { - /** - * @author fenris - */ - constructor(); - /** - * @implementation - * @author fenris - */ - encode(x: type_request): string; - /** - * @implementation - * @author fenris - */ - decode(x: string): type_request; - } - /** - * @author fenris - */ - class class_http_response implements lib_plankton.code.interface_code { - /** - * @author fenris - */ - constructor(); - /** - * @implementation - * @author fenris - */ - encode(x: type_response): string; - /** - * @implementation - * @author fenris - */ - decode(x: string): type_response; - } -} declare namespace lib_plankton.url { /** * @author fenris @@ -2992,7 +3133,7 @@ declare namespace lib_plankton.pit { /** * @todo test */ - function to_datetime(pit: type_pit, { timezone_shift, }?: { + function to_datetime(pit: type_pit, { "timezone_shift": option_timezone_shift, }?: { timezone_shift?: int; }): type_datetime; /** @@ -3001,18 +3142,45 @@ declare namespace lib_plankton.pit { /** */ function is_before(pit: type_pit, reference: type_pit): boolean; + /** + */ + function is_after(pit: type_pit, reference: type_pit): boolean; + /** + */ + function is_equal_or_after(pit: type_pit, reference: type_pit): boolean; /** */ function is_between(pit: type_pit, reference_left: type_pit, reference_right: type_pit): boolean; + /** + */ + function shift_hour(pit: type_pit, increment: int): type_pit; /** */ function shift_day(pit: type_pit, increment: int): type_pit; /** */ function shift_week(pit: type_pit, increment: int): type_pit; + /** + */ + function shift_year(pit: type_pit, increment: int): type_pit; + /** + */ + function trunc_minute(pit: type_pit): type_pit; + /** + */ + function trunc_hour(pit: type_pit): type_pit; + /** + */ + function trunc_day(pit: type_pit): type_pit; /** */ function trunc_week(pit: type_pit): type_pit; + /** + */ + function trunc_month(pit: type_pit): type_pit; + /** + */ + function trunc_year(pit: type_pit): type_pit; /** */ function now(): type_pit; @@ -3021,13 +3189,13 @@ declare namespace lib_plankton.pit { * @param week week according to specified timezone shift * @return the begin of the week (monday, 00:00) */ - function from_ywd(ywd: type_ywd, options?: { + function from_ywd(ywd: type_ywd, { "timezone_shift": option_timezone_shift, }?: { timezone_shift?: int; }): type_pit; /** * @todo timezone */ - function to_ywd(pit: type_pit, options?: { + function to_ywd(pit: type_pit, { "timezone_shift": option_timezone_shift, }?: { timezone_shift?: int; }): type_ywd; /** @@ -3064,13 +3232,13 @@ declare namespace lib_plankton.pit { function date_format(date: type_date): string; /** */ - function time_format(time: type_time, { show_seconds, }?: { + function time_format(time: type_time, { "show_seconds": option_show_seconds, }?: { show_seconds?: boolean; }): string; /** * @todo show timezone */ - function datetime_format(datetime: (null | type_datetime), { timezone_indicator, show_timezone, adjust_to_ce, omit_date, }?: { + function datetime_format(datetime: (null | type_datetime), { "timezone_indicator": option_timezone_indicator, "show_timezone": option_show_timezone, "adjust_to_ce": option_adjust_to_ce, "omit_date": option_omit_date, }?: { timezone_indicator?: string; show_timezone?: boolean; adjust_to_ce?: boolean; @@ -3078,7 +3246,7 @@ declare namespace lib_plankton.pit { }): string; /** */ - function timespan_format(from: type_datetime, to: (null | type_datetime), { timezone_indicator, show_timezone, adjust_to_ce, omit_date, }?: { + function timespan_format(from: type_datetime, to: (null | type_datetime), { "timezone_indicator": option_timezone_indicator, "show_timezone": option_show_timezone, "adjust_to_ce": option_adjust_to_ce, "omit_date": option_omit_date, }?: { timezone_indicator?: string; show_timezone?: boolean; adjust_to_ce?: boolean; @@ -3169,6 +3337,18 @@ declare namespace lib_plankton.translate { /** * @desc retrieves a string by going through the order and trying to fetch it for the current entry * @author fenris + * @todo rename to "get" + */ + function get_new(path: string, { "args": args, "preferred_language": preferred_language, "fallback": fallback, }?: { + args?: Record; + preferred_language?: (null | string); + fallback?: string; + }): string; + /** + * @desc retrieves a string by going through the order and trying to fetch it for the current entry + * @author fenris + * @deprecated use "get_new" + * @todo remove */ function get(path: string, args?: { [id: string]: string; @@ -3228,6 +3408,9 @@ declare namespace lib_plankton.zoo_page { * encodes a location in the URL and loads it */ export function set(location: type_location): void; + /** + */ + export function reload(): Promise; /** */ export function register(location_name: string, handler: type_handler, options?: {}): void; @@ -3613,6 +3796,9 @@ declare namespace lib_plankton.zoo_input { * @author fenris */ export class class_input_list implements interface_input> { + /** + */ + private read_only; /** */ private element_input_factory; @@ -3628,6 +3814,7 @@ declare namespace lib_plankton.zoo_input { /** */ constructor(element_input_factory: (() => interface_input), options?: { + read_only?: boolean; translations?: type_translations; }); /** @@ -3651,6 +3838,41 @@ declare namespace lib_plankton.zoo_input { } export {}; } +declare namespace lib_plankton.zoo_input { + /** + */ + class class_input_set implements lib_plankton.zoo_input.interface_input> { + /** + */ + private options; + /** + */ + private show_element; + /** + */ + private read_only; + /** + */ + private checkboxes; + /** + */ + constructor(options: Array, show_element: ((element: string) => string), { "read_only": read_only, }?: { + read_only?: boolean; + }); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise>; + /** + * [implementation] + */ + write(value: Set): Promise; + } +} declare namespace lib_plankton.zoo_input { /** * @author fenris @@ -3795,7 +4017,7 @@ declare namespace lib_plankton.zoo_input { private core; /** */ - constructor(options?: { + constructor({ "label_timezone_shift": label_timezone_shift, "label_date": label_date, "label_time": label_time, }?: { label_timezone_shift?: string; label_date?: string; label_time?: string; diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 43c4b1e..db470e3 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -1,18 +1,3 @@ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); /* This file is part of »bacterio-plankton:base«. @@ -123,7 +108,7 @@ along with »bacterio-plankton:base«. If not, see this.actions[id](information)); } - }; + } /** * @author frac */ - class_observer.prototype.rollout = function () { - var _this = this; - this.buffer.forEach(function (information) { return _this.notify(information, false); }); + rollout() { + this.buffer.forEach(information => this.notify(information, false)); this.buffer = []; - }; - return class_observer; -}()); + } +} /** * @author frac */ @@ -397,27 +377,23 @@ along with »bacterio-plankton:base«. If not, see x.toString()).join(",") + "]")); + } +} /* This file is part of »bacterio-plankton:base«. @@ -446,9 +422,8 @@ var lib_plankton; * * @author fenris */ - function get_current_timestamp(rounded) { - if (rounded === void 0) { rounded = false; } - var x = (Date.now() / 1000); + function get_current_timestamp(rounded = false) { + const x = (Date.now() / 1000); return (rounded ? Math.round(x) : x); ; } @@ -459,6 +434,24 @@ var lib_plankton; return Object.assign(core, mantle); } base.object_merge = object_merge; + /** + */ + function buffer_show(buffer, { "block_size": option_block_size = 20, "break_char": option_break_char = "\n", } = {}) { + let output = ""; + let count = 0; + // @ts-ignore + for (const entry of buffer) { + count = ((count + 1) % option_block_size); + output += ((typeof (entry) === "string") + ? + entry.charCodeAt(0) + : + entry).toString(16).toUpperCase().padStart(2, "0"); + output += ((count === 0) ? option_break_char : " "); + } + return output; + } + base.buffer_show = buffer_show; })(base = lib_plankton.base || (lib_plankton.base = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -1328,89 +1321,6 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:call«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var call; - (function (call) { - /** - */ - class CancellablePromise extends Promise { - /** - */ - constructor(executor) { - super((resolve, reject) => { }); - this.subject = (new Promise((resolve, reject) => { - Promise.race([ - new Promise(executor), - new Promise((resolve_, reject_) => { - this.interval = setInterval(() => { - if (!this.cancelled) { - // do nothing - } - else { - reject_(new Error("cancelled")); - this.clear(); - } - }, 0); - }), - ]) - .then(resolve, reject); - })); - this.cancelled = false; - this.interval = null; - } - /** - */ - clear() { - if (this.interval === null) { - // do nothing - } - else { - clearInterval(this.interval); - this.interval = null; - } - } - /** - */ - then(onfulfilled, onrejected) { - this.clear(); - return this.subject.then(onfulfilled, onrejected); - } - /** - */ - catch(x) { - this.clear(); - return this.subject.catch(x); - } - /** - */ - cancel() { - this.cancelled = true; - this.clear(); - } - } - call.CancellablePromise = CancellablePromise; - })(call = lib_plankton.call || (lib_plankton.call = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:call«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:call« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:call« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:call«. If not, see . */ @@ -1940,6 +1850,31 @@ var lib_plankton; return result; } call.convey = convey; + /** + */ + class class_value_wrapper { + /** + */ + constructor(value) { + this.value = value; + } + /** + */ + convey(function_) { + return (new class_value_wrapper(function_(this.value))); + } + /** + */ + cull() { + return this.value; + } + } + /** + */ + function wrap(value) { + return (new class_value_wrapper(value)); + } + call.wrap = wrap; /** * @author fenris */ @@ -2062,6 +1997,30 @@ var lib_plankton; } } call.try_catch_wrap = try_catch_wrap; + /** + */ + function try_catch_wrap_async(get_value) { + return (get_value() + .then((value) => Promise.resolve({ + "value": value, + "error": null, + })) + .catch((reason) => Promise.resolve({ + "value": null, + "error": reason, + }))); + } + call.try_catch_wrap_async = try_catch_wrap_async; + /** + */ + function sleep(seconds) { + return (new Promise((resolve, reject) => { + setTimeout(() => { + resolve(undefined); + }, Math.floor(seconds * 1000)); + })); + } + call.sleep = sleep; })(call = lib_plankton.call || (lib_plankton.call = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -2240,21 +2199,6 @@ var lib_plankton; email.send = send; })(email = lib_plankton.email || (lib_plankton.email = {})); })(lib_plankton || (lib_plankton = {})); -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); /* This file is part of »bacterio-plankton:log«. @@ -2289,6 +2233,31 @@ var lib_plankton; enum_level[enum_level["error"] = 4] = "error"; })(enum_level = log.enum_level || (log.enum_level = {})); ; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { /** */ function level_order(level1, level2) { @@ -2297,282 +2266,33 @@ var lib_plankton; log.level_order = level_order; /** */ - function level_show(level) { - switch (level) { - case enum_level.debug: return "debug"; - case enum_level.info: return "info"; - case enum_level.notice: return "notice"; - case enum_level.warning: return "warning"; - case enum_level.error: return "error"; - default: return "(unknown)"; + function level_show(level, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["abbreviated"], option_abbreviated = _c === void 0 ? false : _c; + if (option_abbreviated) { + switch (level) { + case log.enum_level.debug: return "DBG"; + case log.enum_level.info: return "INF"; + case log.enum_level.notice: return "NTC"; + case log.enum_level.warning: return "WRN"; + case log.enum_level.error: return "ERR"; + default: return "(unknown)"; + } + } + else { + switch (level) { + case log.enum_level.debug: return "debug"; + case log.enum_level.info: return "info"; + case log.enum_level.notice: return "notice"; + case log.enum_level.warning: return "warning"; + case log.enum_level.error: return "error"; + default: return "(unknown)"; + } } } log.level_show = level_show; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:lang«. If not, see . - */ -/** - * @deprecated - * @todo remove - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - * @author fenris - */ - /*export*/ var level_stack = [0]; - function level_push(level) { level_stack.push(level); } - log.level_push = level_push; - function level_pop() { if (level_stack.length > 1) { - level_stack.pop(); - } } - log.level_pop = level_pop; - function level_get() { return level_stack.slice(-1)[0]; } - /* - export function level_inc() : void {level_push(level_get()+1);} - export function level_dec() : void {level_push(level_get()-1);} - */ - /** - * @author fenris - */ - var indent_stack = [0]; - function indent_push(indent) { indent_stack.push(indent); } - log.indent_push = indent_push; - function indent_pop() { if (indent_stack.length > 1) { - indent_stack.pop(); - } } - log.indent_pop = indent_pop; - function indent_get() { return level_stack.slice(-1)[0]; } - function indent_inc() { level_push(level_get() + 1); } - log.indent_inc = indent_inc; - function indent_dec() { level_push(level_get() - 1); } - log.indent_dec = indent_dec; - /** - * @author fenris - */ - function write(_a) { - var message = _a["message"], _b = _a["type"], type = _b === void 0 ? null : _b, _c = _a["prefix"], prefix = _c === void 0 ? null : _c, _d = _a["level"], level = _d === void 0 ? 0 : _d, _e = _a["indent"], indent = _e === void 0 ? 0 : _e; - var entry = { - "level": ((type === null) - ? lib_plankton.log.enum_level.info - : { - "debug": lib_plankton.log.enum_level.debug, - "info": lib_plankton.log.enum_level.info, - "notice": lib_plankton.log.enum_level.notice, - "warning": lib_plankton.log.enum_level.warning, - "error": lib_plankton.log.enum_level.error - }[type]), - "incident": message, - "details": { - "prefix": prefix, - "level": level, - "indent": indent - } - }; - lib_plankton.log.add(entry); - } - log.write = write; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { /** */ - var class_channel = /** @class */ (function () { - function class_channel() { - } - return class_channel; - }()); - log.class_channel = class_channel; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - * output for writing log entries to web console - */ - var class_channel_console = /** @class */ (function (_super) { - __extends(class_channel_console, _super); - function class_channel_console() { - return _super !== null && _super.apply(this, arguments) || this; - } - /** - */ - class_channel_console.prototype.add = function (entry) { - var _a; - var renderers = (_a = {}, - _a[log.enum_level.debug] = { - "renderer": function (i, d) { return console.log(i, d); }, - "show_level": true - }, - _a[log.enum_level.info] = { - "renderer": function (i, d) { return console.info(i, d); }, - "show_level": false - }, - _a[log.enum_level.notice] = { - "renderer": function (i, d) { return console.log(i, d); }, - "show_level": true - }, - _a[log.enum_level.warning] = { - "renderer": function (i, d) { return console.warn(i, d); }, - "show_level": false - }, - _a[log.enum_level.error] = { - "renderer": function (i, d) { return console.error(i, d); }, - "show_level": false - }, - _a); - var setting = renderers[entry.level]; - setting.renderer(((setting.show_level - ? ("[" + log.level_show(entry.level) + "]" + " ") - : "") - + - ("" + entry.incident + "")), entry.details); - }; - return class_channel_console; - }(log.class_channel)); - log.class_channel_console = class_channel_console; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - * decorator for filtering out log entries below a certain level threshold - */ - var class_channel_minlevel = /** @class */ (function (_super) { - __extends(class_channel_minlevel, _super); - /** - */ - function class_channel_minlevel(core, threshold) { - var _this = _super.call(this) || this; - _this.core = core; - _this.threshold = threshold; - return _this; - } - /** - */ - class_channel_minlevel.prototype.add = function (entry) { - if (!log.level_order(this.threshold, entry.level)) { - // do nothing - } - else { - this.core.add(entry); - } - }; - return class_channel_minlevel; - }(log.class_channel)); - log.class_channel_minlevel = class_channel_minlevel; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - */ - function translate_level(level_string) { + function level_decode(level_string) { return { "debug": log.enum_level.debug, "info": log.enum_level.info, @@ -2581,30 +2301,402 @@ var lib_plankton; "error": log.enum_level.error }[level_string]; } + log.level_decode = level_decode; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + * @todo use label + */ + function get_logger_logic(logger_data) { + return logger_data.map(function (channel_description) { return lib_plankton.log.get_channel_logic(channel_description); }); + } + log.get_logger_logic = get_logger_logic; /** */ - function channel_make(description) { - var _a; - switch (description.kind) { + function format_entry(format_definition, entry) { + switch (format_definition.kind) { + case "jsonl": { + var now = Date.now(); + var timestamp = (now / 1000); + var datetime = (new Date(now)).toISOString(); + return (JSON.stringify({ + "datetime_timestamp": Math.round(timestamp), + "datetime_string": datetime /*.slice(0, 19)*/, + "level_numeric": entry.level, + "level_name": log.level_show(entry.level, { "abbreviated": false }), + "tags": entry.tags, + "incident": entry.incident, + "details": entry.details + }, undefined, (format_definition.data.structured + ? + "\t" + : + undefined))); + break; + } + case "human_readable": { + var parts = []; + parts.push(("<" + (new Date(Date.now())).toISOString() /*.slice(0, 19)*/ + ">")); + parts.push(("[" + log.level_show(entry.level, { "abbreviated": true }) + "]")); + for (var _i = 0, _a = entry.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + parts.push(("{" + tag + "}")); + } + parts.push(entry.incident); + (entry.details !== null) && parts.push((": " + JSON.stringify(entry.details, undefined, undefined))); + return (parts.join(" ")); + break; + } default: { - throw (new Error("unhandled log channel kind: " + description.kind)); + throw (new Error("unhandled format kind: " + format_definition["kind"])); + break; + } + } + } + log.format_entry = format_entry; + /** + */ + function parse_format_definition(format_definition_raw) { + return lib_plankton.call.distinguish((format_definition_raw !== null && format_definition_raw !== void 0 ? format_definition_raw : { + "kind": "human_readable", + "data": {} + }), { + "jsonl": function (_a) { + var structured = _a["structured"]; + return ({ + "kind": "jsonl", + "data": { + "structured": (structured !== null && structured !== void 0 ? structured : false) + } + }); + }, + "human_readable": function (data_) { return ({ + "kind": "human_readable", + "data": {} + }); } + }); + } + log.parse_format_definition = parse_format_definition; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + var channel; + (function (channel) { + var filtered; + (function (filtered) { + /** + */ + function predicate_incident(substring) { + return (function (entry) { return entry.incident.includes(substring); }); + } + filtered.predicate_incident = predicate_incident; + /** + */ + function predicate_level(threshold) { + return (function (entry) { return log.level_order(threshold, entry.level); }); + } + filtered.predicate_level = predicate_level; + /** + */ + function predicate_tag(tag) { + return (function (entry) { return entry.tags.includes(tag); }); + } + filtered.predicate_tag = predicate_tag; + /** + * combines other predicates in disjunctive normal form + */ + function predicate_complex(definition) { + return (function (entry) { return definition.some(function (clause) { return clause.every(function (literal) { return (literal.item(entry) + === + literal.mode); }); }); }); + } + filtered.predicate_complex = predicate_complex; + /** + */ + function send(subject, entry) { + if (!subject.predicate(entry)) { + // do nothing + } + else { + subject.core.send(entry); + } + } + filtered.send = send; + /** + */ + function logic(subject) { + return { + "send": function (entry) { return send(subject, entry); } + }; + } + filtered.logic = logic; + })(filtered = channel.filtered || (channel.filtered = {})); + })(channel = log.channel || (log.channel = {})); + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + var channel; + (function (channel) { + var minlevel; + (function (minlevel) { + /** + */ + function to_filter_subject(subject) { + return { + "core": subject.core, + "predicate": lib_plankton.log.channel.filtered.predicate_level(subject.threshold) + }; + } + /** + */ + function send(subject, entry) { + lib_plankton.log.channel.filtered.send(to_filter_subject(subject), entry); + } + minlevel.send = send; + /** + */ + function logic(subject) { + return { + "send": function (entry) { return send(subject, entry); } + }; + } + minlevel.logic = logic; + })(minlevel = channel.minlevel || (channel.minlevel = {})); + })(channel = log.channel || (log.channel = {})); + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +/** + * output for writing log entries to web console + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + var channel; + (function (channel) { + var console_; + (function (console_) { + /** + * @todo tags + */ + function send(subject, entry) { + var _a; + var renderers = (_a = {}, + _a[log.enum_level.debug] = { + "renderer": function (i, d) { return console.log(i, d); }, + "show_level": true + }, + _a[log.enum_level.info] = { + "renderer": function (i, d) { return console.info(i, d); }, + "show_level": true + }, + _a[log.enum_level.notice] = { + "renderer": function (i, d) { return console.warn(i, d); }, + "show_level": true + }, + _a[log.enum_level.warning] = { + "renderer": function (i, d) { return console.warn(i, d); }, + "show_level": true + }, + _a[log.enum_level.error] = { + "renderer": function (i, d) { return console.error(i, d); }, + "show_level": true + }, + _a); + var setting = renderers[entry.level]; + setting.renderer(((setting.show_level + ? ("[" + log.level_show(entry.level) + "]" + " ") + : "") + + + ("" + entry.incident + "")), entry.details); + } + console_.send = send; + /** + */ + function logic(subject) { + return { + "send": function (entry) { return send(subject, entry); } + }; + } + console_.logic = logic; + })(console_ = channel.console_ || (channel.console_ = {})); + })(channel = log.channel || (log.channel = {})); + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + function get_channel_logic(channel_description) { + switch (channel_description.kind) { + default: { + throw (new Error("unhandled log channel kind: " + channel_description.kind)); + break; + } + case "filtered": { + return lib_plankton.log.channel.filtered.logic({ + "core": get_channel_logic(channel_description.data.core), + "predicate": lib_plankton.log.channel.filtered.predicate_complex(channel_description.data.predicate.map(function (clause_raw) { return clause_raw.map(function (literal_raw) { + var _a; + return ({ + "mode": ((_a = literal_raw["mode"]) !== null && _a !== void 0 ? _a : true), + "item": lib_plankton.call.distinguish(literal_raw["item"], { + "incident": function (_a) { + var substring = _a["substring"]; + if (substring === undefined) { + throw (new Error("required parameter missing: substring")); + } + else { + return lib_plankton.log.channel.filtered.predicate_incident(substring); + } + }, + "level": function (_a) { + var threshold = _a["threshold"]; + if (threshold === undefined) { + throw (new Error("required parameter missing: threshold")); + } + else { + return lib_plankton.log.channel.filtered.predicate_level(log.level_decode(threshold)); + } + }, + "tag": function (_a) { + var value = _a["value"]; + if (value === undefined) { + throw (new Error("required parameter missing: value")); + } + else { + return lib_plankton.log.channel.filtered.predicate_tag(value); + } + } + }, { + "fallback": function () { return function (entry) { return true; }; } + }) + }); + }); })) + }); + break; + } + case "minlevel": { + return lib_plankton.log.channel.minlevel.logic({ + "core": get_channel_logic(channel_description.data.core), + "threshold": log.level_decode(channel_description.data.threshold) + }); break; } case "console": { - return (new log.class_channel_minlevel(new log.class_channel_console(), translate_level((_a = description.data["threshold"]) !== null && _a !== void 0 ? _a : "debug"))); + return lib_plankton.log.channel.console_.logic({}); break; } } } - log.channel_make = channel_make; - /** - */ - function conf_default() { - return [ - new log.class_channel_minlevel(new log.class_channel_console(), log.enum_level.notice), - ]; - } - log.conf_default = conf_default; + log.get_channel_logic = get_channel_logic; })(log = lib_plankton.log || (lib_plankton.log = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -2632,122 +2724,282 @@ var lib_plankton; (function (log) { /** */ - var _channel_stack = null; - /** - * pushes a new configuration on the stack and activates it - */ - function conf_push(channels) { - if (_channel_stack === null) { - _channel_stack = []; - } - _channel_stack.push(channels); + function default_logger() { + return [ + { + "kind": "minlevel", + "data": { + "core": { + "kind": "console", + "data": {} + }, + "threshold": "info" + } + }, + ]; } - log.conf_push = conf_push; + log.default_logger = default_logger; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { /** - * pops the current active configuration from the stack */ - function conf_pop() { - if (_channel_stack.length > 0) { - _channel_stack.pop(); - } - else { - // do nothing - } + var _main_logger_data = null; + /** + */ + function set_main_logger(logger_data) { + _main_logger_data = logger_data; } - log.conf_pop = conf_pop; + log.set_main_logger = set_main_logger; /** - * makes the logging system ready */ - function setup() { - if (_channel_stack === null) { - _channel_stack = []; - conf_push(log.conf_default()); - } - else { - // do nothing - } + function get_main_logger() { + return (_main_logger_data !== null && _main_logger_data !== void 0 ? _main_logger_data : log.default_logger()); } /** - * consumes a log entry, i.e. sends it to the currently active outputs */ - function add(entry) { - setup(); - _channel_stack.slice(-1)[0].forEach(function (channel) { return channel.add(entry); }); + function get_main_logger_logic() { + return lib_plankton.log.get_logger_logic(get_main_logger()); } - log.add = add; /** + * consumes a log entry, i.e. sends it to all channels */ - function debug(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.debug, "incident": incident, "details": details }); + function send_(logger, entry) { + logger.forEach(function (channel) { return channel.send(entry); }); + } + log.send_ = send_; + /** + * [convenience] + * + * @todo rename to "send" + */ + function debug_(logger, incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + send_(logger, { + "level": log.enum_level.debug, + "incident": incident, + "tags": option_tags, + "details": option_details + }); + } + log.debug_ = debug_; + /** + * [convenience] + * + * @todo rename to "info" + */ + function info_(logger, incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + send_(logger, { + "level": log.enum_level.info, + "incident": incident, + "tags": option_tags, + "details": option_details + }); + } + log.info_ = info_; + /** + * [convenience] + * + * @todo rename to "notice" + */ + function notice_(logger, incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + send_(logger, { + "level": log.enum_level.notice, + "incident": incident, + "tags": option_tags, + "details": option_details + }); + } + log.notice_ = notice_; + /** + * [convenience] + * + * @todo rename to "warning" + */ + function warning_(logger, incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + send_(logger, { + "level": log.enum_level.warning, + "incident": incident, + "tags": option_tags, + "details": option_details + }); + } + log.warning_ = warning_; + /** + * [convenience] + * + * @todo rename to "error" + */ + function error_(logger, incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + send_(logger, { + "level": log.enum_level.error, + "incident": incident, + "tags": option_tags, + "details": option_details + }); + } + log.error_ = error_; + /** + * [convenience] + */ + function _send(entry) { + send_(get_main_logger_logic(), entry); + } + log._send = _send; + /** + * [convenience] + */ + function _debug(incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + debug_(get_main_logger_logic(), incident, { + "tags": option_tags, + "details": option_details + }); + } + log._debug = _debug; + /** + * [convenience] + */ + function _info(incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + info_(get_main_logger_logic(), incident, { + "tags": option_tags, + "details": option_details + }); + } + log._info = _info; + /** + * [convenience] + */ + function _notice(incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + notice_(get_main_logger_logic(), incident, { + "tags": option_tags, + "details": option_details + }); + } + log._notice = _notice; + /** + * [convenience] + */ + function _warning(incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + warning_(get_main_logger_logic(), incident, { + "tags": option_tags, + "details": option_details + }); + } + log._warning = _warning; + /** + * [convenience] + */ + function _error(incident, _a) { + var _b = _a === void 0 ? {} : _a, _c = _b["tags"], option_tags = _c === void 0 ? [] : _c, _d = _b["details"], option_details = _d === void 0 ? null : _d; + error_(get_main_logger_logic(), incident, { + "tags": option_tags, + "details": option_details + }); + } + log._error = _error; + /** + * [convenience] + * + * @deprecated use ._debug instead! + */ + function debug(incident, details, tags) { + if (details === void 0) { details = null; } + if (tags === void 0) { tags = []; } + _debug(incident, { + "details": details, + "tags": tags + }); } log.debug = debug; /** + * [convenience] + * + * @deprecated use ._info instead! */ - function info(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.info, "incident": incident, "details": details }); + function info(incident, details, tags) { + if (details === void 0) { details = null; } + if (tags === void 0) { tags = []; } + _info(incident, { + "details": details, + "tags": tags + }); } log.info = info; /** + * [convenience] + * + * @deprecated use ._notice instead! */ - function notice(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.notice, "incident": incident, "details": details }); + function notice(incident, details, tags) { + if (details === void 0) { details = null; } + if (tags === void 0) { tags = []; } + _notice(incident, { + "details": details, + "tags": tags + }); } log.notice = notice; /** + * [convenience] + * + * @deprecated use ._warning instead! */ - function warning(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.warning, "incident": incident, "details": details }); + function warning(incident, details, tags) { + if (details === void 0) { details = null; } + if (tags === void 0) { tags = []; } + _warning(incident, { + "details": details, + "tags": tags + }); } log.warning = warning; /** + * [convenience] + * + * @deprecated use ._error instead! */ - function error(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.error, "incident": incident, "details": details }); + function error(incident, details, tags) { + if (details === void 0) { details = null; } + if (tags === void 0) { tags = []; } + _error(incident, { + "details": details, + "tags": tags + }); } log.error = error; })(log = lib_plankton.log || (lib_plankton.log = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - */ - log.conf_push([ - log.channel_make({ - "kind": "console", - "data": { - "threshold": "info" - } - }), - ]); - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* This file is part of »bacterio-plankton:object«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -4043,7 +4295,7 @@ var lib_plankton; .map((report_entry) => ({ "incident": report_entry.incident, "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([entry.right]) + "path": [entry.right].concat(report_entry.details.path ?? []), }), }))); } @@ -4074,7 +4326,7 @@ var lib_plankton; .map((report_entry) => ({ "incident": report_entry.incident, "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([entry.left]) + "path": [entry.left].concat(report_entry.details.path ?? []), }), }))); } @@ -4092,7 +4344,7 @@ var lib_plankton; .map((report_entry) => ({ "incident": report_entry.incident, "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([entry.right]) + "path": [entry.right].concat(report_entry.details.path ?? []), }), }))); } @@ -4124,10 +4376,9 @@ var lib_plankton; } } /** - * @todo versioning */ - function refine(schema, value_raw) { - const adaption = adapt(schema, value_raw); + function refine(schema, content) { + const adaption = adapt(schema, content); if (!lib_plankton.pod.is_filled(adaption.result)) { throw (new Error("conf could not be loaded:\n" + @@ -4141,6 +4392,7 @@ var lib_plankton; } conf.refine = refine; /** + * @deprecated */ function load(schema, path) { return (((path === null) @@ -4152,6 +4404,37 @@ var lib_plankton; .then((data_raw) => Promise.resolve(refine(schema, data_raw)))); } conf.load = load; + /** + */ + async function load_versioned(path, get_schema, migrations) { + const file_content = await lib_plankton.file.read(path); + const sheet_raw = lib_plankton.json.decode(file_content); + const schema = get_schema(sheet_raw.version); + let sheet = { + "version": sheet_raw.version, + "content": refine(schema, sheet_raw.content), + }; + while (sheet.version in migrations) { + const migration = migrations[sheet.version]; + if (!(migration === null)) { + lib_plankton.log._info("plankton.conf.load.migration", { + "details": { + "from": sheet.version, + "to": migration.target, + } + }); + sheet = { + "version": migration.target, + "content": migration.function(sheet.content), + }; + } + else { + break; + } + } + return sheet; + } + conf.load_versioned = load_versioned; })(conf = lib_plankton.conf || (lib_plankton.conf = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -4363,6 +4646,7 @@ var lib_plankton; */ function generate(prefix = "string_") { if (index_is > index_max) { + lib_plankton.log.error("plankton.string.generate.out_of_valid_indices", null); throw (new Error("[string_generate] out of valid indices")); } else { @@ -4389,7 +4673,7 @@ var lib_plankton; * @return {Array} * @author fenris */ - function split(chain, separator = " ") { + function split(chain, separator) { if (chain.length == 0) { return []; } @@ -4663,6 +4947,12 @@ var lib_plankton; return slices; } string.slice = slice; + /** + */ + function capitalize(str) { + return (str[0].toUpperCase() + str.slice(1)); + } + string.capitalize = capitalize; })(string = lib_plankton.string || (lib_plankton.string = {})); })(lib_plankton || (lib_plankton = {})); /** @@ -6193,14 +6483,12 @@ var lib_plankton; } complex.npow = npow; /** - * ermittelt die natürliche Potenz einer komplexen Zahl + * ermittelt den Wert der natürlichen Exponential-Funktion * * @author fenris - * @deprecated use "npow" instead - * @todo remove */ - function exp(x, n) { - return npow(x, n); + function exp(x) { + return make_polar(Math.exp(x.rea), x.ima); } complex.exp = exp; /** @@ -6411,8 +6699,8 @@ var lib_plankton; /** * @author fenris */ - class_complex.prototype.exp = function (n) { - return (class_complex._cram(complex.exp(class_complex._tear(this), n))); + class_complex.prototype.exp = function () { + return (class_complex._cram(complex.exp(class_complex._tear(this)))); }; /** * @author fenris @@ -6996,7 +7284,7 @@ var lib_plankton; */ function cardano_reduced(p, q) { // (p/3)^3 + (q/2)^2 - const determinant = (lib_plankton.complex.add(lib_plankton.complex.exp(lib_plankton.complex.scl(p, 1 / 3.0), 3), lib_plankton.complex.exp(lib_plankton.complex.scl(q, 1 / 2.0), 2))); + const determinant = (lib_plankton.complex.add(lib_plankton.complex.npow(lib_plankton.complex.scl(p, 1 / 3.0), 3), lib_plankton.complex.npow(lib_plankton.complex.scl(q, 1 / 2.0), 2))); const [u, v] = (lib_plankton.complex.normroots(2, determinant) .map(w => lib_plankton.complex.sub(w, lib_plankton.complex.scl(q, 1 / 2.0))) .map(z => lib_plankton.complex.normroots(3, z))); @@ -7019,9 +7307,9 @@ var lib_plankton; */ function cardano_normalized(e, f, g) { // p := (-1/3)·e² + f - const p = (lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.exp(e, 2), -1 / 3.0), f)); + const p = (lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.npow(e, 2), -1 / 3.0), f)); // q := (2/27)·e³ + (-1/3)·e·f + g - const q = (lib_plankton.complex.add(lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.exp(e, 3), +2 / 27.0), lib_plankton.complex.scl(lib_plankton.complex.mul(e, f), -1 / 3.0)), g)); + const q = (lib_plankton.complex.add(lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.npow(e, 3), +2 / 27.0), lib_plankton.complex.scl(lib_plankton.complex.mul(e, f), -1 / 3.0)), g)); return (cardano_reduced(p, q) .map(y => lib_plankton.complex.sub(y, lib_plankton.complex.scl(e, 1 / 3.0)))); } @@ -7403,145 +7691,338 @@ var lib_plankton; color_1.give_magenta = give_magenta; })(color = lib_plankton.color || (lib_plankton.color = {})); })(lib_plankton || (lib_plankton = {})); -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); +"use strict"; /* -This file is part of »bacterio-plankton:xml«. +This file is part of »bacterio-plankton:http_base«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:xml« is free software: you can redistribute it and/or modify +»bacterio-plankton:http_base« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -»bacterio-plankton:xml« is distributed in the hope that it will be useful, +»bacterio-plankton:http_base« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:xml«. If not, see . +along with »bacterio-plankton:http_base«. If not, see . */ -/** - * @author fenris +/* +This file is part of »bacterio-plankton:http_base«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:http_base« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:http_base« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:http_base«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var xml; - (function (xml) { + var http_base; + (function (http_base) { /** - * @author fenris */ - function string_repeat(symbol, count) { - return ((count <= 0) ? "" : (string_repeat(symbol, count - 1) + symbol)); + const linebreak = "\r\n"; + /** + */ + function capitalize_all(str) { + return str.split("-").map(x => lib_plankton.string.capitalize(x)).join("-"); } /** - * @author fenris */ - var class_node = /** @class */ (function () { - function class_node() { + function encode_request(encode_method, request) { + let request_raw = ""; + request_raw += lib_plankton.string.coin("{{method}} {{path}}{{query}} {{version}}{{linebreak}}", { + "method": encode_method(request.method), + "path": request.path, + "query": ((request.query === null) ? "" : request.query), + "version": request.version, + "linebreak": linebreak, + }); + if (request.host === null) { + // do nothing } - return class_node; - }()); - xml.class_node = class_node; + else { + request_raw += lib_plankton.string.coin("Host: {{host}}{{linebreak}}", { + "host": request.host, + "linebreak": linebreak, + }); + } + for (const [key, value] of Object.entries(request.headers)) { + request_raw += lib_plankton.string.coin("{{key}}: {{value}}{{linebreak}}", { + "key": capitalize_all(key), + "value": value, + "linebreak": linebreak, + }); + } + request_raw += linebreak; + if (request.body === null) { + // do nothing + } + else { + request_raw += request.body.toString(); + } + return request_raw; + } + http_base.encode_request = encode_request; /** - * @author fenris */ - var class_node_text = /** @class */ (function (_super) { - __extends(class_node_text, _super); - /** - * @author fenris - */ - function class_node_text(content) { - var _this = _super.call(this) || this; - _this.content = content; - return _this; + function decode_request(decode_method, has_body, request_raw) { + const lines = lib_plankton.string.split(request_raw, linebreak); + if (lines.length <= 0) { + throw (new Error("malformed request")); } - /** - * @author fenris - */ - class_node_text.prototype.compile = function (depth) { - if (depth === void 0) { depth = 0; } - return (string_repeat("\t", depth) + this.content + "\n"); - }; - return class_node_text; - }(class_node)); - xml.class_node_text = class_node_text; + else { + const first = lines[0]; + lines.shift(); + const parts = first.split(" "); + const method = decode_method(parts[0]); + const path_and_query = parts[1]; + const parts_ = path_and_query.split("?"); + const path = parts_[0]; + const query = ((parts_.length <= 1) ? null : ("?" + parts_.slice(1).join("?"))); + const version = parts[2]; + let headers = {}; + while (true) { + const line = lines[0]; + lines.shift(); + if (line === "") { + break; + } + else { + const [key, value] = line.split(": ", 2); + headers[key.toLowerCase()] = value; + } + } + const body = (has_body(method) + // @ts-ignore + ? Buffer.from(lines.join(linebreak)) + : null); + const request = { + // TODO + "scheme": "http", + "host": (headers["host"] ?? null), + "path": path, + "version": version, + "method": method, + "query": query, + "headers": headers, + "body": body, + }; + return request; + } + } + http_base.decode_request = decode_request; /** - * @author fenris */ - var class_node_comment = /** @class */ (function (_super) { - __extends(class_node_comment, _super); - /** - * @author fenris - */ - function class_node_comment(content) { - var _this = _super.call(this) || this; - _this.content = content; - return _this; + function encode_response(encode_status_code, get_status_text, response) { + let response_raw = ""; + response_raw += lib_plankton.string.coin("{{version}} {{status_code}} {{status_text}}{{linebreak}}", { + "version": (response.version ?? ""), + "status_code": encode_status_code(response.status_code), + "status_text": get_status_text(response.status_code), + "linebreak": linebreak, + }); + for (const [key, value] of Object.entries(response.headers)) { + response_raw += lib_plankton.string.coin("{{key}}: {{value}}{{linebreak}}", { + "key": capitalize_all(key), + "value": value, + "linebreak": linebreak, + }); } - /** - * @author fenris - */ - class_node_comment.prototype.compile = function (depth) { - if (depth === void 0) { depth = 0; } - return (string_repeat("\t", depth) + "" + "\n"); - }; - return class_node_comment; - }(class_node)); - xml.class_node_comment = class_node_comment; + response_raw += linebreak; + if (response.body === null) { + // do nothing + } + else { + response_raw += response.body.toString(); + } + return response_raw; + } + http_base.encode_response = encode_response; /** - * @author fenris */ - var class_node_complex = /** @class */ (function (_super) { - __extends(class_node_complex, _super); - /** - * @author fenris - */ - function class_node_complex(name, attributes, children) { - if (attributes === void 0) { attributes = {}; } - if (children === void 0) { children = []; } - var _this = _super.call(this) || this; - _this.name = name; - _this.attributes = attributes; - _this.children = children; - return _this; + function decode_response(decode_status_code, response_raw) { + const lines = response_raw.split(linebreak); + const first = lines[0]; + lines.shift(); + const first_parts = first.split(" "); + const version = first_parts[0]; + const status_code = decode_status_code(first_parts[1]); + // first_parts.slice(2) ? probably irrelevant + let headers = {}; + while (true) { + const line = lines[0]; + lines.shift(); + if (line === "") { + break; + } + else { + const [key, value] = line.split(": ", 2); + headers[key.toLowerCase()] = value; + } } - /** - * @author fenris - */ - class_node_complex.prototype.compile = function (depth) { - var _this = this; - if (depth === void 0) { depth = 0; } - var output = ""; - var attributes = (Object.keys(this.attributes) - .filter(function (key) { return (_this.attributes[key] !== null); }) - .map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); }) - .join("")); - output += (string_repeat("\t", depth) + "<" + this.name + attributes + ">" + "\n"); - this.children.forEach(function (child) { return (output += child.compile(depth + 1)); }); - output += (string_repeat("\t", depth) + "" + "\n"); - return output; + // @ts-ignore + const body = Buffer.from(lines.join(linebreak)); + const response = { + // TODO + "version": version, + "status_code": status_code, + "headers": headers, + "body": body, }; - return class_node_complex; - }(class_node)); - xml.class_node_complex = class_node_complex; - })(xml = lib_plankton.xml || (lib_plankton.xml = {})); + return response; + } + http_base.decode_response = decode_response; + /** + * executes an HTTP request + * + * @todo define type_signal + */ + async function call(has_body, encode_method, decode_status_code, request, { "timeout": option_timeout = 5.0, "follow_redirects": option_follow_redirects = false, "implementation": option_implementation = "fetch", } = {}) { + const target = lib_plankton.string.coin("{{scheme}}://{{host}}{{path}}{{query}}", { + "scheme": request.scheme, + "host": (request.host ?? ""), + "path": request.path, + "query": (request.query ?? ""), + }); + switch (option_implementation) { + default: { + return Promise.reject(new Error("invalid implementation: " + option_implementation)); + break; + } + case "fetch": { + function core(signal) { + return (fetch(target, Object.assign({ + "method": encode_method(request.method), + "headers": request.headers, + /* + "redirect": ( + option_follow_redirects + ? + "follow" + : + "manual" + ), + */ + "signal": (signal + ?? + undefined), + // "keepalive": false, + }, ((has_body(request.method) + && + (request.body !== null)) + ? { + "body": request.body.toString(), + } + : {}))) + .catch((reason) => { + // console.info(reason); + return Promise.reject(reason); + }) + .then((response_raw) => (response_raw.text() + .then((body) => Promise.resolve({ + // TODO + "version": null, + "status_code": decode_status_code(response_raw.status.toFixed(0)), + "headers": ((headers_raw => { + let headers = {}; + headers_raw.forEach((value, key) => { + headers[key] = value; + }); + return headers; + })(response_raw.headers)), + "body": body, + }))))); + } + function timeout(controller) { + return (new Promise((resolve, reject) => { + if (option_timeout === null) { + // do nothing (neither resolve nor reject ever) + } + else { + setTimeout(() => { + controller.abort(); + resolve(null); + }, (option_timeout * 1000)); + } + })); + } + const controller = new AbortController(); + const signal = controller.signal; + const response = await Promise.race([ + timeout(controller), + core(signal), + ]); + if (response === null) { + throw (new Error("http_request_timeout")); + } + else { + return response; + } + break; + } + case "http_module": { + // @ts-ignore + const nm_http = require("http"); + // @ts-ignore + const nm_https = require("https"); + return (new Promise((resolve, reject) => { + const req = ((request.scheme === "https") + ? nm_https + : nm_http) + .request(target, { + "method": request.method, + "headers": request.headers, + }, + // @ts-ignore + (res) => { + try { + let response_body = ""; + res.setEncoding("utf8"); + res.on("data", (chunk) => { + response_body += chunk; + }); + res.on("end", () => { + resolve({ + // TODO + "version": null, + "status_code": res.statusCode, + "headers": res.headers, + "body": response_body, + }); + }); + } + catch (error) { + reject(error); + } + }); + req.on("error", (error) => { + reject(error); + }); + req.write(request.body); + req.end(); + })); + break; + } + } + } + http_base.call = call; + })(http_base = lib_plankton.http_base || (lib_plankton.http_base = {})); })(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:http«. @@ -7579,6 +8060,65 @@ var lib_plankton; enum_method["put"] = "put"; enum_method["patch"] = "patch"; })(enum_method = http.enum_method || (http.enum_method = {})); + /** + */ + let enum_status_code; + (function (enum_status_code) { + enum_status_code[enum_status_code["continue_"] = 100] = "continue_"; + enum_status_code[enum_status_code["switching_protocols"] = 101] = "switching_protocols"; + enum_status_code[enum_status_code["early_hints"] = 103] = "early_hints"; + enum_status_code[enum_status_code["ok"] = 200] = "ok"; + enum_status_code[enum_status_code["created"] = 201] = "created"; + enum_status_code[enum_status_code["accepted"] = 202] = "accepted"; + enum_status_code[enum_status_code["non_authoritative_information"] = 203] = "non_authoritative_information"; + enum_status_code[enum_status_code["no_content"] = 204] = "no_content"; + enum_status_code[enum_status_code["reset_content"] = 205] = "reset_content"; + enum_status_code[enum_status_code["partial_coentent"] = 206] = "partial_coentent"; + enum_status_code[enum_status_code["multiple_choices"] = 300] = "multiple_choices"; + enum_status_code[enum_status_code["moved_permanently"] = 301] = "moved_permanently"; + enum_status_code[enum_status_code["found"] = 302] = "found"; + enum_status_code[enum_status_code["see_other"] = 303] = "see_other"; + enum_status_code[enum_status_code["not_modified"] = 304] = "not_modified"; + enum_status_code[enum_status_code["temporary_redirect"] = 307] = "temporary_redirect"; + enum_status_code[enum_status_code["permanent_redirect"] = 308] = "permanent_redirect"; + enum_status_code[enum_status_code["bad_request"] = 400] = "bad_request"; + enum_status_code[enum_status_code["unauthorized"] = 401] = "unauthorized"; + enum_status_code[enum_status_code["payment_required"] = 402] = "payment_required"; + enum_status_code[enum_status_code["forbidden"] = 403] = "forbidden"; + enum_status_code[enum_status_code["not_found"] = 404] = "not_found"; + enum_status_code[enum_status_code["method_not_allowed"] = 405] = "method_not_allowed"; + enum_status_code[enum_status_code["not_acceptable"] = 406] = "not_acceptable"; + enum_status_code[enum_status_code["proxy_authentication_required"] = 407] = "proxy_authentication_required"; + enum_status_code[enum_status_code["request_timeout"] = 408] = "request_timeout"; + enum_status_code[enum_status_code["conflict"] = 409] = "conflict"; + enum_status_code[enum_status_code["gone"] = 410] = "gone"; + enum_status_code[enum_status_code["length_required"] = 411] = "length_required"; + enum_status_code[enum_status_code["precondition_failed"] = 412] = "precondition_failed"; + enum_status_code[enum_status_code["payload_too_large"] = 413] = "payload_too_large"; + enum_status_code[enum_status_code["uri_too_long"] = 414] = "uri_too_long"; + enum_status_code[enum_status_code["unsupported_media_type"] = 415] = "unsupported_media_type"; + enum_status_code[enum_status_code["range_not_satisfiable"] = 416] = "range_not_satisfiable"; + enum_status_code[enum_status_code["expectation_failed"] = 417] = "expectation_failed"; + enum_status_code[enum_status_code["i_m_a_teapot"] = 418] = "i_m_a_teapot"; + enum_status_code[enum_status_code["unprocessable_entity"] = 422] = "unprocessable_entity"; + enum_status_code[enum_status_code["too_early"] = 425] = "too_early"; + enum_status_code[enum_status_code["upgrade_required"] = 426] = "upgrade_required"; + enum_status_code[enum_status_code["precondition_required"] = 428] = "precondition_required"; + enum_status_code[enum_status_code["too_many_requests"] = 429] = "too_many_requests"; + enum_status_code[enum_status_code["request_header_fields_too_large"] = 431] = "request_header_fields_too_large"; + enum_status_code[enum_status_code["unavailable_for_legal_reasons"] = 451] = "unavailable_for_legal_reasons"; + enum_status_code[enum_status_code["internal_server_error"] = 500] = "internal_server_error"; + enum_status_code[enum_status_code["not_implemented"] = 501] = "not_implemented"; + enum_status_code[enum_status_code["bad_gateway"] = 502] = "bad_gateway"; + enum_status_code[enum_status_code["service_unavailable"] = 503] = "service_unavailable"; + enum_status_code[enum_status_code["gateway_timeout"] = 504] = "gateway_timeout"; + enum_status_code[enum_status_code["http_version_not_supported"] = 505] = "http_version_not_supported"; + enum_status_code[enum_status_code["variant_also_negotiates"] = 506] = "variant_also_negotiates"; + enum_status_code[enum_status_code["insufficient_storage"] = 507] = "insufficient_storage"; + enum_status_code[enum_status_code["loop_detected"] = 508] = "loop_detected"; + enum_status_code[enum_status_code["not_extended"] = 510] = "not_extended"; + enum_status_code[enum_status_code["network_authentication"] = 511] = "network_authentication"; + })(enum_status_code = http.enum_status_code || (http.enum_status_code = {})); })(http = lib_plankton.http || (lib_plankton.http = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -7604,22 +8144,6 @@ var lib_plankton; (function (lib_plankton) { var http; (function (http) { - /** - * @author fenris - */ - const linebreak = "\r\n"; - /** - * @todo outsource to string module - */ - function capitalize(str) { - return (str[0].toUpperCase() + str.slice(1)); - } - /** - * @todo outsource to string module - */ - function capitalize_all(str) { - return str.split("-").map(x => capitalize(x)).join("-"); - } /** * @author fenris */ @@ -7651,10 +8175,22 @@ var lib_plankton; default: throw (new Error("unhandled method: " + method_raw)); } } + http.decode_method = decode_method; + /** + */ + function encode_status_code(status_code) { + return status_code.toFixed(0); + } + /** + * @todo check for existance + */ + function decode_status_code(status_code_raw) { + return parseInt(status_code_raw); + } /** * @author fenris */ - function get_statustext(statuscode) { + function get_status_text(statuscode) { switch (statuscode) { case 100: return "Continue"; case 101: return "Switching Protocols"; @@ -7713,140 +8249,43 @@ var lib_plankton; default: throw (new Error("unhandled statuscode: " + statuscode.toFixed(0))); } } + /** + * @author fenris + */ + function has_body(method) { + return [ + http.enum_method.post, + http.enum_method.put, + http.enum_method.patch + ].includes(method); + } + http.has_body = has_body; /** * @author fenris */ function encode_request(request) { - let request_raw = ""; - request_raw += (encode_method(request.method) - + - " " - + - request.path - + - ((request.query === null) ? "" : request.query) - + - " " - + - request.version - + - linebreak); - if (request.host === null) { - // do nothing - } - else { - request_raw += ("Host: " + request.host + linebreak); - } - for (const [key, value] of Object.entries(request.headers)) { - request_raw += (capitalize_all(key) + ": " + value + linebreak); - } - request_raw += linebreak; - if (request.body === null) { - // do nothing - } - else { - request_raw += request.body.toString(); - } - return request_raw; + return lib_plankton.http_base.encode_request(encode_method, request); } http.encode_request = encode_request; /** * @author fenris */ function decode_request(request_raw) { - const lines = request_raw.split(linebreak); - const first = lines.shift(); - const parts = first.split(" "); - const method = decode_method(parts[0]); - const path_and_query = parts[1]; - const parts_ = path_and_query.split("?"); - const path = parts_[0]; - const query = ((parts_.length <= 1) ? null : ("?" + parts_.slice(1).join("?"))); - const version = parts[2]; - let headers = {}; - while (true) { - const line = lines.shift(); - if (line === "") { - break; - } - else { - const [key, value] = line.split(": ", 2); - headers[key.toLowerCase()] = value; - } - } - const body = ([http.enum_method.post, http.enum_method.put, http.enum_method.patch].includes(method) - // @ts-ignore - ? Buffer.from(lines.join(linebreak)) - : null); - const request = { - // TODO - "scheme": "http", - "host": (headers["host"] ?? null), - "path": path, - "version": version, - "method": method, - "query": query, - "headers": headers, - "body": body, - }; - return request; + return lib_plankton.http_base.decode_request(decode_method, has_body, request_raw); } http.decode_request = decode_request; /** * @author fenris */ function encode_response(response) { - let response_raw = ""; - response_raw += (response.version - + - " " - + - response.status_code.toFixed(0) - + - " " - + - get_statustext(response.status_code) - + - linebreak); - for (const [key, value] of Object.entries(response.headers)) { - response_raw += (capitalize_all(key) + ": " + value + linebreak); - } - response_raw += linebreak; - response_raw += response.body; - return response_raw; + return lib_plankton.http_base.encode_response(encode_status_code, get_status_text, response); } http.encode_response = encode_response; /** * @author fenris */ function decode_response(response_raw) { - const lines = response_raw.split(linebreak); - const first = lines.shift(); - const first_parts = first.split(" "); - const version = first_parts[0]; - const status_code = parseInt(first_parts[1]); - // first_parts.slice(2) ? probably irrelevant - let headers = {}; - while (true) { - const line = lines.shift(); - if (line === "") { - break; - } - else { - const [key, value] = line.split(": ", 2); - headers[key.toLowerCase()] = value; - } - } - // @ts-ignore - const body = Buffer.from(lines.join(linebreak)); - const response = { - // TODO - "version": version, - "status_code": status_code, - "headers": headers, - "body": body, - }; - return response; + return lib_plankton.http_base.decode_response(decode_status_code, response_raw); } http.decode_response = decode_response; /** @@ -7854,241 +8293,17 @@ var lib_plankton; * * @todo define type_signal */ - async function call(request, options = {}) { - options = Object.assign({ - "timeout": 5.0, - "follow_redirects": false, - "implementation": "fetch", - }, options); - const target = (request.scheme - + - "://" - + - request.host - + - request.path - + - ((request.query === null) - ? "" - : request.query)); - switch (options.implementation) { - default: { - return Promise.reject("invalid implementation: " + options.implementation); - break; - } - case "fetch": { - function core(signal) { - return (fetch(target, Object.assign({ - "method": ((method => { - switch (method) { - case http.enum_method.head: return "HEAD"; - case http.enum_method.options: return "OPTIONS"; - case http.enum_method.get: return "GET"; - case http.enum_method.delete: return "DELETE"; - case http.enum_method.post: return "POST"; - case http.enum_method.put: return "PUT"; - case http.enum_method.patch: return "PATCH"; - } - })(request.method)), - "headers": request.headers, - /* - "redirect": ( - options.follow_redirects - ? - "follow" - : - "manual" - ), - */ - "signal": (signal - ?? - undefined), - // "keepalive": false, - }, ((((method => { - switch (method) { - case http.enum_method.head: return false; - case http.enum_method.options: return false; - case http.enum_method.get: return false; - case http.enum_method.delete: return false; - case http.enum_method.post: return true; - case http.enum_method.put: return true; - case http.enum_method.patch: return true; - } - })(request.method)) - && - (request.body !== null)) - ? { - "body": request.body.toString(), - } - : {}))) - .catch((reason) => { - // console.info(reason); - return Promise.reject(reason); - }) - .then((response_raw) => (response_raw.text() - .then((body) => Promise.resolve({ - // TODO - "version": null, - "status_code": response_raw.status, - "headers": ((headers_raw => { - let headers = {}; - headers_raw.forEach((value, key) => { - headers[key] = value; - }); - return headers; - })(response_raw.headers)), - "body": body, - }))))); - } - function timeout(controller) { - return (new Promise((resolve, reject) => { - if (options.timeout === null) { - // do nothing (neither resolve nor reject ever) - } - else { - setTimeout(() => { - controller.abort(); - resolve(null); - }, (options.timeout * 1000)); - } - })); - } - const controller = new AbortController(); - const signal = controller.signal; - const response = await Promise.race([ - timeout(controller), - core(signal), - ]); - if (response === null) { - throw (new Error("http_request_timeout")); - } - else { - return response; - } - break; - } - case "http_module": { - // @ts-ignore - const nm_http = require("http"); - // @ts-ignore - const nm_https = require("https"); - return (new Promise((resolve, reject) => { - const req = ((request.scheme === "https") - ? nm_https - : nm_http) - .request(target, { - "method": request.method, - "headers": request.headers, - }, (res) => { - try { - let response_body = ""; - res.setEncoding("utf8"); - res.on("data", (chunk) => { - response_body += chunk; - }); - res.on("end", () => { - resolve({ - // TODO - "version": null, - "status_code": res.statusCode, - "headers": res.headers, - "body": response_body, - }); - }); - } - catch (error) { - reject(error); - } - }); - req.on("error", (error) => { - reject(error); - }); - req.write(request.body); - req.end(); - })); - break; - } - } + async function call(request, { "timeout": option_timeout = 5.0, "follow_redirects": option_follow_redirects = false, "implementation": option_implementation = "fetch", } = {}) { + return lib_plankton.http_base.call(has_body, encode_method, decode_status_code, request, { + "timeout": option_timeout, + "follow_redirects": option_follow_redirects, + "implementation": option_implementation, + }); } http.call = call; })(http = lib_plankton.http || (lib_plankton.http = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:http«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:http« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:http« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:http«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var http; - (function (http) { - /** - * @author fenris - */ - class class_http_request { - /** - * @author fenris - */ - constructor() { - } - /** - * @implementation - * @author fenris - */ - encode(x) { - return http.encode_request(x); - } - /** - * @implementation - * @author fenris - */ - decode(x) { - return http.decode_request(x); - } - } - http.class_http_request = class_http_request; - /** - * @author fenris - */ - class class_http_response { - /** - * @author fenris - */ - constructor() { - } - /** - * @implementation - * @author fenris - */ - encode(x) { - return http.encode_response(x); - } - /** - * @implementation - * @author fenris - */ - decode(x) { - return http.decode_response(x); - } - } - http.class_http_response = class_http_response; - })(http = lib_plankton.http || (lib_plankton.http = {})); -})(lib_plankton || (lib_plankton = {})); -/* This file is part of »bacterio-plankton:url«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -8390,15 +8605,15 @@ var lib_plankton; /** * @todo test */ - function to_datetime(pit, { timezone_shift = 0, } = {}) { + function to_datetime(pit, { "timezone_shift": option_timezone_shift = 0, } = {}) { return lib_plankton.call.convey(pit, [ to_date_object, (x) => x.getTime(), - (x) => (x + ((timezone_shift * (60 * 60)) * 1000)), + (x) => (x + ((option_timezone_shift * (60 * 60)) * 1000)), (x) => new Date(x), x => x.toISOString(), x => ({ - "timezone_shift": timezone_shift, + "timezone_shift": option_timezone_shift, "date": { "year": parseInt(x.slice(0, 4)), "month": parseInt(x.slice(5, 7)), @@ -8442,10 +8657,17 @@ var lib_plankton; function is_after(pit, reference) { return (pit > reference); } + pit_1.is_after = is_after; + /** + */ + function is_equal_or_after(pit, reference) { + return (pit >= reference); + } + pit_1.is_equal_or_after = is_equal_or_after; /** */ function is_between(pit, reference_left, reference_right) { - return (is_after(pit, reference_left) + return (is_equal_or_after(pit, reference_left) && is_before(pit, reference_right)); } @@ -8455,6 +8677,7 @@ var lib_plankton; function shift_hour(pit, increment) { return (pit + (60 * 60 * increment)); } + pit_1.shift_hour = shift_hour; /** */ function shift_day(pit, increment) { @@ -8472,6 +8695,7 @@ var lib_plankton; function shift_year(pit, increment) { return (pit + (60 * 60 * 24 * 365 * increment)); } + pit_1.shift_year = shift_year; /** */ function trunc_minute(pit) { @@ -8499,6 +8723,7 @@ var lib_plankton; }; return from_datetime(datetime_output); } + pit_1.trunc_minute = trunc_minute; /** */ function trunc_hour(pit) { @@ -8522,6 +8747,7 @@ var lib_plankton; }; return from_datetime(datetime_output); } + pit_1.trunc_hour = trunc_hour; /** */ function trunc_day(pit) { @@ -8541,6 +8767,7 @@ var lib_plankton; }; return from_datetime(datetime_output); } + pit_1.trunc_day = trunc_day; /** */ function trunc_week(pit) { @@ -8572,6 +8799,7 @@ var lib_plankton; }; return from_datetime(datetime_output); } + pit_1.trunc_month = trunc_month; /** */ function trunc_year(pit) { @@ -8591,6 +8819,7 @@ var lib_plankton; }; return from_datetime(datetime_output); } + pit_1.trunc_year = trunc_year; /** */ function now() { @@ -8602,12 +8831,9 @@ var lib_plankton; * @param week week according to specified timezone shift * @return the begin of the week (monday, 00:00) */ - function from_ywd(ywd, options = {}) { - options = Object.assign({ - "timezone_shift": 0, - }, options); + function from_ywd(ywd, { "timezone_shift": option_timezone_shift = 0, } = {}) { return lib_plankton.call.convey({ - "timezone_shift": options.timezone_shift, + "timezone_shift": option_timezone_shift, "date": { "year": ywd.year, "month": 1, @@ -8629,10 +8855,7 @@ var lib_plankton; /** * @todo timezone */ - function to_ywd(pit, options = {}) { - options = Object.assign({ - "timezone_shift": 0, - }, options); + function to_ywd(pit, { "timezone_shift": option_timezone_shift = 0, } = {}) { return lib_plankton.call.convey(pit, [ to_date_object, x => ({ @@ -8770,8 +8993,8 @@ var lib_plankton; pit_1.date_format = date_format; /** */ - function time_format(time, { show_seconds = false, } = {}) { - return lib_plankton.string.coin((show_seconds + function time_format(time, { "show_seconds": option_show_seconds = false, } = {}) { + return lib_plankton.string.coin((option_show_seconds ? "{{hour}}:{{minute}}:{{seconds}}" : @@ -8785,12 +9008,12 @@ var lib_plankton; /** * @todo show timezone */ - function datetime_format(datetime, { timezone_indicator = "", show_timezone = false, adjust_to_ce = false, omit_date = false, } = {}) { + function datetime_format(datetime, { "timezone_indicator": option_timezone_indicator = "", "show_timezone": option_show_timezone = false, "adjust_to_ce": option_adjust_to_ce = false, "omit_date": option_omit_date = false, } = {}) { if (datetime === null) { return "-"; } else { - const datetime_adjusted = (adjust_to_ce + const datetime_adjusted = (option_adjust_to_ce ? to_datetime_ce(from_datetime(datetime)) : @@ -8798,7 +9021,7 @@ var lib_plankton; return lib_plankton.string.coin("{{macro_date_and_time}}{{macro_timezone}}", { "macro_date_and_time": ([ // date - (omit_date + (option_omit_date ? null : @@ -8812,10 +9035,10 @@ var lib_plankton; ] .filter(x => (x !== null)) .join(", ")), - "macro_timezone": (show_timezone + "macro_timezone": (option_show_timezone ? lib_plankton.string.coin(" [{{timezone_indicator}}{{timezone_value}}]", { - "timezone_indicator": timezone_indicator, + "timezone_indicator": option_timezone_indicator, "timezone_value": timezone_shift_format(datetime_adjusted.timezone_shift), }) : @@ -8826,8 +9049,8 @@ var lib_plankton; pit_1.datetime_format = datetime_format; /** */ - function timespan_format(from, to, { timezone_indicator = "", show_timezone = false, adjust_to_ce = false, omit_date = false, } = {}) { - const from_adjusted = (adjust_to_ce + function timespan_format(from, to, { "timezone_indicator": option_timezone_indicator = "", "show_timezone": option_show_timezone = false, "adjust_to_ce": option_adjust_to_ce = false, "omit_date": option_omit_date = false, } = {}) { + const from_adjusted = (option_adjust_to_ce ? datetime_translate_ce(from) : @@ -8836,7 +9059,7 @@ var lib_plankton; ? null : - (adjust_to_ce + (option_adjust_to_ce ? datetime_translate_ce(to) : @@ -8845,7 +9068,7 @@ var lib_plankton; "from": datetime_format(from_adjusted, { "show_timezone": false, "adjust_to_ce": false, - "omit_date": omit_date, + "omit_date": option_omit_date, }), "to_macro": ((to_adjusted === null) ? @@ -8860,10 +9083,10 @@ var lib_plankton; (from_adjusted.date.day === to_adjusted.date.day)) }), })), - "macro_timezone": (show_timezone + "macro_timezone": (option_show_timezone ? lib_plankton.string.coin(" [{{timezone_indicator}}{{timezone_value}}]", { - "timezone_indicator": timezone_indicator, + "timezone_indicator": option_timezone_indicator, "timezone_value": timezone_shift_format(from_adjusted.timezone_shift), }) : @@ -9161,8 +9384,9 @@ var lib_plankton; /** * @desc retrieves a string by going through the order and trying to fetch it for the current entry * @author fenris + * @todo rename to "get" */ - function get(path, args = {}, fallback = null) { + function get_new(path, { "args": args = {}, "preferred_language": preferred_language = null, "fallback": fallback = null, } = {}) { if (fallback == null) { fallback = `{${path}}`; } @@ -9170,11 +9394,16 @@ var lib_plankton; console.info(`${_logprefix} getting translation for string '${path}' with arguments ${JSON.stringify(args)} …`); } let result = lib_plankton.pod.make_empty(); - let found = _order.some(identifier => { + const order = ((preferred_language === null) + ? + _order + : + ([preferred_language].concat(_order.filter(x => (x !== preferred_language))))); + const found = order.some(identifier => { if (translate._verbosity >= 2) { console.info(`${_logprefix} trying package '${identifier}' …`); } - let result_ = fetch(identifier, path, args); + const result_ = fetch(identifier, path, args); if (lib_plankton.pod.is_filled(result_)) { result = result_; return true; @@ -9184,20 +9413,33 @@ var lib_plankton; } }); if (found) { - let str = lib_plankton.pod.cull(result); + const str = lib_plankton.pod.cull(result); if (translate._verbosity >= 3) { console.info(`${_logprefix} found translation: '${str}'`); } return str; } else { - let str = fallback; + const str = fallback; if (translate._verbosity >= 1) { console.warn(`${_logprefix} no package provides a translation for string '${path}'; will use the fallback translation '${str}'`); } return str; } } + translate.get_new = get_new; + /** + * @desc retrieves a string by going through the order and trying to fetch it for the current entry + * @author fenris + * @deprecated use "get_new" + * @todo remove + */ + function get(path, args = {}, fallback = null) { + return get_new(path, { + "args": args, + "fallback": fallback, + }); + } translate.get = get; /** * @author fenris @@ -9439,6 +9681,12 @@ var lib_plankton; window.location.hash = encode(location); } zoo_page.set = set; + /** + */ + function reload() { + return load(get()); + } + zoo_page.reload = reload; /** */ function register(location_name, handler, options = {}) { @@ -10379,6 +10627,7 @@ var lib_plankton; */ constructor(element_input_factory, options = {}) { options = Object.assign({ + "read_only": false, "translations": { "add": "add", "remove": "remove", @@ -10387,6 +10636,7 @@ var lib_plankton; this.element_input_factory = element_input_factory; this.elements = []; this.elements_container_dom = null; + this.read_only = options.read_only; this.translations = options.translations; } /** @@ -10412,6 +10662,9 @@ var lib_plankton; remover_dom.classList.add("plankton_input_list_button"); remover_dom.classList.add("plankton_input_list_element_remover"); remover_dom.setAttribute("title", this.translations.remove); + if (this.read_only) { + remover_dom.setAttribute("disabled", "disabled"); + } remover_dom.textContent = "x"; remover_dom.addEventListener("click", (event) => { event.preventDefault(); @@ -10455,6 +10708,9 @@ var lib_plankton; adder_dom.classList.add("plankton_input_list_button"); adder_dom.classList.add("plankton_input_list_adder"); adder_dom.setAttribute("title", this.translations.add); + if (this.read_only) { + adder_dom.setAttribute("disabled", "disabled"); + } adder_dom.textContent = "+"; adder_dom.addEventListener("click", (event) => { event.preventDefault(); @@ -10511,6 +10767,94 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:zoo-input«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + */ + class class_input_set { + /** + */ + constructor(options, show_element, { "read_only": read_only = false, } = {}) { + this.show_element = show_element; + this.options = options; + this.read_only = read_only; + this.checkboxes = new Map(); + } + /** + * [implementation] + */ + setup(parent) { + for (const option of this.options) { + // label + const element_container = document.createElement("label"); + element_container.classList.add("plankton_input_set_option"); + element_container.setAttribute("rel", option); + // checkbox + { + const element_checkbox = document.createElement("input"); + element_checkbox.setAttribute("type", "checkbox"); + (this.read_only && element_checkbox.setAttribute("disabled", "disabled")); + element_container.appendChild(element_checkbox); + this.checkboxes.set(option, element_checkbox); + } + // text + { + const element_text = document.createElement("span"); + element_text.textContent = this.show_element(option); + element_container.appendChild(element_text); + } + parent.appendChild(element_container); + } + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + const result = new Set(); + for (const option of this.options) { + const element_checkbox = this.checkboxes.get(option); + if (element_checkbox.checked) { + result.add(option); + } + } + return Promise.resolve(result); + } + /** + * [implementation] + */ + write(value) { + for (const option of this.options) { + const element_checkbox = this.checkboxes.get(option); + element_checkbox.checked = value.has(option); + } + return Promise.resolve(undefined); + } + } + zoo_input.class_input_set = class_input_set; + })(zoo_input = lib_plankton.zoo_input || (lib_plankton.zoo_input = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:zoo-input«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:zoo-input« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:zoo-input« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License along with »bacterio-plankton:zoo-input«. If not, see . */ @@ -10906,27 +11250,32 @@ var lib_plankton; class class_input_datetime { /** */ - constructor(options = {}) { - options = Object.assign({ - "label_timezone_shift": "", - "label_date": "", - "label_time": "", - }, options); + constructor({ "label_timezone_shift": label_timezone_shift = null, "label_date": label_date = null, "label_time": label_time = null, } = {}) { + /* + options = Object.assign( + { + "label_timezone_shift": "", + "label_date": "", + "label_time": "", + }, + options + ); + */ this.core = new zoo_input.class_input_group([ { "name": "timezone_shift", "input": new zoo_input.class_input_number(), - "label": options.label_timezone_shift, + "label": label_timezone_shift, }, { "name": "date", "input": new zoo_input.class_input_date(), - "label": options.label_date, + "label": label_date, }, { "name": "time", "input": new zoo_input.class_input_soft(new zoo_input.class_input_time()), - "label": options.label_time, + "label": label_time, }, ]); } diff --git a/tools/update-plankton b/tools/update-plankton index c1c150b..8145b92 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -2,7 +2,7 @@ ## consts -dir=lib/plankton +dir=$(pwd)/lib/plankton modules="" modules="${modules} base" @@ -14,7 +14,7 @@ modules="${modules} json" modules="${modules} string" modules="${modules} map" modules="${modules} color" -modules="${modules} xml" +# modules="${modules} xml" modules="${modules} map" modules="${modules} http" modules="${modules} log" @@ -29,6 +29,14 @@ modules="${modules} zoo-input" ## exec +mkdir -p ${dir} +mkdir /tmp/sandbox -p +cd /tmp/sandbox +ptk fetch web ${modules} +schwamm --include=/tmp/sandbox/plankton.swm.json --output=dump:logic-decl > ${dir}/plankton.d.ts +schwamm --include=/tmp/sandbox/plankton.swm.json --output=dump:logic-impl > ${dir}/plankton.js +exit + mkdir -p ${dir} cd ${dir} ptk bundle web ${modules} From 3df888ced3f499d440c7eab248b768834d11b681 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 17:07:37 +0200 Subject: [PATCH 2/2] [mov] conf-example --- conf/example.json => misc/conf-example.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename conf/example.json => misc/conf-example.json (100%) diff --git a/conf/example.json b/misc/conf-example.json similarity index 100% rename from conf/example.json rename to misc/conf-example.json