From 94864eaeec9a49ff764d5af5168ed233f74cca4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Thu, 11 May 2023 12:59:02 +0200 Subject: [PATCH] [add] output:jsonschema [add] output:typescript --- doc/examples/contacts.sindri.json | 64 + doc/sindri.schema.json | 36 +- lib/plankton/plankton.d.ts | 815 +++--- lib/plankton/plankton.js | 3836 +++++++++++++++-------------- source/conf.ts | 67 +- source/main.ts | 37 +- source/outputs/jsonschema.ts | 82 + source/outputs/mysql.ts | 94 +- source/outputs/sqlite.ts | 70 +- source/outputs/typescript.ts | 73 + source/types.ts | 24 +- tools/get-plankton | 1 + tools/makefile | 2 + 13 files changed, 2794 insertions(+), 2407 deletions(-) create mode 100644 doc/examples/contacts.sindri.json create mode 100644 source/outputs/jsonschema.ts create mode 100644 source/outputs/typescript.ts diff --git a/doc/examples/contacts.sindri.json b/doc/examples/contacts.sindri.json new file mode 100644 index 0000000..849f207 --- /dev/null +++ b/doc/examples/contacts.sindri.json @@ -0,0 +1,64 @@ +{ + "domains": [ + { + "name": "address", + "description": "collection of addresses", + "key_field": { + "name": "id" + }, + "data_fields": [ + { + "name": "city", + "description": "the name of the city", + "nullable": false, + "type": "string_medium" + }, + { + "name": "zip", + "description": "the postal code", + "nullable": false, + "type": "string_medium" + }, + { + "name": "street", + "description": "the name of the street and the house number", + "nullable": false, + "type": "string_medium" + + } + ] + }, + { + "name": "person", + "description": "collection of contacts", + "key_field": null, + "data_fields": [ + { + "name": "prename", + "description": "first name of the person", + "nullable": false, + "type": "string_medium" + }, + { + "name": "surname", + "description": "last name of the person", + "nullable": false, + "type": "string_medium" + }, + { + "name": "address_id", + "description": "reference to the associated address dataset", + "nullable": false, + "type": "integer" + }, + { + "name": "email_address", + "description": "optional eMail address", + "nullable": true, + "type": "string_medium", + "default": null + } + ] + } + ] +} diff --git a/doc/sindri.schema.json b/doc/sindri.schema.json index a50c814..12b5c80 100644 --- a/doc/sindri.schema.json +++ b/doc/sindri.schema.json @@ -12,18 +12,27 @@ "type": "string" }, "description": { - "type": ["null", "string"], + "type": [ + "null", + "string" + ], "default": null }, "key_field": { - "type": ["null","object"], + "type": [ + "null", + "object" + ], "additionalProperties": false, "properties": { "name": { "type": "string" }, "description": { - "type": ["null", "string"], + "type": [ + "null", + "string" + ], "default": null } }, @@ -42,7 +51,10 @@ "type": "string" }, "description": { - "type": ["null", "string"], + "type": [ + "null", + "string" + ], "default": null }, "type": { @@ -61,7 +73,13 @@ "default": true }, "default": { - "type": ["null", "boolean", "integer", "float", "string"], + "type": [ + "null", + "boolean", + "integer", + "float", + "string" + ], "default": null } }, @@ -88,10 +106,8 @@ "parameters": { "type": "object", "additionalProperties": "string", - "properties": { - }, - "required": [ - ] + "properties": {}, + "required": [] } }, "required": [ @@ -110,4 +126,4 @@ "required": [ "domains" ] -} +} \ No newline at end of file diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index b4a77fb..ffc5761 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -1,23 +1,35 @@ /** * @author fenris */ -declare type int = number; +type int = number; /** * @author fenris */ -declare type float = number; +type float = number; /** * @author fenris */ -declare type type_time = { +type type_time = { hours: int; minutes: int; seconds: int; }; +declare var process: any; +declare var require: any; +declare class Buffer { + constructor(x: string, modifier?: string); + toString(modifier?: string): string; +} +declare namespace lib_plankton.base { + /** + * @author fenris + */ + function environment(): string; +} /** * @author fenris */ -declare type type_pseudopointer = { +type type_pseudopointer = { value: type_value; }; /** @@ -40,19 +52,6 @@ declare function pseudopointer_read(pseudopointer: type_pseudopointe * @author fenris */ declare function pseudopointer_write(pseudopointer: type_pseudopointer, value: type_value): void; -declare var process: any; -declare var require: any; -declare class Buffer { - constructor(x: string, modifier?: string); - toString(modifier?: string): string; -} -declare var java: any; -declare module lib_base { - /** - * @author fenris - */ - function environment(): string; -} /** * @author fenris */ @@ -380,395 +379,9 @@ declare namespace lib_plankton.base { * @author fenris */ function get_current_timestamp(rounded?: boolean): int; -} -declare var plain_text_to_html: (text: string) => string; -/** - * @desc makes a valid - */ -declare var format_sentence: (str: string, rtl?: boolean, caseSense?: boolean) => string; -declare var fill_string_template: (template_string: string, object: any, fabric: Function, delimiter: string, default_string: string, sloppy: boolean) => string; -declare var make_string_template: (_template: string, _fabrics?: Object) => (object: { - [key: string]: string; -}) => string; -declare var make_eml_header: (object: { - [key: string]: string; -}) => string; -declare var make_eml_body: Object; -declare namespace lib_plankton.string { /** - * @author neuc,frac */ - function empty(str: string): boolean; - /** - * @desc returns a unique string - * @param {string} prefix an optional prefix for the generated string - * @return {string} - * @author fenris - */ - function generate(prefix?: string): string; - /** - * @desc splits a string, but returns an empty list, if the string is empty - * @param {string} chain - * @param {string} separator - * @return {Array} - * @author fenris - */ - function split(chain: string, separator?: string): Array; - /** - * @author neu3no - */ - function explode(str: string, needle: string, max: int): Array; - /** - * @desc concats a given word with itself n times - * @param {string} word - * @param {int} - * @return {string} - * @author fenris - */ - function repeat(word: string, count: int): string; - /** - * @desc lengthens a string by repeatedly appending or prepending another string - * @param {string} word the string to pad - * @param {int} length the length, which the result shall have - * @param {string} symbol the string, which will be added (multiple times) - * @param {boolean} [prepend]; whether to prepend (~true) or append (~false); default: false - * @return {string} the padded string - * @author fenris - */ - function pad(word: string, length: int, symbol?: string, mode?: string): string; - /** - * @desc checks if a given string conttains a certain substring - * @param {string} string - * @param {string} part - * @return {boolean} - * @author fenris - */ - function contains(chain: string, part: string): boolean; - /** - * @desc checks if a given string starts with a certain substring - * @param {string} string - * @param {string} part - * @return {boolean} - * @author fenris - */ - function startsWith(chain: string, part: string): boolean; - /** - * @desc checks if a given string ends with a certain substring - * @param {string} string - * @param {string} part - * @return {boolean} - * @author fenris - */ - function endsWith(chain: string, part: string): boolean; - /** - * @desc count the occourrences of a string in a string - * @param string haystack_string the string wich should be examined - * @param string needle_string the string which should be counted - * @author neuc - */ - function count_occourrences(haystack_string: string, needle_string: string, check_escape: boolean): int; - /** - * @author fenris - */ - function replace(str: string, replacements: Array<{ - from: string; - to: string; - }>, options?: { - debug?: boolean; - }): string; - /** - * @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object - * @author fenris - */ - function coin(str: string, args: { - [id: string]: string; - }, options?: { - legacy?: boolean; - open?: string; - close?: string; - debug?: boolean; - }): string; - /** - * @author fenris - */ - function cut(str: string, length: int, delimiter?: string): string; -} -/** - * @deprecated - */ -declare namespace lib_string { - const empty: typeof lib_plankton.string.empty; - const generate: typeof lib_plankton.string.generate; - const split: typeof lib_plankton.string.split; - const explode: typeof lib_plankton.string.repeat; - const repeat: typeof lib_plankton.string.repeat; - const pad: typeof lib_plankton.string.pad; - const contains: typeof lib_plankton.string.contains; - const startsWith: typeof lib_plankton.string.startsWith; - const endsWith: typeof lib_plankton.string.endsWith; - const count_occourrences: typeof lib_plankton.string.count_occourrences; - const coin: typeof lib_plankton.string.coin; - const stance: typeof lib_plankton.string.coin; - const cut: typeof lib_plankton.string.cut; -} -declare module lib_string { - /** - * an implementation of c sprintf - * @param {string} string format string - * @param {array} args arguments which should be filled into - * @returns {string} - */ - var sprintf: (input: string, args?: Array, original?: any) => string; - /** - * an implementation of c printf - * @param {string} string format string - * @param {array} args arguments which should be filled into - * @returns {string} - */ - function printf(format: any, args: any): void; -} -declare var sprintf: (input: string, args?: Array, original?: any) => string; -declare var printf: typeof lib_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 module lib_code { - /** - * @author fenris - */ - interface interface_code { - /** - * @author fenris - */ - encode(x: type_from): type_to; - /** - * @author fenris - */ - decode(x: type_to): type_from; - } -} -declare module lib_code { - /** - * @author fenris - */ - type type_code = { - /** - * @author fenris - */ - encode: (x: type_from) => type_to; - /** - * @author fenris - */ - decode: (x: type_to) => type_from; - }; -} -declare module lib_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 module lib_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 module lib_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 module lib_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 module lib_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 module lib_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 module lib_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 module lib_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 module lib_json { - /** - * @author fenris - */ - function encode(x: any, formatted?: boolean): string; - /** - * @author fenris - */ - function decode(x: string): any; -} -declare module lib_json { - /** - * @author fenris - */ - class class_json implements lib_code.interface_code { - /** - * @author fenris - */ - constructor(); - /** - * @implementation - * @author fenris - */ - encode(x: any): string; - /** - * @implementation - * @author fenris - */ - decode(x: string): any; - } -} -declare namespace lib_plankton.file { - /** - * @author fenris - */ - function read(path: string): Promise; - /** - * @author fenris - */ - function read_buffer(path: string): Promise; - /** - * @author fenris - */ - function read_stdin(): Promise; - /** - * @author fenris - */ - function write(path: string, content: string, options?: { - encoding?: string; - }): Promise; - /** - * @author fenris - */ - function write_buffer(path: string, content: Buffer, options?: {}): Promise; + function object_merge(core: Record, mantle: Record): Record; } declare namespace lib_plankton.log { /** @@ -798,7 +411,7 @@ declare namespace lib_plankton.log { * @deprecated * @todo remove */ -declare module lib_log { +declare namespace lib_plankton.log { function level_push(level: int): void; function level_pop(): void; function indent_push(indent: int): void; @@ -926,7 +539,393 @@ declare namespace lib_plankton.log { */ function error(incident: string, details?: Record): void; } -declare namespace lib_args { +declare var plain_text_to_html: (text: string) => string; +/** + * @desc makes a valid + */ +declare var format_sentence: (str: string, rtl?: boolean, caseSense?: boolean) => string; +declare var fill_string_template: (template_string: string, object: any, fabric: Function, delimiter: string, default_string: string, sloppy: boolean) => string; +declare var make_string_template: (_template: string, _fabrics?: Object) => (object: { + [key: string]: string; +}) => string; +declare var make_eml_header: (object: { + [key: string]: string; +}) => string; +declare var make_eml_body: Object; +declare namespace lib_plankton.string { + /** + * @author neuc,frac + */ + function empty(str: string): boolean; + /** + * @desc returns a unique string + * @param {string} prefix an optional prefix for the generated string + * @return {string} + * @author fenris + */ + function generate(prefix?: string): string; + /** + * @desc splits a string, but returns an empty list, if the string is empty + * @param {string} chain + * @param {string} separator + * @return {Array} + * @author fenris + */ + function split(chain: string, separator?: string): Array; + /** + * @author neu3no + */ + function explode(str: string, needle: string, max: int): Array; + /** + * @desc concats a given word with itself n times + * @param {string} word + * @param {int} + * @return {string} + * @author fenris + */ + function repeat(word: string, count: int): string; + /** + * @desc lengthens a string by repeatedly appending or prepending another string + * @param {string} word the string to pad + * @param {int} length the length, which the result shall have + * @param {string} symbol the string, which will be added (multiple times) + * @param {boolean} [prepend]; whether to prepend (~true) or append (~false); default: false + * @return {string} the padded string + * @author fenris + */ + function pad(word: string, length: int, symbol?: string, mode?: string): string; + /** + * @desc checks if a given string conttains a certain substring + * @param {string} string + * @param {string} part + * @return {boolean} + * @author fenris + */ + function contains(chain: string, part: string): boolean; + /** + * @desc checks if a given string starts with a certain substring + * @param {string} string + * @param {string} part + * @return {boolean} + * @author fenris + */ + function startsWith(chain: string, part: string): boolean; + /** + * @desc checks if a given string ends with a certain substring + * @param {string} string + * @param {string} part + * @return {boolean} + * @author fenris + */ + function endsWith(chain: string, part: string): boolean; + /** + * @desc count the occourrences of a string in a string + * @param string haystack_string the string wich should be examined + * @param string needle_string the string which should be counted + * @author neuc + */ + function count_occourrences(haystack_string: string, needle_string: string, check_escape: boolean): int; + /** + * @author fenris + */ + function replace(str: string, replacements: Array<{ + from: string; + to: string; + }>, options?: {}): string; + /** + * @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object + * @author fenris + */ + function coin(str: string, args: { + [id: string]: string; + }, options?: { + legacy?: boolean; + open?: string; + close?: string; + }): string; + /** + * @author fenris + */ + function cut(str: string, length: int, delimiter?: string): string; +} +/** + * @deprecated + */ +declare namespace lib_string { + const empty: typeof lib_plankton.string.empty; + const generate: typeof lib_plankton.string.generate; + const split: typeof lib_plankton.string.split; + const explode: typeof lib_plankton.string.repeat; + const repeat: typeof lib_plankton.string.repeat; + const pad: typeof lib_plankton.string.pad; + const contains: typeof lib_plankton.string.contains; + const startsWith: typeof lib_plankton.string.startsWith; + const endsWith: typeof lib_plankton.string.endsWith; + const count_occourrences: typeof lib_plankton.string.count_occourrences; + const coin: typeof lib_plankton.string.coin; + const stance: typeof lib_plankton.string.coin; + const cut: typeof lib_plankton.string.cut; +} +declare namespace lib_plankton.string { + /** + * an implementation of c sprintf + * @param {string} string format string + * @param {array} args arguments which should be filled into + * @returns {string} + */ + var sprintf: (input: string, args?: Array, original?: any) => string; + /** + * an implementation of c printf + * @param {string} string format string + * @param {array} args arguments which should be filled into + * @returns {string} + */ + function printf(format: any, args: any): void; +} +declare var sprintf: (input: string, args?: Array, original?: any) => string; +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.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 { + /** + * @author fenris + */ + function encode(x: any, formatted?: boolean): string; + /** + * @author fenris + */ + function decode(x: string): any; +} +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.file { + /** + * @author fenris + */ + function read(path: string): Promise; + /** + * @author fenris + */ + function read_buffer(path: string): Promise; + /** + * @author fenris + */ + function read_stdin(): Promise; + /** + * @author fenris + */ + function write(path: string, content: string, options?: { + encoding?: string; + }): Promise; + /** + * @author fenris + */ + function write_buffer(path: string, content: Buffer, options?: {}): Promise; +} +declare namespace lib_plankton.args { /** */ enum enum_environment { @@ -954,7 +953,7 @@ declare namespace lib_args { accumulate = "accumulate" } } -declare module lib_args { +declare namespace lib_plankton.args { /** * @author fenris */ @@ -1091,7 +1090,7 @@ declare module lib_args { generate_help(): string; } } -declare module lib_args { +declare namespace lib_plankton.args { /** * @author fenris */ diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index e6e51a6..7c895a7 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -36,7 +36,40 @@ along with »bacterio-plankton:base«. If not, see + +»bacterio-plankton:base« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:base« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:base«. If not, see . + */ +; +var lib_plankton; +(function (lib_plankton) { + var base; + (function (base) { + /** + * @author fenris + */ + function environment() { + return "node"; + } + base.environment = environment; + })(base = lib_plankton.base || (lib_plankton.base = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:base«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -95,74 +128,7 @@ along with »bacterio-plankton:base«. If not, see - -»bacterio-plankton:base« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:base« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:base«. If not, see . - */ -; -var lib_base; -(function (lib_base) { - /** - * @author fenris - */ - function environment() { - var entries = [ - { - "id": "web", - "name": "Web", - "predicate": function () { return (typeof (document) !== "undefined"); }, - }, - { - "id": "node", - "name": "Node.js", - "predicate": function () { return (typeof (process) !== "undefined"); }, - }, - { - "id": "rhino", - "name": "Rhino", - "predicate": function () { return (typeof (java) !== "undefined"); }, - }, - { - "id": "webworker", - "name": "WebWorker", - "predicate": function () { return (typeof (self["WorkerNavigator"]) !== "undefined"); } - } - ]; - var id; - var found = entries.some(function (entry) { - if (entry.predicate()) { - id = entry.id; - return true; - } - else { - return false; - } - }); - if (found) { - return id; - } - else { - throw (new Error("unknown environment")); - } - } - lib_base.environment = environment; -})(lib_base || (lib_base = {})); -/* -This file is part of »bacterio-plankton:base«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -201,7 +167,7 @@ function instance_collate(value1, value2) { } else { if (instance_verbosity >= 1) { - // lib_log.warn("[collate]" + " " + "primitive value; using default implementation"); + // lib_plankton.log.warn("[collate]" + " " + "primitive value; using default implementation"); } return (value1 === value2); } @@ -220,7 +186,7 @@ function instance_compare(value1, value2) { } else { if (instance_verbosity >= 1) { - // lib_log.warn("[compare]" + " " + "primitive value; using default implementation"); + // lib_plankton.log.warn("[compare]" + " " + "primitive value; using default implementation"); } return (value1 <= value2); } @@ -239,7 +205,7 @@ function instance_clone(value) { } else { if (instance_verbosity >= 1) { - // lib_log.warn("[clone]" + " " + "primitive value; using default implementation"); + // lib_plankton.log.warn("[clone]" + " " + "primitive value; using default implementation"); } return value; } @@ -259,7 +225,7 @@ function instance_hash(value) { } else { if (instance_verbosity >= 1) { - // lib_log.warn("[hash]" + " " + "primitive value; using default implementation"); + // lib_plankton.log.warn("[hash]" + " " + "primitive value; using default implementation"); } return String(value); } @@ -285,7 +251,7 @@ function instance_show(value) { } else { if (instance_verbosity >= 1) { - // lib_log.warn("[show]" + " " + "primitive value; using default implementation"); + // lib_plankton.log.warn("[show]" + " " + "primitive value; using default implementation"); } return String(value); } @@ -293,7 +259,7 @@ function instance_show(value) { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -404,7 +370,7 @@ export interface interface_writeable { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -572,7 +538,7 @@ var lib_maybe; */ class_nothing.prototype.cull = function () { var message = "you shouldn't cull a nothing-value …"; - // lib_log.warn(message); + // lib_plankton.log.warn(message); return null; }; /** @@ -659,7 +625,7 @@ var lib_maybe; /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -715,12 +681,617 @@ var lib_plankton; ; } base.get_current_timestamp = get_current_timestamp; + /** + */ + function object_merge(core, mantle) { + return Object.assign(core, mantle); + } + base.object_merge = object_merge; })(base = lib_plankton.base || (lib_plankton.base = {})); })(lib_plankton || (lib_plankton = {})); +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + var enum_level; + (function (enum_level) { + enum_level[enum_level["debug"] = 0] = "debug"; + enum_level[enum_level["info"] = 1] = "info"; + enum_level[enum_level["notice"] = 2] = "notice"; + enum_level[enum_level["warning"] = 3] = "warning"; + enum_level[enum_level["error"] = 4] = "error"; + })(enum_level = log.enum_level || (log.enum_level = {})); + ; + /** + */ + function level_order(level1, level2) { + return (level1 <= level2); + } + log.level_order = level_order; + /** + */ + function level_show(level) { + switch (level) { + case enum_level.debug: return "debug"; + case enum_level.info: return "info"; + case enum_level.notice: return "notice"; + case enum_level.warning: return "warning"; + case enum_level.error: return "error"; + default: return "(unknown)"; + } + } + log.level_show = level_show; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:lang«. If not, see . + */ +/** + * @deprecated + * @todo remove + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + * @author fenris + */ + /*export*/ var level_stack = [0]; + function level_push(level) { level_stack.push(level); } + log.level_push = level_push; + function level_pop() { if (level_stack.length > 1) { + level_stack.pop(); + } } + log.level_pop = level_pop; + function level_get() { return level_stack.slice(-1)[0]; } + /* + export function level_inc() : void {level_push(level_get()+1);} + export function level_dec() : void {level_push(level_get()-1);} + */ + /** + * @author fenris + */ + var indent_stack = [0]; + function indent_push(indent) { indent_stack.push(indent); } + log.indent_push = indent_push; + function indent_pop() { if (indent_stack.length > 1) { + indent_stack.pop(); + } } + log.indent_pop = indent_pop; + function indent_get() { return level_stack.slice(-1)[0]; } + function indent_inc() { level_push(level_get() + 1); } + log.indent_inc = indent_inc; + function indent_dec() { level_push(level_get() - 1); } + log.indent_dec = indent_dec; + /** + * @author fenris + */ + function write(_a) { + var message = _a["message"], _b = _a["type"], type = _b === void 0 ? null : _b, _c = _a["prefix"], prefix = _c === void 0 ? null : _c, _d = _a["level"], level = _d === void 0 ? 0 : _d, _e = _a["indent"], indent = _e === void 0 ? 0 : _e; + var entry = { + "level": ((type === null) + ? lib_plankton.log.enum_level.info + : { + "debug": lib_plankton.log.enum_level.debug, + "info": lib_plankton.log.enum_level.info, + "notice": lib_plankton.log.enum_level.notice, + "warning": lib_plankton.log.enum_level.warning, + "error": lib_plankton.log.enum_level.error + }[type]), + "incident": message, + "details": { + "prefix": prefix, + "level": level, + "indent": indent + } + }; + lib_plankton.log.add(entry); + } + log.write = write; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + var class_channel = /** @class */ (function () { + function class_channel() { + } + return class_channel; + }()); + log.class_channel = class_channel; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + * output for writing log entries to stdout + */ + var class_channel_stdout = /** @class */ (function (_super) { + __extends(class_channel_stdout, _super); + function class_channel_stdout() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + */ + class_channel_stdout.prototype.add = function (entry) { + process.stdout.write(("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") + + + " " + + + ("[" + log.level_show(entry.level) + "]") + + + " " + + + ("" + entry.incident + "") + + + ": " + + + JSON.stringify(entry.details, undefined, " ") + + + "\n"); + }; + return class_channel_stdout; + }(log.class_channel)); + log.class_channel_stdout = class_channel_stdout; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + var class_channel_file = /** @class */ (function (_super) { + __extends(class_channel_file, _super); + /** + * [constructor] + */ + function class_channel_file(path) { + var _this = _super.call(this) || this; + _this.path = path; + return _this; + } + /** + */ + class_channel_file.prototype.add = function (entry) { + var _this = this; + var nm_fs = require("fs"); + nm_fs.writeFile(this.path, { + "flag": "a+" + }, (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") + + + " " + + + ("[" + log.level_show(entry.level) + "]") + + + " " + + + ("" + entry.incident + "") + + + ": " + + + JSON.stringify(entry.details, undefined, " ") + + + "\n"), function (error) { + process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n"); + }); + }; + return class_channel_file; + }(log.class_channel)); + log.class_channel_file = class_channel_file; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + * output for desktop notifications via "libnotify" + */ + var class_channel_notify = /** @class */ (function (_super) { + __extends(class_channel_notify, _super); + function class_channel_notify() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** + */ + class_channel_notify.prototype.add = function (entry) { + var nm_child_process = require("child_process"); + var command = ("notify-send" + + + " " + + + ("'" + + + ("[" + log.level_show(entry.level) + "]") + + + " " + + + entry.incident + + + "'") + + + " " + + + ("'" + + + (Object.keys(entry.details) + .map(function (key) { return (key + ": " + JSON.stringify(entry.details[key])); }) + .join("\n")) + + + "'")); + nm_child_process.exec(command, function (error, stdout, stderr) { + // do noting + }); + }; + return class_channel_notify; + }(log.class_channel)); + log.class_channel_notify = class_channel_notify; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + * decorator for filtering out log entries below a certain level threshold + */ + var class_channel_minlevel = /** @class */ (function (_super) { + __extends(class_channel_minlevel, _super); + /** + */ + function class_channel_minlevel(core, threshold) { + var _this = _super.call(this) || this; + _this.core = core; + _this.threshold = threshold; + return _this; + } + /** + */ + class_channel_minlevel.prototype.add = function (entry) { + if (!log.level_order(this.threshold, entry.level)) { + // do nothing + } + else { + this.core.add(entry); + } + }; + return class_channel_minlevel; + }(log.class_channel)); + log.class_channel_minlevel = class_channel_minlevel; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + function translate_level(level_string) { + return { + "debug": log.enum_level.debug, + "info": log.enum_level.info, + "notice": log.enum_level.notice, + "warning": log.enum_level.warning, + "error": log.enum_level.error + }[level_string]; + } + /** + */ + function channel_make(description) { + var _a, _b, _c, _d; + switch (description.kind) { + default: { + throw (new Error("unhandled log channel kind: " + description.kind)); + break; + } + case "stdout": { + return (new log.class_channel_minlevel(new log.class_channel_stdout(), translate_level((_a = description.data["threshold"]) !== null && _a !== void 0 ? _a : "debug"))); + break; + } + case "file": { + return (new log.class_channel_minlevel(new log.class_channel_file((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug"))); + break; + } + case "notify": { + return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "debug"))); + break; + } + } + } + log.channel_make = channel_make; + /** + */ + function conf_default() { + return [ + new log.class_channel_minlevel(new log.class_channel_stdout(), log.enum_level.notice), + new log.class_channel_minlevel(new log.class_channel_notify(), log.enum_level.error), + ]; + } + log.conf_default = conf_default; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + var _channel_stack = null; + /** + * pushes a new configuration on the stack and activates it + */ + function conf_push(channels) { + if (_channel_stack === null) { + _channel_stack = []; + } + _channel_stack.push(channels); + } + log.conf_push = conf_push; + /** + * pops the current active configuration from the stack + */ + function conf_pop() { + if (_channel_stack.length > 0) { + _channel_stack.pop(); + } + else { + // do nothing + } + } + log.conf_pop = conf_pop; + /** + * makes the logging system ready + */ + function setup() { + if (_channel_stack === null) { + _channel_stack = []; + conf_push(log.conf_default()); + } + else { + // do nothing + } + } + /** + * consumes a log entry, i.e. sends it to the currently active outputs + */ + function add(entry) { + setup(); + _channel_stack.slice(-1)[0].forEach(function (channel) { return channel.add(entry); }); + } + log.add = add; + /** + */ + function debug(incident, details) { + if (details === void 0) { details = {}; } + add({ "level": log.enum_level.debug, "incident": incident, "details": details }); + } + log.debug = debug; + /** + */ + function info(incident, details) { + if (details === void 0) { details = {}; } + add({ "level": log.enum_level.info, "incident": incident, "details": details }); + } + log.info = info; + /** + */ + function notice(incident, details) { + if (details === void 0) { details = {}; } + add({ "level": log.enum_level.notice, "incident": incident, "details": details }); + } + log.notice = notice; + /** + */ + function warning(incident, details) { + if (details === void 0) { details = {}; } + add({ "level": log.enum_level.warning, "incident": incident, "details": details }); + } + log.warning = warning; + /** + */ + function error(incident, details) { + if (details === void 0) { details = {}; } + add({ "level": log.enum_level.error, "incident": incident, "details": details }); + } + log.error = error; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -879,7 +1450,7 @@ var make_eml_body = (function () { /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -929,7 +1500,7 @@ var lib_plankton; throw (new Error("[string_generate] out of valid indices")); } else { - return sprintf(prefix + "%0" + hexdigits.toString() + "X", [index_is++]); + return string.sprintf(prefix + "%0" + hexdigits.toString() + "X", [index_is++]); } } string.generate = generate; @@ -1116,15 +1687,13 @@ var lib_plankton; * @author fenris */ function replace(str, replacements, options = {}) { - options = Object.assign({ - "debug": false, - }, options); + options = Object.assign({}, options); let result = str; replacements.forEach(replacement => { - if (options.debug) { - process.stderr.write(">> lib_plankton.string.replace.from: " + replacement.from + "\n"); - process.stderr.write(">> lib_plankton.string.replace.to: " + replacement.to + "\n"); - } + lib_plankton.log.debug("lib_plankton.string.replace", { + "from": replacement.from, + "to": replacement.to, + }); result = result.replace(new RegExp(replacement.from, "g"), replacement.to); }); return result; @@ -1139,39 +1708,30 @@ var lib_plankton; "legacy": false, "open": "{{", "close": "}}", - "debug": false, }, options); Object.keys(args).forEach((key) => { // old syntax { if (options.legacy) { const value = args[key]; - if (options.debug) { - process.stderr.write(">> lib_plankton.string.coin.key: " + key + "\n"); - } const regexp_argument = new RegExp("\\${" + key + "}", "g"); - if (options.debug) { - process.stderr.write(">> lib_plankton.string.coin.regex: " + regexp_argument.toString() + "\n"); - } - if (options.debug) { - process.stderr.write(">> lib_plankton.string.coin.value: " + value + "\n"); - } + lib_plankton.log.debug("lib_plankton.string.coin", { + "key": key, + "regex": regexp_argument.toString(), + "value": value, + }); str = str.replace(regexp_argument, value); } } // new syntax { const value = args[key]; - if (options.debug) { - process.stderr.write(">> lib_plankton.string.coin.key: " + key + "\n"); - } const regexp_argument = new RegExp(options.open + key + options.close, "g"); - if (options.debug) { - process.stderr.write(">> lib_plankton.string.coin.regex: " + regexp_argument.toString() + "\n"); - } - if (options.debug) { - process.stderr.write(">> lib_plankton.string.coin.value: " + value + "\n"); - } + lib_plankton.log.debug("lib_plankton.string.coin", { + "key": key, + "regex": regexp_argument.toString(), + "value": value, + }); str = str.replace(regexp_argument, value); } }); @@ -1214,7 +1774,7 @@ var lib_string; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -1230,252 +1790,255 @@ 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:string«. If not, see . */ -var lib_string; -(function (lib_string) { - var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/; - var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g; - function split_format(format) { - var tmp = format.match(pattern); - if (tmp === null) - return null; - return { - 'flags': tmp[1].split(""), - 'width': Number(tmp[2]), - 'precision': tmp[3] === '' ? null : Number(tmp[3]), - 'specifier': tmp[4], - 'string': format +var lib_plankton; +(function (lib_plankton) { + var string; + (function (string) { + var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/; + var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g; + function split_format(format) { + var tmp = format.match(pattern); + if (tmp === null) + return null; + return { + 'flags': tmp[1].split(""), + 'width': Number(tmp[2]), + 'precision': tmp[3] === '' ? null : Number(tmp[3]), + 'specifier': tmp[4], + 'string': format + }; + } + function make_err(format, arg, should) { + return ("[sprintf]" + " " + "argument for '" + format.string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!"); + } + function test_arg(format, arg, should) { + if (typeof arg !== should) { + console.warn(make_err(format, arg, should)); + return false; + } + return true; + } + function string_fill(str, char, len, left) { + while (str.length < len) { + if (left) { + str += char; + } + else { + str = char + str; + } + } + return str; + } + /** + * the known_parameters are used to parse the different identifiers for the welln known syntax: + * flag width precision identifier + * %{[0#+- ]}{[0-9]*}.{[0-9]*}[fFdiueEgGsoxXaAsn] + * flags: + * 0 - fill with '0' instead of ' ' if the string length < width + * # - not implemented + * - - left-justified -> fill on the right side to reach width + * + - force using '+' on positive numbers + * ' ' - add a single space before positive numbers + * + * identifiers + * %f, %F - interpret given number as float, width: the minimal total width (fill with ' ' or '0' if the + * resulting string is too short, precision: cut more then given decimal places + * %d, %i, %u - interpret number as integer, decimal places will be cut. width: like float, precision: + * fill with '0' on right side until length given in precision is reached + * %e - interpret as float and write as scientifical number, width & precision like in float + * %E - same es %e but uppercase 'E' + * %g - use the shortest string of %f or %e + * %G - use the shortest string of %E or %E + * %s - simply print a string + * %o - print the given number in octal notation + * %x - print the given number in hex notation + * %X - same as %x but with uppercase characters + * %a - alias to %x + * %A - alias to %X + * %n - just print nothing + * @type {{}} + */ + var known_params = {}; + known_params["f"] = function (format, arg) { + if (!test_arg(format, arg, "number")) + return "Ø"; + var tmp = Math.abs(arg); + var sign = (arg < 0) ? -1 : 1; + var tmp_result = null; + if (format.precision !== null) { + tmp = Math.floor(Math.pow(10, format.precision) * tmp) / Math.pow(10, format.precision); + var tmp_ = (tmp * sign).toString().split("."); + if (tmp_.length === 1) + tmp_.push(""); + tmp_[1] = string_fill(tmp_[1], "0", format.precision, true); + tmp_result = tmp_.join("."); + } + else { + tmp_result = (sign * tmp).toString(); + } + if ((format.flags.indexOf(" ") >= 0) && (arg >= 0)) { + tmp_result = " " + tmp; + } + else if ((format.flags.indexOf("+") >= 0) && (arg >= 0)) { + tmp_result = "+" + tmp; + } + tmp_result = string_fill(tmp, (format.flags.indexOf("0") >= 0) ? "0" : " ", format.width, (format.flags.indexOf("-") >= 0)); + return tmp_result; }; - } - function make_err(format, arg, should) { - return ("[sprintf]" + " " + "argument for '" + format.string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!"); - } - function test_arg(format, arg, should) { - if (typeof arg !== should) { - console.warn(make_err(format, arg, should)); - return false; - } - return true; - } - function string_fill(str, char, len, left) { - while (str.length < len) { - if (left) { - str += char; + known_params["F"] = known_params["f"]; + known_params["d"] = function (format, arg) { + if (!test_arg(format, arg, 'number')) + return 'Ø'; + var tmp = (((arg < 0 && format.specifier !== 'u') ? -1 : 1) * Math.floor(Math.abs(arg))).toString(); + if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf(' ') >= 0 && arg >= 0) { + tmp = ' ' + tmp; + } + else if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf('+') >= 0 && arg >= 0) { + tmp = '+' + tmp; + } + tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); + tmp = string_fill(tmp, '0', format.precision === null ? 0 : format.precision, false); + return tmp; + }; + known_params["i"] = known_params["d"]; + known_params["u"] = known_params["d"]; + known_params["e"] = function (format, arg) { + if (!test_arg(format, arg, 'number')) + return 'Ø'; + var tmp = arg.toExponential(format.precision === null ? undefined : format.precision).toString(); + if (format.flags.indexOf(' ') >= 0 && arg >= 0) { + tmp = ' ' + tmp; + } + else if (format.flags.indexOf('+') >= 0 && arg >= 0) { + tmp = '+' + tmp; + } + tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); + return tmp; + }; + known_params["E"] = function (format, arg) { + return known_params["e"](format, arg).toUpperCase(); + }; + known_params["g"] = function (format, arg) { + if (!test_arg(format, arg, 'number')) + return 'Ø'; + var tmpf = known_params["f"](format, arg); + var tmpe = known_params["e"](format, arg); + if (tmpf.length < tmpe.length) { + return tmpf; } else { - str = char + str; + return tmpe; } - } - return str; - } - /** - * the known_parameters are used to parse the different identifiers for the welln known syntax: - * flag width precision identifier - * %{[0#+- ]}{[0-9]*}.{[0-9]*}[fFdiueEgGsoxXaAsn] - * flags: - * 0 - fill with '0' instead of ' ' if the string length < width - * # - not implemented - * - - left-justified -> fill on the right side to reach width - * + - force using '+' on positive numbers - * ' ' - add a single space before positive numbers - * - * identifiers - * %f, %F - interpret given number as float, width: the minimal total width (fill with ' ' or '0' if the - * resulting string is too short, precision: cut more then given decimal places - * %d, %i, %u - interpret number as integer, decimal places will be cut. width: like float, precision: - * fill with '0' on right side until length given in precision is reached - * %e - interpret as float and write as scientifical number, width & precision like in float - * %E - same es %e but uppercase 'E' - * %g - use the shortest string of %f or %e - * %G - use the shortest string of %E or %E - * %s - simply print a string - * %o - print the given number in octal notation - * %x - print the given number in hex notation - * %X - same as %x but with uppercase characters - * %a - alias to %x - * %A - alias to %X - * %n - just print nothing - * @type {{}} - */ - var known_params = {}; - known_params["f"] = function (format, arg) { - if (!test_arg(format, arg, "number")) - return "Ø"; - var tmp = Math.abs(arg); - var sign = (arg < 0) ? -1 : 1; - var tmp_result = null; - if (format.precision !== null) { - tmp = Math.floor(Math.pow(10, format.precision) * tmp) / Math.pow(10, format.precision); - var tmp_ = (tmp * sign).toString().split("."); - if (tmp_.length === 1) - tmp_.push(""); - tmp_[1] = string_fill(tmp_[1], "0", format.precision, true); - tmp_result = tmp_.join("."); - } - else { - tmp_result = (sign * tmp).toString(); - } - if ((format.flags.indexOf(" ") >= 0) && (arg >= 0)) { - tmp_result = " " + tmp; - } - else if ((format.flags.indexOf("+") >= 0) && (arg >= 0)) { - tmp_result = "+" + tmp; - } - tmp_result = string_fill(tmp, (format.flags.indexOf("0") >= 0) ? "0" : " ", format.width, (format.flags.indexOf("-") >= 0)); - return tmp_result; - }; - known_params["F"] = known_params["f"]; - known_params["d"] = function (format, arg) { - if (!test_arg(format, arg, 'number')) - return 'Ø'; - var tmp = (((arg < 0 && format.specifier !== 'u') ? -1 : 1) * Math.floor(Math.abs(arg))).toString(); - if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf(' ') >= 0 && arg >= 0) { - tmp = ' ' + tmp; - } - else if ((format.specifier === 'd' || format.specifier === 'i') && format.flags.indexOf('+') >= 0 && arg >= 0) { - tmp = '+' + tmp; - } - tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); - tmp = string_fill(tmp, '0', format.precision === null ? 0 : format.precision, false); - return tmp; - }; - known_params["i"] = known_params["d"]; - known_params["u"] = known_params["d"]; - known_params["e"] = function (format, arg) { - if (!test_arg(format, arg, 'number')) - return 'Ø'; - var tmp = arg.toExponential(format.precision === null ? undefined : format.precision).toString(); - if (format.flags.indexOf(' ') >= 0 && arg >= 0) { - tmp = ' ' + tmp; - } - else if (format.flags.indexOf('+') >= 0 && arg >= 0) { - tmp = '+' + tmp; - } - tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); - return tmp; - }; - known_params["E"] = function (format, arg) { - return known_params["e"](format, arg).toUpperCase(); - }; - known_params["g"] = function (format, arg) { - if (!test_arg(format, arg, 'number')) - return 'Ø'; - var tmpf = known_params["f"](format, arg); - var tmpe = known_params["e"](format, arg); - if (tmpf.length < tmpe.length) { - return tmpf; - } - else { - return tmpe; - } - }; - known_params["G"] = function (format, arg) { - return known_params["g"](format, arg).toUpperCase(); - }; - known_params["s"] = function (format, arg) { - if (!test_arg(format, arg, 'string')) - return 'o.O'; - var tmp = format.precision !== null ? arg.substr(0, format.precision) : arg; - tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); - return tmp; - }; - known_params["o"] = function (format, arg) { - if (!test_arg(format, arg, 'number')) - return 'Ø'; - var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); - return known_params["s"](format, tmp.toString(8)); - }; - known_params["x"] = function (format, arg) { - if (!test_arg(format, arg, 'number')) - return 'Ø'; - var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); - return known_params["s"](format, tmp.toString(16)); - }; - known_params["a"] = known_params["x"]; - known_params["X"] = function (format, arg) { - if (!test_arg(format, arg, 'number')) - return 'Ø'; - return known_params["x"](format, arg).toUpperCase(); - }; - known_params["A"] = known_params["X"]; - known_params["c"] = function (format, arg) { - var tmp = ""; - if (typeof arg === "number") { - tmp = String.fromCharCode(arg); - } - else if ((typeof arg === "string") && (arg.length === 1)) { - tmp = arg[0]; - } - else { - console.warn(make_err(format, arg, "number|string") + " and if string it needs to have the length of 1!"); - } - return known_params["s"](format, tmp); - }; - known_params["n"] = function () { - return ""; - }; - var decompose = function (chain, regexp) { - var result = regexp.exec(chain); - if (result == null) { - return null; - } - else { - var front = chain.substring(0, result.index); - var back = chain.substring(result.index + result[0].length); - return { "front": front, "match": result[0], "back": back }; - } - }; - /** - * an implementation of c sprintf - * @param {string} string format string - * @param {array} args arguments which should be filled into - * @returns {string} - */ - lib_string.sprintf = function (input, args = [], original = null) { - if (original == null) - original = input; - var components = decompose(input, pattern); - if (components == null) { - if (args.length > 0) { - console.warn("[sprintf] superfluous arguments while formatting '" + original + "': ", args); + }; + known_params["G"] = function (format, arg) { + return known_params["g"](format, arg).toUpperCase(); + }; + known_params["s"] = function (format, arg) { + if (!test_arg(format, arg, 'string')) + return 'o.O'; + var tmp = format.precision !== null ? arg.substr(0, format.precision) : arg; + tmp = string_fill(tmp, format.flags.indexOf('0') >= 0 ? '0' : ' ', format.width, format.flags.indexOf('-') >= 0); + return tmp; + }; + known_params["o"] = function (format, arg) { + if (!test_arg(format, arg, 'number')) + return 'Ø'; + var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); + return known_params["s"](format, tmp.toString(8)); + }; + known_params["x"] = function (format, arg) { + if (!test_arg(format, arg, 'number')) + return 'Ø'; + var tmp = Math.floor(Math.round(Math.abs(arg))) * ((arg < 0) ? -1 : 1); + return known_params["s"](format, tmp.toString(16)); + }; + known_params["a"] = known_params["x"]; + known_params["X"] = function (format, arg) { + if (!test_arg(format, arg, 'number')) + return 'Ø'; + return known_params["x"](format, arg).toUpperCase(); + }; + known_params["A"] = known_params["X"]; + known_params["c"] = function (format, arg) { + var tmp = ""; + if (typeof arg === "number") { + tmp = String.fromCharCode(arg); } - return input; - } - else { - var arg; - var rest; - if (args.length > 0) { - arg = args[0]; - rest = args.slice(1); + else if ((typeof arg === "string") && (arg.length === 1)) { + tmp = arg[0]; } else { - console.warn("[sprintf] out of arguments while formatting '" + original + "'"); - arg = null; - rest = []; + console.warn(make_err(format, arg, "number|string") + " and if string it needs to have the length of 1!"); + } + return known_params["s"](format, tmp); + }; + known_params["n"] = function () { + return ""; + }; + var decompose = function (chain, regexp) { + var result = regexp.exec(chain); + if (result == null) { + return null; + } + else { + var front = chain.substring(0, result.index); + var back = chain.substring(result.index + result[0].length); + return { "front": front, "match": result[0], "back": back }; + } + }; + /** + * an implementation of c sprintf + * @param {string} string format string + * @param {array} args arguments which should be filled into + * @returns {string} + */ + string.sprintf = function (input, args = [], original = null) { + if (original == null) + original = input; + var components = decompose(input, pattern); + if (components == null) { + if (args.length > 0) { + console.warn("[sprintf] superfluous arguments while formatting '" + original + "': ", args); + } return input; } - var fmt = split_format(components["match"]); - return (components["front"] - + known_params[fmt.specifier](fmt, arg) - + lib_string.sprintf(components["back"], rest, original)); + else { + var arg; + var rest; + if (args.length > 0) { + arg = args[0]; + rest = args.slice(1); + } + else { + console.warn("[sprintf] out of arguments while formatting '" + original + "'"); + arg = null; + rest = []; + return input; + } + var fmt = split_format(components["match"]); + return (components["front"] + + known_params[fmt.specifier](fmt, arg) + + string.sprintf(components["back"], rest, original)); + } + }; + /** + * an implementation of c printf + * @param {string} string format string + * @param {array} args arguments which should be filled into + * @returns {string} + */ + function printf(format, args) { + console.log(string.sprintf(format, args)); } - }; - /** - * an implementation of c printf - * @param {string} string format string - * @param {array} args arguments which should be filled into - * @returns {string} - */ - function printf(format, args) { - console.log(lib_string.sprintf(format, args)); - } - lib_string.printf = printf; -})(lib_string || (lib_string = {})); -var sprintf = lib_string.sprintf; -var printf = lib_string.printf; + string.printf = printf; + })(string = lib_plankton.string || (lib_plankton.string = {})); +})(lib_plankton || (lib_plankton = {})); +var sprintf = lib_plankton.string.sprintf; +var printf = lib_plankton.string.printf; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -1607,7 +2170,7 @@ var make_logger = (function () { /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -1626,7 +2189,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -1645,7 +2208,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -1661,170 +2224,30 @@ 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_code; -(function (lib_code) { - /** - * @author fenris - */ - function inverse_encode(decode, to) { - return decode(to); - } - lib_code.inverse_encode = inverse_encode; - /** - * @author fenris - */ - function inverse_decode(encode, from) { - return encode(from); - } - lib_code.inverse_decode = inverse_decode; -})(lib_code || (lib_code = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2021 '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_code; -(function (lib_code) { - /** - * @author fenris - */ - var class_code_inverse = /** @class */ (function () { +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { /** * @author fenris */ - function class_code_inverse(subject) { - this.subject = subject; + function inverse_encode(decode, to) { + return decode(to); } - /** - * @implementation - * @author fenris - */ - class_code_inverse.prototype.encode = function (to) { - var _this = this; - return lib_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 lib_code.inverse_decode(function (x) { return _this.subject.encode(x); }, from); - }; - return class_code_inverse; - }()); - lib_code.class_code_inverse = class_code_inverse; -})(lib_code || (lib_code = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2021 '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_code; -(function (lib_code) { - /** - * @author fenris - */ - function pair_encode(encode_first, encode_second, from) { - var between = encode_first(from); - var to = encode_second(between); - return to; - } - lib_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; - } - lib_code.pair_decode = pair_decode; -})(lib_code || (lib_code = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2021 '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_code; -(function (lib_code) { - /** - * @author fenris - */ - var class_code_pair = /** @class */ (function () { + code.inverse_encode = inverse_encode; /** * @author fenris */ - function class_code_pair(first, second) { - this.first = first; - this.second = second; + function inverse_decode(encode, from) { + return encode(from); } - /** - * @implementation - * @author fenris - */ - class_code_pair.prototype.encode = function (from) { - var _this = this; - return lib_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 lib_code.pair_decode(function (x) { return _this.first.decode(x); }, function (x) { return _this.second.decode(x); }, to); - }; - return class_code_pair; - }()); - lib_code.class_code_pair = class_code_pair; -})(lib_code || (lib_code = {})); + 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-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -1840,144 +2263,193 @@ 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_code; -(function (lib_code) { - /** - * @author fenris - */ - function chain_encode(encode_links, from) { - var value = from; - encode_links - .forEach(function (link) { - value = link(value); - }); - return value; - } - lib_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; - } - lib_code.chain_decode = chain_decode; -})(lib_code || (lib_code = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2021 '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_code; -(function (lib_code) { - /** - * @author fenris - */ - var class_code_chain = /** @class */ (function () { +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { /** * @author fenris */ - function class_code_chain(links) { - this.links = links; - } - /** - * @implementation - * @author fenris - */ - class_code_chain.prototype.encode = function (from) { - return lib_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 lib_code.chain_decode(this.links.map(function (link) { return (function (x) { return link.decode(x); }); }), to); - }; - return class_code_chain; - }()); - lib_code.class_code_chain = class_code_chain; -})(lib_code || (lib_code = {})); -/* -This file is part of »bacterio-plankton:code«. - -Copyright 2016-2021 '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_code; -(function (lib_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")); + 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-2023 '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; } - return { - "keys": keys, - "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }) - }; - } - lib_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; + 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-2023 '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-2023 '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 dataset_; - })); - } - lib_code.flatten_decode = flatten_decode; -})(lib_code || (lib_code = {})); + 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-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -1993,39 +2465,154 @@ 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_code; -(function (lib_code) { - /** - * @author fenris - */ - var class_code_flatten = /** @class */ (function () { +var lib_plankton; +(function (lib_plankton) { + var code; + (function (code) { /** * @author fenris */ - function class_code_flatten() { + 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-2023 '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-2023 '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) { /** - * @implementation * @author fenris */ - class_code_flatten.prototype.encode = function (x) { - return lib_code.flatten_encode(x); - }; - /** - * @implementation - * @author fenris - */ - class_code_flatten.prototype.decode = function (x) { - return lib_code.flatten_decode(x); - }; - return class_code_flatten; - }()); - lib_code.class_code_flatten = class_code_flatten; -})(lib_code || (lib_code = {})); + 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-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -2041,27 +2628,30 @@ 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_json; -(function (lib_json) { - /** - * @author fenris - */ - function encode(x, formatted = false) { - return JSON.stringify(x, undefined, formatted ? "\t" : undefined); - } - lib_json.encode = encode; - /** - * @author fenris - */ - function decode(x) { - return JSON.parse(x); - } - lib_json.decode = decode; -})(lib_json || (lib_json = {})); +var lib_plankton; +(function (lib_plankton) { + var json; + (function (json) { + /** + * @author fenris + */ + function encode(x, formatted = false) { + return JSON.stringify(x, undefined, formatted ? "\t" : undefined); + } + json.encode = encode; + /** + * @author fenris + */ + function decode(x) { + return JSON.parse(x); + } + json.decode = decode; + })(json = lib_plankton.json || (lib_plankton.json = {})); +})(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -2077,38 +2667,41 @@ 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_json; -(function (lib_json) { - /** - * @author fenris - */ - class class_json { +var lib_plankton; +(function (lib_plankton) { + var json; + (function (json) { /** * @author fenris */ - constructor() { + class class_json { + /** + * @author fenris + */ + constructor() { + } + /** + * @implementation + * @author fenris + */ + encode(x) { + return json.encode(x); + } + /** + * @implementation + * @author fenris + */ + decode(x) { + return json.decode(x); + } } - /** - * @implementation - * @author fenris - */ - encode(x) { - return lib_json.encode(x); - } - /** - * @implementation - * @author fenris - */ - decode(x) { - return lib_json.decode(x); - } - } - lib_json.class_json = class_json; -})(lib_json || (lib_json = {})); + json.class_json = class_json; + })(json = lib_plankton.json || (lib_plankton.json = {})); +})(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:file«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:file« is free software: you can redistribute it and/or modify @@ -2136,7 +2729,7 @@ var lib_plankton; return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { "encoding": "utf8", - "flag": "r" + "flag": "r", }, function (error, content) { if (error == null) { resolve(content); @@ -2155,7 +2748,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { - "flag": "r" + "flag": "r", }, function (error, content) { if (error == null) { resolve(content); @@ -2192,13 +2785,13 @@ var lib_plankton; function write(path, content, options) { if (options === void 0) { options = {}; } options = Object.assign({ - "encoding": "utf-8" + "encoding": "utf-8", }, options); var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { "encoding": options.encoding, - "flag": "w" + "flag": "w", }, function (error) { if (error == null) { resolve(undefined); @@ -2219,7 +2812,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { - "flag": "w" + "flag": "w", }, function (error) { if (error == null) { resolve(undefined); @@ -2233,1364 +2826,783 @@ var lib_plankton; file.write_buffer = write_buffer; })(file = lib_plankton.file || (lib_plankton.file = {})); })(lib_plankton || (lib_plankton = {})); -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); /* -This file is part of »bacterio-plankton:log«. +This file is part of »bacterio-plankton:args«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:log« is free software: you can redistribute it and/or modify +»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:lang« is distributed in the hope that it will be useful, +»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:log«. If not, see . +along with »bacterio-plankton:args«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var log; - (function (log) { + var args; + (function (args) { /** */ - var enum_level; - (function (enum_level) { - enum_level[enum_level["debug"] = 0] = "debug"; - enum_level[enum_level["info"] = 1] = "info"; - enum_level[enum_level["notice"] = 2] = "notice"; - enum_level[enum_level["warning"] = 3] = "warning"; - enum_level[enum_level["error"] = 4] = "error"; - })(enum_level = log.enum_level || (log.enum_level = {})); + var enum_environment; + (function (enum_environment) { + enum_environment["cli"] = "cli"; + enum_environment["url"] = "url"; + })(enum_environment = args.enum_environment || (args.enum_environment = {})); ; /** */ - function level_order(level1, level2) { - return (level1 <= level2); - } - log.level_order = level_order; + var enum_kind; + (function (enum_kind) { + enum_kind["positional"] = "positional"; + enum_kind["volatile"] = "volatile"; + })(enum_kind = args.enum_kind || (args.enum_kind = {})); + ; /** */ - function level_show(level) { - switch (level) { - case enum_level.debug: return "debug"; - case enum_level.info: return "info"; - case enum_level.notice: return "notice"; - case enum_level.warning: return "warning"; - case enum_level.error: return "error"; - default: return "(unknown)"; - } - } - log.level_show = level_show; - })(log = lib_plankton.log || (lib_plankton.log = {})); + 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:log«. +This file is part of »bacterio-plankton:args«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:log« is free software: you can redistribute it and/or modify +»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:lang« is distributed in the hope that it will be useful, +»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:lang«. If not, see . +along with »bacterio-plankton:args«. If not, see . */ -/** - * @deprecated - * @todo remove - */ -var lib_log; -(function (lib_log) { - /** - * @author fenris - */ - /*export*/ var level_stack = [0]; - function level_push(level) { level_stack.push(level); } - lib_log.level_push = level_push; - function level_pop() { if (level_stack.length > 1) { - level_stack.pop(); - } } - lib_log.level_pop = level_pop; - function level_get() { return level_stack.slice(-1)[0]; } - /* - export function level_inc() : void {level_push(level_get()+1);} - export function level_dec() : void {level_push(level_get()-1);} - */ - /** - * @author fenris - */ - var indent_stack = [0]; - function indent_push(indent) { indent_stack.push(indent); } - lib_log.indent_push = indent_push; - function indent_pop() { if (indent_stack.length > 1) { - indent_stack.pop(); - } } - lib_log.indent_pop = indent_pop; - function indent_get() { return level_stack.slice(-1)[0]; } - function indent_inc() { level_push(level_get() + 1); } - lib_log.indent_inc = indent_inc; - function indent_dec() { level_push(level_get() - 1); } - lib_log.indent_dec = indent_dec; - /** - * @author fenris - */ - function write(_a) { - var message = _a["message"], _b = _a["type"], type = _b === void 0 ? null : _b, _c = _a["prefix"], prefix = _c === void 0 ? null : _c, _d = _a["level"], level = _d === void 0 ? 0 : _d, _e = _a["indent"], indent = _e === void 0 ? 0 : _e; - var entry = { - "level": ((type === null) - ? lib_plankton.log.enum_level.info - : { - "debug": lib_plankton.log.enum_level.debug, - "info": lib_plankton.log.enum_level.info, - "notice": lib_plankton.log.enum_level.notice, - "warning": lib_plankton.log.enum_level.warning, - "error": lib_plankton.log.enum_level.error - }[type]), - "incident": message, - "details": { - "prefix": prefix, - "level": level, - "indent": indent - } +var lib_plankton; +(function (lib_plankton) { + var args; + (function (args) { + /* + export enum_mode { + replace = "replace", + accumulate = "accumulate", }; - lib_plankton.log.add(entry); - } - lib_log.write = write; -})(lib_log || (lib_log = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** */ - var class_channel = /** @class */ (function () { - function class_channel() { - } - return class_channel; - }()); - log.class_channel = class_channel; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { /** - * output for writing log entries to stdout + * @author fenris */ - var class_channel_stdout = /** @class */ (function (_super) { - __extends(class_channel_stdout, _super); - function class_channel_stdout() { - return _super !== null && _super.apply(this, arguments) || this; + 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")); + } } /** + * @author fenris */ - class_channel_stdout.prototype.add = function (entry) { - process.stdout.write(("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") - + - " " - + - ("[" + log.level_show(entry.level) + "]") - + - " " - + - ("" + entry.incident + "") - + - ": " - + - JSON.stringify(entry.details, undefined, " ") - + - "\n"); + 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, + }, + })); }; - return class_channel_stdout; - }(log.class_channel)); - log.class_channel_stdout = class_channel_stdout; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - */ - var class_channel_file = /** @class */ (function (_super) { - __extends(class_channel_file, _super); /** - * [constructor] + * @author fenris */ - function class_channel_file(path) { - var _this = _super.call(this) || this; - _this.path = path; - return _this; - } + 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_channel_file.prototype.add = function (entry) { + class_argument.prototype.check = function () { var _this = this; - var nm_fs = require("fs"); - nm_fs.writeFile(this.path, { - "flag": "a+" - }, (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") - + - " " - + - ("[" + log.level_show(entry.level) + "]") - + - " " - + - ("" + entry.incident + "") - + - ": " - + - JSON.stringify(entry.details, undefined, " ") - + - "\n"), function (error) { - process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n"); - }); + 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(); }); }; - return class_channel_file; - }(log.class_channel)); - log.class_channel_file = class_channel_file; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - * output for desktop notifications via "libnotify" - */ - var class_channel_notify = /** @class */ (function (_super) { - __extends(class_channel_notify, _super); - function class_channel_notify() { - return _super !== null && _super.apply(this, arguments) || this; - } /** + * @author fenris */ - class_channel_notify.prototype.add = function (entry) { - var nm_child_process = require("child_process"); - var command = ("notify-send" - + - " " - + - ("'" - + - ("[" + log.level_show(entry.level) + "]") - + - " " - + - entry.incident - + - "'") - + - " " - + - ("'" - + - (Object.keys(entry.details) - .map(function (key) { return (key + ": " + JSON.stringify(entry.details[key])); }) - .join("\n")) - + - "'")); - nm_child_process.exec(command, function (error, stdout, stderr) { - // do noting - }); + class_argument.prototype.name_get = function () { + return this.name; }; - return class_channel_notify; - }(log.class_channel)); - log.class_channel_notify = class_channel_notify; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - * decorator for filtering out log entries below a certain level threshold - */ - var class_channel_minlevel = /** @class */ (function (_super) { - __extends(class_channel_minlevel, _super); /** + * @author fenris */ - function class_channel_minlevel(core, threshold) { - var _this = _super.call(this) || this; - _this.core = core; - _this.threshold = threshold; - return _this; - } + class_argument.prototype.kind_get = function () { + return this.kind; + }; /** + * @author fenris */ - class_channel_minlevel.prototype.add = function (entry) { - if (!log.level_order(this.threshold, entry.level)) { - // do nothing + 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 { - this.core.add(entry); + return null; } }; - return class_channel_minlevel; - }(log.class_channel)); - log.class_channel_minlevel = class_channel_minlevel; - })(log = lib_plankton.log || (lib_plankton.log = {})); + /** + * @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; + } + } + }; + /** + * @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; + } + } + }; + /** + * @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] = []; + } + */ + data[target].push(value); + break; + } + default: { + throw (new Error("unhandled mode ".concat(this.mode))); + } + } + }; + /** + * @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(" | ")); + } + 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(" | ")); + } + line += "\n"; + output += line; + } + } + } + { + 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()); + } + line += "\n"; + output += line; + } + return output; + }; + return class_argument; + }()); + args.class_argument = class_argument; + })(args = lib_plankton.args || (lib_plankton.args = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:log«. +This file is part of »bacterio-plankton:args«. -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:log« is free software: you can redistribute it and/or modify +»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:lang« is distributed in the hope that it will be useful, +»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:log«. If not, see . +along with »bacterio-plankton:args«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var log; - (function (log) { - /** - */ - function translate_level(level_string) { - return { - "debug": log.enum_level.debug, - "info": log.enum_level.info, - "notice": log.enum_level.notice, - "warning": log.enum_level.warning, - "error": log.enum_level.error - }[level_string]; - } - /** - */ - function channel_make(description) { - var _a, _b, _c, _d; - switch (description.kind) { - default: { - throw (new Error("unhandled log channel kind: " + description.kind)); - break; - } - case "stdout": { - return (new log.class_channel_minlevel(new log.class_channel_stdout(), translate_level((_a = description.data["threshold"]) !== null && _a !== void 0 ? _a : "debug"))); - break; - } - case "file": { - return (new log.class_channel_minlevel(new log.class_channel_file((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug"))); - break; - } - case "notify": { - return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "debug"))); - break; - } - } - } - log.channel_make = channel_make; - /** - */ - function conf_default() { - return [ - new log.class_channel_minlevel(new log.class_channel_stdout(), log.enum_level.notice), - new log.class_channel_minlevel(new log.class_channel_notify(), log.enum_level.error), - ]; - } - log.conf_default = conf_default; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:log«. - -Copyright 2016-2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:log« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:lang« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:log«. If not, see . - */ -var lib_plankton; -(function (lib_plankton) { - var log; - (function (log) { - /** - */ - var _channel_stack = null; - /** - * pushes a new configuration on the stack and activates it - */ - function conf_push(channels) { - if (_channel_stack === null) { - _channel_stack = []; - } - _channel_stack.push(channels); - } - log.conf_push = conf_push; - /** - * pops the current active configuration from the stack - */ - function conf_pop() { - if (_channel_stack.length > 0) { - _channel_stack.pop(); - } - else { - // do nothing - } - } - log.conf_pop = conf_pop; - /** - * makes the logging system ready - */ - function setup() { - if (_channel_stack === null) { - _channel_stack = []; - conf_push(log.conf_default()); - } - else { - // do nothing - } - } - /** - * consumes a log entry, i.e. sends it to the currently active outputs - */ - function add(entry) { - setup(); - _channel_stack.slice(-1)[0].forEach(function (channel) { return channel.add(entry); }); - } - log.add = add; - /** - */ - function debug(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.debug, "incident": incident, "details": details }); - } - log.debug = debug; - /** - */ - function info(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.info, "incident": incident, "details": details }); - } - log.info = info; - /** - */ - function notice(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.notice, "incident": incident, "details": details }); - } - log.notice = notice; - /** - */ - function warning(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.warning, "incident": incident, "details": details }); - } - log.warning = warning; - /** - */ - function error(incident, details) { - if (details === void 0) { details = {}; } - add({ "level": log.enum_level.error, "incident": incident, "details": details }); - } - log.error = error; - })(log = lib_plankton.log || (lib_plankton.log = {})); -})(lib_plankton || (lib_plankton = {})); -/* -This file is part of »bacterio-plankton:args«. - -Copyright 2016-2021 '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_args; -(function (lib_args) { - /** - */ - var enum_environment; - (function (enum_environment) { - enum_environment["cli"] = "cli"; - enum_environment["url"] = "url"; - })(enum_environment = lib_args.enum_environment || (lib_args.enum_environment = {})); - ; - /** - */ - var enum_kind; - (function (enum_kind) { - enum_kind["positional"] = "positional"; - enum_kind["volatile"] = "volatile"; - })(enum_kind = lib_args.enum_kind || (lib_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 = lib_args.enum_type || (lib_args.enum_type = {})); - ; - /** - */ - var enum_mode; - (function (enum_mode) { - enum_mode["replace"] = "replace"; - enum_mode["accumulate"] = "accumulate"; - })(enum_mode = lib_args.enum_mode || (lib_args.enum_mode = {})); - ; -})(lib_args || (lib_args = {})); -/* -This file is part of »bacterio-plankton:args«. - -Copyright 2016-2021 '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_args; -(function (lib_args) { - /** - * @author fenris - */ - var class_argument = /** @class */ (function () { + var args; + (function (args) { /** * @author fenris */ - function class_argument(_a) { - var name = _a["name"], _b = _a["type"], type = _b === void 0 ? lib_args.enum_type.string : _b, _c = _a["kind"], kind = _c === void 0 ? lib_args.enum_kind.positional : _c, _d = _a["mode"], mode = _d === void 0 ? lib_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")); - } - } - /** - * @author fenris - */ - class_argument.positional = function (_a) { - var name = _a["name"], _b = _a["type"], type = _b === void 0 ? lib_args.enum_type.string : _b, _c = _a["mode"], mode = _c === void 0 ? lib_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": lib_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 ? lib_args.enum_type.string : _b, _c = _a["mode"], mode = _c === void 0 ? lib_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": lib_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 == lib_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 === lib_args.enum_kind.volatile) { - return this.parameters["indicators_long"][0]; - } - else { - return null; - } - }; - /** - * @author fenris - */ - class_argument.prototype.pattern_value = function () { - switch (this.type) { - case lib_args.enum_type.boolean: { - return "false|true"; - break; - } - case lib_args.enum_type.integer: { - return "[0-9]+"; - break; - } - case lib_args.enum_type.float: { - return "\\d*(?:\\.\\d+)?"; - break; - } - case lib_args.enum_type.string: { - return "\\S+"; - break; - } - default: { - throw (new Error("unhandled type ".concat(this.type))); - break; - } - } - }; - /** - * @author fenris - */ - class_argument.prototype.extract = function (raw) { - switch (this.type) { - case lib_args.enum_type.boolean: { - return (raw != "false"); - break; - } - case lib_args.enum_type.integer: { - return parseInt(raw); - break; - } - case lib_args.enum_type.float: { - return parseFloat(raw); - break; - } - case lib_args.enum_type.string: { - return raw; - break; - } - default: { - throw (new Error("unhandled type ".concat(this.type))); - break; - } - } - }; - /** - * @author fenris - */ - class_argument.prototype.assign = function (data, target, raw) { - var value = this.extract(raw); - switch (this.mode) { - case lib_args.enum_mode.replace: { - data[target] = value; - break; - } - case lib_args.enum_mode.accumulate: { - /* - if (! (this.name in data)) { - data[this.name] = []; + var settings = { + "environment": { + "cli": { + "symbols": { + "delimiter": " ", + "prefix": "--", + "assignment": "=", + }, + }, + "url": { + "symbols": { + "delimiter": "&", + "prefix": "", + "assignment": "=", } - */ - data[target].push(value); - break; - } - default: { - throw (new Error("unhandled mode ".concat(this.mode))); - } - } - }; - /** - * @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 lib_args.enum_kind.positional: { - var line = ""; - line += "\t"; - line += "<".concat(this.name, ">"); - line += "\n"; - output += line; - } - case lib_args.enum_kind.volatile: { - var line = ""; - line += "\t"; - if (this.type === lib_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(" | ")); - } - 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(" | ")); - } - line += "\n"; - output += line; - } - } - } - { - 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()); - } - line += "\n"; - output += line; - } - return output; - }; - return class_argument; - }()); - lib_args.class_argument = class_argument; -})(lib_args || (lib_args = {})); -/* -This file is part of »bacterio-plankton:args«. - -Copyright 2016-2021 '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_args; -(function (lib_args) { - /** - * @author fenris - */ - var settings = { - "environment": { - "cli": { - "symbols": { - "delimiter": " ", - "prefix": "--", - "assignment": "=" } }, - "url": { - "symbols": { - "delimiter": "&", - "prefix": "", - "assignment": "=" - } - } - } - }; - /** - * @author fenris - */ - lib_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_; }; /** * @author fenris */ - class_handler.prototype.read = function (environment, input, data) { - var _this = this; - if (data === void 0) { data = {}; } - switch (environment) { - case lib_args.enum_environment.cli: - case lib_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(); - } + 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; } - // preprocessing - { - // short indicators (lil hacky ...) + } + return arguments_; + }; + /** + * @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 { - if (environment == lib_args.enum_environment.cli) { - for (var _c = 0, _d = Object.entries(this.filter(lib_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() == lib_args.enum_type.boolean) { - pattern_to += settings["environment"][environment]["symbols"]["delimiter"]; - } - else { - pattern_to += settings["environment"][environment]["symbols"]["assignment"]; - } - } - 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; - } + 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(); } } - 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(lib_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 = ""; + // 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 = ""; { - var pattern_front = ""; - pattern_front += "".concat(settings["environment"][environment]["symbols"]["prefix"]); - pattern_front += "(?:".concat(argument.parameters_get()["indicators_long"].join("|"), ")"); - pattern += pattern_front; + 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 = ""; { - var pattern_back = ""; - pattern_back += "".concat(settings["environment"][environment]["symbols"]["assignment"]); - pattern_back += "(".concat(argument.pattern_value(), ")"); - if (argument.type_get() == lib_args.enum_type.boolean) { - pattern_back = "(?:".concat(pattern_back, ")?"); + 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 { + pattern_to += settings["environment"][environment]["symbols"]["assignment"]; } - pattern += pattern_back; } - lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", { - "pattern": pattern + 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, }); - 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; - } + input = result; } - return false; - }, - function () { - lib_plankton.log.debug("lib_args:read:probing_as_positional", { - "part": part - }); - var positional = _this.filter(lib_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) { - // do nothing - } - else { - lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", { + } + } + 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() + "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_positional:pattern", { - "pattern": pattern + 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_positional:matching", { - "matching": matching + lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", { + "matching": matching, }); if (matching == null) { - return false; + // do nothing } else { argument.assign(data, name, matching[1]); - index_expected_1 += 1; return true; } } - } - return false; - }, - ].some(function (x) { return x(); }); - if (!found) { - lib_plankton.log.warning("lib_args:read:could_not_parse", { - "part": part - }); - } - }); + 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) { + // 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; + } + else { + argument.assign(data, name, matching[1]); + index_expected_1 += 1; + return true; + } + } + } + return false; + }, + ].some(function (x) { return x(); }); + if (!found) { + lib_plankton.log.warning("lib_args:read:could_not_parse", { + "part": part, + }); + } + }); + } + return data; + break; + } + default: { + throw (new Error("unhandled environment ".concat(environment))); + break; } - return data; - break; } - default: { - throw (new Error("unhandled environment ".concat(environment))); - 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 lib_args.enum_environment.cli: { - return (([] - .concat(Object.entries(this.filter(lib_args.enum_kind.volatile)).map(function (_a) { - var name = _a[0], argument = _a[1]; - var values; - switch (argument.mode_get()) { - case lib_args.enum_mode.replace: { - values = [data[argument.name_get()]]; - 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; + } } - case lib_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 (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(lib_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; + return raw; + }))) + .join(settings["environment"][environment]["symbols"]["delimiter"])); + break; + } + default: { + throw (new Error("unhandled environment ".concat(environment))); + 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 = lib_args.enum_environment.cli; - var output = ""; - { - var section = ""; + }; + /** + * @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 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 += "INFO"; line += "\n"; section += line; } { var line = ""; line += "\t"; - line += "".concat(author); + line += "".concat(programname, " -- ").concat(description); 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(lib_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(lib_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(), ">"); + if (author != null) { + var section = ""; + { + var line = ""; + line += ""; + line += "AUTHOR"; + line += "\n"; + section += line; } - 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; + { + var line = ""; + line += "\t"; + line += "".concat(author); + line += "\n"; + section += line; + } + section += "\n"; + output += section; + } } { - 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")); + 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; } - section += "\n"; - output += section; - } - return output; - }; - return class_handler; - }()); - lib_args.class_handler = class_handler; -})(lib_args || (lib_args = {})); + { + 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 = {})); +})(lib_plankton || (lib_plankton = {})); diff --git a/source/conf.ts b/source/conf.ts index ace3388..f73f4b0 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -1,7 +1,8 @@ + /** * @todo generate generic */ -function schema( +function input_schema( ) : any { return { @@ -118,3 +119,67 @@ function schema( ] } } + + +/** + */ +function input_normalize( + input_raw : any +) : type_input +{ + // validate + if (! input_raw.hasOwnProperty("domains")) { + throw (new Error("input node is missing mandatory field 'domains'")); + } + else { + // sanitize + return { + "domains": ( + input_raw["domains"] + .map( + domain_raw => ({ + "name": domain_raw["name"], + "description": (domain_raw["description"] ?? null), + "key_field": ( + (domain_raw.hasOwnProperty("key_field") && (domain_raw["key_field"] !== null)) + ? { + "name": domain_raw["key_field"]["name"], + "description": (domain_raw["key_field"]["description"] ?? null), + } + : null + ), + "data_fields": ( + (domain_raw.hasOwnProperty("data_fields") && (domain_raw["data_fields"] !== null)) + ? ( + domain_raw["data_fields"] + .map( + data_field_raw => ({ + "name": data_field_raw["name"], + "description": (data_field_raw["description"] ?? null), + "type": data_field_raw["type"], + "nullable": (data_field_raw["nullable"] ?? true), + "default": data_field_raw["default"], + }) + ) + ) + : [] + ), + "constraints": ( + (domain_raw.hasOwnProperty("constraints") && (domain_raw["constraints"] !== null)) + ? ( + domain_raw["constraints"] + .map( + constraint_raw => ({ + "kind": constraint_raw["kind"], + "parameters": (constraint_raw["parameters"] ?? {}), + }) + ) + ) + : [] + ), + }) + ) + ), + }; + } +} diff --git a/source/main.ts b/source/main.ts index 15e7841..4a757ef 100644 --- a/source/main.ts +++ b/source/main.ts @@ -7,15 +7,17 @@ async function main( const outputs : Record = { "sqlite": output_sqlite, "mysql": output_mysql, + "typescript": output_typescript, + "jsonschema": output_jsonschema, }; - const arg_handler = new lib_args.class_handler( + const arg_handler = new lib_plankton.args.class_handler( { - "format": new lib_args.class_argument({ + "format": new lib_plankton.args.class_argument({ "name": "format", - "type": lib_args.enum_type.string, - "kind": lib_args.enum_kind.volatile, - "mode": lib_args.enum_mode.replace, + "type": lib_plankton.args.enum_type.string, + "kind": lib_plankton.args.enum_kind.volatile, + "mode": lib_plankton.args.enum_mode.replace, "default": "sqlite", "parameters": { "indicators_long": ["format"], @@ -23,11 +25,11 @@ async function main( }, "info": "output format", }), - "schema": new lib_args.class_argument({ + "schema": new lib_plankton.args.class_argument({ "name": "schema", - "type": lib_args.enum_type.boolean, - "kind": lib_args.enum_kind.volatile, - "mode": lib_args.enum_mode.replace, + "type": lib_plankton.args.enum_type.boolean, + "kind": lib_plankton.args.enum_kind.volatile, + "mode": lib_plankton.args.enum_mode.replace, "default": false, "parameters": { "indicators_long": ["schema"], @@ -35,11 +37,11 @@ async function main( }, "info": "print sindri JSON schema to stdout and exit", }), - "help": new lib_args.class_argument({ + "help": new lib_plankton.args.class_argument({ "name": "help", - "type": lib_args.enum_type.boolean, - "kind": lib_args.enum_kind.volatile, - "mode": lib_args.enum_mode.replace, + "type": lib_plankton.args.enum_type.boolean, + "kind": lib_plankton.args.enum_kind.volatile, + "mode": lib_plankton.args.enum_mode.replace, "default": false, "parameters": { "indicators_long": ["help"], @@ -49,7 +51,7 @@ async function main( }), } ); - const args : Record = arg_handler.read(lib_args.enum_environment.cli, args_raw.join(" ")); + const args : Record = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" ")); if (args["help"]) { process.stdout.write( @@ -66,14 +68,13 @@ async function main( else { if (args["schema"]) { process.stdout.write( - JSON.stringify(schema(), undefined, "\t") + JSON.stringify(input_schema(), undefined, "\t") ); } else { const input_content : string = await lib_plankton.file.read_stdin(); - const input_data : type_input_data = lib_json.decode(input_content); - - // TODO: sanitize & normalize input_data + const input_data_raw : any = lib_plankton.json.decode(input_content); + const input_data : type_input = input_normalize(input_data_raw); if (! outputs.hasOwnProperty(args["format"])) { throw (new Error("unhandled output format: " + args["format"])); diff --git a/source/outputs/jsonschema.ts b/source/outputs/jsonschema.ts new file mode 100644 index 0000000..f869ee0 --- /dev/null +++ b/source/outputs/jsonschema.ts @@ -0,0 +1,82 @@ +const output_jsonschema : type_output = { + "render": function (input_data) { + return lib_plankton.json.encode( + Object.fromEntries( + input_data.domains.map( + domain => ([ + domain.name, + { + "type": ["array"], + "items": { + "type": ["object"], + "additionalProperties": false, + "properties": Object.fromEntries( + [] + .concat( + (domain.key_field === null) + ? [] + : [ + [ + domain.key_field.name, + { + "type": ["integer"], + "description": (domain.key_field.description ?? undefined), + } + ] + ] + ) + .concat( + domain.data_fields + .map( + data_field => ([ + data_field.name, + { + "type": ( + [] + .concat( + data_field.nullable + ? ["null"] + : [] + ) + .concat( + [ + { + "boolean": "boolean", + "integer": "integer", + "float": "number", + "string_short": "string", + "string_medium": "string", + "string_long": "string", + }[data_field.type] + ] + ) + ), + "description": (data_field.description ?? undefined), + } + ]) + ) + ) + ), + "required": ( + [] + .concat( + (domain.key_field === null) + ? [] + : [domain.key_field.name] + ) + .concat( + domain.data_fields + .map( + data_field => data_field.name + ) + ) + ) + }, + } + ]) + ) + ), + true + ); + }, +}; diff --git a/source/outputs/mysql.ts b/source/outputs/mysql.ts index 04d61ce..6c8639d 100644 --- a/source/outputs/mysql.ts +++ b/source/outputs/mysql.ts @@ -1,23 +1,48 @@ +function mysql_value_encode( + value : any +) : string +{ + if (value === null) { + return "NULL"; + } + else { + switch (typeof(value)) { + case "boolean": { + return (value ? "TRUE" : "FALSE"); + break; + } + case "number": { + return value.toString(); + break; + } + case "string": { + return ("'" + value + "'"); + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + } +} + const output_mysql : type_output = { "render": function (input_data) { return ( - input_data["domains"] + input_data.domains .map( (domain) => lib_plankton.string.coin( "CREATE TABLE\n\t`{{name}}`(\n{{entries}}\n\t){{comment}}\n;", { - "name": domain["name"], + "name": domain.name, "comment": ( - ( - ! domain.hasOwnProperty("description") - || - (domain["description"] === null) - ) + (domain.description === null) ? "" : lib_plankton.string.coin( " COMMENT '{{comment}}'", { - "comment": domain["description"], + "comment": domain.description, } ) ), @@ -26,12 +51,12 @@ const output_mysql : type_output = { [] // key field .concat( - (domain["key_field"] === null) + (domain.key_field === null) ? [] : lib_plankton.string.coin( "`{{name}}` {{parameters}}", { - "name": domain["key_field"]["name"], + "name": domain.key_field.name, "parameters": ( [ "INTEGER", @@ -39,17 +64,13 @@ const output_mysql : type_output = { "AUTO INCREMENT", ] .concat( - ( - ! domain["key_field"].hasOwnProperty("description") - || - (domain["key_field"]["description"] === null) - ) + (domain.key_field.description === null) ? [] : [ lib_plankton.string.coin( "COMMENT '{{comment}}'", { - "comment": domain["key_field"]["description"], + "comment": domain.key_field.description, } ), ] @@ -61,12 +82,12 @@ const output_mysql : type_output = { ) // data fields .concat( - domain["data_fields"] + domain.data_fields .map( (data_field) => lib_plankton.string.coin( "`{{name}}` {{parameters}}", { - "name": data_field["name"], + "name": data_field.name, "parameters": ( ( // type @@ -77,27 +98,36 @@ const output_mysql : type_output = { "string_short": "VARCHAR(63)", "string_medium": "VARCHAR(255)", "string_long": "TEXT", - }[data_field["type"]], + }[data_field.type], ] // nullability .concat( - data_field["nullable"] + data_field.nullable ? ["NULL"] : [] ) + // default + .concat( + (data_field.default === undefined) + ? [] + : [ + lib_plankton.string.coin( + "DEFAULT {{value}}", + { + "value": mysql_value_encode(data_field.default), + } + ), + ] + ) // comment .concat( - ( - ! data_field.hasOwnProperty("description") - || - (data_field["description"] === null) - ) + (data_field.description === null) ? [] : [ lib_plankton.string.coin( "COMMENT '{{comment}}'", { - "comment": data_field["description"], + "comment": data_field.description, } ), ] @@ -114,9 +144,9 @@ const output_mysql : type_output = { domain["constraints"] .map( (constraint) => { - switch (constraint["kind"]) { + switch (constraint.kind) { default: { - throw (new Error("unhandled constraint kind: " + constraint["kind"])); + throw (new Error("unhandled constraint kind: " + constraint.kind)); break; } case "foreign_key": { @@ -124,13 +154,13 @@ const output_mysql : type_output = { "FOREIGN KEY ({{fields}}) REFERENCES `{{reference_name}}`({{reference_fields}})", { "fields": ( - constraint["parameters"]["fields"] + constraint.parameters["fields"] .map(x => ('`' + x + '`')) .join(",") ), - "reference_name": constraint["parameters"]["reference"]["name"], + "reference_name": constraint.parameters["reference"]["name"], "reference_fields": ( - constraint["parameters"]["reference"]["fields"] + constraint.parameters["reference"]["fields"] .map(x => ('`' + x + '`')) .join(",") ), @@ -143,7 +173,7 @@ const output_mysql : type_output = { "UNIQUE ({{fields}})", { "fields": ( - constraint["parameters"]["fields"] + constraint.parameters["fields"] .map(x => ('`' + x + '`')) .join(",") ), diff --git a/source/outputs/sqlite.ts b/source/outputs/sqlite.ts index f2b371c..334420a 100644 --- a/source/outputs/sqlite.ts +++ b/source/outputs/sqlite.ts @@ -1,3 +1,32 @@ +function sqlite_value_encode( + value : any +) : string +{ + if (value === null) { + return "NULL"; + } + else { + switch (typeof(value)) { + case "boolean": { + return (value ? "TRUE" : "FALSE"); + break; + } + case "number": { + return value.toString(); + break; + } + case "string": { + return ("'" + value + "'"); + break; + } + default: { + throw (new Error("unhandled")); + break; + } + } + } +} + const output_sqlite : type_output = { "render": function (input_data) { return ( @@ -6,18 +35,18 @@ const output_sqlite : type_output = { (domain) => lib_plankton.string.coin( "CREATE TABLE\n\t`{{name}}`(\n{{entries}}\n\t)\n;", { - "name": domain["name"], + "name": domain.name, "entries": ( ( [] // key field .concat( - (domain["key_field"] === null) + (domain.key_field === null) ? [] : lib_plankton.string.coin( "`{{name}}` {{parameters}}", { - "name": domain["key_field"]["name"], + "name": domain.key_field.name, "parameters": ( [ "INTEGER", @@ -31,12 +60,12 @@ const output_sqlite : type_output = { ) // data fields .concat( - domain["data_fields"] + domain.data_fields .map( (data_field) => lib_plankton.string.coin( "`{{name}}` {{parameters}}", { - "name": data_field["name"], + "name": data_field.name, "parameters": ( ( // type @@ -47,14 +76,27 @@ const output_sqlite : type_output = { "string_short": "VARCHAR(63)", "string_medium": "VARCHAR(255)", "string_long": "TEXT", - }[data_field["type"]], + }[data_field.type], ] // nullability .concat( - data_field["nullable"] + data_field.nullable ? ["NULL"] : [] ) + // default + .concat( + (data_field.default === undefined) + ? [] + : [ + lib_plankton.string.coin( + "DEFAULT {{value}}", + { + "value": sqlite_value_encode(data_field.default), + } + ), + ] + ) ) .join(" ") ) @@ -64,12 +106,12 @@ const output_sqlite : type_output = { ) // constraints .concat( - domain["constraints"] + domain.constraints .map( (constraint) => { - switch (constraint["kind"]) { + switch (constraint.kind) { default: { - throw (new Error("unhandled constraint kind: " + constraint["kind"])); + throw (new Error("unhandled constraint kind: " + constraint.kind)); break; } case "foreign_key": { @@ -77,13 +119,13 @@ const output_sqlite : type_output = { "FOREIGN KEY ({{fields}}) REFERENCES `{{reference_name}}`({{reference_fields}})", { "fields": ( - constraint["parameters"]["fields"] + constraint.parameters["fields"] .map(x => ('`' + x + '`')) .join(",") ), - "reference_name": constraint["parameters"]["reference"]["name"], + "reference_name": constraint.parameters["reference"]["name"], "reference_fields": ( - constraint["parameters"]["reference"]["fields"] + constraint.parameters["reference"]["fields"] .map(x => ('`' + x + '`')) .join(",") ), @@ -96,7 +138,7 @@ const output_sqlite : type_output = { "UNIQUE ({{fields}})", { "fields": ( - constraint["parameters"]["fields"] + constraint.parameters["fields"] .map(x => ('`' + x + '`')) .join(",") ), diff --git a/source/outputs/typescript.ts b/source/outputs/typescript.ts new file mode 100644 index 0000000..a7af22b --- /dev/null +++ b/source/outputs/typescript.ts @@ -0,0 +1,73 @@ +const output_typescript : type_output = { + "render": function (input_data) { + return ( + input_data["domains"] + .map( + (domain) => lib_plankton.string.coin( + "type type_{{name}} = {\n{{fields}}\n};\nlet collection_{{name}} : {{collection_type}} = {{collection_value}};\n", + { + "name": domain.name, + "fields": ( + domain.data_fields + .map( + (data_field) => lib_plankton.string.coin( + "\t{{name}} : {{type}};{{macro_comment}}", + { + "name": data_field.name, + "type": lib_plankton.string.coin( + (data_field.nullable ? "(null | {{core}})" : "{{core}}"), + { + "core": { + "boolean": "boolean", + "integer": "number", + "float": "number", + "string_short": "string", + "string_medium": "string", + "string_long": "string", + }[data_field["type"]], + } + ), + "macro_comment": ( + (data_field.description !== null) + ? lib_plankton.string.coin( + " // {{comment}}", + { + "comment": data_field.description, + } + ) + : "" + ), + } + ) + ) + // .map(x => ("\t" + x)) + .join("\n") + ), + "collection_type": ( + (domain.key_field === null) + ? lib_plankton.string.coin( + "Array", + { + "name": domain.name, + } + ) + : lib_plankton.string.coin( + "Record", + { + "name": domain.name, + } + ) + ), + "collection_value": ( + (domain.key_field === null) + ? "[]" + : "{}" + ), + } + ) + ) + .map(x => (x + "\n")) + .join("\n") + ); + }, +}; diff --git a/source/types.ts b/source/types.ts index bb3968b..307f3b4 100644 --- a/source/types.ts +++ b/source/types.ts @@ -1,33 +1,33 @@ /** */ -type type_input_data = { +type type_input = { domains : Array< { name : string; - key_field ?: ( + description : (null | string); + key_field : ( null | { name : string; - comment ?: (null | string); + description ?: (null | string); } ); - data_fields ?: Array< + data_fields : Array< { name : string; - type : string; - nullable ?: boolean; - default ?: any; - comment ?: (null | string); + description : (null | string); + type : ("boolean" | "integer" | "float" | "string_short" | "string_medium" | "string_long"); + nullable : boolean; + default : (null | boolean | int | float | string); } >; constraints ?: Array< { - kind : string; - parameters ?: Record; + kind : ("unique" | "foreign_key"); + parameters : Record; } >; - comment ?: (null | string); } >; }; @@ -36,5 +36,5 @@ type type_input_data = { /** */ type type_output = { - render : ((input_data : type_input_data) => string); + render : ((input_data : type_input) => string); }; diff --git a/tools/get-plankton b/tools/get-plankton index e298ff5..673b026 100755 --- a/tools/get-plankton +++ b/tools/get-plankton @@ -2,6 +2,7 @@ modules="" modules="${modules} base" +# modules="${modules} call" modules="${modules} string" modules="${modules} json" modules="${modules} file" diff --git a/tools/makefile b/tools/makefile index 7be20ac..148b489 100644 --- a/tools/makefile +++ b/tools/makefile @@ -18,6 +18,8 @@ lib/plankton/plankton.d.ts \ source/types.ts \ source/outputs/sqlite.ts \ source/outputs/mysql.ts \ +source/outputs/typescript.ts \ +source/outputs/jsonschema.ts \ source/conf.ts \ source/main.ts @ ${cmd_log} "compiling …"