diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 8b4eea3..ed0937f 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -310,6 +310,233 @@ declare module lib_plankton.pod { distinguish(function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result; } } +declare namespace lib_plankton.code { + /** + * @author fenris + */ + interface interface_code { + /** + * @author fenris + */ + encode(x: type_from): type_to; + /** + * @author fenris + */ + decode(x: type_to): type_from; + } +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + type type_code = { + /** + * @author fenris + */ + encode: (x: type_from) => type_to; + /** + * @author fenris + */ + decode: (x: type_to) => type_from; + }; +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + function inverse_encode(decode: (to: type_to) => type_from, to: type_to): type_from; + /** + * @author fenris + */ + function inverse_decode(encode: (from: type_from) => type_to, from: type_from): type_to; +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + class class_code_inverse implements interface_code { + /** + * @author fenris + */ + protected subject: interface_code; + /** + * @author fenris + */ + constructor(subject: interface_code); + /** + * @implementation + * @author fenris + */ + encode(to: type_to): type_from; + /** + * @implementation + * @author fenris + */ + decode(from: type_from): type_to; + } +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + function pair_encode(encode_first: (from: type_from) => type_between, encode_second: (between: type_between) => type_to, from: type_from): type_to; + /** + * @author fenris + */ + function pair_decode(decode_first: (between: type_between) => type_from, decode_second: (to: type_to) => type_between, to: type_to): type_from; +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + class class_code_pair implements interface_code { + /** + * @author fenris + */ + protected first: interface_code; + /** + * @author fenris + */ + protected second: interface_code; + /** + * @author fenris + */ + constructor(first: interface_code, second: interface_code); + /** + * @implementation + * @author fenris + */ + encode(from: type_from): type_to; + /** + * @implementation + * @author fenris + */ + decode(to: type_to): type_from; + } +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + function chain_encode(encode_links: Array<(from: any) => any>, from: any): any; + /** + * @author fenris + */ + function chain_decode(decode_links: Array<(to: any) => any>, to: any): any; +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + class class_code_chain implements interface_code { + /** + * @author fenris + */ + protected links: Array>; + /** + * @author fenris + */ + constructor(links: Array>); + /** + * @implementation + * @author fenris + */ + encode(from: any): any; + /** + * @implementation + * @author fenris + */ + decode(to: any): any; + } +} +declare namespace lib_plankton.code { + /** + * @author Christian Fraß + */ + type type_flatten_from = Array<{ + [name: string]: any; + }>; + /** + * @author Christian Fraß + */ + type type_flatten_to = { + keys: Array; + data: Array>; + }; + /** + * @author Christian Fraß + */ + function flatten_encode(from: type_flatten_from, keys?: Array): type_flatten_to; + /** + * @author Christian Fraß + */ + function flatten_decode(to: type_flatten_to): type_flatten_from; +} +declare namespace lib_plankton.code { + /** + * @author fenris + */ + class class_code_flatten implements interface_code { + /** + * @author fenris + */ + constructor(); + /** + * @implementation + * @author fenris + */ + encode(x: type_flatten_from): type_flatten_to; + /** + * @implementation + * @author fenris + */ + decode(x: type_flatten_to): type_flatten_from; + } +} +declare namespace lib_plankton.json { + /** + */ + type type_source = any; + /** + */ + type type_target = string; + /** + * @author fenris + */ + export function encode(source: type_source, options?: { + formatted?: boolean; + }): type_target; + /** + * @author fenris + */ + export function decode(target: type_target): type_source; + /** + * @author fenris + */ + export function implementation_code(): lib_plankton.code.type_code; + export {}; +} +declare namespace lib_plankton.json { + /** + * @author fenris + */ + class class_json implements lib_plankton.code.interface_code { + /** + * @author fenris + */ + constructor(); + /** + * @implementation + * @author fenris + */ + encode(x: any): string; + /** + * @implementation + * @author fenris + */ + decode(x: string): any; + } +} /** * might be completely obsolete */ @@ -718,233 +945,6 @@ declare namespace lib_plankton.file { */ function blob_write_text(text: string): lib_plankton.call.type_promise; } -declare namespace lib_plankton.code { - /** - * @author fenris - */ - interface interface_code { - /** - * @author fenris - */ - encode(x: type_from): type_to; - /** - * @author fenris - */ - decode(x: type_to): type_from; - } -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - type type_code = { - /** - * @author fenris - */ - encode: (x: type_from) => type_to; - /** - * @author fenris - */ - decode: (x: type_to) => type_from; - }; -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - function inverse_encode(decode: (to: type_to) => type_from, to: type_to): type_from; - /** - * @author fenris - */ - function inverse_decode(encode: (from: type_from) => type_to, from: type_from): type_to; -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - class class_code_inverse implements interface_code { - /** - * @author fenris - */ - protected subject: interface_code; - /** - * @author fenris - */ - constructor(subject: interface_code); - /** - * @implementation - * @author fenris - */ - encode(to: type_to): type_from; - /** - * @implementation - * @author fenris - */ - decode(from: type_from): type_to; - } -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - function pair_encode(encode_first: (from: type_from) => type_between, encode_second: (between: type_between) => type_to, from: type_from): type_to; - /** - * @author fenris - */ - function pair_decode(decode_first: (between: type_between) => type_from, decode_second: (to: type_to) => type_between, to: type_to): type_from; -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - class class_code_pair implements interface_code { - /** - * @author fenris - */ - protected first: interface_code; - /** - * @author fenris - */ - protected second: interface_code; - /** - * @author fenris - */ - constructor(first: interface_code, second: interface_code); - /** - * @implementation - * @author fenris - */ - encode(from: type_from): type_to; - /** - * @implementation - * @author fenris - */ - decode(to: type_to): type_from; - } -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - function chain_encode(encode_links: Array<(from: any) => any>, from: any): any; - /** - * @author fenris - */ - function chain_decode(decode_links: Array<(to: any) => any>, to: any): any; -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - class class_code_chain implements interface_code { - /** - * @author fenris - */ - protected links: Array>; - /** - * @author fenris - */ - constructor(links: Array>); - /** - * @implementation - * @author fenris - */ - encode(from: any): any; - /** - * @implementation - * @author fenris - */ - decode(to: any): any; - } -} -declare namespace lib_plankton.code { - /** - * @author Christian Fraß - */ - type type_flatten_from = Array<{ - [name: string]: any; - }>; - /** - * @author Christian Fraß - */ - type type_flatten_to = { - keys: Array; - data: Array>; - }; - /** - * @author Christian Fraß - */ - function flatten_encode(from: type_flatten_from, keys?: Array): type_flatten_to; - /** - * @author Christian Fraß - */ - function flatten_decode(to: type_flatten_to): type_flatten_from; -} -declare namespace lib_plankton.code { - /** - * @author fenris - */ - class class_code_flatten implements interface_code { - /** - * @author fenris - */ - constructor(); - /** - * @implementation - * @author fenris - */ - encode(x: type_flatten_from): type_flatten_to; - /** - * @implementation - * @author fenris - */ - decode(x: type_flatten_to): type_flatten_from; - } -} -declare namespace lib_plankton.json { - /** - */ - type type_source = any; - /** - */ - type type_target = string; - /** - * @author fenris - */ - export function encode(source: type_source, options?: { - formatted?: boolean; - }): type_target; - /** - * @author fenris - */ - export function decode(target: type_target): type_source; - /** - * @author fenris - */ - export function implementation_code(): lib_plankton.code.type_code; - export {}; -} -declare namespace lib_plankton.json { - /** - * @author fenris - */ - class class_json implements lib_plankton.code.interface_code { - /** - * @author fenris - */ - constructor(); - /** - * @implementation - * @author fenris - */ - encode(x: any): string; - /** - * @implementation - * @author fenris - */ - decode(x: string): any; - } -} declare namespace lib_plankton.email { /** */ @@ -1086,225 +1086,341 @@ declare namespace lib_plankton.log { } declare namespace lib_plankton.log { } -declare namespace lib_plankton.args { +declare namespace lib_plankton.object { + /** + * @author fenris + * @deprecated use the "??" operator instead + */ + function fetch(object: Object, fieldname: string, options?: { + fallback?: type_value; + escalate?: boolean; + }): type_value; /** */ - enum enum_environment { - cli = "cli", - url = "url" - } + function map(object_from: Record, transformator: ((value_from: type_from, key?: string) => type_to)): Record; /** + * gibt ein Objekt mit bestimmten Einträgen des Eingabe-Objekts zurück */ - enum enum_kind { - positional = "positional", - volatile = "volatile" - } + function filter(object_from: Record, predicate: ((value_from: type_value, key?: string) => boolean)): Record; /** + * wandelt ein Array mit Einträgen der Form {key,value} in ein entsprechendes Objekt um + * + * @deprecated use Object.fromEntries instead! */ - enum enum_type { - boolean = "boolean", - integer = "int", - float = "float", - string = "string" - } + function from_array(array: Array<{ + key: string; + value: type_value; + }>): Record; /** + * wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form {key,value} um + * + * @deprecated use Object.entries insetad! */ - enum enum_mode { - replace = "replace", - accumulate = "accumulate" - } + function to_array(object: Record): Array<{ + key: string; + value: type_value; + }>; + /** + * gibt eine Liste von Schlüsseln eines Objekts zurück + * + * @deprecated use Object.keys instead! + */ + function keys(object: Record): Array; + /** + * gibt eine Liste von Werten eines Objekts zurück + * + * @deprecated use Object.values instead! + */ + function values(object: Record): Array; + /** + * liest ein Baum-artiges Objekt an einer bestimmten Stelle aus + */ + function path_read(object: Object, path: string, options?: { + fallback?: type_value; + escalate?: boolean; + }): type_value; + /** + * schreibt einen Wert an eine bestimmte Stelle in einem Baum-artigen Objekt + */ + function path_write(object: Object, path: string, value: type_value, construct?: boolean): void; + /** + * prüft ob ein Objekt einem bestimmten Muster entspricht + * + * @deprecated not very useful + */ + function matches(object: Record, pattern: Record, options?: { + collate?: ((value_pattern: type_value_pattern, value_object: type_value_object) => boolean); + }): boolean; + /** + * erzeugt eine Projektion eines Baum-artigen Objekts in ein Listen-artiges Objekt + */ + function flatten(value: any, options?: { + separator?: string; + key_for_array_element?: ((index: int) => string); + }): Record; + /** + * @deprecated use Object.assign instead! + */ + function clash(x: Record, y: Record, options?: { + overwrite?: boolean; + hooks?: { + existing?: ((key?: string, value_old?: any, value_new?: any) => void); + }; + }): Record; + /** + * @deprecated use Object.assign instead! + */ + function patch(core: (null | Record), mantle: (null | Record), options?: { + deep?: boolean; + path?: (null | string); + }): void; + /** + * @deprecated use Object.assign instead! + */ + function patched(core: Record, mantle: Record, options?: { + deep?: boolean; + }): Record; + /** + * @deprecated use Object.assign instead! + */ + function attached(object: Record, key: string, value: any): Record; + /** + * @author fenris + */ + function copy(object: Record): Record; } -declare namespace lib_plankton.args { +declare namespace lib_plankton.pair { /** - * @author fenris */ - class class_argument { - /** - * @author fenris - */ - protected name: string; - /** - * @author fenris - */ - protected kind: enum_kind; - /** - * @author fenris - */ - protected type: enum_type; - /** - * @author fenris - */ - protected mode: enum_mode; - /** - * @author fenris - */ - protected default_: any; - /** - * @author fenris - */ - protected info: string; - /** - * @author fenris - */ - protected parameters: Object; - /** - * @author fenris - */ - protected hidden: boolean; - /** - * @author fenris - */ - constructor({ "name": name, "type": type, "kind": kind, "mode": mode, "default": default_, "info": info, "parameters": parameters, "hidden": hidden, }: { - name: string; - type?: enum_type; - kind?: enum_kind; - mode?: enum_mode; - default?: any; - info?: string; - parameters?: Object; - hidden?: boolean; - }); - /** - * @author fenris - */ - static positional({ "name": name, "type": type, "mode": mode, "default": default_, "info": info, "hidden": hidden, "index": index, }: { - name: string; - type?: enum_type; - mode?: enum_mode; - default?: any; - info?: string; - hidden?: boolean; - index: int; - }): class_argument; - /** - * @author fenris - */ - static volatile({ "name": name, "type": type, "mode": mode, "default": default_, "info": info, "hidden": hidden, "indicators_short": indicators_short, "indicators_long": indicators_long, }: { - name: string; - type?: enum_type; - mode?: enum_mode; - default?: any; - info?: string; - hidden?: boolean; - indicators_short: Array; - indicators_long: Array; - }): class_argument; - /** - * @author fenris - */ - check(): boolean; - /** - * @author fenris - */ - name_get(): string; - /** - * @author fenris - */ - kind_get(): enum_kind; - /** - * @author fenris - */ - type_get(): enum_type; - /** - * @author fenris - */ - mode_get(): enum_mode; - /** - * @author fenris - */ - default_get(): any; - /** - * @author fenris - */ - parameters_get(): Object; - /** - * @author fenris - */ - hidden_get(): boolean; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - indicator_main(): string; - /** - * @author fenris - */ - pattern_value(): string; - /** - * @author fenris - */ - extract(raw: string): any; - /** - * @author fenris - */ - assign(data: Object, target: string, raw: string): void; - /** - * @author fenris - */ - make(data: Object, target: string): string; - /** - * @author fenris - */ - generate_help(): string; - } + type type_pair = { + first: type_first; + second: type_second; + }; } -declare namespace lib_plankton.args { +declare namespace lib_plankton.pair { /** - * @author fenris */ - var verbosity: int; + function swap(pair: type_pair): type_pair; /** - * @author fenris - * @todo check validity */ - class class_handler { - /** - * @author fenris - */ - protected arguments_: { - [name: string]: class_argument; - }; - /** - * @author fenris - */ - constructor(arguments_: { - [name: string]: class_argument; - }); - /** - * @author fenris - */ - filter(kind: enum_kind): { - [name: string]: class_argument; - }; - /** - * @author fenris - */ - read(environment: enum_environment, input: string, data?: { - [name: string]: any; - }): { - [name: string]: any; - }; - /** - * @author fenris - * @todo handle if the data object doesn't have the required field or the type is wrong or sth. - */ - write(environment: enum_environment, data: { - [name: string]: any; - }): string; - /** - * @desc manpage-like info-sheet - * @author fenris - */ - generate_help({ "programname": programname, "author": author, "description": description, "executable": executable, }: { - programname?: string; - author?: string; - description?: string; - executable?: string; - }): string; - } + function show(pair: type_pair, options?: { + show_first?: ((first: type_first) => string); + show_second?: ((second: type_second) => string); + }): string; +} +declare namespace lib_plankton.list { + /** + */ + type type_separation = { + yes: Array; + no: Array; + }; + /** + */ + type type_result_max = (null | { + index: int; + element: type_element; + value: type_value; + }); +} +declare namespace lib_plankton.list { + /** + * returns a certain list of integer numbers + */ + function range(from: int, to: int, options?: { + step?: int; + }): Array; + /** + * returns a certain list of consecutiv integer numbers, beginning with 0 + */ + function sequence(length: int): Array; + /** + */ + function from_iterator(iterator: Iterator): Array; + /** + */ + function is_empty(list: Array): boolean; + /** + * combines two lists into one + * + * @param {boolean} [options.cut] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths; default: true + */ + function zip(list_first: Array, list_second: Array, options?: { + cut?: boolean; + }): Array>; + /** + * checks whether two lists are equal + * + * @todo define common function "equals" and default predicate to + */ + function equals(list1: Array, list2: Array, options?: { + collate_element?: ((element1: type_element, element2: type_element) => boolean); + }): boolean; + /** + * creates a list with the elements from the input list, which fulfil a certain predicate (~ filter) + */ + function keep(list: Array, predicate: ((element: type_element) => boolean)): Array; + /** + * creates a list with the elements from the input list, which do not fulfil a certain predicate (~ dual filter) + */ + function drop(list: Array, predicate: ((element: type_element) => boolean)): Array; + /** + */ + function filter_inplace(list: Array, predicate: ((element: type_element) => boolean)): void; + /** + * returns a list with no duplicates (like unix' "unique") + */ + function cleaned(list: Array, options?: { + collate_element?: ((x: type_element, y: type_element) => boolean); + }): Array; + /** + * creates a binary partition of the list according to a given predicate + */ + function separate(list: Array, predicate: ((element: type_element) => boolean)): type_separation; + /** + */ + function clone(list: Array): Array; + /** + */ + function reversed(list: Array): Array; + /** + * @todo use Array.toSorted? + */ + function sorted(list: Array, options: { + compare_element?: ((element1: type_element, element2: type_element) => boolean); + }): Array; + /** + * die Liste in gleich große Blöcke zerlegen + */ + function chop(list: Array, chunk_size: int): Array>; + /** + */ + function group(list: Array, collate_element: ((x: type_element, y: type_element) => boolean)): Array>; + /** + */ + function has(list: Array, predicate: ((element: type_element) => boolean)): boolean; + /** + * @deprecate use Array.includes or Array.some + */ + function contains(list: Array, element: type_element, options: { + collate_element?: ((element1: type_element, element2: type_element) => boolean); + }): boolean; + /** + * retrieves the element and its index of the list, which has the maximum value + */ + function max(list: Array, target_function: ((element: type_element) => type_value), options: { + compare_value: ((value1: type_value, value2: type_value) => boolean); + }): type_result_max; + /** + * retrieves the element and its index of the list, which has the mininum value + */ + function min(list: Array, target_function: (element: type_element) => type_value, options: { + compare_value: ((value1: type_value, value2: type_value) => boolean); + }): type_result_max; + /** + * implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)" + * example: distribute([[1,2],[3],[4,5,6]]) = [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]] + */ + function distribute(lists: Array>): Array>; + /** + */ + function contrast(list_left: Array, extract_key_left: ((left: type_left) => string), list_right: Array, extract_key_right: ((right: type_right) => string)): { + both: Array<{ + key: string; + left: type_left; + right: type_right; + }>; + only_left: Array<{ + key: string; + left: type_left; + }>; + only_right: Array<{ + key: string; + right: type_right; + }>; + }; +} +declare namespace lib_plankton.conf { + /** + */ + type type_schema = ({ + enum?: Array; + default?: any; + description?: string; + } | { + type: "null"; + description?: string; + } | { + type: "boolean"; + nullable?: boolean; + enum?: Array; + default?: boolean; + description?: string; + } | { + type: "integer"; + nullable?: boolean; + enum?: Array; + default?: int; + description?: string; + } | { + type: "number"; + nullable?: boolean; + enum?: Array; + default?: number; + description?: string; + } | { + type: "string"; + nullable?: boolean; + enum?: Array; + default?: string; + description?: string; + } | { + type: "array"; + nullable?: boolean; + items: type_schema; + enum?: Array>; + default?: Array; + description?: string; + } | { + type: "object"; + nullable?: boolean; + properties?: Record; + required?: Array; + additionalProperties?: (false | type_schema); + enum?: Array>; + default?: Record; + description?: string; + } | { + anyOf: Array; + default?: any; + } | { + allOf: Array; + } | { + oneOf: Array; + } | { + not: type_schema; + }); + /** + */ + type type_report = { + incident: string; + details: Record; + }; + /** + */ + type type_adaption = { + reports: Array; + result: lib_plankton.pod.type_pod; + }; +} +declare namespace lib_plankton.conf { + /** + * @todo versioning + */ + function refine(schema: type_schema, value_raw: any): type_result; + /** + */ + function load(schema: type_schema, path: (null | string)): Promise; } declare var plain_text_to_html: (text: string) => string; /** @@ -1468,6 +1584,338 @@ declare var printf: typeof lib_plankton.string.printf; declare var eml_log: any; declare var track_exports: any; declare var make_logger: (prefix: any, current_loglevel: any) => (obj: any, lvl: any) => void; +declare namespace lib_plankton.database { + /** + */ + type type_query = { + template: string; + arguments: Record; + }; + /** + */ + enum enum_type { + boolean = "boolean", + integer = "integer", + string_short = "string_short", + string_medium = "string_medium", + string_long = "string_long", + float = "float" + } + /** + */ + type type_description_create_table = { + name: string; + key_field?: (null | { + name: string; + type?: enum_type; + comment?: (null | string); + auto_increment?: (null | boolean); + description?: (null | string); + }); + data_fields?: Array<{ + name: string; + nullable?: boolean; + type: enum_type; + default?: any; + description?: (null | string); + }>; + constraints?: Array<{ + kind: string; + parameters?: Record; + }>; + description?: (null | string); + }; + /** + */ + type type_description_insert = { + table_name: string; + values: Record; + returning?: (null | string); + }; + /** + */ + type type_description_update = { + table_name: string; + values: Record; + condition?: (null | string); + arguments?: (null | Record); + }; + /** + */ + type type_description_delete = { + table_name: string; + condition?: (null | string); + arguments?: (null | Record); + }; + /** + */ + type type_description_select = { + source: string; + fields?: (null | Array); + condition?: (null | string); + group_by?: (null | string); + having?: (null | string); + order_by?: (null | string); + limit?: (null | int); + arguments?: (null | Record); + }; + /** + * rows + */ + type type_result_get = Array>; + /** + * auto insert id + */ + type type_result_put = (null | int); + /** + * number of affected rows + */ + type type_result_set = int; + /** + * @author fenris + */ + type type_database = { + wrap_name: ((name: string) => string); + query_free_get: ((query: type_query) => Promise); + query_free_put: ((query: type_query) => Promise); + query_free_set: ((query: type_query) => Promise); + query_create_table: ((description_create_table: type_description_create_table) => Promise); + query_insert: ((description_insert: type_description_insert) => Promise); + query_update: ((description_update: type_description_update) => Promise); + query_delete: ((description_delete: type_description_delete) => Promise); + query_select: ((description_select: type_description_select) => Promise); + }; + /** + */ + type interface_database = database.type_database; +} +declare namespace lib_plankton.storage { + /** + * implements the idea of a database, which houses datasets (type_value) and manages their access by ids or sth. similar (type_key) + * + * @author fenris + */ + type type_store = { + /** + * shall prepare the storage instance for use + * + * @author fenris + */ + setup(input: type_setup_input): Promise; + /** + * shall insert a new dataset and return its automatically assign key + * + * @author fenris + */ + create(value: type_value): Promise; + /** + * shall modify an existing dataset + * + * @author fenris + */ + update(key: type_key, value: type_value): Promise; + /** + * shall remove an existing dataset + * + * @author fenris + */ + delete(key: type_key): Promise; + /** + * shall get an existing dataset by its key + * + * @author fenris + */ + read(key: type_key): Promise; + /** + * shall list keys and previews of existing datasets, which match a certain search term + * + * @author fenris + */ + search(term?: (null | type_searchterm)): Promise>; + }; + /** + * for class wrappers + */ + type interface_store = type_store; +} +declare namespace lib_plankton.storage { + /** + * implements the idea of a storage without managed keys + * + * @author fenris + */ + type type_chest = { + /** + * shall prepare the storage instance for use + * + * @author fenris + */ + setup(input: type_setup_input): Promise; + /** + * shall remove all items + */ + clear(): Promise; + /** + * shall insert a new or modify an existing dataset and return whether it is new + * + * @author fenris + */ + write(key: type_key, value: type_value): Promise; + /** + * shall remove an existing dataset + * + * @author fenris + */ + delete(key: type_key): Promise; + /** + * shall get an existing dataset by its key + * + * @author fenris + */ + read(key: type_key): Promise; + /** + * shall list keys and previews of existing datasets, which match a certain search term + * + * @author fenris + */ + search(term?: (null | type_searchterm)): Promise>; + }; + /** + * for class wrappers + */ + type interface_chest = type_chest; +} +declare namespace lib_plankton.storage.memory { + /** + * @author fenris + */ + type type_subject = { + data: Record; + }; + /** + */ + type type_parameters = {}; + /** + * @author fenris + */ + function make(parameters: type_parameters): type_subject; + /** + * @author fenris + */ + function clear(subject: type_subject): void; + /** + * @author fenris + */ + function write(subject: type_subject, key: string, value: type_value): boolean; + /** + * @author fenris + */ + function delete_(subject: type_subject, key: string): void; + /** + * @author fenris + */ + function read(subject: type_subject, key: string): type_value; + /** + * @author fenris + */ + function list(subject: type_subject): Array; + /** + * @author fenris + */ + function search(subject: type_subject, term: (null | string)): Array<{ + key: string; + preview: string; + }>; + /** + * @author fenris + */ + function implementation_chest(parameters: type_parameters): type_chest; +} +declare namespace lib_plankton.storage.memory { + /** + * @author fenris + */ + class class_chest implements type_chest { + private subject; + constructor(parameters: type_parameters); + setup(input: any): Promise; + clear(): Promise; + write(key: any, value: any): Promise; + delete(key: any): Promise; + read(key: any): Promise>; + search(term: any): Promise<{ + key: string; + preview: string; + }[]>; + } +} +declare namespace lib_plankton.storage.localstorage { + /** + * @author fenris + */ + type type_subject = { + corner: string; + }; + /** + * @author fenris + */ + type type_parameters = { + corner?: string; + }; + /** + * @author fenris + */ + function make(parameters: type_parameters): type_subject; + /** + * @author fenris + */ + function clear(subject: type_subject): void; + /** + * @author fenris + */ + function write(subject: type_subject, key: string, item: string): boolean; + /** + * @author fenris + */ + function delete_(subject: type_subject, key: string): void; + /** + * @author fenris + */ + function read(subject: type_subject, key: string): string; + /** + * @author fenris + */ + function list(subject: type_subject): Array; + /** + */ + function implementation_chest(parameters: type_parameters): type_chest; +} +declare namespace lib_plankton.storage.localstorage { + /** + * uses the browsers localstorage as chest + * + * @author fenris + */ + class class_chest implements type_chest { + private subject; + constructor(parameters: type_parameters); + setup(input: any): Promise; + clear(): Promise; + write(key: any, value: any): Promise; + delete(key: any): Promise; + read(key: any): Promise; + search(term: any): Promise<{ + key: string; + preview: string; + }[]>; + } +} declare namespace lib_plankton.complex { /** * @author fenris @@ -2536,342 +2984,6 @@ declare namespace lib_plankton.url { decode(x: string): any; } } -declare namespace lib_plankton.object { - /** - * @author fenris - * @deprecated use the "??" operator instead - */ - function fetch(object: Object, fieldname: string, options?: { - fallback?: type_value; - escalate?: boolean; - }): type_value; - /** - */ - function map(object_from: Record, transformator: ((value_from: type_from, key?: string) => type_to)): Record; - /** - * gibt ein Objekt mit bestimmten Einträgen des Eingabe-Objekts zurück - */ - function filter(object_from: Record, predicate: ((value_from: type_value, key?: string) => boolean)): Record; - /** - * wandelt ein Array mit Einträgen der Form {key,value} in ein entsprechendes Objekt um - * - * @deprecated use Object.fromEntries instead! - */ - function from_array(array: Array<{ - key: string; - value: type_value; - }>): Record; - /** - * wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form {key,value} um - * - * @deprecated use Object.entries insetad! - */ - function to_array(object: Record): Array<{ - key: string; - value: type_value; - }>; - /** - * gibt eine Liste von Schlüsseln eines Objekts zurück - * - * @deprecated use Object.keys instead! - */ - function keys(object: Record): Array; - /** - * gibt eine Liste von Werten eines Objekts zurück - * - * @deprecated use Object.values instead! - */ - function values(object: Record): Array; - /** - * liest ein Baum-artiges Objekt an einer bestimmten Stelle aus - */ - function path_read(object: Object, path: string, options?: { - fallback?: type_value; - escalate?: boolean; - }): type_value; - /** - * schreibt einen Wert an eine bestimmte Stelle in einem Baum-artigen Objekt - */ - function path_write(object: Object, path: string, value: type_value, construct?: boolean): void; - /** - * prüft ob ein Objekt einem bestimmten Muster entspricht - * - * @deprecated not very useful - */ - function matches(object: Record, pattern: Record, options?: { - collate?: ((value_pattern: type_value_pattern, value_object: type_value_object) => boolean); - }): boolean; - /** - * erzeugt eine Projektion eines Baum-artigen Objekts in ein Listen-artiges Objekt - */ - function flatten(value: any, options?: { - separator?: string; - key_for_array_element?: ((index: int) => string); - }): Record; - /** - * @deprecated use Object.assign instead! - */ - function clash(x: Record, y: Record, options?: { - overwrite?: boolean; - hooks?: { - existing?: ((key?: string, value_old?: any, value_new?: any) => void); - }; - }): Record; - /** - * @deprecated use Object.assign instead! - */ - function patch(core: (null | Record), mantle: (null | Record), options?: { - deep?: boolean; - path?: (null | string); - }): void; - /** - * @deprecated use Object.assign instead! - */ - function patched(core: Record, mantle: Record, options?: { - deep?: boolean; - }): Record; - /** - * @deprecated use Object.assign instead! - */ - function attached(object: Record, key: string, value: any): Record; - /** - * @author fenris - */ - function copy(object: Record): Record; -} -declare namespace lib_plankton.pair { - /** - */ - type type_pair = { - first: type_first; - second: type_second; - }; -} -declare namespace lib_plankton.pair { - /** - */ - function swap(pair: type_pair): type_pair; - /** - */ - function show(pair: type_pair, options?: { - show_first?: ((first: type_first) => string); - show_second?: ((second: type_second) => string); - }): string; -} -declare namespace lib_plankton.list { - /** - */ - type type_separation = { - yes: Array; - no: Array; - }; - /** - */ - type type_result_max = (null | { - index: int; - element: type_element; - value: type_value; - }); -} -declare namespace lib_plankton.list { - /** - * returns a certain list of integer numbers - */ - function range(from: int, to: int, options?: { - step?: int; - }): Array; - /** - * returns a certain list of consecutiv integer numbers, beginning with 0 - */ - function sequence(length: int): Array; - /** - */ - function from_iterator(iterator: Iterator): Array; - /** - */ - function is_empty(list: Array): boolean; - /** - * combines two lists into one - * - * @param {boolean} [options.cut] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths; default: true - */ - function zip(list_first: Array, list_second: Array, options?: { - cut?: boolean; - }): Array>; - /** - * checks whether two lists are equal - * - * @todo define common function "equals" and default predicate to - */ - function equals(list1: Array, list2: Array, options?: { - collate_element?: ((element1: type_element, element2: type_element) => boolean); - }): boolean; - /** - * creates a list with the elements from the input list, which fulfil a certain predicate (~ filter) - */ - function keep(list: Array, predicate: ((element: type_element) => boolean)): Array; - /** - * creates a list with the elements from the input list, which do not fulfil a certain predicate (~ dual filter) - */ - function drop(list: Array, predicate: ((element: type_element) => boolean)): Array; - /** - */ - function filter_inplace(list: Array, predicate: ((element: type_element) => boolean)): void; - /** - * returns a list with no duplicates (like unix' "unique") - */ - function cleaned(list: Array, options?: { - collate_element?: ((x: type_element, y: type_element) => boolean); - }): Array; - /** - * creates a binary partition of the list according to a given predicate - */ - function separate(list: Array, predicate: ((element: type_element) => boolean)): type_separation; - /** - */ - function clone(list: Array): Array; - /** - */ - function reversed(list: Array): Array; - /** - * @todo use Array.toSorted? - */ - function sorted(list: Array, options: { - compare_element?: ((element1: type_element, element2: type_element) => boolean); - }): Array; - /** - * die Liste in gleich große Blöcke zerlegen - */ - function chop(list: Array, chunk_size: int): Array>; - /** - */ - function group(list: Array, collate_element: ((x: type_element, y: type_element) => boolean)): Array>; - /** - */ - function has(list: Array, predicate: ((element: type_element) => boolean)): boolean; - /** - * @deprecate use Array.includes or Array.some - */ - function contains(list: Array, element: type_element, options: { - collate_element?: ((element1: type_element, element2: type_element) => boolean); - }): boolean; - /** - * retrieves the element and its index of the list, which has the maximum value - */ - function max(list: Array, target_function: ((element: type_element) => type_value), options: { - compare_value: ((value1: type_value, value2: type_value) => boolean); - }): type_result_max; - /** - * retrieves the element and its index of the list, which has the mininum value - */ - function min(list: Array, target_function: (element: type_element) => type_value, options: { - compare_value: ((value1: type_value, value2: type_value) => boolean); - }): type_result_max; - /** - * implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)" - * example: distribute([[1,2],[3],[4,5,6]]) = [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]] - */ - function distribute(lists: Array>): Array>; - /** - */ - function contrast(list_left: Array, extract_key_left: ((left: type_left) => string), list_right: Array, extract_key_right: ((right: type_right) => string)): { - both: Array<{ - key: string; - left: type_left; - right: type_right; - }>; - only_left: Array<{ - key: string; - left: type_left; - }>; - only_right: Array<{ - key: string; - right: type_right; - }>; - }; -} -declare namespace lib_plankton.conf { - /** - */ - type type_schema = ({ - enum?: Array; - default?: any; - description?: string; - } | { - type: "null"; - description?: string; - } | { - type: "boolean"; - nullable?: boolean; - enum?: Array; - default?: boolean; - description?: string; - } | { - type: "integer"; - nullable?: boolean; - enum?: Array; - default?: int; - description?: string; - } | { - type: "number"; - nullable?: boolean; - enum?: Array; - default?: number; - description?: string; - } | { - type: "string"; - nullable?: boolean; - enum?: Array; - default?: string; - description?: string; - } | { - type: "array"; - nullable?: boolean; - items: type_schema; - enum?: Array>; - default?: Array; - description?: string; - } | { - type: "object"; - nullable?: boolean; - properties?: Record; - required?: Array; - additionalProperties?: (false | type_schema); - enum?: Array>; - default?: Record; - description?: string; - } | { - anyOf: Array; - default?: any; - } | { - allOf: Array; - } | { - oneOf: Array; - } | { - not: type_schema; - }); - /** - */ - type type_report = { - incident: string; - details: Record; - }; - /** - */ - type type_adaption = { - reports: Array; - result: lib_plankton.pod.type_pod; - }; -} -declare namespace lib_plankton.conf { - /** - * @todo versioning - */ - function refine(schema: type_schema, value_raw: any): type_result; - /** - */ - function load(schema: type_schema, path: (null | string)): Promise; -} declare namespace lib_plankton.www_form { /** */ @@ -2909,3 +3021,617 @@ declare namespace lib_plankton.www_form { decode(target: type_target): type_source; } } +declare namespace lib_plankton.zoo_page { + /** + */ + export type type_location = { + name: string; + parameters: Record; + }; + /** + */ + type type_handler = ((parameters: Record, target_element: Element) => void); + /** + */ + export let _pool: Record; + /** + */ + export function encode(location: type_location): string; + /** + */ + export function add_nav_entry(location: type_location, options?: { + label?: (null | string); + }): void; + /** + * encodes a location in the URL and loads it + */ + export function set(location: type_location): void; + /** + */ + export function register(location_name: string, handler: type_handler, options?: {}): void; + /** + */ + export function init(target_element: Element, options?: { + pool?: Record; + fallback?: (null | type_location); + }): void; + /** + */ + export function start(): void; + export {}; +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + interface interface_input { + /** + */ + setup(parent: HTMLElement): Promise; + /** + */ + read(): Promise; + /** + */ + write(value: type_value): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_wrapped implements interface_input { + /** + */ + private core; + /** + */ + private wrap; + /** + */ + private unwrap; + /** + */ + constructor(core: interface_input, wrap: ((value_inner: type_value_inner) => type_value_outer), unwrap: ((value_outer: type_value_outer) => type_value_inner), options?: {}); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: type_value_outer): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_hidden implements interface_input { + /** + */ + private dom_input; + /** + */ + private value; + /** + */ + constructor(options?: { + initial_value?: any; + }); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: any): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + * @todo abstract + */ + class class_input_text implements interface_input { + /** + */ + private read_only; + /** + */ + private pattern; + /** + */ + /** + */ + private dom_input; + /** + */ + constructor(options?: { + read_only?: boolean; + pattern?: (null | string); + }); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: string): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_email implements interface_input { + /** + */ + private dom_input; + /** + */ + constructor(); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: string): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_textarea implements interface_input { + /** + */ + private dom_textarea; + /** + */ + constructor(); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: string): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_date implements interface_input<(null | type_date)> { + /** + */ + private required; + /** + */ + private dom_input; + /** + */ + constructor(options?: { + required?: boolean; + }); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise<(null | type_date)>; + /** + * [implementation] + */ + write(value: (null | type_date)): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + * @todo abstract + */ + class class_input_number implements interface_input { + /** + */ + private read_only; + /** + */ + private step; + /** + */ + private dom_input; + /** + */ + constructor(options?: { + read_only?: boolean; + step?: (null | float); + }); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: number): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_checkbox implements interface_input { + /** + */ + private read_only; + /** + */ + private dom_input; + /** + */ + private hooks_change; + /** + */ + constructor(options?: { + read_only?: boolean; + hooks_change?: Array<((value: boolean) => void)>; + }); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: boolean): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_selection implements interface_input { + /** + */ + private options; + /** + */ + private dom_select; + /** + */ + constructor(options: Array<{ + value: string; + label: string; + }>); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: string): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_enumeration implements interface_input { + /** + */ + private options; + /** + */ + private dom_inputs; + /** + */ + constructor(options: Array<{ + value: string; + label: string; + }>); + /** + * [implementation] + * @todo unique name + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: string): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + */ + type type_translations = { + add?: string; + remove?: string; + }; + /** + * @author fenris + */ + export class class_input_list implements interface_input> { + /** + */ + private element_input_factory; + /** + */ + private elements_container_dom; + /** + */ + private elements; + /** + */ + private translations; + /** + */ + constructor(element_input_factory: (() => interface_input), options?: { + translations?: type_translations; + }); + /** + */ + private clear; + /** + */ + private add; + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise>; + /** + * [implementation] + */ + write(value: Array): Promise; + } + export {}; +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_password implements interface_input { + /** + */ + private dom_input; + /** + */ + constructor(); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: string): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_switch implements interface_input { + /** + */ + private dom_element; + /** + */ + private value; + /** + */ + constructor(); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: boolean): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_time implements interface_input<(null | type_time)> { + /** + */ + private dom_input; + /** + */ + constructor(); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise<(null | type_time)>; + /** + * [implementation] + */ + write(value: (null | type_time)): Promise; + } +} +declare namespace lib_plankton.zoo_input { + /** + * @author fenris + */ + class class_input_group implements interface_input { + /** + */ + private fields; + /** + */ + constructor(fields_raw: Array<{ + name: string; + input: interface_input; + label?: (null | string); + help?: (null | string); + }>); + /** + * [implementation] + */ + setup(parent: HTMLElement): Promise; + /** + * [implementation] + */ + read(): Promise; + /** + * [implementation] + */ + write(value: type_record): Promise; + } +} +declare namespace lib_plankton.zoo_form { + /** + */ + type type_field = { + name: string; + type: string; + label: (null | string); + }; + /** + */ + export type type_form = { + method: string; + fields: Array; + encode: ((value: type_value) => Record); + decode: ((raw: Record) => type_value); + class_prefix: string; + root_element: (null | Element); + }; + /** + */ + export function make(method: string, fields: Array<{ + name: string; + type: string; + label?: (null | string); + }>, encode: ((value: type_value) => Record), decode: ((raw: Record) => type_value), options?: { + class_prefix?: string; + }): type_form; + /** + */ + export function make_simple(method: string, fields: Array<{ + name: string; + type: string; + label?: (null | string); + }>, options?: { + class_prefix?: string; + }): type_form>; + /** + */ + export function clear(subject: type_form): void; + /** + */ + export function write(subject: type_form, value: type_value): void; + /** + */ + export function read(subject: type_form): type_value; + /** + */ + export function render(subject: type_form, target: Element): Promise; + export {}; +} +declare namespace lib_plankton.zoo_form { + /** + */ + type type_action = { + label: string; + target?: string; + procedure?: ((get_value?: (() => Promise), get_representation?: (() => Promise)) => void); + }; + /** + * @author fenris + */ + export class class_form { + /** + */ + private encode; + /** + */ + private decode; + /** + */ + private actions; + /** + */ + private input; + /** + */ + constructor(encode: ((value: type_value) => type_representation), decode: ((representation: type_representation) => type_value), input: lib_plankton.zoo_input.interface_input, actions: Array>); + /** + */ + setup(parent: HTMLElement): Promise; + /** + */ + input_read_raw(): Promise; + /** + */ + input_read(): Promise; + /** + */ + input_write(value: type_value): Promise; + } + export {}; +} diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 4362588..f314f8c 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -607,6 +607,550 @@ var lib_plankton; })(pod = lib_plankton.pod || (lib_plankton.pod = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + function inverse_encode(decode, to) { + return decode(to); + } + code.inverse_encode = inverse_encode; + /** + * @author fenris + */ + function inverse_decode(encode, from) { + return encode(from); + } + code.inverse_decode = inverse_decode; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + var class_code_inverse = /** @class */ (function () { + /** + * @author fenris + */ + function class_code_inverse(subject) { + this.subject = subject; + } + /** + * @implementation + * @author fenris + */ + class_code_inverse.prototype.encode = function (to) { + var _this = this; + return code.inverse_encode(function (x) { return _this.subject.decode(x); }, to); + }; + /** + * @implementation + * @author fenris + */ + class_code_inverse.prototype.decode = function (from) { + var _this = this; + return code.inverse_decode(function (x) { return _this.subject.encode(x); }, from); + }; + return class_code_inverse; + }()); + code.class_code_inverse = class_code_inverse; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + function pair_encode(encode_first, encode_second, from) { + var between = encode_first(from); + var to = encode_second(between); + return to; + } + code.pair_encode = pair_encode; + /** + * @author fenris + */ + function pair_decode(decode_first, decode_second, to) { + var between = decode_second(to); + var from = decode_first(between); + return from; + } + code.pair_decode = pair_decode; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + var class_code_pair = /** @class */ (function () { + /** + * @author fenris + */ + function class_code_pair(first, second) { + this.first = first; + this.second = second; + } + /** + * @implementation + * @author fenris + */ + class_code_pair.prototype.encode = function (from) { + var _this = this; + return code.pair_encode(function (x) { return _this.first.encode(x); }, function (x) { return _this.second.encode(x); }, from); + }; + /** + * @implementation + * @author fenris + */ + class_code_pair.prototype.decode = function (to) { + var _this = this; + return code.pair_decode(function (x) { return _this.first.decode(x); }, function (x) { return _this.second.decode(x); }, to); + }; + return class_code_pair; + }()); + code.class_code_pair = class_code_pair; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + function chain_encode(encode_links, from) { + var value = from; + encode_links + .forEach(function (link) { + value = link(value); + }); + return value; + } + code.chain_encode = chain_encode; + /** + * @author fenris + */ + function chain_decode(decode_links, to) { + var value = to; + decode_links + .reverse() + .forEach(function (link) { + value = link(value); + }); + return value; + } + code.chain_decode = chain_decode; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + var class_code_chain = /** @class */ (function () { + /** + * @author fenris + */ + function class_code_chain(links) { + this.links = links; + } + /** + * @implementation + * @author fenris + */ + class_code_chain.prototype.encode = function (from) { + return code.chain_encode(this.links.map(function (link) { return (function (x) { return link.encode(x); }); }), from); + }; + /** + * @implementation + * @author fenris + */ + class_code_chain.prototype.decode = function (to) { + return code.chain_decode(this.links.map(function (link) { return (function (x) { return link.decode(x); }); }), to); + }; + return class_code_chain; + }()); + code.class_code_chain = class_code_chain; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author Christian Fraß + */ + function flatten_encode(from, keys) { + if (keys === void 0) { keys = null; } + if (keys === null) { + if (from.length > 0) { + keys = Object.keys(from[0]); + } + else { + throw (new Error("encoding impossible")); + } + } + return { + "keys": keys, + "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }) + }; + } + code.flatten_encode = flatten_encode; + /** + * @author Christian Fraß + */ + function flatten_decode(to) { + return (to.data + .map(function (dataset) { + var dataset_ = {}; + dataset + .forEach(function (value, index) { + var name = to.keys[index]; + dataset_[name] = value; + }); + return dataset_; + })); + } + code.flatten_decode = flatten_decode; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:code«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:code« 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:code« 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:code«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { + /** + * @author fenris + */ + var class_code_flatten = /** @class */ (function () { + /** + * @author fenris + */ + function class_code_flatten() { + } + /** + * @implementation + * @author fenris + */ + class_code_flatten.prototype.encode = function (x) { + return code.flatten_encode(x); + }; + /** + * @implementation + * @author fenris + */ + class_code_flatten.prototype.decode = function (x) { + return code.flatten_decode(x); + }; + return class_code_flatten; + }()); + code.class_code_flatten = class_code_flatten; + })(code = lib_plankton.code || (lib_plankton.code = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:json«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:json« 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:json« 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:json«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var json; + (function (json) { + /** + * @author fenris + */ + function encode(source, options = {}) { + options = Object.assign({ + "formatted": false, + }, options); + return JSON.stringify(source, undefined, (options.formatted ? "\t" : undefined)); + } + json.encode = encode; + /** + * @author fenris + */ + function decode(target) { + return JSON.parse(target); + } + json.decode = decode; + /** + * @author fenris + */ + function implementation_code() { + return { + "encode": x => encode(x), + "decode": decode, + }; + } + json.implementation_code = implementation_code; + })(json = lib_plankton.json || (lib_plankton.json = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:json«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:json« 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:json« 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:json«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var json; + (function (json) { + /** + * @author fenris + */ + class class_json { + /** + * @author fenris + */ + constructor() { + } + /** + * @implementation + * @author fenris + */ + encode(x) { + return json.encode(x); + } + /** + * @implementation + * @author fenris + */ + decode(x) { + return json.decode(x); + } + } + json.class_json = class_json; + })(json = lib_plankton.json || (lib_plankton.json = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:call«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -1666,550 +2210,6 @@ var lib_plankton; file.blob_write_text = blob_write_text; })(file = lib_plankton.file || (lib_plankton.file = {})); })(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - function inverse_encode(decode, to) { - return decode(to); - } - code.inverse_encode = inverse_encode; - /** - * @author fenris - */ - function inverse_decode(encode, from) { - return encode(from); - } - code.inverse_decode = inverse_decode; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - var class_code_inverse = /** @class */ (function () { - /** - * @author fenris - */ - function class_code_inverse(subject) { - this.subject = subject; - } - /** - * @implementation - * @author fenris - */ - class_code_inverse.prototype.encode = function (to) { - var _this = this; - return code.inverse_encode(function (x) { return _this.subject.decode(x); }, to); - }; - /** - * @implementation - * @author fenris - */ - class_code_inverse.prototype.decode = function (from) { - var _this = this; - return code.inverse_decode(function (x) { return _this.subject.encode(x); }, from); - }; - return class_code_inverse; - }()); - code.class_code_inverse = class_code_inverse; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - function pair_encode(encode_first, encode_second, from) { - var between = encode_first(from); - var to = encode_second(between); - return to; - } - code.pair_encode = pair_encode; - /** - * @author fenris - */ - function pair_decode(decode_first, decode_second, to) { - var between = decode_second(to); - var from = decode_first(between); - return from; - } - code.pair_decode = pair_decode; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - var class_code_pair = /** @class */ (function () { - /** - * @author fenris - */ - function class_code_pair(first, second) { - this.first = first; - this.second = second; - } - /** - * @implementation - * @author fenris - */ - class_code_pair.prototype.encode = function (from) { - var _this = this; - return code.pair_encode(function (x) { return _this.first.encode(x); }, function (x) { return _this.second.encode(x); }, from); - }; - /** - * @implementation - * @author fenris - */ - class_code_pair.prototype.decode = function (to) { - var _this = this; - return code.pair_decode(function (x) { return _this.first.decode(x); }, function (x) { return _this.second.decode(x); }, to); - }; - return class_code_pair; - }()); - code.class_code_pair = class_code_pair; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - function chain_encode(encode_links, from) { - var value = from; - encode_links - .forEach(function (link) { - value = link(value); - }); - return value; - } - code.chain_encode = chain_encode; - /** - * @author fenris - */ - function chain_decode(decode_links, to) { - var value = to; - decode_links - .reverse() - .forEach(function (link) { - value = link(value); - }); - return value; - } - code.chain_decode = chain_decode; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - var class_code_chain = /** @class */ (function () { - /** - * @author fenris - */ - function class_code_chain(links) { - this.links = links; - } - /** - * @implementation - * @author fenris - */ - class_code_chain.prototype.encode = function (from) { - return code.chain_encode(this.links.map(function (link) { return (function (x) { return link.encode(x); }); }), from); - }; - /** - * @implementation - * @author fenris - */ - class_code_chain.prototype.decode = function (to) { - return code.chain_decode(this.links.map(function (link) { return (function (x) { return link.decode(x); }); }), to); - }; - return class_code_chain; - }()); - code.class_code_chain = class_code_chain; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author Christian Fraß - */ - function flatten_encode(from, keys) { - if (keys === void 0) { keys = null; } - if (keys === null) { - if (from.length > 0) { - keys = Object.keys(from[0]); - } - else { - throw (new Error("encoding impossible")); - } - } - return { - "keys": keys, - "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }) - }; - } - code.flatten_encode = flatten_encode; - /** - * @author Christian Fraß - */ - function flatten_decode(to) { - return (to.data - .map(function (dataset) { - var dataset_ = {}; - dataset - .forEach(function (value, index) { - var name = to.keys[index]; - dataset_[name] = value; - }); - return dataset_; - })); - } - code.flatten_decode = flatten_decode; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:code« 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:code« 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:code«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var code; - (function (code) { - /** - * @author fenris - */ - var class_code_flatten = /** @class */ (function () { - /** - * @author fenris - */ - function class_code_flatten() { - } - /** - * @implementation - * @author fenris - */ - class_code_flatten.prototype.encode = function (x) { - return code.flatten_encode(x); - }; - /** - * @implementation - * @author fenris - */ - class_code_flatten.prototype.decode = function (x) { - return code.flatten_decode(x); - }; - return class_code_flatten; - }()); - code.class_code_flatten = class_code_flatten; - })(code = lib_plankton.code || (lib_plankton.code = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:json«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:json« 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:json« 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:json«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var json; - (function (json) { - /** - * @author fenris - */ - function encode(source, options = {}) { - options = Object.assign({ - "formatted": false, - }, options); - return JSON.stringify(source, undefined, (options.formatted ? "\t" : undefined)); - } - json.encode = encode; - /** - * @author fenris - */ - function decode(target) { - return JSON.parse(target); - } - json.decode = decode; - /** - * @author fenris - */ - function implementation_code() { - return { - "encode": x => encode(x), - "decode": decode, - }; - } - json.implementation_code = implementation_code; - })(json = lib_plankton.json || (lib_plankton.json = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:json«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:json« 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:json« 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:json«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var json; - (function (json) { - /** - * @author fenris - */ - class class_json { - /** - * @author fenris - */ - constructor() { - } - /** - * @implementation - * @author fenris - */ - encode(x) { - return json.encode(x); - } - /** - * @implementation - * @author fenris - */ - decode(x) { - return json.decode(x); - } - } - json.class_json = class_json; - })(json = lib_plankton.json || (lib_plankton.json = {})); -})(lib_plankton || (lib_plankton = {})); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -2789,784 +2789,1411 @@ var lib_plankton; })(log = lib_plankton.log || (lib_plankton.log = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:args«. +This file is part of »bacterio-plankton:object«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:args« is free software: you can redistribute it and/or modify +»bacterio-plankton:object« 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:args« is distributed in the hope that it will be useful, +»bacterio-plankton:object« 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:args«. If not, see . +along with »bacterio-plankton:object«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var args; - (function (args) { - /** - */ - var enum_environment; - (function (enum_environment) { - enum_environment["cli"] = "cli"; - enum_environment["url"] = "url"; - })(enum_environment = args.enum_environment || (args.enum_environment = {})); - ; - /** - */ - var enum_kind; - (function (enum_kind) { - enum_kind["positional"] = "positional"; - enum_kind["volatile"] = "volatile"; - })(enum_kind = args.enum_kind || (args.enum_kind = {})); - ; - /** - */ - var enum_type; - (function (enum_type) { - enum_type["boolean"] = "boolean"; - enum_type["integer"] = "int"; - enum_type["float"] = "float"; - enum_type["string"] = "string"; - })(enum_type = args.enum_type || (args.enum_type = {})); - ; - /** - */ - var enum_mode; - (function (enum_mode) { - enum_mode["replace"] = "replace"; - enum_mode["accumulate"] = "accumulate"; - })(enum_mode = args.enum_mode || (args.enum_mode = {})); - ; - })(args = lib_plankton.args || (lib_plankton.args = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:args«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:args« 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:args« 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:args«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var args; - (function (args) { - /* - export enum_mode { - replace = "replace", - accumulate = "accumulate", - }; - */ + var object; + (function (object_1) { /** * @author fenris + * @deprecated use the "??" operator instead */ - var class_argument = /** @class */ (function () { - /** - * @author fenris - */ - function class_argument(_a) { - var name = _a["name"], _b = _a["type"], type = _b === void 0 ? args.enum_type.string : _b, _c = _a["kind"], kind = _c === void 0 ? args.enum_kind.positional : _c, _d = _a["mode"], mode = _d === void 0 ? args.enum_mode.replace : _d, _e = _a["default"], default_ = _e === void 0 ? null : _e, _f = _a["info"], info = _f === void 0 ? null : _f, _g = _a["parameters"], parameters = _g === void 0 ? {} : _g, _h = _a["hidden"], hidden = _h === void 0 ? false : _h; - this.name = name; - this.type = type; - this.kind = kind; - this.mode = mode; - this.default_ = default_; - this.info = info; - this.parameters = parameters; - this.hidden = hidden; - if (!this.check()) { - throw (new Error("invalid argument-setup")); - } + function fetch(object, fieldname, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "fallback": null, + "escalation": 1 + }, options); + if ((fieldname in object) + && + (object[fieldname] !== undefined)) { + return object[fieldname]; } - /** - * @author fenris - */ - class_argument.positional = function (_a) { - var name = _a["name"], _b = _a["type"], type = _b === void 0 ? args.enum_type.string : _b, _c = _a["mode"], mode = _c === void 0 ? args.enum_mode.replace : _c, _d = _a["default"], default_ = _d === void 0 ? null : _d, _e = _a["info"], info = _e === void 0 ? null : _e, _f = _a["hidden"], hidden = _f === void 0 ? false : _f, index = _a["index"]; - return (new class_argument({ - "name": name, - "kind": args.enum_kind.positional, - "type": type, - "mode": mode, - "default": default_, - "info": info, - "hidden": hidden, - "parameters": { - "index": index - } - })); - }; - /** - * @author fenris - */ - class_argument.volatile = function (_a) { - var name = _a["name"], _b = _a["type"], type = _b === void 0 ? args.enum_type.string : _b, _c = _a["mode"], mode = _c === void 0 ? args.enum_mode.replace : _c, _d = _a["default"], default_ = _d === void 0 ? null : _d, _e = _a["info"], info = _e === void 0 ? null : _e, _f = _a["hidden"], hidden = _f === void 0 ? false : _f, indicators_short = _a["indicators_short"], indicators_long = _a["indicators_long"]; - return (new class_argument({ - "name": name, - "kind": args.enum_kind.volatile, - "type": type, - "mode": mode, - "default": default_, - "info": info, - "hidden": hidden, - "parameters": { - "indicators_short": indicators_short, - "indicators_long": indicators_long - } - })); - }; - /** - * @author fenris - */ - class_argument.prototype.check = function () { - var _this = this; - return [ - function () { return ((!(_this.kind == args.enum_kind.volatile)) - || - (("indicators_long" in _this.parameters) - && - (_this.parameters["indicators_long"]["length"] >= 0))); }, - ].every(function (condition) { return condition(); }); - }; - /** - * @author fenris - */ - class_argument.prototype.name_get = function () { - return this.name; - }; - /** - * @author fenris - */ - class_argument.prototype.kind_get = function () { - return this.kind; - }; - /** - * @author fenris - */ - class_argument.prototype.type_get = function () { - return this.type; - }; - /** - * @author fenris - */ - class_argument.prototype.mode_get = function () { - return this.mode; - }; - /** - * @author fenris - */ - class_argument.prototype.default_get = function () { - return this.default_; - }; - /** - * @author fenris - */ - class_argument.prototype.parameters_get = function () { - return this.parameters; - }; - /** - * @author fenris - */ - class_argument.prototype.hidden_get = function () { - return this.hidden; - }; - /** - * @author fenris - */ - class_argument.prototype.toString = function () { - return "<".concat(this.name, ">"); - }; - /** - * @author fenris - */ - class_argument.prototype.indicator_main = function () { - if (this.kind === args.enum_kind.volatile) { - return this.parameters["indicators_long"][0]; + else { + if (!options.escalate) { + return options.fallback; } else { - return null; + throw (new Error("field '" + fieldname + "' not in structure")); } - }; - /** - * @author fenris - */ - class_argument.prototype.pattern_value = function () { - switch (this.type) { - case args.enum_type.boolean: { - return "false|true"; - break; - } - case args.enum_type.integer: { - return "[0-9]+"; - break; - } - case args.enum_type.float: { - return "\\d*(?:\\.\\d+)?"; - break; - } - case args.enum_type.string: { - return "\\S+"; - break; - } - default: { - throw (new Error("unhandled type ".concat(this.type))); - break; - } + } + } + object_1.fetch = fetch; + /** + */ + function map(object_from, transformator) { + return (Object.fromEntries(Object.entries(object_from) + .map(function (_a) { + var key = _a[0], value = _a[1]; + return ([key, transformator(value, key)]); + }))); + } + object_1.map = map; + /** + * gibt ein Objekt mit bestimmten Einträgen des Eingabe-Objekts zurück + */ + function filter(object_from, predicate) { + return (Object.fromEntries(Object.entries(object_from) + .filter(function (_a) { + var key = _a[0], value = _a[1]; + return predicate(value, key); + }))); + } + object_1.filter = filter; + /** + * wandelt ein Array mit Einträgen der Form {key,value} in ein entsprechendes Objekt um + * + * @deprecated use Object.fromEntries instead! + */ + function from_array(array) { + return (Object.fromEntries(array + .map(function (_a) { + var key = _a["key"], value = _a["value"]; + return ([key, value]); + }))); + } + object_1.from_array = from_array; + /** + * wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form {key,value} um + * + * @deprecated use Object.entries insetad! + */ + function to_array(object) { + return (Object.entries(object) + .map(function (_a) { + var key = _a[0], value = _a[1]; + return ({ "key": key, "value": value }); + })); + } + object_1.to_array = to_array; + /** + * gibt eine Liste von Schlüsseln eines Objekts zurück + * + * @deprecated use Object.keys instead! + */ + function keys(object) { + return Object.keys(object); + } + object_1.keys = keys; + /** + * gibt eine Liste von Werten eines Objekts zurück + * + * @deprecated use Object.values instead! + */ + function values(object) { + return Object.values(object); + } + object_1.values = values; + /** + * liest ein Baum-artiges Objekt an einer bestimmten Stelle aus + */ + function path_read(object, path, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "fallback": null, + "escalate": false + }, options); + var steps = ((path.length == 0) ? [] : path.split(".")); + if (steps.length == 0) { + throw (new Error("empty path")); + } + else { + var position_1 = object; + var reachable = ((position_1 != null) + && + (steps.slice(0, steps.length - 1) + .every(function (step) { + position_1 = lib_plankton.object.fetch(position_1, step, { + "fallback": null, + "escalate": false + }); + return (position_1 != null); + }))); + if (reachable) { + return lib_plankton.object.fetch(position_1, steps[steps.length - 1], { + "fallback": options.fallback, + "escalate": options.escalate + }); } - }; - /** - * @author fenris - */ - class_argument.prototype.extract = function (raw) { - switch (this.type) { - case args.enum_type.boolean: { - return (raw != "false"); - break; - } - case args.enum_type.integer: { - return parseInt(raw); - break; - } - case args.enum_type.float: { - return parseFloat(raw); - break; - } - case args.enum_type.string: { - return raw; - break; - } - default: { - throw (new Error("unhandled type ".concat(this.type))); - break; - } + else { + return lib_plankton.object.fetch({}, "_dummy_", { + "fallback": options.fallback, + "escalate": options.escalate + }); } - }; - /** - * @author fenris - */ - class_argument.prototype.assign = function (data, target, raw) { - var value = this.extract(raw); - switch (this.mode) { - case args.enum_mode.replace: { - data[target] = value; - break; - } - case args.enum_mode.accumulate: { - /* - if (! (this.name in data)) { - data[this.name] = []; + } + } + object_1.path_read = path_read; + /** + * schreibt einen Wert an eine bestimmte Stelle in einem Baum-artigen Objekt + */ + function path_write(object, path, value, construct) { + if (construct === void 0) { construct = true; } + var steps = ((path.length == 0) ? [] : path.split(".")); + if (steps.length == 0) { + throw (new Error("empty path")); + } + else { + var position_2 = object; + var reachable = steps.slice(0, steps.length - 1).every(function (step) { + var position_ = lib_plankton.object.fetch(position_2, step, { + "fallback": null, + "escalate": false + }); + if (position_ == null) { + if (construct) { + position_2[step] = {}; + position_2 = position_2[step]; + return true; + } + else { + return false; } - */ - data[target].push(value); - break; } - default: { - throw (new Error("unhandled mode ".concat(this.mode))); + else { + position_2 = position_; + return true; + } + }); + if (reachable) { + position_2[steps[steps.length - 1]] = value; + } + else { + throw (new Error("path '" + path + "' does not exist and may not be constructed")); + } + } + } + object_1.path_write = path_write; + /** + * prüft ob ein Objekt einem bestimmten Muster entspricht + * + * @deprecated not very useful + */ + function matches(object, pattern, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "collate": instance_collate + }, options); + return (Object.entries(pattern) + .every(function (_a) { + var key = _a[0], value = _a[1]; + return options.collate(value, object[key]); + })); + } + object_1.matches = matches; + /** + * erzeugt eine Projektion eines Baum-artigen Objekts in ein Listen-artiges Objekt + */ + function flatten(value, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "separator": ".", + "key_for_array_element": (function (index) { return ("element_" + index.toFixed(0)); }) + }, options); + var integrate = function (result, key, value) { + if (value == null) { + result[key] = value; + } + else { + // primitive Werte direkt übernehmen + if (typeof (value) != "object") { + result[key] = value; + } + // sonst durch rekursiven Aufruf die flache Variante des Wertes ermitteln und einarbeiten + else { + var result_ = flatten(value, { + "separator": options.separator, + "key_for_array_element": options.key_for_array_element + }); + Object.entries(result_).forEach(function (_a) { + var key_ = _a[0], value_ = _a[1]; + result[(key + options.separator + key_)] = value_; + }); } } }; - /** - * @author fenris - */ - class_argument.prototype.make = function (data, target) { - var value = data[target]; - return value.toString(); - }; - /** - * @author fenris - */ - class_argument.prototype.generate_help = function () { - var _this = this; - var _a, _b, _c, _d; - var output = ""; - { - switch (this.kind) { - case args.enum_kind.positional: { - var line = ""; - line += "\t"; - line += "<".concat(this.name, ">"); - line += "\n"; - output += line; - } - case args.enum_kind.volatile: { - var line = ""; - line += "\t"; - if (this.type === args.enum_type.boolean) { - line += ([] - .concat(((_a = this.parameters["indicators_short"]) !== null && _a !== void 0 ? _a : []).map(function (indicator) { return ("-" + indicator); })) - .concat(((_b = this.parameters["indicators_long"]) !== null && _b !== void 0 ? _b : []).map(function (indicator) { return ("--" + indicator); })) - .join(" | ")); + if ((value === null) + || + (value === undefined)) { + return null; + } + else { + var result_1 = {}; + if (typeof (value) != "object") { + result_1["value"] = value; + } + else { + if (value instanceof Array) { + value.forEach(function (element, index) { + integrate(result_1, options.key_for_array_element(index), element); + }); + } + else { + Object.entries(value).forEach(function (_a) { + var key = _a[0], value = _a[1]; + integrate(result_1, key, value); + }); + } + } + return result_1; + } + } + object_1.flatten = flatten; + /** + * @deprecated use Object.assign instead! + */ + function clash(x, y, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "overwrite": true, + "hooks": { + "existing": function (key, value_old, value_new) { + lib_plankton.log.warning("object_clash_field_already_defined", { + "key": key + }); + } + } + }, options); + var z = {}; + Object.keys(x).forEach(function (key) { + z[key] = x[key]; + }); + Object.keys(y).forEach(function (key) { + if (key in z) { + if (options.hooks.existing != null) { + options.hooks.existing(key, z[key], y[key]); + } + if (options.overwrite) { + z[key] = y[key]; + } + } + else { + z[key] = y[key]; + } + }); + return z; + } + object_1.clash = clash; + /** + * @deprecated use Object.assign instead! + */ + function patch(core, mantle, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "deep": true, + "path": null + }, options); + if (mantle == null) { + lib_plankton.log.warning("object_patch_mantle_is_null", { + "core": core + }); + } + else { + Object.keys(mantle).forEach(function (key) { + var path_ = ((options.path == null) + ? + key + : + (options.path + "." + key)); + var value_mantle = mantle[key]; + if (!(key in core)) { + if ((typeof (value_mantle) == "object") + && + (value_mantle != null) + && + options.deep) { + if (value_mantle instanceof Array) { + core[key] = []; + value_mantle.forEach(function (element) { + if ((typeof (element) == "object") + && + (element != null)) { + var element_ = {}; + patch(element_, element); + core[key].push(element_); + } + else { + core[key].push(element); + } + }); } else { - line += ([] - .concat(((_c = this.parameters["indicators_short"]) !== null && _c !== void 0 ? _c : []).map(function (indicator) { return ("-" + indicator + " " + ("<" + _this.name + ">")); })) - .concat(((_d = this.parameters["indicators_long"]) !== null && _d !== void 0 ? _d : []).map(function (indicator) { return ("--" + indicator + "=" + ("<" + _this.name + ">")); })) - .join(" | ")); + core[key] = {}; + patch(core[key], value_mantle, { + "deep": options.deep, + "path": path_ + }); } - line += "\n"; - output += line; + } + else { + core[key] = value_mantle; } } - } - { - var line = ""; - line += "\t\t"; - var infotext = ((this.info == null) ? "(no info available)" : this.info); - line += infotext; - if ((this.type != "boolean") && (this.default_ != null)) { - line += "; default: ".concat(this.default_.toString()); + else { + var value_core = core[key]; + if (typeof (value_core) == typeof (value_mantle)) { + if ((typeof (value_mantle) == "object") + && + (value_mantle != null) + && + options.deep) { + patch(core[key], value_mantle, { + "deep": options.deep, + "path": path_ + }); + } + else { + core[key] = value_mantle; + } + } + else { + if ((value_core != null) + && + (value_mantle != null)) { + lib_plankton.log.warning("object_path_different_shapes", { + "path": path_, + "core_type": typeof (value_core), + "mantle_type": typeof (value_mantle) + }); + } + core[key] = value_mantle; + // throw (new Error(message)); + } } - line += "\n"; - output += line; - } - return output; - }; - return class_argument; - }()); - args.class_argument = class_argument; - })(args = lib_plankton.args || (lib_plankton.args = {})); + }); + } + } + object_1.patch = patch; + /** + * @deprecated use Object.assign instead! + */ + function patched(core, mantle, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "deep": true + }, options); + var result = {}; + patch(result, core, { "deep": options.deep }); + patch(result, mantle, { "deep": options.deep }); + return result; + } + object_1.patched = patched; + /** + * @deprecated use Object.assign instead! + */ + function attached(object, key, value) { + var mantle = {}; + mantle[key] = value; + return patched(object, mantle, { "deep": false }); + } + object_1.attached = attached; + /** + * @author fenris + */ + function copy(object) { + return patched({}, object); + } + object_1.copy = copy; + })(object = lib_plankton.object || (lib_plankton.object = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:args«. +This file is part of »bacterio-plankton:pair«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:args« is free software: you can redistribute it and/or modify +»bacterio-plankton:pair« 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:args« is distributed in the hope that it will be useful, +»bacterio-plankton:pair« 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:args«. If not, see . +along with »bacterio-plankton:pair«. If not, see . + */ +/* +This file is part of »bacterio-plankton:pair«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pair« 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:pair« 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:pair«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var args; - (function (args) { + var pair; + (function (pair_1) { /** - * @author fenris */ - var settings = { - "environment": { - "cli": { - "symbols": { - "delimiter": " ", - "prefix": "--", - "assignment": "=" - } - }, - "url": { - "symbols": { - "delimiter": "&", - "prefix": "", - "assignment": "=" - } - } - } - }; - /** - * @author fenris - */ - args.verbosity = 0; - /** - * @author fenris - * @todo check validity - */ - var class_handler = /** @class */ (function () { - /** - * @author fenris - */ - function class_handler(arguments_) { - this.arguments_ = arguments_; - } - /** - * @author fenris - */ - class_handler.prototype.filter = function (kind) { - var arguments_ = {}; - for (var _i = 0, _a = Object.entries(this.arguments_); _i < _a.length; _i++) { - var _b = _a[_i], name = _b[0], argument = _b[1]; - if (argument.kind_get() == kind) { - arguments_[name] = argument; - } - } - return arguments_; + function swap(pair) { + return { + "first": pair.second, + "second": pair.first }; - /** - * @author fenris - */ - class_handler.prototype.read = function (environment, input, data) { - var _this = this; - if (data === void 0) { data = {}; } - switch (environment) { - case args.enum_environment.cli: - case args.enum_environment.url: { - // default values - { - for (var _i = 0, _a = Object.entries(this.arguments_); _i < _a.length; _i++) { - var _b = _a[_i], name = _b[0], argument = _b[1]; - data[name] = argument.default_get(); + } + pair_1.swap = swap; + /** + */ + function show(pair, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "show_first": instance_show, + "show_second": instance_show + }, options); + return ("(" + + + options.show_first(pair.first) + + + "," + + + options.show_second(pair.second) + + + ")"); + } + pair_1.show = show; + })(pair = lib_plankton.pair || (lib_plankton.pair = {})); +})(lib_plankton || (lib_plankton = {})); +"use strict"; +/* +This file is part of »bacterio-plankton:list«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:list« 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:list« 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:list«. If not, see . + */ +/* +This file is part of »bacterio-plankton:list«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:list« 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:list« 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:list«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var list; + (function (list_1) { + /** + * returns a certain list of integer numbers + */ + function range(from, to, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "step": 1 + }, options); + var list = []; + for (var value = from; value <= to; value += options.step) { + list.push(value); + } + return list; + } + list_1.range = range; + /** + * returns a certain list of consecutiv integer numbers, beginning with 0 + */ + function sequence(length) { + return range(0, length - 1); + } + list_1.sequence = sequence; + /** + */ + function from_iterator(iterator) { + var list = []; + // @ts-ignore + for (var _i = 0, iterator_1 = iterator; _i < iterator_1.length; _i++) { + var element = iterator_1[_i]; + list.push(element); + } + return list; + } + list_1.from_iterator = from_iterator; + /** + */ + function is_empty(list) { + return (list.length <= 0); + } + list_1.is_empty = is_empty; + /** + * combines two lists into one + * + * @param {boolean} [options.cut] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths; default: true + */ + function zip(list_first, list_second, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "cut": true + }, options); + var empty_first = is_empty(list_first); + var empty_second = is_empty(list_second); + if (empty_first || empty_second) { + if (options.cut || (empty_first && empty_second)) { + return []; + } + else { + throw (new Error("lists have different lengths")); + } + } + else { + return ([{ "first": list_first[0], "second": list_second[0] }] + .concat(zip(list_first.slice(1), list_second.slice(1), { + "cut": options.cut + }))); + } + } + list_1.zip = zip; + /** + * checks whether two lists are equal + * + * @todo define common function "equals" and default predicate to + */ + function equals(list1, list2, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "collate_element": instance_collate + }, options); + if (list1.length == list2.length) { + return (zip(list1, list2, { "cut": true }) + .every(function (pair) { return options.collate_element(pair.first, pair.second); })); + } + else { + return false; + } + } + list_1.equals = equals; + /** + * creates a list with the elements from the input list, which fulfil a certain predicate (~ filter) + */ + function keep(list, predicate) { + return (list + .filter(function (element, index) { return predicate(element); })); + } + list_1.keep = keep; + /** + * creates a list with the elements from the input list, which do not fulfil a certain predicate (~ dual filter) + */ + function drop(list, predicate) { + return (list + .filter(function (element, index) { return (!predicate(element)); })); + } + list_1.drop = drop; + /** + */ + function filter_inplace(list, predicate) { + var index = 0; + while (index < list.length) { + var element = list[index]; + if (predicate(element)) { + index += 1; + } + else { + list.splice(index, 1); + } + } + } + list_1.filter_inplace = filter_inplace; + /** + * returns a list with no duplicates (like unix' "unique") + */ + function cleaned(list, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "collate_element": instance_collate + }, options); + var list_ = []; + list.forEach(function (element) { + if (!list_.some(function (element_) { return options.collate_element(element, element_); })) { + list_.push(element); + } + else { + // do nothing + } + }); + return list_; + } + list_1.cleaned = cleaned; + /** + * creates a binary partition of the list according to a given predicate + */ + function separate(list, predicate) { + return (list + .reduce(function (seperation, element) { + return (predicate(element) + ? { "yes": seperation.yes.concat([element]), "no": seperation["no"] } + : { "yes": seperation.yes, "no": seperation["no"].concat([element]) }); + }, { "yes": [], "no": [] })); + } + list_1.separate = separate; + ; + /** + */ + function clone(list) { + return keep(list, function (x) { return true; }); + } + list_1.clone = clone; + /** + */ + function reversed(list) { + var list_ = clone(list); + list_.reverse(); + return list_; + } + list_1.reversed = reversed; + /** + * @todo use Array.toSorted? + */ + function sorted(list, options) { + options = Object.assign({ + "compare_element": instance_compare + }, options); + var list_ = clone(list); + list_.sort(function (x, y) { return (options.compare_element(x, y) ? -1 : +1); }); + return list_; + } + list_1.sorted = sorted; + /** + * die Liste in gleich große Blöcke zerlegen + */ + function chop(list, chunk_size) { + var chunks = []; + var index = 0; + while (index < list.length) { + var chunk = list.slice(index, Math.min(list.length, index + chunk_size)); + index += chunk_size; + chunks.push(chunk); + } + return chunks; + } + list_1.chop = chop; + /** + */ + function group(list, collate_element) { + var result = []; + list.forEach(function (element) { + var target = result.find( + // @ts-ignore + function (group) { return collate_element(group[0], element); }); + if (target === undefined) { + target = []; + result.push(target); + } + target.push(element); + }); + return result; + } + list_1.group = group; + /** + */ + function has(list, predicate) { + return (list.find(predicate) !== undefined); + } + list_1.has = has; + /** + * @deprecate use Array.includes or Array.some + */ + function contains(list, element, options) { + options = Object.assign({ + "collate": instance_collate + }, options); + return has(list, function (element_) { return options.collate_element(element_, element); }); + } + list_1.contains = contains; + /** + * retrieves the element and its index of the list, which has the maximum value + */ + function max(list, target_function, options) { + options = Object.assign({ + "compare_value": instance_compare + }, options); + if (is_empty(list)) { + throw (new Error("the max-arg of an empty list is not defined")); + } + else { + return (list + .reduce(function (result, element, index) { + var value = target_function(element); + if ((result == null) + || + (!options.compare_value(value, result.value))) { + return { "index": index, "element": element, "value": value }; + } + else { + return result; + } + }, null)); + } + } + list_1.max = max; + /** + * retrieves the element and its index of the list, which has the mininum value + */ + function min(list, target_function, options) { + options = Object.assign({ + "compare_value": instance_compare + }, options); + return max(list, target_function, { + "compare_value": function (x, y) { return options.compare_value(y, x); } + }); + } + list_1.min = min; + /** + * implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)" + * example: distribute([[1,2],[3],[4,5,6]]) = [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]] + */ + function distribute(lists) { + if (is_empty(lists)) { + return [[]]; + } + else { + var subresult_1 = distribute(lists.slice(1)); + return (lists[0] + .map(function (element) { return subresult_1.map(function (list) { return [element].concat(list); }); }) + .reduce(function (x, y) { return x.concat(y); }, [])); + } + } + list_1.distribute = distribute; + /** + */ + function contrast(list_left, extract_key_left, list_right, extract_key_right) { + var gathering = {}; + list_left.forEach(function (source_left) { + var _a; + var key = extract_key_left(source_left); + gathering[key] = Object.assign(((_a = gathering[key]) !== null && _a !== void 0 ? _a : {}), { "left": source_left }); + }); + list_right.forEach(function (source_right) { + var _a; + var key = extract_key_right(source_right); + gathering[key] = Object.assign(((_a = gathering[key]) !== null && _a !== void 0 ? _a : {}), { "right": source_right }); + }); + var result = { + "both": [], + "only_left": [], + "only_right": [] + }; + Object.entries(gathering).forEach(function (_a) { + var key = _a[0], value = _a[1]; + if ("left" in value) { + if ("right" in value) { + result.both.push({ "key": key, "left": value.left, "right": value.right }); + } + else { + result.only_left.push({ "key": key, "left": value.left }); + } + } + else { + if ("right" in value) { + result.only_right.push({ "key": key, "right": value.right }); + } + else { + // impossible + // do nothing + } + } + }); + return result; + } + list_1.contrast = contrast; + })(list = lib_plankton.list || (lib_plankton.list = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:conf«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:conf« 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:conf« 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:conf«. If not, see . + */ +/* +This file is part of »bacterio-plankton:conf«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:conf« 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:conf« 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:conf«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var conf; + (function (conf) { + /** + */ + function adapt_primitive(schema, value) { + if (value === undefined) { + if (!("default" in schema)) { + return { + "reports": [ + { + "incident": "neither explicit value provided nor default value specified", + "details": {} + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + return { + "reports": [], + "result": lib_plankton.pod.make_filled(schema.default), + }; + } + } + else { + if (value === null) { + if (("nullable" in schema) + && + (!schema.nullable)) { + return { + "reports": [ + { + "incident": "null not allowed", + "details": {} + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + return { + "reports": [], + "result": lib_plankton.pod.make_filled(null), + }; + } + } + else { + if (("enum" in schema) + && + (!schema.enum.includes(value))) { + return { + "reports": [ + { + "incident": "provided value not in enumeration of valid values", + "details": { + "enumerated_values": schema.enum, + "provided_value": value, + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + const type_map = { + "boolean": "boolean", + "integer": "number", + "number": "number", + "string": "string", + }; + // @ts-ignore + if (!(typeof (value) === type_map[schema.type])) { + return { + "reports": [ + { + // @ts-ignore + "incident": ("value should be " + type_map[schema.type]), + "details": { + "provided_value": value, + "type": typeof (value), + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + return { + "reports": [], + "result": lib_plankton.pod.make_filled(value) + }; + } + } + } + } + } + /** + * @todo anyOf + * @todo allOf + * @todo oneOf + * @todo not + * @todo tests + */ + function adapt(schema, value_raw) { + let value = value_raw; + if (!("type" in schema)) { + if ("anyOf" in schema) { + if (value === undefined) { + if (!("default" in schema)) { + return { + "reports": [ + { + "incident": "neither explicit value provided nor default value specified", + "details": {} + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + value = schema.default; + } + } + else { + // do nothing + } + const sub_adaptions = (schema.anyOf + .map((sub_schema) => adapt(sub_schema, value))); + const valid_sub_adaptions = (sub_adaptions + .filter((sub_adaption) => lib_plankton.pod.is_filled(sub_adaption.result))); + if (valid_sub_adaptions.length <= 0) { + return { + "reports": [ + { + "incident": "no valid apaptions", + "details": { + "sub_adaptions": sub_adaptions, + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + if (valid_sub_adaptions.length > 1) { + return { + "reports": [ + { + "incident": "multiple valid apaptions", + "details": { + "valid_sub_adaptions": valid_sub_adaptions, + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + return valid_sub_adaptions[0]; + } + } + } + else { + throw (new Error("not implemented")); + } + } + else { + switch (schema.type) { + case "boolean": + return adapt_primitive(schema, value); + break; + case "integer": + return adapt_primitive(schema, value); + break; + case "number": + return adapt_primitive(schema, value); + break; + case "string": { + return adapt_primitive(schema, value); + break; + } + case "array": { + if (value === undefined) { + if (!("default" in schema)) { + return { + "reports": [ + { + "incident": "neither explicit value provided nor default value specified", + "details": {} + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + value = schema.default; } } - // preprocessing - { - // short indicators (lil hacky ...) - { - if (environment == args.enum_environment.cli) { - for (var _c = 0, _d = Object.entries(this.filter(args.enum_kind.volatile)); _c < _d.length; _c++) { - var _e = _d[_c], name = _e[0], argument = _e[1]; - // console.info(argument.parameters_get()["indicators_short"].join("|")); - var pattern_from = ""; - { - pattern_from += "(?:^|".concat(settings["environment"][environment]["symbols"]["delimiter"], ")"); - pattern_from += "-".concat(argument.parameters_get()["indicators_short"].join("|")); - pattern_from += "(?:$|".concat(settings["environment"][environment]["symbols"]["delimiter"], ")"); - } - var pattern_to = ""; - { - pattern_to += settings["environment"][environment]["symbols"]["delimiter"]; - pattern_to += settings["environment"][environment]["symbols"]["prefix"]; - pattern_to += argument.indicator_main(); - if (argument.type_get() == args.enum_type.boolean) { - pattern_to += settings["environment"][environment]["symbols"]["delimiter"]; + /*else*/ { + if (value === null) { + if (("nullable" in schema) + && + (!schema.nullable)) { + return { + "reports": [ + { + "incident": "null not allowed", + "details": {} } - else { - pattern_to += settings["environment"][environment]["symbols"]["assignment"]; + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + return { + "reports": [], + "result": lib_plankton.pod.make_filled(null), + }; + } + } + else { + /*if ( + ("enum" in schema) + && + (! schema.enum.includes(value)) // TODO + ) { + return { + "reports": [ + { + "incident": "provided value not in enumeration of valid values", + "details": { + "enumerated_values": schema.enum, + "provided_value": value, + } } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else*/ { + if ((!(typeof (value) === "object")) + && + (value.constructor.name !== "Array")) { + return { + "reports": [ + { + "incident": "value should be array", + "details": { + "provided_value": value, + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + if (!("items" in schema)) { + // do nothing + return { + "reports": [], + "result": lib_plankton.pod.make_filled(value), + }; + } + else { + let reports = []; + for (let index = 0; index < value.length; index += 1) { + const adaption = adapt(schema.items, value[index]); + if (!lib_plankton.pod.is_filled(adaption.result)) { + reports = reports.concat(adaption.reports.map((report_entry) => ({ + "incident": report_entry.incident, + "details": Object.assign(report_entry.details, { + "path": (report_entry.details.path ?? []).concat([index]) + }), + }))); + } + else { + value[index] = lib_plankton.pod.cull(adaption.result); + } + } + return { + "reports": reports, + "result": ((reports.length > 0) + ? + lib_plankton.pod.make_empty() + : + lib_plankton.pod.make_filled(value)), + }; } - var result = input.replace(new RegExp(pattern_from, "g"), pattern_to); - lib_plankton.log.debug("lib_args:read:replacing", { - "pattern_from": pattern_from, - "pattern_to": pattern_to, - "input": input, - "result": result - }); - input = result; } } } - lib_plankton.log.debug("lib_args:read:current_input", { - "input": input - }); } - // parsing - { - var parts = input - .split(settings["environment"][environment]["symbols"]["delimiter"]) - .filter(function (x) { return (x != ""); }); - var index_expected_1 = 0; - parts.forEach(function (part) { - lib_plankton.log.debug("lib_args:read:analyzing", { - "part": part - }); - var found = [ - function () { - lib_plankton.log.debug("lib_args:read:probing_as_volatile", { - "part": part - }); - for (var _i = 0, _a = Object.entries(_this.filter(args.enum_kind.volatile)); _i < _a.length; _i++) { - var _b = _a[_i], name = _b[0], argument = _b[1]; - lib_plankton.log.debug("lib_args:read:probing_as_volatile:trying", { - "part": part, - "argument": argument.toString() - }); - var pattern = ""; - { - var pattern_front = ""; - pattern_front += "".concat(settings["environment"][environment]["symbols"]["prefix"]); - pattern_front += "(?:".concat(argument.parameters_get()["indicators_long"].join("|"), ")"); - pattern += pattern_front; - } - { - var pattern_back = ""; - pattern_back += "".concat(settings["environment"][environment]["symbols"]["assignment"]); - pattern_back += "(".concat(argument.pattern_value(), ")"); - if (argument.type_get() == args.enum_type.boolean) { - pattern_back = "(?:".concat(pattern_back, ")?"); - } - pattern += pattern_back; - } - lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", { - "pattern": pattern - }); - var regexp = new RegExp(pattern); - var matching = regexp.exec(part); - lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", { - "matching": matching - }); - if (matching == null) { - // do nothing - } - else { - argument.assign(data, name, matching[1]); - return true; - } + break; + } + case "object": { + if (value === undefined) { + if (!("default" in schema)) { + return { + "reports": [ + { + "incident": "neither explicit value provided nor default value specified", + "details": {} } - return false; - }, - function () { - lib_plankton.log.debug("lib_args:read:probing_as_positional", { - "part": part - }); - var positional = _this.filter(args.enum_kind.positional); - for (var _i = 0, _a = Object.entries(positional); _i < _a.length; _i++) { - var _b = _a[_i], name = _b[0], argument = _b[1]; - if (argument.parameters_get()['index'] !== index_expected_1) { + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + value = schema.default; + } + } + /*else*/ { + if (value === null) { + if (("nullable" in schema) + && + (!schema.nullable)) { + return { + "reports": [ + { + "incident": "null not allowed", + "details": {} + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + return { + "reports": [], + "result": lib_plankton.pod.make_filled(null), + }; + } + } + else { + /*if ( + ("enum" in schema) + && + (! schema.enum.includes(value)) // TODO + ) { + return { + "reports": [ + { + "incident": "provided value not in enumeration of valid values", + "details": { + "enumerated_values": schema.enum, + "provided_value": value, + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else*/ { + if (!(typeof (value) === "object")) { + return { + "reports": [ + { + "incident": "value should be object", + "details": { + "provided_value": value, + } + } + ], + "result": lib_plankton.pod.make_empty(), + }; + } + else { + value = lib_plankton.object.copy(value); + const contrast = lib_plankton.list.contrast(Object.keys(schema.properties), x => x, Object.keys(value), x => x); + let reports = []; + // gratuitous fields + { + if (contrast.only_right.length <= 0) { // do nothing } else { - lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", { - "part": part, - "argument": argument.toString() - }); - var pattern = ""; - { - var pattern_back = ""; - pattern_back += "(".concat(argument.pattern_value(), ")"); - pattern += pattern_back; - } - lib_plankton.log.debug("lib_args:read:probing_as_positional:pattern", { - "pattern": pattern - }); - var regexp = new RegExp(pattern); - var matching = regexp.exec(part); - lib_plankton.log.debug("lib_args:read:probing_as_positional:matching", { - "matching": matching - }); - if (matching == null) { - return false; + const additional_properties = (schema.additionalProperties ?? false); + if (additional_properties === false) { + reports = reports.concat(contrast.only_right + .map((entry) => ({ + "incident": "gratuitous field", + "details": { + "path": [entry.right], + } + }))); } else { - argument.assign(data, name, matching[1]); - index_expected_1 += 1; - return true; + contrast.only_right.forEach((entry) => { + const sub_adaption = adapt(additional_properties, value[entry.right]); + if (!lib_plankton.pod.is_filled(sub_adaption.result)) { + reports = reports.concat(sub_adaption.reports + .map((report_entry) => ({ + "incident": report_entry.incident, + "details": Object.assign(report_entry.details, { + "path": (report_entry.details.path ?? []).concat([entry.right]) + }), + }))); + } + else { + value[entry.right] = lib_plankton.pod.cull(sub_adaption.result); + } + }); } } } - return false; - }, - ].some(function (x) { return x(); }); - if (!found) { - lib_plankton.log.warning("lib_args:read:could_not_parse", { - "part": part - }); + // missing fields + { + contrast.only_left.forEach((entry) => { + if (("required" in schema) + && + schema.required.includes(entry.left)) { + reports.push({ + "incident": "missing field", + "details": { + "path": [entry.left], + } + }); + } + else { + const sub_adaption = adapt(schema.properties[entry.left], undefined); + if (!lib_plankton.pod.is_filled(sub_adaption.result)) { + reports = reports.concat(sub_adaption.reports + .map((report_entry) => ({ + "incident": report_entry.incident, + "details": Object.assign(report_entry.details, { + "path": (report_entry.details.path ?? []).concat([entry.left]) + }), + }))); + } + else { + value[entry.left] = lib_plankton.pod.cull(sub_adaption.result); + } + } + }); + // regular fields + { + contrast.both.forEach((entry) => { + const sub_adaption = adapt(schema.properties[entry.left], value[entry.right]); + if (!lib_plankton.pod.is_filled(sub_adaption.result)) { + reports = reports.concat(sub_adaption.reports + .map((report_entry) => ({ + "incident": report_entry.incident, + "details": Object.assign(report_entry.details, { + "path": (report_entry.details.path ?? []).concat([entry.right]) + }), + }))); + } + else { + value[entry.right] = lib_plankton.pod.cull(sub_adaption.result); + } + }); + } + return { + "reports": reports, + "result": ((reports.length > 0) + ? + lib_plankton.pod.make_empty() + : + lib_plankton.pod.make_filled(value)), + }; + } + } } - }); + } } - return data; break; } default: { - throw (new Error("unhandled environment ".concat(environment))); + throw (new Error("unhandled schema type: " + schema.type)); break; } } - }; - /** - * @author fenris - * @todo handle if the data object doesn't have the required field or the type is wrong or sth. - */ - class_handler.prototype.write = function (environment, data) { - switch (environment) { - case args.enum_environment.cli: { - return (([] - .concat(Object.entries(this.filter(args.enum_kind.volatile)).map(function (_a) { - var name = _a[0], argument = _a[1]; - var values; - switch (argument.mode_get()) { - case args.enum_mode.replace: { - values = [data[argument.name_get()]]; - break; - } - case args.enum_mode.accumulate: { - values = data[argument.name_get()]; - break; - } - } - return (values - .map(function (value) { return ((settings["environment"][environment]["symbols"]["prefix"] - + - argument.parameters_get()["indicators_long"][0]) - + - (settings["environment"][environment]["symbols"]["assignment"] - + - value.toString())); }) - .join(" ")); - })) - .concat(Object.entries(this.filter(args.enum_kind.positional)).map(function (_a) { - var name = _a[0], argument = _a[1]; - var raw = ""; - { - var raw_back = ""; - raw_back += argument.make(data, name); - raw += raw_back; - } - return raw; - }))) - .join(settings["environment"][environment]["symbols"]["delimiter"])); - break; - } - default: { - throw (new Error("unhandled environment ".concat(environment))); - break; - } - } - }; - /** - * @desc manpage-like info-sheet - * @author fenris - */ - class_handler.prototype.generate_help = function (_a) { - var _b = _a["programname"], programname = _b === void 0 ? null : _b, _c = _a["author"], author = _c === void 0 ? null : _c, _d = _a["description"], description = _d === void 0 ? null : _d, _e = _a["executable"], executable = _e === void 0 ? null : _e; - var environment = args.enum_environment.cli; - var output = ""; - { - var section = ""; - { - var line = ""; - line += ""; - line += "INFO"; - line += "\n"; - section += line; - } - { - var line = ""; - line += "\t"; - line += "".concat(programname, " -- ").concat(description); - line += "\n"; - section += line; - } - section += "\n"; - output += section; - } - { - if (author != null) { - var section = ""; - { - var line = ""; - line += ""; - line += "AUTHOR"; - line += "\n"; - section += line; - } - { - var line = ""; - line += "\t"; - line += "".concat(author); - line += "\n"; - section += line; - } - section += "\n"; - output += section; - } - } - { - var section = ""; - { - var line = ""; - line += ""; - line += "SYNOPSIS"; - line += "\n"; - section += line; - } - { - var line = ""; - line += "\t"; - line += executable; - line += settings["environment"][environment]["symbols"]["delimiter"]; - line += Object.entries(this.filter(args.enum_kind.positional)) - .map(function (_a) { - var name = _a[0], argument = _a[1]; - var part = ""; - part += "<".concat(argument.name_get(), ">"); - return part; - }) - .join(settings["environment"][environment]["symbols"]["delimiter"]); - line += settings["environment"][environment]["symbols"]["delimiter"]; - line += Object.entries(this.filter(args.enum_kind.volatile)) - .filter(function (_a) { - var name = _a[0], argument = _a[1]; - return (!argument.hidden_get()); - }) - .map(function (_a) { - var name = _a[0], argument = _a[1]; - var part = ""; - // part += settings["environment"][environment]["symbols"]["prefix"]; - part += "-"; - part += argument.parameters_get()["indicators_short"][0]; - if (argument.type_get() != "boolean") { - /* - part += settings["environment"][environment]["symbols"]["assignment"]; - part += `<${argument.name_get()}>`; - */ - part += " "; - part += "<".concat(argument.name_get(), ">"); - } - part = "[".concat(part, "]"); - return part; - }) - .join(settings["environment"][environment]["symbols"]["delimiter"]); - line += "\n"; - section += line; - } - section += "\n"; - output += section; - } - { - var section = ""; - { - var line = ""; - line += ""; - line += "OPTIONS"; - line += "\n"; - section += line; - } - { - section += (Object.entries(this.arguments_) - .filter(function (_a) { - var name = _a[0], argument = _a[1]; - return (!argument.hidden_get()); - }) - .map(function (_a) { - var name = _a[0], argument = _a[1]; - return argument.generate_help(); - }) - .join("\n")); - } - section += "\n"; - output += section; - } - return output; - }; - return class_handler; - }()); - args.class_handler = class_handler; - })(args = lib_plankton.args || (lib_plankton.args = {})); + } + } + /** + * @todo versioning + */ + function refine(schema, value_raw) { + const adaption = adapt(schema, value_raw); + if (!lib_plankton.pod.is_filled(adaption.result)) { + throw (new Error("conf could not be loaded:\n" + + + (adaption.reports + .map((report) => ("- " + report.incident + " | " + JSON.stringify(report.details, undefined, "\t"))) + .join("\n")))); + } + else { + return lib_plankton.pod.cull(adaption.result); + } + } + conf.refine = refine; + /** + */ + function load(schema, path) { + return (((path === null) + ? + Promise.resolve(undefined) + : + (lib_plankton.file.read(path) + .then((content) => Promise.resolve(lib_plankton.json.decode(content))))) + .then((data_raw) => Promise.resolve(refine(schema, data_raw)))); + } + conf.load = load; + })(conf = lib_plankton.conf || (lib_plankton.conf = {})); })(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:string«. @@ -4485,6 +5112,408 @@ var make_logger = (function () { return make_logger; })(); /* +This file is part of »bacterio-plankton:database«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:database« 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:database« 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:database«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var database; + (function (database) { + /** + */ + let enum_type; + (function (enum_type) { + enum_type["boolean"] = "boolean"; + enum_type["integer"] = "integer"; + enum_type["string_short"] = "string_short"; + enum_type["string_medium"] = "string_medium"; + enum_type["string_long"] = "string_long"; + enum_type["float"] = "float"; + })(enum_type = database.enum_type || (database.enum_type = {})); + })(database = lib_plankton.database || (lib_plankton.database = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« 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:storage« 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:storage«. If not, see . + */ +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« 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:storage« 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:storage«. If not, see . + */ +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« 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:storage« 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:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var memory; + (function (memory) { + /** + * @author fenris + */ + function make(parameters) { + return { + "data": {} + }; + } + memory.make = make; + /** + * @author fenris + */ + function clear(subject) { + subject.data = {}; + } + memory.clear = clear; + /** + * @author fenris + */ + function write(subject, key, value) { + var exists = (key in subject.data); + subject.data[key] = value; + return exists; + } + memory.write = write; + /** + * @author fenris + */ + function delete_(subject, key) { + if (!(key in subject.data)) { + throw (new Error("no value for key '" + key + "'")); + } + else { + delete subject.data[key]; + } + } + memory.delete_ = delete_; + /** + * @author fenris + */ + function read(subject, key) { + if (!(key in subject.data)) { + throw (new Error("no value for key '" + key + "'")); + } + else { + return subject.data[key]; + } + } + memory.read = read; + /** + * @author fenris + */ + function list(subject) { + return Object.keys(subject.data); + } + memory.list = list; + /** + * @author fenris + */ + function search(subject, term) { + return (list(subject) + .map(function (key) { return ({ "key": key, "preview": key }); })); + } + memory.search = search; + /** + * @author fenris + */ + function implementation_chest(parameters) { + function wrap(core) { + return (new Promise(function (resolve, reject) { resolve(core()); })); + } + var subject = make(parameters); + return { + "setup": function (input) { return Promise.resolve(undefined); }, + "clear": function () { return wrap(function () { return clear(subject); }); }, + "write": function (key, value) { return wrap(function () { return write(subject, key, value); }); }, + "delete": function (key) { return wrap(function () { return delete_(subject, key); }); }, + "read": function (key) { return wrap(function () { return read(subject, key); }); }, + "search": function (term) { return wrap(function () { return search(subject, term); }); } + }; + } + memory.implementation_chest = implementation_chest; + })(memory = storage.memory || (storage.memory = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« 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:storage« 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:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var memory; + (function (memory) { + /** + * @author fenris + */ + var class_chest = /** @class */ (function () { + function class_chest(parameters) { + this.subject = memory.make(parameters); + } + class_chest.prototype.setup = function (input) { return Promise.resolve(undefined); }; + class_chest.prototype.clear = function () { memory.clear(this.subject); return Promise.resolve(undefined); }; + class_chest.prototype.write = function (key, value) { return Promise.resolve(memory.write(this.subject, key, value)); }; + class_chest.prototype["delete"] = function (key) { memory.delete_(this.subject, key); return Promise.resolve(undefined); }; + class_chest.prototype.read = function (key) { return Promise.resolve(memory.read(this.subject, key)); }; + class_chest.prototype.search = function (term) { return Promise.resolve(memory.search(this.subject, term)); }; + return class_chest; + }()); + memory.class_chest = class_chest; + })(memory = storage.memory || (storage.memory = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« 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:storage« 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:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var localstorage; + (function (localstorage) { + /** + * @author fenris + */ + function make(parameters) { + parameters = Object.assign({ + "corner": "plankton" + }, parameters); + return { + "corner": parameters.corner + }; + } + localstorage.make = make; + /** + */ + function compose_full_key(subject, key) { + return (subject.corner + "_" + key); + } + /** + */ + function decompose_full_key(subject, full_key) { + var parts = full_key.split("_"); + return ((parts[0] === subject.corner) + ? parts.slice(1).join("_") + : null); + } + /** + * @author fenris + */ + function has(subject, key) { + return localStorage.hasOwnProperty(compose_full_key(subject, key)); + } + /** + * @author fenris + */ + function clear(subject) { + (Object.keys(localStorage) + .map(function (x) { return decompose_full_key(subject, x); }) + .filter(function (x) { return (x !== null); }) + .forEach(function (x) { return localStorage.removeItem(x); })); + } + localstorage.clear = clear; + /** + * @author fenris + */ + function write(subject, key, item) { + var exists = has(subject, key); + localStorage.setItem(compose_full_key(subject, key), item); + return exists; + } + localstorage.write = write; + /** + * @author fenris + */ + function delete_(subject, key) { + localStorage.removeItem(compose_full_key(subject, key)); + } + localstorage.delete_ = delete_; + /** + * @author fenris + */ + function read(subject, key) { + var full_key = compose_full_key(subject, key); + if (!localStorage.hasOwnProperty(full_key)) { + throw (new Error("not found")); + } + else { + return localStorage.getItem(full_key); + } + } + localstorage.read = read; + /** + * @author fenris + */ + function list(subject) { + return (Object.keys(localStorage) + .map(function (x) { return decompose_full_key(subject, x); }) + .filter(function (x) { return (x !== null); })); + } + localstorage.list = list; + /** + */ + function implementation_chest(parameters) { + function wrap(core) { + return (new Promise(function (resolve, reject) { resolve(core()); })); + } + var subject = make(parameters); + return { + "setup": function (input) { return Promise.resolve(undefined); }, + "clear": function () { return wrap(function () { return clear(subject); }); }, + "write": function (key, item) { return wrap(function () { return write(subject, key, item); }); }, + "delete": function (key) { return wrap(function () { return delete_(subject, key); }); }, + "read": function (key) { return wrap(function () { return read(subject, key); }); }, + "search": function (term) { return Promise.resolve(list(subject) + .map(function (key) { return ({ "key": key, "preview": key }); })); } + }; + } + localstorage.implementation_chest = implementation_chest; + })(localstorage = storage.localstorage || (storage.localstorage = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:storage«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:storage« 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:storage« 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:storage«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var storage; + (function (storage) { + var localstorage; + (function (localstorage) { + /** + * uses the browsers localstorage as chest + * + * @author fenris + */ + var class_chest = /** @class */ (function () { + function class_chest(parameters) { + this.subject = localstorage.make(parameters); + } + class_chest.prototype.setup = function (input) { return Promise.resolve(undefined); }; + class_chest.prototype.clear = function () { return Promise.resolve(localstorage.clear(this.subject)); }; + class_chest.prototype.write = function (key, value) { return Promise.resolve(localstorage.write(this.subject, key, value)); }; + class_chest.prototype["delete"] = function (key) { return Promise.resolve(localstorage.delete_(this.subject, key)); }; + class_chest.prototype.read = function (key) { return Promise.resolve(localstorage.read(this.subject, key)); }; + class_chest.prototype.search = function (term) { + return Promise.resolve(localstorage.list(this.subject) + .map(function (key) { return ({ "key": key, "preview": key }); })); + }; + return class_chest; + }()); + localstorage.class_chest = class_chest; + })(localstorage = storage.localstorage || (storage.localstorage = {})); + })(storage = lib_plankton.storage || (lib_plankton.storage = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:complex«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -7287,1413 +8316,6 @@ var lib_plankton; })(url = lib_plankton.url || (lib_plankton.url = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:object«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:object« 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:object« 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:object«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var object; - (function (object_1) { - /** - * @author fenris - * @deprecated use the "??" operator instead - */ - function fetch(object, fieldname, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "fallback": null, - "escalation": 1 - }, options); - if ((fieldname in object) - && - (object[fieldname] !== undefined)) { - return object[fieldname]; - } - else { - if (!options.escalate) { - return options.fallback; - } - else { - throw (new Error("field '" + fieldname + "' not in structure")); - } - } - } - object_1.fetch = fetch; - /** - */ - function map(object_from, transformator) { - return (Object.fromEntries(Object.entries(object_from) - .map(function (_a) { - var key = _a[0], value = _a[1]; - return ([key, transformator(value, key)]); - }))); - } - object_1.map = map; - /** - * gibt ein Objekt mit bestimmten Einträgen des Eingabe-Objekts zurück - */ - function filter(object_from, predicate) { - return (Object.fromEntries(Object.entries(object_from) - .filter(function (_a) { - var key = _a[0], value = _a[1]; - return predicate(value, key); - }))); - } - object_1.filter = filter; - /** - * wandelt ein Array mit Einträgen der Form {key,value} in ein entsprechendes Objekt um - * - * @deprecated use Object.fromEntries instead! - */ - function from_array(array) { - return (Object.fromEntries(array - .map(function (_a) { - var key = _a["key"], value = _a["value"]; - return ([key, value]); - }))); - } - object_1.from_array = from_array; - /** - * wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form {key,value} um - * - * @deprecated use Object.entries insetad! - */ - function to_array(object) { - return (Object.entries(object) - .map(function (_a) { - var key = _a[0], value = _a[1]; - return ({ "key": key, "value": value }); - })); - } - object_1.to_array = to_array; - /** - * gibt eine Liste von Schlüsseln eines Objekts zurück - * - * @deprecated use Object.keys instead! - */ - function keys(object) { - return Object.keys(object); - } - object_1.keys = keys; - /** - * gibt eine Liste von Werten eines Objekts zurück - * - * @deprecated use Object.values instead! - */ - function values(object) { - return Object.values(object); - } - object_1.values = values; - /** - * liest ein Baum-artiges Objekt an einer bestimmten Stelle aus - */ - function path_read(object, path, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "fallback": null, - "escalate": false - }, options); - var steps = ((path.length == 0) ? [] : path.split(".")); - if (steps.length == 0) { - throw (new Error("empty path")); - } - else { - var position_1 = object; - var reachable = ((position_1 != null) - && - (steps.slice(0, steps.length - 1) - .every(function (step) { - position_1 = lib_plankton.object.fetch(position_1, step, { - "fallback": null, - "escalate": false - }); - return (position_1 != null); - }))); - if (reachable) { - return lib_plankton.object.fetch(position_1, steps[steps.length - 1], { - "fallback": options.fallback, - "escalate": options.escalate - }); - } - else { - return lib_plankton.object.fetch({}, "_dummy_", { - "fallback": options.fallback, - "escalate": options.escalate - }); - } - } - } - object_1.path_read = path_read; - /** - * schreibt einen Wert an eine bestimmte Stelle in einem Baum-artigen Objekt - */ - function path_write(object, path, value, construct) { - if (construct === void 0) { construct = true; } - var steps = ((path.length == 0) ? [] : path.split(".")); - if (steps.length == 0) { - throw (new Error("empty path")); - } - else { - var position_2 = object; - var reachable = steps.slice(0, steps.length - 1).every(function (step) { - var position_ = lib_plankton.object.fetch(position_2, step, { - "fallback": null, - "escalate": false - }); - if (position_ == null) { - if (construct) { - position_2[step] = {}; - position_2 = position_2[step]; - return true; - } - else { - return false; - } - } - else { - position_2 = position_; - return true; - } - }); - if (reachable) { - position_2[steps[steps.length - 1]] = value; - } - else { - throw (new Error("path '" + path + "' does not exist and may not be constructed")); - } - } - } - object_1.path_write = path_write; - /** - * prüft ob ein Objekt einem bestimmten Muster entspricht - * - * @deprecated not very useful - */ - function matches(object, pattern, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "collate": instance_collate - }, options); - return (Object.entries(pattern) - .every(function (_a) { - var key = _a[0], value = _a[1]; - return options.collate(value, object[key]); - })); - } - object_1.matches = matches; - /** - * erzeugt eine Projektion eines Baum-artigen Objekts in ein Listen-artiges Objekt - */ - function flatten(value, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "separator": ".", - "key_for_array_element": (function (index) { return ("element_" + index.toFixed(0)); }) - }, options); - var integrate = function (result, key, value) { - if (value == null) { - result[key] = value; - } - else { - // primitive Werte direkt übernehmen - if (typeof (value) != "object") { - result[key] = value; - } - // sonst durch rekursiven Aufruf die flache Variante des Wertes ermitteln und einarbeiten - else { - var result_ = flatten(value, { - "separator": options.separator, - "key_for_array_element": options.key_for_array_element - }); - Object.entries(result_).forEach(function (_a) { - var key_ = _a[0], value_ = _a[1]; - result[(key + options.separator + key_)] = value_; - }); - } - } - }; - if ((value === null) - || - (value === undefined)) { - return null; - } - else { - var result_1 = {}; - if (typeof (value) != "object") { - result_1["value"] = value; - } - else { - if (value instanceof Array) { - value.forEach(function (element, index) { - integrate(result_1, options.key_for_array_element(index), element); - }); - } - else { - Object.entries(value).forEach(function (_a) { - var key = _a[0], value = _a[1]; - integrate(result_1, key, value); - }); - } - } - return result_1; - } - } - object_1.flatten = flatten; - /** - * @deprecated use Object.assign instead! - */ - function clash(x, y, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "overwrite": true, - "hooks": { - "existing": function (key, value_old, value_new) { - lib_plankton.log.warning("object_clash_field_already_defined", { - "key": key - }); - } - } - }, options); - var z = {}; - Object.keys(x).forEach(function (key) { - z[key] = x[key]; - }); - Object.keys(y).forEach(function (key) { - if (key in z) { - if (options.hooks.existing != null) { - options.hooks.existing(key, z[key], y[key]); - } - if (options.overwrite) { - z[key] = y[key]; - } - } - else { - z[key] = y[key]; - } - }); - return z; - } - object_1.clash = clash; - /** - * @deprecated use Object.assign instead! - */ - function patch(core, mantle, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "deep": true, - "path": null - }, options); - if (mantle == null) { - lib_plankton.log.warning("object_patch_mantle_is_null", { - "core": core - }); - } - else { - Object.keys(mantle).forEach(function (key) { - var path_ = ((options.path == null) - ? - key - : - (options.path + "." + key)); - var value_mantle = mantle[key]; - if (!(key in core)) { - if ((typeof (value_mantle) == "object") - && - (value_mantle != null) - && - options.deep) { - if (value_mantle instanceof Array) { - core[key] = []; - value_mantle.forEach(function (element) { - if ((typeof (element) == "object") - && - (element != null)) { - var element_ = {}; - patch(element_, element); - core[key].push(element_); - } - else { - core[key].push(element); - } - }); - } - else { - core[key] = {}; - patch(core[key], value_mantle, { - "deep": options.deep, - "path": path_ - }); - } - } - else { - core[key] = value_mantle; - } - } - else { - var value_core = core[key]; - if (typeof (value_core) == typeof (value_mantle)) { - if ((typeof (value_mantle) == "object") - && - (value_mantle != null) - && - options.deep) { - patch(core[key], value_mantle, { - "deep": options.deep, - "path": path_ - }); - } - else { - core[key] = value_mantle; - } - } - else { - if ((value_core != null) - && - (value_mantle != null)) { - lib_plankton.log.warning("object_path_different_shapes", { - "path": path_, - "core_type": typeof (value_core), - "mantle_type": typeof (value_mantle) - }); - } - core[key] = value_mantle; - // throw (new Error(message)); - } - } - }); - } - } - object_1.patch = patch; - /** - * @deprecated use Object.assign instead! - */ - function patched(core, mantle, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "deep": true - }, options); - var result = {}; - patch(result, core, { "deep": options.deep }); - patch(result, mantle, { "deep": options.deep }); - return result; - } - object_1.patched = patched; - /** - * @deprecated use Object.assign instead! - */ - function attached(object, key, value) { - var mantle = {}; - mantle[key] = value; - return patched(object, mantle, { "deep": false }); - } - object_1.attached = attached; - /** - * @author fenris - */ - function copy(object) { - return patched({}, object); - } - object_1.copy = copy; - })(object = lib_plankton.object || (lib_plankton.object = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:pair«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:pair« 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:pair« 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:pair«. If not, see . - */ -/* -This file is part of »bacterio-plankton:pair«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:pair« 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:pair« 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:pair«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var pair; - (function (pair_1) { - /** - */ - function swap(pair) { - return { - "first": pair.second, - "second": pair.first - }; - } - pair_1.swap = swap; - /** - */ - function show(pair, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "show_first": instance_show, - "show_second": instance_show - }, options); - return ("(" - + - options.show_first(pair.first) - + - "," - + - options.show_second(pair.second) - + - ")"); - } - pair_1.show = show; - })(pair = lib_plankton.pair || (lib_plankton.pair = {})); -})(lib_plankton || (lib_plankton = {})); -"use strict"; -/* -This file is part of »bacterio-plankton:list«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:list« 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:list« 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:list«. If not, see . - */ -/* -This file is part of »bacterio-plankton:list«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:list« 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:list« 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:list«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var list; - (function (list_1) { - /** - * returns a certain list of integer numbers - */ - function range(from, to, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "step": 1 - }, options); - var list = []; - for (var value = from; value <= to; value += options.step) { - list.push(value); - } - return list; - } - list_1.range = range; - /** - * returns a certain list of consecutiv integer numbers, beginning with 0 - */ - function sequence(length) { - return range(0, length - 1); - } - list_1.sequence = sequence; - /** - */ - function from_iterator(iterator) { - var list = []; - // @ts-ignore - for (var _i = 0, iterator_1 = iterator; _i < iterator_1.length; _i++) { - var element = iterator_1[_i]; - list.push(element); - } - return list; - } - list_1.from_iterator = from_iterator; - /** - */ - function is_empty(list) { - return (list.length <= 0); - } - list_1.is_empty = is_empty; - /** - * combines two lists into one - * - * @param {boolean} [options.cut] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths; default: true - */ - function zip(list_first, list_second, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "cut": true - }, options); - var empty_first = is_empty(list_first); - var empty_second = is_empty(list_second); - if (empty_first || empty_second) { - if (options.cut || (empty_first && empty_second)) { - return []; - } - else { - throw (new Error("lists have different lengths")); - } - } - else { - return ([{ "first": list_first[0], "second": list_second[0] }] - .concat(zip(list_first.slice(1), list_second.slice(1), { - "cut": options.cut - }))); - } - } - list_1.zip = zip; - /** - * checks whether two lists are equal - * - * @todo define common function "equals" and default predicate to - */ - function equals(list1, list2, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "collate_element": instance_collate - }, options); - if (list1.length == list2.length) { - return (zip(list1, list2, { "cut": true }) - .every(function (pair) { return options.collate_element(pair.first, pair.second); })); - } - else { - return false; - } - } - list_1.equals = equals; - /** - * creates a list with the elements from the input list, which fulfil a certain predicate (~ filter) - */ - function keep(list, predicate) { - return (list - .filter(function (element, index) { return predicate(element); })); - } - list_1.keep = keep; - /** - * creates a list with the elements from the input list, which do not fulfil a certain predicate (~ dual filter) - */ - function drop(list, predicate) { - return (list - .filter(function (element, index) { return (!predicate(element)); })); - } - list_1.drop = drop; - /** - */ - function filter_inplace(list, predicate) { - var index = 0; - while (index < list.length) { - var element = list[index]; - if (predicate(element)) { - index += 1; - } - else { - list.splice(index, 1); - } - } - } - list_1.filter_inplace = filter_inplace; - /** - * returns a list with no duplicates (like unix' "unique") - */ - function cleaned(list, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "collate_element": instance_collate - }, options); - var list_ = []; - list.forEach(function (element) { - if (!list_.some(function (element_) { return options.collate_element(element, element_); })) { - list_.push(element); - } - else { - // do nothing - } - }); - return list_; - } - list_1.cleaned = cleaned; - /** - * creates a binary partition of the list according to a given predicate - */ - function separate(list, predicate) { - return (list - .reduce(function (seperation, element) { - return (predicate(element) - ? { "yes": seperation.yes.concat([element]), "no": seperation["no"] } - : { "yes": seperation.yes, "no": seperation["no"].concat([element]) }); - }, { "yes": [], "no": [] })); - } - list_1.separate = separate; - ; - /** - */ - function clone(list) { - return keep(list, function (x) { return true; }); - } - list_1.clone = clone; - /** - */ - function reversed(list) { - var list_ = clone(list); - list_.reverse(); - return list_; - } - list_1.reversed = reversed; - /** - * @todo use Array.toSorted? - */ - function sorted(list, options) { - options = Object.assign({ - "compare_element": instance_compare - }, options); - var list_ = clone(list); - list_.sort(function (x, y) { return (options.compare_element(x, y) ? -1 : +1); }); - return list_; - } - list_1.sorted = sorted; - /** - * die Liste in gleich große Blöcke zerlegen - */ - function chop(list, chunk_size) { - var chunks = []; - var index = 0; - while (index < list.length) { - var chunk = list.slice(index, Math.min(list.length, index + chunk_size)); - index += chunk_size; - chunks.push(chunk); - } - return chunks; - } - list_1.chop = chop; - /** - */ - function group(list, collate_element) { - var result = []; - list.forEach(function (element) { - var target = result.find( - // @ts-ignore - function (group) { return collate_element(group[0], element); }); - if (target === undefined) { - target = []; - result.push(target); - } - target.push(element); - }); - return result; - } - list_1.group = group; - /** - */ - function has(list, predicate) { - return (list.find(predicate) !== undefined); - } - list_1.has = has; - /** - * @deprecate use Array.includes or Array.some - */ - function contains(list, element, options) { - options = Object.assign({ - "collate": instance_collate - }, options); - return has(list, function (element_) { return options.collate_element(element_, element); }); - } - list_1.contains = contains; - /** - * retrieves the element and its index of the list, which has the maximum value - */ - function max(list, target_function, options) { - options = Object.assign({ - "compare_value": instance_compare - }, options); - if (is_empty(list)) { - throw (new Error("the max-arg of an empty list is not defined")); - } - else { - return (list - .reduce(function (result, element, index) { - var value = target_function(element); - if ((result == null) - || - (!options.compare_value(value, result.value))) { - return { "index": index, "element": element, "value": value }; - } - else { - return result; - } - }, null)); - } - } - list_1.max = max; - /** - * retrieves the element and its index of the list, which has the mininum value - */ - function min(list, target_function, options) { - options = Object.assign({ - "compare_value": instance_compare - }, options); - return max(list, target_function, { - "compare_value": function (x, y) { return options.compare_value(y, x); } - }); - } - list_1.min = min; - /** - * implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)" - * example: distribute([[1,2],[3],[4,5,6]]) = [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]] - */ - function distribute(lists) { - if (is_empty(lists)) { - return [[]]; - } - else { - var subresult_1 = distribute(lists.slice(1)); - return (lists[0] - .map(function (element) { return subresult_1.map(function (list) { return [element].concat(list); }); }) - .reduce(function (x, y) { return x.concat(y); }, [])); - } - } - list_1.distribute = distribute; - /** - */ - function contrast(list_left, extract_key_left, list_right, extract_key_right) { - var gathering = {}; - list_left.forEach(function (source_left) { - var _a; - var key = extract_key_left(source_left); - gathering[key] = Object.assign(((_a = gathering[key]) !== null && _a !== void 0 ? _a : {}), { "left": source_left }); - }); - list_right.forEach(function (source_right) { - var _a; - var key = extract_key_right(source_right); - gathering[key] = Object.assign(((_a = gathering[key]) !== null && _a !== void 0 ? _a : {}), { "right": source_right }); - }); - var result = { - "both": [], - "only_left": [], - "only_right": [] - }; - Object.entries(gathering).forEach(function (_a) { - var key = _a[0], value = _a[1]; - if ("left" in value) { - if ("right" in value) { - result.both.push({ "key": key, "left": value.left, "right": value.right }); - } - else { - result.only_left.push({ "key": key, "left": value.left }); - } - } - else { - if ("right" in value) { - result.only_right.push({ "key": key, "right": value.right }); - } - else { - // impossible - // do nothing - } - } - }); - return result; - } - list_1.contrast = contrast; - })(list = lib_plankton.list || (lib_plankton.list = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:conf«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:conf« 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:conf« 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:conf«. If not, see . - */ -/* -This file is part of »bacterio-plankton:conf«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:conf« 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:conf« 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:conf«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var conf; - (function (conf) { - /** - */ - function adapt_primitive(schema, value) { - if (value === undefined) { - if (!("default" in schema)) { - return { - "reports": [ - { - "incident": "neither explicit value provided nor default value specified", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - return { - "reports": [], - "result": lib_plankton.pod.make_filled(schema.default), - }; - } - } - else { - if (value === null) { - if (("nullable" in schema) - && - (!schema.nullable)) { - return { - "reports": [ - { - "incident": "null not allowed", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - return { - "reports": [], - "result": lib_plankton.pod.make_filled(null), - }; - } - } - else { - if (("enum" in schema) - && - (!schema.enum.includes(value))) { - return { - "reports": [ - { - "incident": "provided value not in enumeration of valid values", - "details": { - "enumerated_values": schema.enum, - "provided_value": value, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - const type_map = { - "boolean": "boolean", - "integer": "number", - "number": "number", - "string": "string", - }; - // @ts-ignore - if (!(typeof (value) === type_map[schema.type])) { - return { - "reports": [ - { - // @ts-ignore - "incident": ("value should be " + type_map[schema.type]), - "details": { - "provided_value": value, - "type": typeof (value), - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - return { - "reports": [], - "result": lib_plankton.pod.make_filled(value) - }; - } - } - } - } - } - /** - * @todo anyOf - * @todo allOf - * @todo oneOf - * @todo not - * @todo tests - */ - function adapt(schema, value_raw) { - let value = value_raw; - if (!("type" in schema)) { - if ("anyOf" in schema) { - if (value === undefined) { - if (!("default" in schema)) { - return { - "reports": [ - { - "incident": "neither explicit value provided nor default value specified", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - value = schema.default; - } - } - else { - // do nothing - } - const sub_adaptions = (schema.anyOf - .map((sub_schema) => adapt(sub_schema, value))); - const valid_sub_adaptions = (sub_adaptions - .filter((sub_adaption) => lib_plankton.pod.is_filled(sub_adaption.result))); - if (valid_sub_adaptions.length <= 0) { - return { - "reports": [ - { - "incident": "no valid apaptions", - "details": { - "sub_adaptions": sub_adaptions, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - if (valid_sub_adaptions.length > 1) { - return { - "reports": [ - { - "incident": "multiple valid apaptions", - "details": { - "valid_sub_adaptions": valid_sub_adaptions, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - return valid_sub_adaptions[0]; - } - } - } - else { - throw (new Error("not implemented")); - } - } - else { - switch (schema.type) { - case "boolean": - return adapt_primitive(schema, value); - break; - case "integer": - return adapt_primitive(schema, value); - break; - case "number": - return adapt_primitive(schema, value); - break; - case "string": { - return adapt_primitive(schema, value); - break; - } - case "array": { - if (value === undefined) { - if (!("default" in schema)) { - return { - "reports": [ - { - "incident": "neither explicit value provided nor default value specified", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - value = schema.default; - } - } - /*else*/ { - if (value === null) { - if (("nullable" in schema) - && - (!schema.nullable)) { - return { - "reports": [ - { - "incident": "null not allowed", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - return { - "reports": [], - "result": lib_plankton.pod.make_filled(null), - }; - } - } - else { - /*if ( - ("enum" in schema) - && - (! schema.enum.includes(value)) // TODO - ) { - return { - "reports": [ - { - "incident": "provided value not in enumeration of valid values", - "details": { - "enumerated_values": schema.enum, - "provided_value": value, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else*/ { - if ((!(typeof (value) === "object")) - && - (value.constructor.name !== "Array")) { - return { - "reports": [ - { - "incident": "value should be array", - "details": { - "provided_value": value, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - if (!("items" in schema)) { - // do nothing - return { - "reports": [], - "result": lib_plankton.pod.make_filled(value), - }; - } - else { - let reports = []; - for (let index = 0; index < value.length; index += 1) { - const adaption = adapt(schema.items, value[index]); - if (!lib_plankton.pod.is_filled(adaption.result)) { - reports = reports.concat(adaption.reports.map((report_entry) => ({ - "incident": report_entry.incident, - "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([index]) - }), - }))); - } - else { - value[index] = lib_plankton.pod.cull(adaption.result); - } - } - return { - "reports": reports, - "result": ((reports.length > 0) - ? - lib_plankton.pod.make_empty() - : - lib_plankton.pod.make_filled(value)), - }; - } - } - } - } - } - break; - } - case "object": { - if (value === undefined) { - if (!("default" in schema)) { - return { - "reports": [ - { - "incident": "neither explicit value provided nor default value specified", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - value = schema.default; - } - } - /*else*/ { - if (value === null) { - if (("nullable" in schema) - && - (!schema.nullable)) { - return { - "reports": [ - { - "incident": "null not allowed", - "details": {} - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - return { - "reports": [], - "result": lib_plankton.pod.make_filled(null), - }; - } - } - else { - /*if ( - ("enum" in schema) - && - (! schema.enum.includes(value)) // TODO - ) { - return { - "reports": [ - { - "incident": "provided value not in enumeration of valid values", - "details": { - "enumerated_values": schema.enum, - "provided_value": value, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else*/ { - if (!(typeof (value) === "object")) { - return { - "reports": [ - { - "incident": "value should be object", - "details": { - "provided_value": value, - } - } - ], - "result": lib_plankton.pod.make_empty(), - }; - } - else { - value = lib_plankton.object.copy(value); - const contrast = lib_plankton.list.contrast(Object.keys(schema.properties), x => x, Object.keys(value), x => x); - let reports = []; - // gratuitous fields - { - if (contrast.only_right.length <= 0) { - // do nothing - } - else { - const additional_properties = (schema.additionalProperties ?? false); - if (additional_properties === false) { - reports = reports.concat(contrast.only_right - .map((entry) => ({ - "incident": "gratuitous field", - "details": { - "path": [entry.right], - } - }))); - } - else { - contrast.only_right.forEach((entry) => { - const sub_adaption = adapt(additional_properties, value[entry.right]); - if (!lib_plankton.pod.is_filled(sub_adaption.result)) { - reports = reports.concat(sub_adaption.reports - .map((report_entry) => ({ - "incident": report_entry.incident, - "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([entry.right]) - }), - }))); - } - else { - value[entry.right] = lib_plankton.pod.cull(sub_adaption.result); - } - }); - } - } - } - // missing fields - { - contrast.only_left.forEach((entry) => { - if (("required" in schema) - && - schema.required.includes(entry.left)) { - reports.push({ - "incident": "missing field", - "details": { - "path": [entry.left], - } - }); - } - else { - const sub_adaption = adapt(schema.properties[entry.left], undefined); - if (!lib_plankton.pod.is_filled(sub_adaption.result)) { - reports = reports.concat(sub_adaption.reports - .map((report_entry) => ({ - "incident": report_entry.incident, - "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([entry.left]) - }), - }))); - } - else { - value[entry.left] = lib_plankton.pod.cull(sub_adaption.result); - } - } - }); - // regular fields - { - contrast.both.forEach((entry) => { - const sub_adaption = adapt(schema.properties[entry.left], value[entry.right]); - if (!lib_plankton.pod.is_filled(sub_adaption.result)) { - reports = reports.concat(sub_adaption.reports - .map((report_entry) => ({ - "incident": report_entry.incident, - "details": Object.assign(report_entry.details, { - "path": (report_entry.details.path ?? []).concat([entry.right]) - }), - }))); - } - else { - value[entry.right] = lib_plankton.pod.cull(sub_adaption.result); - } - }); - } - return { - "reports": reports, - "result": ((reports.length > 0) - ? - lib_plankton.pod.make_empty() - : - lib_plankton.pod.make_filled(value)), - }; - } - } - } - } - } - break; - } - default: { - throw (new Error("unhandled schema type: " + schema.type)); - break; - } - } - } - } - /** - * @todo versioning - */ - function refine(schema, value_raw) { - const adaption = adapt(schema, value_raw); - if (!lib_plankton.pod.is_filled(adaption.result)) { - throw (new Error("conf could not be loaded:\n" - + - (adaption.reports - .map((report) => ("- " + report.incident + " | " + JSON.stringify(report.details, undefined, "\t"))) - .join("\n")))); - } - else { - return lib_plankton.pod.cull(adaption.result); - } - } - conf.refine = refine; - /** - */ - function load(schema, path) { - return (((path === null) - ? - Promise.resolve(undefined) - : - (lib_plankton.file.read(path) - .then((content) => Promise.resolve(lib_plankton.json.decode(content))))) - .then((data_raw) => Promise.resolve(refine(schema, data_raw)))); - } - conf.load = load; - })(conf = lib_plankton.conf || (lib_plankton.conf = {})); -})(lib_plankton || (lib_plankton = {})); -/* This file is part of »bacterio-plankton:www_form«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -8794,3 +8416,1647 @@ var lib_plankton; www_form.class_www_form = class_www_form; })(www_form = lib_plankton.www_form || (lib_plankton.www_form = {})); })(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:zoo-page«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:zoo-page« 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-page« 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-page«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_page; + (function (zoo_page) { + /** + */ + zoo_page._pool = {}; + /** + */ + let _fallback = null; + /** + */ + let _current = null; + /** + */ + let _target_element = null; + /** + */ + function encode(location) { + return ("#" + + + ([location.name] + .concat(Object.entries(location.parameters) + .filter(([key, value]) => (value !== null)) + .map(([key, value]) => (key + "=" + value))))); + } + zoo_page.encode = encode; + /** + */ + function decode(encoded) { + if (encoded === "") { + return null; + } + else { + if (!encoded.startsWith("#")) { + return null; + } + else { + const parts = encoded.slice(1).split(","); + return { + "name": parts[0], + "parameters": Object.fromEntries(parts.slice(1) + .map(part => { + const parts_ = part.split("="); + return [parts_[0], parts_[1]]; + })), + }; + } + } + } + /** + * renders a page to the main element + */ + async function load(location) { + // _target_element.innerHTML = "[loading …]"; + _target_element.innerHTML = ""; + if (location === null) { + // do nothing + } + else { + if (!(location.name in zoo_page._pool)) { + _target_element.innerHTML = "not found"; + } + else { + await zoo_page._pool[location.name](location.parameters, _target_element); + _current = location; + } + } + } + /** + */ + function add_nav_entry(location, options = {}) { + options = Object.assign({ + "label": null, + }, options); + let ul_element = document.querySelector("nav > ul"); + { + let li_element = document.createElement("li"); + { + let a_element = document.createElement("a"); + a_element.setAttribute("href", encode(location)); + a_element.textContent = (options.label ?? location.name); + li_element.appendChild(a_element); + } + ul_element.appendChild(li_element); + } + } + zoo_page.add_nav_entry = add_nav_entry; + /** + * retrieves the location from the set URL + */ + function get() { + return decode(window.location.hash); + } + /** + * encodes a location in the URL and loads it + */ + function set(location) { + window.location.hash = encode(location); + } + zoo_page.set = set; + /** + */ + function register(location_name, handler, options = {}) { + options = Object.assign({}, options); + zoo_page._pool[location_name] = handler; + } + zoo_page.register = register; + /** + */ + function init(target_element, options = {}) { + options = Object.assign({ + "pool": {}, + "fallback": null, + }, options); + _target_element = target_element; + _fallback = options.fallback; + Object.entries(options.pool).forEach(([location_name, handler]) => { + register(location_name, handler); + }); + window.addEventListener("hashchange", () => { + const location_old = _current; + const location_new = (get() ?? _fallback); + if (((location_old === null) + && + (location_new !== null)) + || + ((location_old !== null) + && + (location_new !== null) + && + (location_old.name !== location_new.name))) { + load(location_new); + } + else { + // do nothing + } + }); + } + zoo_page.init = init; + /** + */ + function start() { + const location = (get() ?? _fallback); + set(location); + load(location); + } + zoo_page.start = start; + })(zoo_page = lib_plankton.zoo_page || (lib_plankton.zoo_page = {})); +})(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 . + */ +/* +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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_wrapped { + /** + */ + constructor(core, wrap, unwrap, options = {}) { + options = Object.assign({}, options); + this.core = core; + this.wrap = wrap; + this.unwrap = unwrap; + } + /** + * [implementation] + */ + setup(parent) { + return this.core.setup(parent); + } + /** + * [implementation] + */ + read() { + return (this.core.read() + .then(value_inner => Promise.resolve(this.wrap(value_inner)))); + } + /** + * [implementation] + */ + write(value) { + return this.core.write(this.unwrap(value)); + } + } + zoo_input.class_input_wrapped = class_input_wrapped; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_hidden { + /** + */ + constructor(options = {}) { + options = Object.assign({ + "initial_value": null, + }, options); + this.dom_input = null; + this.value = options.initial_value; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "hidden"); + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.value); + } + /** + * [implementation] + */ + write(value) { + this.value = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_hidden = class_input_hidden; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + * @todo abstract + */ + class class_input_text { + /** + */ + constructor(options = {}) { + options = Object.assign({ + "read_only": false, + "pattern": null, + // "autocompletion_list": null, + }, options); + this.read_only = options.read_only; + this.pattern = options.pattern; + // this.autocompletion_list = options.autocompletion_list; + this.dom_input = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "text"); + { + if (!this.read_only) { + // do nothing + } + else { + this.dom_input.setAttribute("disabled", "disabled"); + } + } + { + if (this.pattern === null) { + // do nothing + } + else { + this.dom_input.setAttribute("pattern", this.pattern); + } + } + { + /* + if (this.autocompletion_list === null) { + // do nothing + } + else { + const autocomplete : class_autocomplete = new class_autocomplete( + this.dom_input, + this.autocompletion_list + ); + autocomplete.init(); + } + */ + } + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.dom_input.value); + } + /** + * [implementation] + */ + write(value) { + this.dom_input.value = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_text = class_input_text; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_email { + /** + */ + constructor() { + this.dom_input = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "email"); + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.dom_input.value); + } + /** + * [implementation] + */ + write(value) { + this.dom_input.value = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_email = class_input_email; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_textarea { + /** + */ + constructor() { + this.dom_textarea = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_textarea = document.createElement("textarea"); + parent.appendChild(this.dom_textarea); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.dom_textarea.value); + } + /** + * [implementation] + */ + write(value) { + this.dom_textarea.value = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_textarea = class_input_textarea; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + */ + function value_decode(datestring) { + const parts = datestring.split("-"); + return { + "year": parseInt(parts[0]), + "month": parseInt(parts[1]), + "day": parseInt(parts[2]), + }; + } + /** + */ + function value_encode(date) { + return lib_plankton.string.coin("{{year}}-{{month}}-{{day}}", { + "year": date.year.toFixed(0).padStart(4, "0"), + "month": date.month.toFixed(0).padStart(2, "0"), + "day": date.day.toFixed(0).padStart(2, "0"), + }); + } + /** + * @author fenris + */ + class class_input_date { + /** + */ + constructor(options = {}) { + options = Object.assign({ + "required": false, + }, options); + this.required = options.required; + this.dom_input = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "date"); + if (!this.required) { + // do nothing + } + else { + this.dom_input.setAttribute("required", "required"); + } + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + if (this.required && (!this.dom_input.reportValidity())) { + return Promise.reject("required"); + } + else { + return Promise.resolve((this.dom_input.value === "") + ? null + : value_decode(this.dom_input.value)); + } + } + /** + * [implementation] + */ + write(value) { + this.dom_input.value = ((value === null) + ? "" + : value_encode(value)); + return Promise.resolve(undefined); + } + } + zoo_input.class_input_date = class_input_date; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + * @todo abstract + */ + class class_input_number { + /** + */ + constructor(options = {}) { + options = Object.assign({ + "read_only": false, + "step": null, + }, options); + this.read_only = options.read_only; + this.step = options.step; + this.dom_input = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "number"); + // readonly + { + if (!this.read_only) { + // do nothing + } + else { + this.dom_input.setAttribute("disabled", "disabled"); + } + } + // step + { + if (this.step === null) { + // do nothing + } + else { + this.dom_input.setAttribute("step", this.step.toString()); + } + } + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(Number(this.dom_input.value)); + } + /** + * [implementation] + */ + write(value) { + this.dom_input.value = value.toString(); + return Promise.resolve(undefined); + } + } + zoo_input.class_input_number = class_input_number; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_checkbox { + /** + */ + constructor(options = {}) { + options = Object.assign({ + "read_only": false, + "hooks_change": [], + }, options); + this.read_only = options.read_only; + this.dom_input = null; + this.hooks_change = options.hooks_change; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "checkbox"); + { + if (this.read_only) { + this.dom_input.setAttribute("disabled", "disabled"); + } + else { + // do nothing + } + } + this.dom_input.addEventListener("change", (event) => { + const value = event.target.checked; + this.hooks_change.forEach(procedure => { + procedure(value); + }); + }); + // this.dom_input.style.display = "initial"; // n3o!!! + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.dom_input.checked); + } + /** + * [implementation] + */ + write(value) { + this.dom_input.checked = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_checkbox = class_input_checkbox; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_selection { + /** + */ + constructor(options) { + this.options = options; + this.dom_select = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_select = document.createElement("select"); + this.options.forEach((option) => { + let dom_option = document.createElement("option"); + dom_option.setAttribute("value", option.value); + dom_option.textContent = option.label; + this.dom_select.appendChild(dom_option); + }); + parent.appendChild(this.dom_select); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.dom_select.value); + } + /** + * [implementation] + */ + write(value) { + this.dom_select.value = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_selection = class_input_selection; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_enumeration { + /** + */ + constructor(options) { + this.options = options; + this.dom_inputs = []; + } + /** + * [implementation] + * @todo unique name + */ + setup(parent) { + let dom_container = document.createElement("div"); + dom_container.classList.add("plankton_input_enumeration"); + const name = "radio"; + this.options.forEach((option) => { + let dom_label = document.createElement("label"); + let dom_input = document.createElement("input"); + dom_input.setAttribute("type", "radio"); + dom_input.setAttribute("name", name); + dom_input.setAttribute("value", option.value); + dom_label.appendChild(dom_input); + let dom_span = document.createElement("span"); + dom_span.textContent = option.label; + dom_label.appendChild(dom_span); + dom_container.appendChild(dom_label); + this.dom_inputs.push(dom_input); + }); + parent.appendChild(dom_container); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + const active = (this.dom_inputs + .filter(dom_input => dom_input.checked) + .map(dom_input => dom_input.value)); + if (active.length != 1) { + return Promise.reject("nothing picked"); + } + else { + return Promise.resolve(active[0]); + } + } + /** + * [implementation] + */ + write(value) { + this.dom_inputs.forEach(dom_input => { + dom_input.checked = (value === dom_input.value); + }); + return Promise.resolve(undefined); + } + } + zoo_input.class_input_enumeration = class_input_enumeration; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_list { + /** + */ + constructor(element_input_factory, options = {}) { + options = Object.assign({ + "translations": { + "add": "add", + "remove": "remove", + }, + }, options); + this.element_input_factory = element_input_factory; + this.elements = []; + this.elements_container_dom = null; + this.translations = options.translations; + } + /** + */ + clear() { + this.elements_container_dom.innerHTML = ""; + this.elements = []; + return Promise.resolve(undefined); + } + /** + */ + async add() { + // model + let element_dom = document.createElement("div"); + const input = this.element_input_factory(); + this.elements.push({ "dom": element_dom, "input": input }); + // view & control + { + element_dom.classList.add("plankton_input_list_element"); + // remover + { + let remover_dom = document.createElement("button"); + remover_dom.classList.add("plankton_input_list_button"); + remover_dom.classList.add("plankton_input_list_element_remover"); + remover_dom.setAttribute("title", this.translations.remove); + remover_dom.textContent = "x"; + remover_dom.addEventListener("click", (event) => { + event.preventDefault(); + const index = this.elements.findIndex(element => (element.input === input)); + const element = this.elements[index]; + this.elements_container_dom.removeChild(element.dom); + this.elements.splice(index, 1); + }); + element_dom.appendChild(remover_dom); + } + // input + { + let input_dom = document.createElement("div"); + input_dom.classList.add("plankton_input_list_element_input"); + await input.setup(input_dom); + element_dom.appendChild(input_dom); + } + this.elements_container_dom.appendChild(element_dom); + } + return Promise.resolve(input); + } + /** + * [implementation] + */ + setup(parent) { + let container_dom = document.createElement("div"); + container_dom.classList.add("plankton_input_list"); + // elements + { + this.elements_container_dom = document.createElement("div"); + this.elements_container_dom.classList.add("plankton_input_list_elements"); + container_dom.appendChild(this.elements_container_dom); + } + // foot + { + let footer_dom = document.createElement("div"); + footer_dom.classList.add("plankton_input_list_foot"); + // adder + { + let adder_dom = document.createElement("button"); + adder_dom.classList.add("plankton_input_list_button"); + adder_dom.classList.add("plankton_input_list_adder"); + adder_dom.setAttribute("title", this.translations.add); + adder_dom.textContent = "+"; + adder_dom.addEventListener("click", (event) => { + event.preventDefault(); + this.add(); + }); + footer_dom.appendChild(adder_dom); + } + container_dom.appendChild(footer_dom); + } + parent.appendChild(container_dom); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return (Promise.all(this.elements + .map((element, index) => (element.input.read() + .then((element_value) => Promise.resolve({ + "index": index, + "value": element_value, + }))))) + .then((elements) => Promise.resolve(elements + .sort((x, y) => ((x.index <= y.index) ? 0 : 1)) + .map(element => element.value)))); + } + /** + * [implementation] + */ + write(value) { + return (this.clear() + .then(() => Promise.all(value + .map((element_value) => (this.add() + .then(element_input => element_input.write(element_value)))))) + .then(() => Promise.resolve(undefined))); + } + } + zoo_input.class_input_list = class_input_list; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_password { + /** + */ + constructor() { + this.dom_input = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "password"); + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.dom_input.value); + } + /** + * [implementation] + */ + write(value) { + this.dom_input.value = value; + return Promise.resolve(undefined); + } + } + zoo_input.class_input_password = class_input_password; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_switch { + /** + */ + constructor() { + this.dom_element = null; + this.value = false; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_element = document.createElement("input"); + this.dom_element.setAttribute("type", "text"); + this.dom_element.setAttribute("readonly", "readonly"); + this.dom_element.addEventListener("click", (event) => { + this.write(!this.value); + }); + parent.appendChild(this.dom_element); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve(this.value); + } + /** + * [implementation] + */ + write(value) { + this.value = value; + if (value) { + this.dom_element.value = "✔"; + } + else { + this.dom_element.value = " "; + } + return Promise.resolve(undefined); + } + } + zoo_input.class_input_switch = class_input_switch; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + */ + function value_encode(time) { + return lib_plankton.string.coin("{{hour}}:{{minute}}", { + "hour": time.hour.toFixed(0).padStart(2, "0"), + "minute": time.minute.toFixed(0).padStart(2, "0"), + }); + } + /** + */ + function value_decode(timestring) { + const parts = timestring.split(":"); + return { + "hour": parseInt(parts[0]), + "minute": parseInt(parts[1]), + "second": 0, + }; + } + /** + * @author fenris + */ + class class_input_time { + /** + */ + constructor() { + this.dom_input = null; + } + /** + * [implementation] + */ + setup(parent) { + this.dom_input = document.createElement("input"); + this.dom_input.setAttribute("type", "time"); + parent.appendChild(this.dom_input); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + read() { + return Promise.resolve((this.dom_input.value === "") + ? null + : value_decode(this.dom_input.value)); + } + /** + * [implementation] + */ + write(value) { + this.dom_input.value = ((value === null) + ? "" + : value_encode(value)); + return Promise.resolve(undefined); + } + } + zoo_input.class_input_time = class_input_time; + })(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 . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_input; + (function (zoo_input) { + /** + * @author fenris + */ + class class_input_group { + /** + */ + constructor(fields_raw) { + this.fields = (fields_raw + .map(field_raw => ({ + "name": field_raw.name, + "input": field_raw.input, + "label": (field_raw.label ?? null), + "help": (field_raw.help ?? null), + }))); + } + /** + * [implementation] + */ + async setup(parent) { + let dom_group = document.createElement("div"); + dom_group.classList.add("plankton_input_group"); + await Promise.all(this.fields.map(async (field) => { + let dom_field = document.createElement("div"); + dom_field.classList.add("plankton_input_group_field"); + dom_field.setAttribute("rel", field.name); + await Promise.all([ + // label + new Promise((resolve, reject) => { + if (field.label === null) { + // do nothing + } + else { + let dom_label = document.createElement("label"); + dom_label.classList.add("plankton_input_group_field_label"); + dom_label.textContent = field.label; + dom_field.appendChild(dom_label); + } + resolve(undefined); + }), + // help + new Promise((resolve, reject) => { + if (field.help === null) { + // do nothing + } + else { + let dom_help = document.createElement("span"); + dom_help.classList.add("plankton_input_group_field_help"); + dom_help.textContent = "(?)"; + dom_help.setAttribute("title", field.help); + dom_field.appendChild(dom_help); + } + resolve(undefined); + }), + // input + field.input.setup(dom_field), + ]); + dom_group.appendChild(dom_field); + return Promise.resolve(undefined); + })); + parent.appendChild(dom_group); + return Promise.resolve(undefined); + } + /** + * [implementation] + */ + async read() { + return (Promise.all(this.fields.map((field) => (field.input.read() + .then((value) => Promise.resolve({ "key": field.name, "value": value }))))) + .then(pairs => Promise.resolve(Object.fromEntries(pairs.map((pair) => ([pair.key, pair.value])))))); + } + /** + * [implementation] + */ + write(value) { + return (Promise.resolve(Object.entries(value).map(([key, value]) => ({ "key": key, "value": value }))) + .then((pairs) => Promise.all(pairs.map((pair) => (Promise.all(this.fields.filter((field) => (field.name === pair.key)) + .map((field) => field.input.write(pair.value))) + .then(() => Promise.resolve(undefined)))))) + .then(() => Promise.resolve(undefined))); + } + } + zoo_input.class_input_group = class_input_group; + })(zoo_input = lib_plankton.zoo_input || (lib_plankton.zoo_input = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:zoo-form«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:zoo-form« 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-form« 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-form«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_form; + (function (zoo_form) { + /** + */ + function make(method, fields, encode, decode, options = {}) { + options = Object.assign({ + "class_prefix": "plankton_form_", + }, options); + return { + "method": method, + "fields": fields.map(field_raw => ({ + "name": field_raw.name, + "type": field_raw.type, + "label": (field_raw.label ?? null), + })), + "encode": encode, + "decode": decode, + "class_prefix": options.class_prefix, + "root_element": null, + }; + } + zoo_form.make = make; + /** + */ + function make_simple(method, fields, options = {}) { + options = Object.assign({ + "class_prefix": "plankton_form_", + }, options); + return { + "method": method, + "fields": fields.map(field_raw => ({ + "name": field_raw.name, + "type": field_raw.type, + "label": (field_raw.label ?? null), + })), + "encode": x => x, + "decode": x => x, + "class_prefix": options.class_prefix, + "root_element": null, + }; + } + zoo_form.make_simple = make_simple; + /** + */ + function class_name(subject, name) { + return lib_plankton.string.coin("{{class_prefix}}{{name}}", { + "class_prefix": subject.class_prefix, + "name": name, + }); + } + /** + */ + function field_input(subject, field) { + return subject.root_element.querySelector(lib_plankton.string.coin(".{{class}}[name=\"{{name}}\"]", { + "class": class_name(subject, "input"), + "name": field.name, + })); + } + /** + */ + function clear(subject) { + subject.fields.forEach(field => { + switch (field.type) { + default: { + field_input(subject, field).value = ""; + break; + } + case "checkbox": { + field_input(subject, field).checked = false; + break; + } + } + }); + } + zoo_form.clear = clear; + /** + */ + function write(subject, value) { + let raw = subject.encode(value); + subject.fields.forEach(field => { + switch (field.type) { + default: { + field_input(subject, field).value = raw[field.name]; + break; + } + case "checkbox": { + field_input(subject, field).checked = (raw[field.name] === "on"); + break; + } + } + }); + } + zoo_form.write = write; + /** + */ + function read(subject) { + let raw = {}; + subject.fields.forEach(field => { + switch (field.type) { + default: { + raw[field.name] = field_input(subject, field).value; + break; + } + case "checkbox": { + raw[field.name] = (field_input(subject, field).checked ? "on" : "off"); + break; + } + } + }); + const value = subject.decode(raw); + return value; + } + zoo_form.read = read; + /** + */ + async function render(subject, target) { + let element_form = document.createElement("form"); + element_form.classList.add(class_name(subject, "form")); + subject.fields.forEach(field => { + let element_field = document.createElement("div"); + element_field.classList.add(class_name(subject, "field")); + // label + { + let element_label = document.createElement("label"); + element_label.classList.add(class_name(subject, "label")); + element_field.appendChild(element_label); + element_label.textContent = (field.label + ?? + field.name.split("_").join(" ")); + } + // input + { + let element_input = document.createElement("input"); + element_input.classList.add(class_name(subject, "input")); + element_input.setAttribute("name", field.name); + element_input.setAttribute("type", field.type); + element_field.appendChild(element_input); + } + element_form.appendChild(element_field); + }); + subject.root_element = element_form; + target.appendChild(element_form); + return Promise.resolve(undefined); + } + zoo_form.render = render; + })(zoo_form = lib_plankton.zoo_form || (lib_plankton.zoo_form = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:zoo-form«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:zoo-form« 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-form« 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-form«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var zoo_form; + (function (zoo_form) { + /** + * @author fenris + */ + class class_form { + /** + */ + constructor(encode, decode, input, actions) { + this.encode = encode; + this.decode = decode; + this.input = input; + this.actions = actions; + } + /** + */ + async setup(parent) { + let dom_form = document.createElement("form"); + dom_form.classList.add("plankton_form"); + // input + { + let dom_container = document.createElement("div"); + dom_container.classList.add("plankton_form_input"); + await this.input.setup(dom_container); + dom_form.appendChild(dom_container); + } + // actions + { + let dom_container = document.createElement("div"); + dom_container.classList.add("plankton_form_actions"); + this.actions.forEach((action) => { + let dom_button = document.createElement("button"); + // dom_button.setAttribute("type", "submit"); + dom_button.textContent = action.label; + if (action.target !== undefined) { + dom_button.setAttribute("formaction", action.target); + } + if (action.procedure !== undefined) { + dom_button.addEventListener("click", (event) => { + event.preventDefault(); + action.procedure(() => this.input_read(), () => this.input_read_raw()); + }); + } + dom_container.appendChild(dom_button); + }); + dom_form.appendChild(dom_container); + } + parent.appendChild(dom_form); + } + /** + */ + input_read_raw() { + return this.input.read(); + } + /** + */ + async input_read() { + return this.decode(await this.input.read()); + } + /** + */ + input_write(value) { + return this.input.write(this.encode(value)); + } + } + zoo_form.class_form = class_form; + })(zoo_form = lib_plankton.zoo_form || (lib_plankton.zoo_form = {})); +})(lib_plankton || (lib_plankton = {})); diff --git a/source/index.html b/source/index.html index 85765d3..2f55141 100644 --- a/source/index.html +++ b/source/index.html @@ -22,5 +22,13 @@ document.addEventListener( +
+ +
+
+
diff --git a/source/logic/backend.ts b/source/logic/backend.ts index 25be5f5..630cb2d 100644 --- a/source/logic/backend.ts +++ b/source/logic/backend.ts @@ -5,7 +5,48 @@ namespace _zeitbild.frontend_web.backend /** */ - var _session_key : (null | string) = null; + var _data_chest : ( + null + | + lib_plankton.storage.type_chest + ) = null; + + + /** + */ + export async function init( + ) : Promise + { + _data_chest = lib_plankton.storage.localstorage.implementation_chest( + { + "corner": "zeitbild", + } + ); + return Promise.resolve(undefined); + } + + + /** + */ + async function get_session_key( + ) : Promise<(null | string)> + { + try { + return (await _data_chest.read("session_key")); + } + catch (error) { + return null; + } + } + + + /** + */ + export async function is_logged_in( + ) : Promise + { + return ((await get_session_key()) !== null); + } /** @@ -23,6 +64,7 @@ namespace _zeitbild.frontend_web.backend lib_plankton.http.enum_method.patch, ].includes(method) ); + const session_key : (null | string) = await get_session_key(); const http_request : lib_plankton.http.type_request = { "version": "HTTP/2", "scheme": ( @@ -64,11 +106,11 @@ namespace _zeitbild.frontend_web.backend {"Content-Type": "application/json"} ), ( - (_session_key === null) + (session_key === null) ? {} : - {"X-Session-Key": _session_key} + {"X-Session-Key": session_key} ) ), "body": ( @@ -80,8 +122,19 @@ namespace _zeitbild.frontend_web.backend ), }; const http_response : lib_plankton.http.type_response = await lib_plankton.http.call(http_request); - const output : any = lib_plankton.json.decode(http_response.body.toString()); - return Promise.resolve(output); + if ( + ! ( + (http_response.status_code >= 200) + && + (http_response.status_code < 300) + ) + ) { + return Promise.reject(http_response.body.toString()); + } + else { + const output : any = lib_plankton.json.decode(http_response.body.toString()); + return Promise.resolve(output); + } } @@ -92,7 +145,7 @@ namespace _zeitbild.frontend_web.backend password : string ) : Promise { - _session_key = await call( + const session_key : string = await call( lib_plankton.http.enum_method.post, "/session/begin", { @@ -100,6 +153,7 @@ namespace _zeitbild.frontend_web.backend "password": password, } ); + await _data_chest.write("session_key", session_key); return Promise.resolve(undefined); } @@ -109,11 +163,13 @@ namespace _zeitbild.frontend_web.backend export async function session_end( ) : Promise { - return call( + await call( lib_plankton.http.enum_method.delete, "/session/end", null ); + await _data_chest.delete("session_key"); + return Promise.resolve(undefined); } @@ -121,9 +177,9 @@ namespace _zeitbild.frontend_web.backend */ export async function calendar_list( ) : Promise< - Array< + Array< { - key : type_calendar_id; + key : _zeitbild.frontend_web.type.calendar_id; preview : { name : string; } @@ -146,14 +202,14 @@ namespace _zeitbild.frontend_web.backend from_pit : _zeitbild.frontend_web.helpers.type_pit, to_pit : _zeitbild.frontend_web.helpers.type_pit, options : { - calendar_ids ?: (null | Array); + calendar_ids ?: (null | Array<_zeitbild.frontend_web.type.calendar_id>); } = {} ) : Promise< Array< { - calendar_id : type_calendar_id; + calendar_id : _zeitbild.frontend_web.type.calendar_id; calendar_name : string; - event : type_event; + event : _zeitbild.frontend_web.type.event_object; } > > diff --git a/source/logic/cli.ts b/source/logic/cli.ts deleted file mode 100644 index cd3af7e..0000000 --- a/source/logic/cli.ts +++ /dev/null @@ -1,218 +0,0 @@ - - -/** - */ -async function main( - args_raw : Array -) : Promise -{ - const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler({ - "data_path": lib_plankton.args.class_argument.volatile({ - "indicators_long": ["data-path"], - "indicators_short": ["d"], - "type": lib_plankton.args.enum_type.string, - "mode": lib_plankton.args.enum_mode.replace, - "default": "data.json", - // "info": null, - "name": "data-path", - }), - "timezone_shift": lib_plankton.args.class_argument.volatile({ - "indicators_long": ["timezone-shift"], - "indicators_short": ["t"], - "type": lib_plankton.args.enum_type.integer, - "mode": lib_plankton.args.enum_mode.replace, - "default": 0, - // "info": null, - "name": "timezone-shift", - }), - "calendar_id": lib_plankton.args.class_argument.volatile({ - "indicators_long": ["calendar"], - "indicators_short": ["c"], - "type": lib_plankton.args.enum_type.integer, - "mode": lib_plankton.args.enum_mode.replace, - "default": 1, - // "info": null, - "name": "calendar_id", - }), - "view_mode": lib_plankton.args.class_argument.volatile({ - "indicators_long": ["view-moode"], - "indicators_short": ["m"], - "type": lib_plankton.args.enum_type.string, - "mode": lib_plankton.args.enum_mode.replace, - "default": "table", - // "info": null, - "name": "view_mode", - }), - "help": lib_plankton.args.class_argument.volatile({ - "indicators_long": ["help"], - "indicators_short": ["h"], - "type": lib_plankton.args.enum_type.boolean, - "mode": lib_plankton.args.enum_mode.replace, - "default": false, - // "info": null, - "name": "help", - }), - }); - const args : Record = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" ")); - - // init - lib_plankton.log.conf_push( - [ - // lib_plankton.log.channel_make({"kind": "file", "data": {"threshold": "debug", "path": "/tmp/kalender.log"}}), - lib_plankton.log.channel_make({"kind": "file", "data": {"threshold": "info", "path": "/dev/stderr"}}), - // lib_plankton.log.channel_make({"kind": "stdout", "data": {"threshold": "info"}}), - ] - ); - - // exec - if (args["help"]) { - process.stdout.write( - arg_handler.generate_help( - { - "programname": "kalender", - "description": "Kalender", - "executable": "kalender", - } - ) - + - "\n" - ); - } - else { - const data : type_datamodel = lib_plankton.call.convey( - await lib_plankton.file.read(args["data_path"]), - [ - lib_plankton.json.decode, - (data_raw : any) => ( - ({ - "users": data_raw["users"], - "calendars": ( - data_raw["calendars"] - .map( - (calendar_entry_raw : any) => ({ - "id": calendar_entry_raw["id"], - "object": ( - ((calendar_object_raw) => { - switch (calendar_object_raw["kind"]) { - default: { - return calendar_object_raw; - break; - } - case "concrete": { - return { - "kind": "concrete", - "data": { - "name": calendar_object_raw["data"]["name"], - "users": calendar_object_raw["data"]["users"], - "events": ( - calendar_object_raw["data"]["events"] - .map( - (event_raw : any) => ({ - "name": event_raw["name"], - "begin": event_raw["begin"], - "end": ( - (event_raw["end"] === null) - ? - null - : - event_raw["end"] - ), - "description": event_raw["description"], - }) - ) - ), - }, - }; - break; - } - } - }) (calendar_entry_raw["object"]) - ), - }) - ) - ), - }) as type_datamodel - ), - ] - ); - let content : string; - switch (args["view_mode"]) { - default: { - content = ""; - throw (new Error("invalid view mode")); - break; - } - case "table": { - content = await calendar_view_table_html( - data, - args.calendar_id, - { - "timezone_shift": args["timezone_shift"], - } - ); - break; - } - case "list": { - content = await calendar_view_list_html( - data, - args.calendar_id, - { - "timezone_shift": args["timezone_shift"], - } - ); - break; - } - } - const output : string = template_coin( - "main", - { - "content": content, - } - ); - process.stdout.write(output); - } - return Promise.resolve(undefined); -} - -/* -process.stderr.write( - JSON.stringify( - { - "x1": datetime_from_date_object( - new Date(Date.now()), - { - "timezone_shift": 2, - } - ), - "x2": datetime_from_date_object( - new Date(Date.now()), - { - "timezone_shift": 0, - } - ), - "x3": pit_from_year_and_week( - 2024, - 37, - { - "timezone_shift": 0, - } - ), - }, - undefined, - "\t" - ) - + - "\n" -); - */ -( - main(process.argv.slice(2)) - .then( - () => {} - ) - /* - .catch( - (error) => {process.stderr.write(String(error) + "\n");} - ) - */ -); diff --git a/source/logic/helpers.ts b/source/logic/helpers.ts index 8c92314..15d5c4c 100644 --- a/source/logic/helpers.ts +++ b/source/logic/helpers.ts @@ -8,7 +8,7 @@ namespace _zeitbild.frontend_web.helpers */ var _template_cache : Record = {}; - + /** * @todo caching */ @@ -44,8 +44,8 @@ namespace _zeitbild.frontend_web.helpers ) ); } - - + + /** * @todo outsource */ diff --git a/source/logic/main.ts b/source/logic/main.ts index a3568b7..a4fff12 100644 --- a/source/logic/main.ts +++ b/source/logic/main.ts @@ -4,130 +4,133 @@ namespace _zeitbild.frontend_web { - /** - */ - type type_conf = { - view_mode : string; - calendar_ids : Array; - timezone_shift : int; - }; - - - /** - */ - async function render( - ) : Promise - { - const target : HTMLElement = (document.querySelector("body") as HTMLBodyElement); - const view_type : string = "table"; - switch (view_type) { - default: { - throw (new Error("invalid view mode")); - break; - } - case "table": { - const content : string = await _zeitbild.frontend_web.view.calendar_view_table_html( - { - "calendar_ids": null, - "from": { - "year": 2024, - "week": 37 - }, - "to": { - "year": 2024, - "week": 43 - }, - "timezone_shift": /*conf.timezone_shift*/0, - } - ); - target.innerHTML = content; - /* - document.querySelectorAll(".tableview-sources-entry").forEach( - (element) => { - element.addEventListener( - "click", - (event) => { - const element_ : HTMLElement = (event.target as HTMLElement); - const calendar_id : type_calendar_id = parseInt(element_.getAttribute("rel") as string); - const active : boolean = element_.classList.toggle("tableview-sources-entry-active"); - render( - conf, - lib_plankton.call.convey( - calendar_ids, - [ - (x : Array) => ( - active - ? - calendar_ids.concat([calendar_id]) - : - calendar_ids.filter(y => (y !== calendar_id)) - ), - ] - ) - ); - } - ); - } - ); - */ - break; - } - case "list": { - const content : string = await _zeitbild.frontend_web.view.calendar_view_list_html( - null, - { - "timezone_shift": /*conf.timezone_shift*/0, - } - ); - target.innerHTML = content; - break; - } - } - return Promise.resolve(undefined); - } - - /** */ export async function main( ) : Promise { - // init - lib_plankton.log.conf_push( - [ - lib_plankton.log.channel_make({"kind": "console", "data": {"threshold": "info"}}), - ] - ); - // conf - await _zeitbild.frontend_web.conf.init(("conf.json")); + await _zeitbild.frontend_web.conf.init("conf.json"); - // setup - await _zeitbild.frontend_web.backend.session_begin( - "alice", - "alice" + // init + await _zeitbild.frontend_web.backend.init(); + lib_plankton.zoo_page.init( + document.querySelector("main"), + { + "pool": { + "login": async (parameters, target_element) => { + target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin( + "login", + { + "form": "", + } + ); + const form : lib_plankton.zoo_form.class_form< + {name : string; password : string;}, + {name : string; password : string;} + > = new lib_plankton.zoo_form.class_form< + {name : string; password : string;}, + {name : string; password : string;} + >( + x => x, + x => x, + new lib_plankton.zoo_input.class_input_group< + {name : string; password : string;} + >( + [ + { + "name": "name", + "input": new lib_plankton.zoo_input.class_input_text(), + "label": "Name", // TODO: translate + }, + { + "name": "password", + "input": new lib_plankton.zoo_input.class_input_password(), + "label": "Kennwort", // TODO: translate + }, + ] + ), + [ + { + "label": "Anmelden", // TODO: translate + "target": "submit", + "procedure": async (get_value, get_representation) => { + const value : any = await get_value(); + try { + await _zeitbild.frontend_web.backend.session_begin( + value.name, + value.password + ); + lib_plankton.zoo_page.set( + { + "name": "events", + "parameters": {} + } + ); + } + catch (error) { + lib_plankton.zoo_page.set( + { + "name": "login", + "parameters": { + "name": value.name, + } + } + ); + } + } + }, + ] + ); + await form.setup(document.querySelector("#login")); + await form.input_write( + { + "name": (parameters.name ?? ""), + "password": "", + } + ); + }, + "logout": async (parameters, target_element) => { + await _zeitbild.frontend_web.backend.session_end( + ); + lib_plankton.zoo_page.set( + { + "name": "login", + "parameters": { + } + } + ); + }, + "events": async (parameters, target_element) => { + const content = await _zeitbild.frontend_web.view.calendar_view_table_html( + { + "calendar_ids": null, + "from": { + "year": 2024, + "week": 37 + }, + "to": { + "year": 2024, + "week": 43 + }, + "timezone_shift": /*conf.timezone_shift*/0, + } + ); + target_element.innerHTML = content; + }, + }, + "fallback": { + "name": "login", + "parameters": {} + } + } ); - - // args - /* - const url : URL = new URL(window.location.toString()); - const calendar_ids : Array = ( - (url.searchParams.get("ids") !== null) - ? - lib_plankton.call.convey( - url.searchParams.get("ids"), - [ - (x : string) => lib_plankton.string.split(x, ","), - (x : Array) => x.map(y => parseInt(y)), - ] - ) - : - (await _zeitbild.frontend_web.backend.calendar_list()).map(x => x.key) - ); - */ + lib_plankton.zoo_page.add_nav_entry({"name": "login", "parameters": {}}); + lib_plankton.zoo_page.add_nav_entry({"name": "events", "parameters": {}}); + lib_plankton.zoo_page.add_nav_entry({"name": "logout", "parameters": {}}); // exec - await render(); + lib_plankton.zoo_page.start(); return Promise.resolve(undefined); } diff --git a/source/logic/types.ts b/source/logic/types.ts index 527ec67..ee36ca4 100644 --- a/source/logic/types.ts +++ b/source/logic/types.ts @@ -1,12 +1,14 @@ /** */ -namespace _zeitbild.frontend_web +namespace _zeitbild.frontend_web.type { /** */ - type type_role = ( + export type role = ( + "admin" + | "editor" | "viewer" @@ -15,19 +17,24 @@ namespace _zeitbild.frontend_web /** */ - type type_user_id = int; + export type user_id = int; /** */ - type type_user_object = { + export type user_object = { name : string; + email_address : ( + null + | + string + ); }; /** */ - export type type_event = { + export type event_object = { name : string; begin : _zeitbild.frontend_web.helpers.type_datetime; end : ( @@ -50,54 +57,48 @@ namespace _zeitbild.frontend_web /** */ - export type type_calendar_id = int; + export type resource_id = int; /** */ - export type type_calendar_object = ( + export type resource_object = ( { - kind : "concrete"; + kind : "local"; data : { - name : string; - private : boolean; - users : Array< - { - id : type_user_id; - role : type_role; - } + events : Array< + event_object >; - events : Array; }; } | { kind : "caldav"; data : { - name : string; - private : boolean; read_only : boolean; - source_url : string; - } + url : string; + }; } ); /** */ - export type type_datamodel = { - users : Array< + export type calendar_id = int; + + + /** + */ + export type calendar_object = { + name : string; + public : boolean; + members : Array< { - id : type_user_id; - object : type_user_object; - } - >; - calendars : Array< - { - id : type_calendar_id; - object : type_calendar_object; + user_id : user_id; + role : role; } >; + resource_id : resource_id; }; } diff --git a/source/logic/view.ts b/source/logic/view.ts index f6200a7..26f48fa 100644 --- a/source/logic/view.ts +++ b/source/logic/view.ts @@ -8,7 +8,7 @@ namespace _zeitbild.frontend_web.view */ function event_generate_tooltip( calendar_name : string, - event : type_event + event : _zeitbild.frontend_web.type.event_object ) : string { return ( @@ -137,7 +137,7 @@ namespace _zeitbild.frontend_web.view calendar_ids : ( null | - Array + Array<_zeitbild.frontend_web.type.calendar_id> ), from : { year : int; @@ -151,7 +151,7 @@ namespace _zeitbild.frontend_web.view ) : Promise< { sources : lib_plankton.map.type_map< - type_calendar_id, + _zeitbild.frontend_web.type.calendar_id, { name : string; } @@ -164,8 +164,8 @@ namespace _zeitbild.frontend_web.view pit : _zeitbild.frontend_web.helpers.type_pit; entries : Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } >; today : boolean; @@ -177,12 +177,6 @@ namespace _zeitbild.frontend_web.view > { const now_pit : _zeitbild.frontend_web.helpers.type_pit = _zeitbild.frontend_web.helpers.pit_now(); - /* - const calendar_object : type_calendar_object = calendar_read( - data, - calendar_id - ); - */ const from_pit : _zeitbild.frontend_web.helpers.type_pit = _zeitbild.frontend_web.helpers.pit_from_year_and_week( (from as {year : int; week : int}).year, (from as {year : int; week : int}).week, @@ -201,9 +195,9 @@ namespace _zeitbild.frontend_web.view // prepare const entries : Array< { - calendar_id : type_calendar_id; + calendar_id : _zeitbild.frontend_web.type.calendar_id; calendar_name : string; - event : type_event; + event : _zeitbild.frontend_web.type.event_object; } > = await _zeitbild.frontend_web.backend.events( from_pit, @@ -214,7 +208,7 @@ namespace _zeitbild.frontend_web.view ); let result : { sources : lib_plankton.map.type_map< - type_calendar_id, + _zeitbild.frontend_web.type.calendar_id, { name : string; } @@ -227,8 +221,8 @@ namespace _zeitbild.frontend_web.view pit : _zeitbild.frontend_web.helpers.type_pit; entries : Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } >; today : boolean; @@ -264,8 +258,8 @@ namespace _zeitbild.frontend_web.view pit : _zeitbild.frontend_web.helpers.type_pit; entries : Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } >; today : boolean; @@ -373,7 +367,7 @@ namespace _zeitbild.frontend_web.view calendar_ids ?: ( null | - Array + Array<_zeitbild.frontend_web.type.calendar_id> ); from ?: { year : int; @@ -419,7 +413,7 @@ namespace _zeitbild.frontend_web.view ); const stuff : { sources : lib_plankton.map.type_map< - type_calendar_id, + _zeitbild.frontend_web.type.calendar_id, { name : string; } @@ -432,8 +426,8 @@ namespace _zeitbild.frontend_web.view pit : _zeitbild.frontend_web.helpers.type_pit; entries : Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } >; today : boolean; @@ -448,7 +442,7 @@ namespace _zeitbild.frontend_web.view options.timezone_shift ); const sources : lib_plankton.map.type_map< - type_calendar_id, + _zeitbild.frontend_web.type.calendar_id, { name : string; color : lib_plankton.color.type_color; @@ -588,7 +582,7 @@ namespace _zeitbild.frontend_web.view /** */ async function calendar_view_list_data( - calendar_ids : Array, + calendar_ids : Array<_zeitbild.frontend_web.type.calendar_id>, options : { from ?: _zeitbild.frontend_web.helpers.type_pit; to ?: _zeitbild.frontend_web.helpers.type_pit; @@ -597,8 +591,8 @@ namespace _zeitbild.frontend_web.view ) : Promise< Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } > > @@ -625,8 +619,8 @@ namespace _zeitbild.frontend_web.view const entries : Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } > = await _zeitbild.frontend_web.backend.events( (options.from as _zeitbild.frontend_web.helpers.type_pit), @@ -651,7 +645,7 @@ namespace _zeitbild.frontend_web.view /** */ export async function calendar_view_list_html( - calendar_ids : Array, + calendar_ids : Array<_zeitbild.frontend_web.type.calendar_id>, options : { from ?: _zeitbild.frontend_web.helpers.type_pit; to ?: _zeitbild.frontend_web.helpers.type_pit; @@ -661,8 +655,8 @@ namespace _zeitbild.frontend_web.view { const stuff : Array< { - calendar_id : type_calendar_id; - event : type_event; + calendar_id : _zeitbild.frontend_web.type.calendar_id; + event : _zeitbild.frontend_web.type.event_object; } > = await calendar_view_list_data( calendar_ids, diff --git a/source/style/main.css b/source/style/main.css index 61cd645..3583fd5 100644 --- a/source/style/main.css +++ b/source/style/main.css @@ -4,6 +4,29 @@ html { font-family: sans-serif; } +header { + border-bottom: 2px solid #888; + padding-bottom: 16px; + margin-bottom: 16px; +} + +nav > ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +nav > ul > li { + display: inline-block; + margin: 16px; + padding: 8px; +} + +a { + text-decoration: none; + color: hsl(0, 0%, 100%); +} + .calendar { display: flex; flex-direction: row; @@ -82,3 +105,13 @@ html { font-weight: bold; cursor: pointer; } + +.plankton_input_group_field { + margin-bottom: 8px; +} + +.plankton_input_group_field_label { + display: block; + font-weight: bold; + font-size: 0.8em; +} diff --git a/source/templates/login.html.tpl b/source/templates/login.html.tpl new file mode 100644 index 0000000..d386a39 --- /dev/null +++ b/source/templates/login.html.tpl @@ -0,0 +1,2 @@ +
+
diff --git a/tools/update-plankton b/tools/update-plankton index 452a3e2..e9b5412 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -6,20 +6,22 @@ dir=lib/plankton modules="" modules="${modules} base" +modules="${modules} conf" modules="${modules} call" +modules="${modules} storage" modules="${modules} file" modules="${modules} json" -modules="${modules} args" modules="${modules} string" modules="${modules} color" modules="${modules} xml" modules="${modules} map" -# modules="${modules} ical" modules="${modules} http" modules="${modules} log" modules="${modules} url" -modules="${modules} conf" modules="${modules} www_form" +modules="${modules} zoo-page" +modules="${modules} zoo-form" +modules="${modules} zoo-input" ## exec