From 8b121af099d4f83853c1a5e8205e24f1c7b5f201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Fri, 25 Oct 2024 11:26:43 +0200 Subject: [PATCH] [fix] postgresql --- lib/plankton/plankton.d.ts | 670 ++++-- lib/plankton/plankton.js | 2020 ++++++++++++++----- source/outputs/database/postgresql/logic.ts | 28 +- source/outputs/other/jsonschema/logic.ts | 4 +- todo.md | 2 + 5 files changed, 2094 insertions(+), 630 deletions(-) diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index f3191a8..20f1256 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -6,18 +6,11 @@ type int = number; * @author fenris */ type float = number; -/** - * @author fenris - */ -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); + static from(x: string, encoding?: string): any; toString(modifier?: string): string; } declare namespace lib_plankton.base { @@ -202,154 +195,6 @@ declare class class_observer { /** * @author frac */ -declare module lib_maybe { - /** - * @author fenris - */ - type type_maybe = { - kind: string; - parameters: Object; - }; - /** - * @author fenris - */ - function make_nothing(): type_maybe; - /** - * @author fenris - */ - function make_just(value: type_value): type_maybe; - /** - * @author fenris - */ - function is_nothing(maybe: type_maybe): boolean; - /** - * @author fenris - */ - function is_just(maybe: type_maybe): boolean; - /** - * @author fenris - */ - function cull(maybe: type_maybe): type_value; - /** - * @author fenris - */ - function propagate(maybe: type_maybe, function_: (value: type_value) => type_maybe): type_maybe; -} -/** - * @author fenris - */ -declare class class_maybe implements interface_showable { - /** - * @desc whether the wrapper is nothing - * @author fenris - */ - is_nothing(): boolean; - /** - * @desc whether the wrapper is just - * @author fenris - */ - is_just(): boolean; - /** - * @desc return the value, stored in the maybe-wrapper - * @author fenris - */ - cull(): type_value; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void; - /** - * @author fenris - */ - propagate(action: (value: type_value) => class_maybe): class_maybe; - /** - * @desc [implementation] - * @author fenris - */ - _show(): string; -} -/** - * @author fenris - */ -declare class class_nothing extends class_maybe { - /** - * @author fenris - */ - private reason; - /** - * @author fenris - */ - constructor(reason?: string); - /** - * @author fenris - */ - is_nothing(): boolean; - /** - * @author fenris - */ - is_just(): boolean; - /** - * @author fenris - */ - cull(): type_value; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - reason_get(): string; - /** - * @author fenris - */ - distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void; - /** - * @author fenris - */ - propagate(action: (value: type_value) => class_maybe): class_maybe; -} -/** - * @author fenris - */ -declare class class_just extends class_maybe { - /** - * @author fenris - */ - private value; - /** - * @author fenris - */ - constructor(value: type_value); - /** - * @author fenris - */ - is_nothing(): boolean; - /** - * @author fenris - */ - is_just(): boolean; - /** - * @author fenris - */ - cull(): type_value; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void; - /** - * @author fenris - */ - propagate(action: (value: type_value) => class_maybe): class_maybe; -} /** * @author frac */ @@ -378,11 +223,21 @@ declare namespace lib_plankton.base { * * @author fenris */ - function get_current_timestamp(rounded?: boolean): int; + function get_current_timestamp(rounded?: boolean): float; /** */ function object_merge(core: Record, mantle: Record): Record; } +declare namespace lib_plankton.email { + /** + */ + function send(smtp_credentials: { + host: string; + port: int; + username: string; + password: string; + }, sender: string, receivers: Array, subject: string, content: string): Promise; +} declare namespace lib_plankton.log { /** */ @@ -456,10 +311,40 @@ declare namespace lib_plankton.log { * the path of the log file */ private path; + /** + */ + private human_readable; /** * [constructor] */ - constructor(path: string); + constructor(path: string, human_readable: boolean); + /** + */ + add(entry: type_entry): void; + } +} +declare namespace lib_plankton.log { + /** + */ + class class_channel_email extends class_channel { + /** + */ + private smtp_credentials; + /** + */ + private sender; + /** + */ + private receivers; + /** + * [constructor] + */ + constructor(smtp_credentials: { + host: string; + port: int; + username: string; + password: string; + }, sender: string, receivers: Array); /** */ add(entry: type_entry): void; @@ -539,6 +424,8 @@ declare namespace lib_plankton.log { */ function error(incident: string, details?: Record): void; } +declare namespace lib_plankton.log { +} declare var plain_text_to_html: (text: string) => string; /** * @desc makes a valid @@ -886,13 +773,26 @@ declare namespace lib_plankton.code { } declare namespace lib_plankton.json { /** - * @author fenris */ - function encode(x: any, formatted?: boolean): string; + type type_source = any; + /** + */ + type type_target = string; /** * @author fenris */ - function decode(x: string): any; + export function encode(source: type_source, options?: { + formatted?: boolean; + }): type_target; + /** + * @author fenris + */ + export function decode(target: type_target): type_source; + /** + * @author fenris + */ + export function implementation_code(): lib_plankton.code.type_code; + export {}; } declare namespace lib_plankton.json { /** @@ -915,7 +815,455 @@ declare namespace lib_plankton.json { decode(x: string): any; } } +declare module lib_plankton.pod { + /** + * @author fenris + */ + type type_pod = { + kind: ("empty" | "filled"); + value?: type_value; + }; + /** + * @author fenris + */ + function make_empty(): type_pod; + /** + * @author fenris + */ + function make_filled(value: type_value): type_pod; + /** + * whether the pod is filled + * + * @author fenris + */ + function is_filled(pod: type_pod): boolean; + /** + * return the value, stored in the pod-wrapper + * + * @author fenris + */ + function cull(pod: type_pod): type_value; + /** + * to pass on a empty-pod or to use a filled-pod + * + * @author fenris + */ + function propagate(pod: type_pod, function_: ((value: type_value) => type_value_)): type_pod; + /** + * @author fenris + */ + function distinguish(pod: type_pod, function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result; + /** + */ + function show(pod: type_pod, options?: { + show_value?: ((value: type_value) => string); + }): string; +} +declare module lib_plankton.pod { + /** + */ + class class_pod { + private subject; + constructor(subject: type_pod); + tear(): type_pod; + static empty(): class_pod; + static filled(value: type_value): class_pod; + is_empty(): boolean; + is_filled(): boolean; + cull(): type_value; + show(show_value?: any): string; + toString(): string; + propagate(function_: ((value: type_value) => type_value_)): class_pod; + distinguish(function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result; + } +} +/** + * might be completely obsolete + */ +declare namespace lib_plankton.call { + /** + * @author fenris + */ + type type_promise = Promise; + /** + * @author fenris + */ + function promise_reject(reason: type_reason): type_promise; + /** + * @author fenris + */ + function promise_resolve(result: type_result): type_promise; + /** + * @author fenris + */ + function promise_make(executor: (resolve: ((result?: type_result) => void), reject: ((reason?: type_reason) => void)) => void): type_promise; + /** + * @author fenris + */ + function promise_then_close(promise: type_promise, resolver: ((result: type_result) => void), rejector: ((reason: type_reason) => void)): void; + /** + * @author fenris + */ + function promise_then_append(promise: type_promise, resolver: ((result: type_result) => type_promise), rejector?: ((reason: type_reason) => type_promise)): type_promise; + /** + * @author fenris + */ + function promise_all(promises: Array>): type_promise, type_reason>; + /** + * @author fenris + */ + function promise_chain(promises: (Array<(input: type_result) => type_promise>), start?: type_result): type_promise; + /** + * @author fenris + */ + function promise_condense(promises: Array<() => type_promise>): type_promise, type_reason>; + /** + * @author fenris + */ + function promise_group(promises: Record type_promise)>, options?: { + serial?: boolean; + }): type_promise, type_reason>; + /** + * @author fenris + */ + function promise_wrap(promise: type_promise, transformator_result: ((reason: type_result_inner) => type_result_outer), transformator_reason?: ((reason: type_reason) => type_reason)): type_promise; + /** + * @author fenris + */ + /** + * @author fenris + */ + /** + * @author fenris + */ + function promise_attach(state: Record, promise: type_promise, name: string): type_promise, type_reason>; + /** + * @author fenris + */ + function promise_delay(promise: type_promise, delay: int): type_promise; +} +declare namespace lib_plankton.call { + /** + */ + class CancellablePromise extends Promise { + /** + */ + private cancelled; + /** + */ + private interval; + /** + */ + private subject; + /** + */ + constructor(executor: ((resolve: any, reject: any) => void)); + /** + */ + private clear; + /** + */ + then(onfulfilled?: ((value: type_result) => (type_next_resolved | PromiseLike)), onrejected?: ((reason: any) => (type_next_rejected | PromiseLike))): Promise; + /** + */ + catch(x: any): Promise; + /** + */ + cancel(): void; + } +} +/** + * initializer might be obsolete, since promises are reusable after having been resolved or rejected + */ +declare namespace lib_plankton.call { + /** + * @author fenris + */ + enum enum_initializer_state { + initial = 0, + waiting = 1, + successful = 2, + failed = 3 + } + /** + * @author fenris + */ + type type_initializer = { + fetcher: (() => type_promise); + state?: enum_initializer_state; + queue: Array<{ + resolve: ((result?: type_result) => void); + reject: ((reason?: type_reason) => void); + }>; + result?: type_result; + reason?: type_reason; + }; + /** + * @author fenris + */ + function initializer_make(fetcher: (() => type_promise)): type_initializer; + /** + * @author fenris + */ + function initializer_reset(subject: type_initializer): void; + /** + * @author fenris + */ + function initializer_state(subject: type_initializer): enum_initializer_state; + /** + * @author fenris + */ + function initializer_get(subject: type_initializer): type_promise; +} +declare namespace lib_plankton.call { + /** + * @author fenris + */ + type type_deferral = { + representation: (input: type_input) => Promise; + }; + /** + * @author fenris + * @desc activates the deferral and handles its output according to a given procedure + * @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument + */ + function deferral_use(deferral: type_deferral, input: type_input, procedure: (output: type_output) => void): void; + /** + * @author fenris + * @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject") + */ + function deferral_make(handler: (input: type_input, convey: (output: type_output) => void) => void): type_deferral; + /** + * @author fenris + * @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject") + */ + function deferral_wrap(function_: (input: type_input) => type_output): type_deferral; + /** + * @author fenris + */ + function deferral_id(): type_deferral; + /** + * @author fenris + */ + function deferral_const(value: type_value): type_deferral; + /** + * @author fenris + */ + function deferral_delay(output: type_output, delay: int): type_deferral; + /** + * @author fenris + * @desc connects two deferrals to form a new one; the output of the first is taken as input for the second + * (similar to "Promise.then" when passing a function which returns a new promise) + * @param {type_deferral} first a simple deferral + * @param {(value1 : type_value1)=>type_deferral} second a function depending from a value returning a deferral + */ + function deferral_compose_serial(first: type_deferral, second: type_deferral): type_deferral; + /** + * @author fenris + */ + function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }: { + left: type_deferral; + right: type_deferral; + }): type_deferral; + /** + * @author fenris + * @desc repeatedly applied serial composition + */ + function deferral_chain(members: Array>): type_deferral; + /** + * @author fenris + */ +} +declare namespace lib_plankton.call { + /** + * @author fenris + */ + class class_deferral { + /** + * @author fenris + */ + private subject; + /** + * @author fenris + */ + private constructor(); + /** + * @author fenris + */ + private static _cram; + /** + * @author fenris + */ + private static _tear; + /** + * @author fenris + */ + static make(handler: (input: type_input, convey: (value: type_output) => void) => void): class_deferral; + /** + * @author fenris + */ + use(input: type_input, procedure: (value: type_output) => void): void; + /** + * @author fenris + */ + compose_serial(second: class_deferral): class_deferral; + /** + * @author fenris + */ + static chain(members: Array>): class_deferral; + /** + * @author fenris + */ + static wrap(function_: (input: type_input) => type_output): class_deferral; + /** + * @author fenris + */ + static const_(value: type_value): class_deferral; + /** + * @author fenris + */ + static delay(output: type_output, delay: int): class_deferral; + } +} +declare namespace lib_plankton.call { + /** + * converts the "arguments"-map into an array + * + * @param {Object} args + * @author fenris + */ + function args2list(args: any): Array; + /** + * just the empty function; useful for some callbacks etc. + * + * @author fenris + */ + function nothing(): void; + /** + * just the identity; useful for some callbacks etc.; defined as function instead of const for using type parameters + * + * @author fenris + */ + function id(x: type_value): type_value; + /** + * just the identity; useful for some callbacks etc. + * + * @author fenris + */ + function const_(x: type_value): ((y: any) => type_value); + /** + * composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions) + * + * @param {function} function_f + * @param {function} function_g + * @author fenris + */ + function compose(function_f: ((type_x: any) => type_y), function_g: ((type_y: any) => type_z)): ((value: type_x) => type_z); + /** + * transforms a function with sequential input to a function with leveled input; example: add(2,3) = curryfy(add)(2)(3) + * + * @param {function} f + * @return {function} the currified version of the in put function + * @author fenris + */ + function curryfy(f: Function): Function; + /** + * @author fenris + */ + function convey(value: any, functions: Array): any; + /** + * @author fenris + */ + function timeout(procedure: (() => void), delay_in_seconds: float): int; + /** + * Promise version of "setTimeout" + * + * @author fenris + */ + function defer(seconds: float, action: (() => type_result)): Promise; + /** + * a definition for a value being "defined" + * + * @author neuc + */ + function is_def(obj: type_value, options?: { + null_is_valid?: boolean; + }): boolean; + /** + * returns the value if set and, when a type is specified, if the type is correct, if not return default_value + * + * @author neuc + */ + function def_val(value: any, default_value: any, options?: { + type?: (null | string); + null_is_valid?: boolean; + }): any; + /** + * provides the call for an attribute of a class as a regular function; useful for processing lists of objects + * + * @param {string} name the name of the attribute + * @return {function} + * @author fenris + */ + function attribute(name: string): ((object: type_object) => type_attribute); + /** + * provides a method of a class as a regular function; useful for processing lists of objects + * + * @param {string} name the name of the method + * @return {function} + * @author fenris + */ + function method(name: string): ((object: type_object) => type_output); + /** + * @author fenris + */ + type type_coproduct = { + kind: string; + data?: any; + }; + /** + * @author fenris + */ + function distinguish(coproduct: type_coproduct, handlers: Record type_output)>, options?: { + fallback?: (null | ((coproduct?: type_coproduct) => type_output)); + }): type_output; + /** + * for rate_limit_check + * + * @author fenris + */ + type type_mana_snapshot = { + timestamp: float; + value: float; + }; + /** + * rate limiting algorithm, based on the idea of mana (magic power) in video games: + * - an actor has a fixed mana capacity, i.e. the maximum amount of available power + * - an actor has a fixed rate of mana regeneration, i.e. how fast the power is filled up (linear growth) + * - an action has a defined mana heft, i.e. how much power is required and deducted in order to execute it + * - mana states are represented by snapshots, i.e. the amount of power at a certain point in time + * + * @author fenris + */ + function rate_limit_check(setup: { + capacity: float; + regeneration_rate: float; + get_snapshot: (() => Promise<(null | type_mana_snapshot)>); + set_snapshot: ((snapshot: type_mana_snapshot) => Promise); + update_snapshot: ((timestamp: float, value_increment: float) => Promise); + }, heft: float): Promise<{ + granted: boolean; + seconds: (null | float); + }>; +} declare namespace lib_plankton.file { + /** + * @author fenris + */ + function exists(path: string): Promise; /** * @author fenris */ diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index f0e7fc3..bceb84b 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-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -36,7 +36,7 @@ along with »bacterio-plankton:base«. If not, see »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -69,7 +69,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -128,7 +128,7 @@ along with »bacterio-plankton:base«. If not, see »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -259,7 +259,7 @@ function instance_show(value) { /* This file is part of »bacterio-plankton:base«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -370,262 +370,7 @@ export interface interface_writeable { /* 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 -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_maybe; -(function (lib_maybe) { - /** - * @author fenris - */ - function make_nothing() { - return { - "kind": "nothing", - "parameters": {} - }; - } - lib_maybe.make_nothing = make_nothing; - /** - * @author fenris - */ - function make_just(value) { - return { - "kind": "just", - "parameters": { - "value": value - } - }; - } - lib_maybe.make_just = make_just; - /** - * @author fenris - */ - function is_nothing(maybe) { - return (maybe.kind === "nothing"); - } - lib_maybe.is_nothing = is_nothing; - /** - * @author fenris - */ - function is_just(maybe) { - return (maybe.kind === "just"); - } - lib_maybe.is_just = is_just; - /** - * @author fenris - */ - function cull(maybe) { - if (!is_just(maybe)) { - var message = "cull from nothing"; - throw (new Error(message)); - } - else { - var value = maybe.parameters["value"]; - return value; - } - } - lib_maybe.cull = cull; - /** - * @author fenris - */ - function propagate(maybe, function_) { - if (!is_just(maybe)) { - } - else { - var value = maybe.parameters["value"]; - var maybe_ = function_(value); - return maybe_; - } - } - lib_maybe.propagate = propagate; -})(lib_maybe || (lib_maybe = {})); -/** - * @author fenris - */ -/*export*/ var class_maybe = /** @class */ (function () { - function class_maybe() { - } - /** - * @desc whether the wrapper is nothing - * @author fenris - */ - class_maybe.prototype.is_nothing = function () { - throw (new Error("not implemented: class_maybe.is_nothing")); - }; - /** - * @desc whether the wrapper is just - * @author fenris - */ - class_maybe.prototype.is_just = function () { - throw (new Error("not implemented: class_maybe.is_just")); - }; - /** - * @desc return the value, stored in the maybe-wrapper - * @author fenris - */ - class_maybe.prototype.cull = function () { - throw (new Error("not implemented: class_maybe.cull")); - }; - /** - * @author fenris - */ - class_maybe.prototype.toString = function () { - throw (new Error("not implemented: class_maybe.cull")); - }; - /** - * @author fenris - */ - class_maybe.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - throw (new Error("not implemented: class_maybe.distinguish")); - }; - /** - * @author fenris - */ - class_maybe.prototype.propagate = function (action) { - throw (new Error("not implemented: class_maybe.propagate")); - }; - /** - * @desc [implementation] - * @author fenris - */ - class_maybe.prototype._show = function () { - return this.toString(); - }; - return class_maybe; -}()); -/** - * @author fenris - */ -/*export*/ var class_nothing = /** @class */ (function (_super) { - __extends(class_nothing, _super); - /** - * @author fenris - */ - function class_nothing(reason) { - if (reason === void 0) { reason = null; } - var _this = _super.call(this) || this; - _this.reason = reason; - return _this; - } - /** - * @author fenris - */ - class_nothing.prototype.is_nothing = function () { - return true; - }; - /** - * @author fenris - */ - class_nothing.prototype.is_just = function () { - return false; - }; - /** - * @author fenris - */ - class_nothing.prototype.cull = function () { - var message = "you shouldn't cull a nothing-value …"; - // lib_plankton.log.warn(message); - return null; - }; - /** - * @author fenris - */ - class_nothing.prototype.toString = function () { - return "<\u00B7>"; - }; - /** - * @author fenris - */ - class_nothing.prototype.reason_get = function () { - var content = ((this.reason == null) ? "·" : this.reason); - return "<- ".concat(content, " ->"); - }; - /** - * @author fenris - */ - class_nothing.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - action_nothing(this.reason); - }; - /** - * @author fenris - */ - class_nothing.prototype.propagate = function (action) { - return (new class_nothing(this.reason)); - }; - return class_nothing; -}(class_maybe)); -/** - * @author fenris - */ -/*export*/ var class_just = /** @class */ (function (_super) { - __extends(class_just, _super); - /** - * @author fenris - */ - function class_just(value) { - var _this = _super.call(this) || this; - _this.value = value; - return _this; - } - /** - * @author fenris - */ - class_just.prototype.is_nothing = function () { - return false; - }; - /** - * @author fenris - */ - class_just.prototype.is_just = function () { - return true; - }; - /** - * @author fenris - */ - class_just.prototype.cull = function () { - return this.value; - }; - /** - * @author fenris - */ - class_just.prototype.toString = function () { - var content = instance_show(this.value); - return "<+ ".concat(content, " +>"); - }; - /** - * @author fenris - */ - class_just.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - action_just(this.value); - }; - /** - * @author fenris - */ - class_just.prototype.propagate = function (action) { - return action(this.value); - }; - return class_just; -}(class_maybe)); -/* -This file is part of »bacterio-plankton:base«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:base« is free software: you can redistribute it and/or modify @@ -665,6 +410,25 @@ var class_error = /** @class */ (function (_super) { }; return class_error; }(Error)); +/* +This file is part of »bacterio-plankton:base«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»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; @@ -689,6 +453,100 @@ var lib_plankton; base.object_merge = object_merge; })(base = lib_plankton.base || (lib_plankton.base = {})); })(lib_plankton || (lib_plankton = {})); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +/* +This file is part of »bacterio-plankton:email«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:email« 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:email«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var email; + (function (email) { + /** + */ + function send(smtp_credentials, sender, receivers, subject, content) { + return __awaiter(this, void 0, void 0, function () { + var nm_nodemailer, transporter, info; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + nm_nodemailer = require("nodemailer"); + transporter = nm_nodemailer.createTransport({ + "host": smtp_credentials.host, + "port": smtp_credentials.port, + "secure": false, + "auth": { + "user": smtp_credentials.username, + "pass": smtp_credentials.password + }, + "debug": true + }); + return [4 /*yield*/, transporter.sendMail({ + "from": sender, + "to": receivers.join(", "), + "subject": subject, + "text": content + })]; + case 1: + info = _a.sent(); + return [2 /*return*/]; + } + }); + }); + } + email.send = send; + })(email = lib_plankton.email || (lib_plankton.email = {})); +})(lib_plankton || (lib_plankton = {})); var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || @@ -707,7 +565,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -762,7 +620,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -846,7 +704,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -879,7 +737,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -934,7 +792,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -961,9 +819,10 @@ var lib_plankton; /** * [constructor] */ - function class_channel_file(path) { + function class_channel_file(path, human_readable) { var _this = _super.call(this) || this; _this.path = path; + _this.human_readable = human_readable; return _this; } /** @@ -971,24 +830,40 @@ var lib_plankton; class_channel_file.prototype.add = function (entry) { var _this = this; var nm_fs = require("fs"); - nm_fs.writeFile(this.path, { + var line = (this.human_readable + ? (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") + + + " " + + + ("[" + log.level_show(entry.level) + "]") + + + " " + + + ("" + entry.incident + "") + + + ": " + + + JSON.stringify(entry.details, undefined, " ") + + + "\n") + : (JSON.stringify({ + "timestamp": lib_plankton.base.get_current_timestamp(), + "level_number": entry.level, + "level_name": log.level_show(entry.level), + "incident": entry.incident, + "details": entry.details + }) + + + "\n")); + nm_fs.writeFile(this.path, line, { "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"); + }, function (error) { + if (error !== null) { + process.stderr.write('-- [plankton] could not add log entry to file ' + _this.path + "\n"); + } + else { + // do nothing + } }); }; return class_channel_file; @@ -999,7 +874,59 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + var class_channel_email = /** @class */ (function (_super) { + __extends(class_channel_email, _super); + /** + * [constructor] + */ + function class_channel_email(smtp_credentials, sender, receivers) { + var _this = _super.call(this) || this; + _this.smtp_credentials = smtp_credentials; + _this.sender = sender; + _this.receivers = receivers; + return _this; + } + /** + */ + class_channel_email.prototype.add = function (entry) { + var nm_fs = require("fs"); + lib_plankton.email.send(this.smtp_credentials, this.sender, this.receivers, (("[" + log.level_show(entry.level) + "]") + + + " " + + + ("" + entry.incident + "")), JSON.stringify(entry.details, undefined, " ")); + }; + return class_channel_email; + }(log.class_channel)); + log.class_channel_email = class_channel_email; + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1066,7 +993,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1117,7 +1044,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1151,7 +1078,7 @@ var lib_plankton; /** */ function channel_make(description) { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e; switch (description.kind) { default: { throw (new Error("unhandled log channel kind: " + description.kind)); @@ -1162,11 +1089,15 @@ var lib_plankton; 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"))); + return (new log.class_channel_minlevel(new log.class_channel_file(((_b = description.data["path"]) !== null && _b !== void 0 ? _b : "/tmp/plankton.log"), false), translate_level((_c = description.data["threshold"]) !== null && _c !== void 0 ? _c : "debug"))); + break; + } + case "email": { + return (new log.class_channel_minlevel(new log.class_channel_email(description.data["smtp_credentials"], description.data["sender"], description.data["receivers"]), translate_level((_d = description.data["threshold"]) !== null && _d !== void 0 ? _d : "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"))); + return (new log.class_channel_minlevel(new log.class_channel_notify(), translate_level((_e = description.data["threshold"]) !== null && _e !== void 0 ? _e : "debug"))); break; } } @@ -1186,7 +1117,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:log«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:log« is free software: you can redistribute it and/or modify @@ -1289,9 +1220,44 @@ var lib_plankton; })(log = lib_plankton.log || (lib_plankton.log = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:log«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:log« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:lang« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:log«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var log; + (function (log) { + /** + */ + log.conf_push([ + log.channel_make({ + "kind": "stdout", + "data": { + "threshold": "info" + } + }), + ]); + })(log = lib_plankton.log || (lib_plankton.log = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -1450,7 +1416,7 @@ var make_eml_body = (function () { /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -1811,7 +1777,7 @@ var lib_string; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -2075,7 +2041,7 @@ var printf = lib_plankton.string.printf; /* This file is part of »bacterio-plankton:string«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:string« is free software: you can redistribute it and/or modify @@ -2207,7 +2173,7 @@ var make_logger = (function () { /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2226,7 +2192,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2245,7 +2211,7 @@ along with »bacterio-plankton:code«. If not, see »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2284,7 +2250,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2338,7 +2304,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2381,7 +2347,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2436,7 +2402,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2486,7 +2452,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2538,7 +2504,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2598,7 +2564,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:code«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:code« is free software: you can redistribute it and/or modify @@ -2649,7 +2615,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -2672,23 +2638,36 @@ var lib_plankton; /** * @author fenris */ - function encode(x, formatted = false) { - return JSON.stringify(x, undefined, formatted ? "\t" : undefined); + function encode(source, options = {}) { + options = Object.assign({ + "formatted": false, + }, options); + return JSON.stringify(source, undefined, (options.formatted ? "\t" : undefined)); } json.encode = encode; /** * @author fenris */ - function decode(x) { - return JSON.parse(x); + function decode(target) { + return JSON.parse(target); } json.decode = decode; + /** + * @author fenris + */ + function implementation_code() { + return { + "encode": x => encode(x), + "decode": decode, + }; + } + json.implementation_code = implementation_code; })(json = lib_plankton.json || (lib_plankton.json = {})); })(lib_plankton || (lib_plankton = {})); /* This file is part of »bacterio-plankton:json«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:json« is free software: you can redistribute it and/or modify @@ -2736,9 +2715,1109 @@ var lib_plankton; })(json = lib_plankton.json || (lib_plankton.json = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:pod«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pod« 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:pod« 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:pod«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var pod; + (function (pod_1) { + /** + * @author fenris + */ + function make_empty() { + return { + "kind": "empty" + }; + } + pod_1.make_empty = make_empty; + /** + * @author fenris + */ + function make_filled(value) { + return { + "kind": "filled", + "value": value + }; + } + pod_1.make_filled = make_filled; + /** + * whether the pod is filled + * + * @author fenris + */ + function is_filled(pod) { + return (pod.kind === "filled"); + } + pod_1.is_filled = is_filled; + /** + * return the value, stored in the pod-wrapper + * + * @author fenris + */ + function cull(pod) { + if (!is_filled(pod)) { + throw (new Error("cull from empty")); + } + else { + return pod.value; + } + } + pod_1.cull = cull; + /** + * to pass on a empty-pod or to use a filled-pod + * + * @author fenris + */ + function propagate(pod, function_) { + if (!is_filled(pod)) { + return make_empty(); + } + else { + return make_filled(function_(pod.value)); + } + } + pod_1.propagate = propagate; + /** + * @author fenris + */ + function distinguish(pod, function_empty, function_filled) { + return ((!is_filled(pod)) + ? function_empty() + : function_filled(pod.value)); + } + pod_1.distinguish = distinguish; + /** + */ + function show(pod, options = {}) { + options = Object.assign({ + "show_value": value => String(value), + }, options); + if (!is_filled(pod)) { + return "<·>"; + } + else { + return ("<- " + options.show_value(pod.value) + " ->"); + } + } + pod_1.show = show; + })(pod = lib_plankton.pod || (lib_plankton.pod = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:pod«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pod« 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:pod« 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:pod«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var pod; + (function (pod) { + /** + */ + class class_pod { + constructor(subject) { this.subject = subject; } + tear() { return this.subject; } + static empty() { return (new class_pod(pod.make_empty())); } + static filled(value) { return (new class_pod(pod.make_filled(value))); } + is_empty() { return (!pod.is_filled(this.subject)); } + is_filled() { return pod.is_filled(this.subject); } + cull() { return pod.cull(this.subject); } + show(show_value = undefined) { return pod.show(this.subject, show_value); } + toString() { return this.show(); } + propagate(function_) { return new class_pod(pod.propagate(this.subject, function_)); } + distinguish(function_empty, function_filled) { return pod.distinguish(this.subject, function_empty, function_filled); } + } + pod.class_pod = class_pod; + })(pod = lib_plankton.pod || (lib_plankton.pod = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:call« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:call«. If not, see . + */ +/** + * might be completely obsolete + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * @author fenris + */ + function promise_reject(reason) { + return Promise.reject(reason); + } + call.promise_reject = promise_reject; + /** + * @author fenris + */ + function promise_resolve(result) { + return Promise.resolve(result); + } + call.promise_resolve = promise_resolve; + /** + * @author fenris + */ + function promise_make(executor) { + return (new Promise(executor)); + } + call.promise_make = promise_make; + /** + * @author fenris + */ + function promise_then_close(promise, resolver, rejector) { + promise.then(resolver, rejector); + } + call.promise_then_close = promise_then_close; + /** + * @author fenris + */ + function promise_then_append(promise, resolver, rejector = null) { + if (rejector == null) { + rejector = (reason) => promise_reject(reason); + } + return (promise.then(resolver, rejector)); + } + call.promise_then_append = promise_then_append; + /** + * @author fenris + */ + function promise_all(promises) { + return Promise.all(promises); + } + call.promise_all = promise_all; + /** + * @author fenris + */ + function promise_chain(promises, start = undefined) { + return (promises.reduce((chain, promise) => promise_then_append(chain, promise), promise_resolve(start))); + } + call.promise_chain = promise_chain; + /** + * @author fenris + */ + function promise_condense(promises) { + return (promise_chain(promises.map(promise => result => promise_then_append(promise(), element => promise_resolve(result.concat([element])))), [])); + } + call.promise_condense = promise_condense; + /** + * @author fenris + */ + function promise_group(promises, options = { + "serial": false, + }) { + const decorate = function (promise, name) { + return (() => promise_then_append(promise(), value => promise_resolve({ "key": name, "value": value }))); + }; + if (options.serial) { + return (promise_then_append(promise_condense(Object.keys(promises) + .map(name => decorate(promises[name], name))), list => promise_resolve(Object.fromEntries(list.map(({ "key": key, "value": value }) => ([key, value])))))); + } + else { + return (promise_then_append(promise_all(Object.keys(promises) + .map(name => decorate(promises[name], name)) + .map(promise => promise())), list => promise_resolve(Object.fromEntries(list.map(({ "key": key, "value": value }) => ([key, value])))))); + } + } + call.promise_group = promise_group; + /** + * @author fenris + */ + function promise_wrap(promise, transformator_result, transformator_reason = lib_plankton.call.id) { + return (promise_make((resolve, reject) => { + promise_then_close(promise, result => resolve(transformator_result(result)), reason => reject(transformator_reason(reason))); + })); + } + call.promise_wrap = promise_wrap; + /** + * @author fenris + */ + /* + export function promise_show(label : string) : (result : type_result)=>type_promise { + return ( + result => promise_make( + (resolve, reject) => { + // lib_plankton.log.info(label + ": " + instance_show(result)); + process.stdout.write(label + ": " + instance_show(result)); + resolve(result); + } + ) + ); + } + */ + /** + * @author fenris + */ + /* + export function promise_log(result : type_result) : (result : type_result)=>type_promise { + return promise_show("log"); + } + */ + /** + * @author fenris + */ + function promise_attach(state, promise, name) { + return (promise_wrap(promise, result => { + state[name] = result; + return state; + })); + } + call.promise_attach = promise_attach; + /** + * @author fenris + */ + function promise_delay(promise, delay) { + return promise_make((resolve, reject) => { + call.timeout(() => { + promise_then_close(promise, resolve, reject); + return null; + }, delay); + }); + } + call.promise_delay = promise_delay; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:call« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + */ + class CancellablePromise extends Promise { + /** + */ + constructor(executor) { + super((resolve, reject) => { }); + this.subject = (new Promise((resolve, reject) => { + Promise.race([ + new Promise(executor), + new Promise((resolve_, reject_) => { + this.interval = setInterval(() => { + if (!this.cancelled) { + // do nothing + } + else { + reject_(new Error("cancelled")); + this.clear(); + } + }, 0); + }), + ]) + .then(resolve, reject); + })); + this.cancelled = false; + this.interval = null; + } + /** + */ + clear() { + if (this.interval === null) { + // do nothing + } + else { + clearInterval(this.interval); + this.interval = null; + } + } + /** + */ + then(onfulfilled, onrejected) { + this.clear(); + return this.subject.then(onfulfilled, onrejected); + } + /** + */ + catch(x) { + this.clear(); + return this.subject.catch(x); + } + /** + */ + cancel() { + this.cancelled = true; + this.clear(); + } + } + call.CancellablePromise = CancellablePromise; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:call« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:call«. If not, see . + */ +/** + * initializer might be obsolete, since promises are reusable after having been resolved or rejected + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * @author fenris + */ + let enum_initializer_state; + (function (enum_initializer_state) { + enum_initializer_state[enum_initializer_state["initial"] = 0] = "initial"; + enum_initializer_state[enum_initializer_state["waiting"] = 1] = "waiting"; + enum_initializer_state[enum_initializer_state["successful"] = 2] = "successful"; + enum_initializer_state[enum_initializer_state["failed"] = 3] = "failed"; + })(enum_initializer_state = call.enum_initializer_state || (call.enum_initializer_state = {})); + /** + * @author fenris + */ + function initializer_make(fetcher) { + let subject = { + "fetcher": fetcher, + "state": enum_initializer_state.initial, + "queue": [], + "result": undefined, + "reason": undefined, + }; + return subject; + } + call.initializer_make = initializer_make; + /** + * @author fenris + */ + function initializer_actuate(subject) { + switch (subject.state) { + case enum_initializer_state.successful: { + subject.queue.forEach(entry => entry.resolve(subject.result)); + break; + } + case enum_initializer_state.failed: { + subject.queue.forEach(entry => entry.reject(subject.reason)); + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + /** + * @author fenris + */ + function initializer_reset(subject) { + subject.state = enum_initializer_state.initial; + subject.queue = []; + } + call.initializer_reset = initializer_reset; + /** + * @author fenris + */ + function initializer_state(subject) { + return subject.state; + } + call.initializer_state = initializer_state; + /** + * @author fenris + */ + function initializer_get(subject) { + switch (subject.state) { + case enum_initializer_state.initial: { + subject.state = enum_initializer_state.waiting; + return (call.promise_make((resolve, reject) => { + subject.queue.push({ "resolve": resolve, "reject": reject }); + subject.fetcher().then(result => { + subject.state = enum_initializer_state.successful; + subject.result = result; + initializer_actuate(subject); + }, reason => { + subject.state = enum_initializer_state.failed; + subject.reason = reason; + initializer_actuate(subject); + }); + })); + break; + } + case enum_initializer_state.waiting: { + return (call.promise_make((resolve, reject) => { + subject.queue.push({ "resolve": resolve, "reject": reject }); + })); + break; + } + case enum_initializer_state.successful: { + return (call.promise_resolve(subject.result)); + break; + } + case enum_initializer_state.failed: { + return (call.promise_reject(subject.reason)); + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + call.initializer_get = initializer_get; + /** + * @author fenris + */ + function initializer_get_sync(subject) { + switch (subject.state) { + case enum_initializer_state.successful: { + return subject.result; + break; + } + case enum_initializer_state.failed: { + throw subject.reason; + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + /** + * @author fenris + */ + function initializer_set_sync(subject, result) { + switch (subject.state) { + case enum_initializer_state.successful: { + subject.result = result; + break; + } + case enum_initializer_state.failed: { + subject.state = enum_initializer_state.successful; + subject.result = result; + break; + } + default: { + throw (new Error(`unhandled state ${subject.state}`)); + break; + } + } + } + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:call« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /* + The core idea of this library is to provide means for asynchronous program flow. The old-school way to do is, + is to use callbacks. While this approach is simple and easy to understand, it has some disadvantages. As an + attempt to relief and improve this, the promise-system was introduced. In principle it solves most of the + problems found in the callback-approach; however it has some downsides as well: + + - Convolution of multiple principles + Promises unite the ideas of asynchronous program flow and error handling. + + - Instant execution + Creating a promise results in the instant execution of the given executor prodecure. While this might be + convenient in some cases, it can be quite disturbing and counter-intuitive in others. + + - Broken typing + The Promise system doesn't distinguish between an appending "then" (i.e. passing a function, which returns a + new promise) and a closing "then" (i.e. passing a function, which has no return value). On top of that it + allows returning simple values in an appending "then", which results in an implicit call of the executors + "resolve"-function. The price for these "pragmatic" features is that the whole system can't be typed well. + And even though JavaScript is not a strictly typed language, it was a quite questionable decision to design + the promise system in a way, which breaks typing from the start. + + The deferral-system forseeks to solve these issues while retaining the advantages of the promise-system. + */ + /** + * @author fenris + * @desc activates the deferral and handles its output according to a given procedure + * @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument + */ + function deferral_use(deferral, input, procedure) { + deferral.representation(input).then(value => { + procedure(value); + }, reason => { + throw reason; + }); + } + call.deferral_use = deferral_use; + /** + * @author fenris + * @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject") + */ + function deferral_make(handler) { + return ({ + "representation": ((input) => (new Promise((resolve, reject) => { + handler(input, resolve); + }))) + }); + } + call.deferral_make = deferral_make; + /** + * @author fenris + * @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject") + */ + function deferral_wrap(function_) { + return (deferral_make((input, convey) => convey(function_(input)))); + } + call.deferral_wrap = deferral_wrap; + /** + * @author fenris + */ + function deferral_id() { + return (deferral_make((input, convey) => convey(input))); + } + call.deferral_id = deferral_id; + /** + * @author fenris + */ + function deferral_const(value) { + return (deferral_make((input, convey) => convey(value))); + } + call.deferral_const = deferral_const; + /** + * @author fenris + */ + function deferral_delay(output, delay) { + return (deferral_make((input, convey) => { + setTimeout(() => convey(output), delay); + })); + } + call.deferral_delay = deferral_delay; + /** + * @author fenris + * @desc connects two deferrals to form a new one; the output of the first is taken as input for the second + * (similar to "Promise.then" when passing a function which returns a new promise) + * @param {type_deferral} first a simple deferral + * @param {(value1 : type_value1)=>type_deferral} second a function depending from a value returning a deferral + */ + function deferral_compose_serial(first, second) { + return { + "representation": ((input) => first.representation(input).then((between) => second.representation(between))) + }; + } + call.deferral_compose_serial = deferral_compose_serial; + /** + * @author fenris + */ + function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }) { + return (deferral_make((input, convey) => { + let object = { + "left": lib_plankton.pod.make_empty(), + "right": lib_plankton.pod.make_empty(), + }; + let finish = function () { + if (lib_plankton.pod.is_filled(object.left) + && + lib_plankton.pod.is_filled(object.right)) { + let result = { + "left": lib_plankton.pod.cull(object.left), + "right": lib_plankton.pod.cull(object.right), + }; + convey(result); + } + else { + // do nothing + } + }; + deferral_use(deferral_left, input, output_left => { + object.left = lib_plankton.pod.make_filled(output_left); + finish(); + }); + deferral_use(deferral_right, input, output_right => { + object.right = lib_plankton.pod.make_filled(output_right); + finish(); + }); + })); + } + call.deferral_compose_parallel = deferral_compose_parallel; + /** + * @author fenris + * @desc repeatedly applied serial composition + */ + function deferral_chain(members) { + return (members.reduce( + // (result, current) => deferral_compose_serial(result, current), + deferral_compose_serial, deferral_id())); + } + call.deferral_chain = deferral_chain; + /** + * @author fenris + */ + /* + export function deferral_bunch( + members : {[name : string] : type_deferral} + ) : type_deferral { + + } + */ + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:call« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * @author fenris + */ + class class_deferral { + /** + * @author fenris + */ + constructor(subject) { + this.subject = subject; + } + /** + * @author fenris + */ + static _cram(subject) { + return (new class_deferral(subject)); + } + /** + * @author fenris + */ + static _tear(instance) { + return instance.subject; + } + /** + * @author fenris + */ + static make(handler) { + return (class_deferral._cram(call.deferral_make(handler))); + } + /** + * @author fenris + */ + use(input, procedure) { + return (call.deferral_use(class_deferral._tear(this), input, procedure)); + } + /** + * @author fenris + */ + compose_serial(second) { + return (class_deferral._cram(call.deferral_compose_serial(class_deferral._tear(this), class_deferral._tear(second)))); + } + /** + * @author fenris + */ + static chain(members) { + return (class_deferral._cram(call.deferral_chain(members.map(member => class_deferral._tear(member))))); + } + /** + * @author fenris + */ + static wrap(function_) { + return (class_deferral._cram(call.deferral_wrap(function_))); + } + /** + * @author fenris + */ + static const_(value) { + return (class_deferral._cram(call.deferral_const(value))); + } + /** + * @author fenris + */ + static delay(output, delay) { + return (class_deferral._cram(call.deferral_delay(output, delay))); + } + } + call.class_deferral = class_deferral; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:call«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:call« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:call« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:call«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var call; + (function (call) { + /** + * converts the "arguments"-map into an array + * + * @param {Object} args + * @author fenris + */ + function args2list(args) { + return Object.keys(args).map(key => args[key]); + } + call.args2list = args2list; + /** + * just the empty function; useful for some callbacks etc. + * + * @author fenris + */ + function nothing() { + } + call.nothing = nothing; + /** + * just the identity; useful for some callbacks etc.; defined as function instead of const for using type parameters + * + * @author fenris + */ + function id(x) { + return x; + } + call.id = id; + /** + * just the identity; useful for some callbacks etc. + * + * @author fenris + */ + function const_(x) { + return (y => x); + } + call.const_ = const_; + /** + * composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions) + * + * @param {function} function_f + * @param {function} function_g + * @author fenris + */ + function compose(function_f, function_g) { + return (function (x) { + // return function_g(function_f(x)); + return function_g(function_f.apply(function_f, args2list(arguments))); + }); + } + call.compose = compose; + /** + * @author fenris + */ + function curryfy_real(f, n) { + switch (n) { + case 0: { + throw (new Error("[curryfy] impossible")); + // break; + } + case 1: { + return f; + // break; + } + default: { + return (function (x) { + return (curryfy_real(function () { return f.apply(f, [x].concat(args2list(arguments))); }, n - 1)); + }); + // break; + } + } + } + /** + * transforms a function with sequential input to a function with leveled input; example: add(2,3) = curryfy(add)(2)(3) + * + * @param {function} f + * @return {function} the currified version of the in put function + * @author fenris + */ + function curryfy(f) { + return curryfy_real(f, f.length); + } + call.curryfy = curryfy; + /** + * @author fenris + */ + function convey(value, functions) { + let result = value; + functions.forEach(function_ => { + result = function_(result); + }); + return result; + } + call.convey = convey; + /** + * @author fenris + */ + function timeout(procedure, delay_in_seconds) { + return ( + /*window.*/ setTimeout(procedure, Math.floor(delay_in_seconds * 1000))); + } + call.timeout = timeout; + /** + * Promise version of "setTimeout" + * + * @author fenris + */ + function defer(seconds, action) { + return (new Promise((resolve, reject) => { + setTimeout(() => resolve(action()), Math.floor(seconds * 1000)); + })); + } + call.defer = defer; + /** + * a definition for a value being "defined" + * + * @author neuc + */ + function is_def(obj, options = {}) { + options = Object.assign({ + "null_is_valid": false, + }, options); + return (!((typeof (obj) === "undefined") + || + (!options.null_is_valid && (obj === null)))); + } + call.is_def = is_def; + /** + * returns the value if set and, when a type is specified, if the type is correct, if not return default_value + * + * @author neuc + */ + function def_val(value, default_value, options = {}) { + options = Object.assign({ + "type": null, + "null_is_valid": false, + }, options); + if (is_def(value, { "null_is_valid": options.null_is_valid }) + && + (is_def(options.type) + ? ((typeof (value) === options.type) + || + ((value === null) + && + options.null_is_valid)) + : true)) { + return value; + } + else { + return default_value; + } + } + call.def_val = def_val; + ; + /** + * provides the call for an attribute of a class as a regular function; useful for processing lists of objects + * + * @param {string} name the name of the attribute + * @return {function} + * @author fenris + */ + function attribute(name) { + return (object => object[name]); + } + call.attribute = attribute; + /** + * provides a method of a class as a regular function; useful for processing lists of objects + * + * @param {string} name the name of the method + * @return {function} + * @author fenris + */ + function method(name) { + return (function (object) { return object[name].apply(object, args2list(arguments).slice(1)); }); + } + call.method = method; + /** + * @author fenris + */ + function distinguish(coproduct, handlers, options = {}) { + options = Object.assign({ + "fallback": null, + }, options); + if (coproduct.kind in handlers) { + const handler = handlers[coproduct.kind]; + return handler(coproduct.data); + } + else { + const message = ("unhandled kind '" + coproduct.kind + "'"); + if (options.fallback !== null) { + console.warn(message); + return options.fallback(coproduct); + } + else { + throw (new Error(message)); + } + } + } + call.distinguish = distinguish; + /** + * rate limiting algorithm, based on the idea of mana (magic power) in video games: + * - an actor has a fixed mana capacity, i.e. the maximum amount of available power + * - an actor has a fixed rate of mana regeneration, i.e. how fast the power is filled up (linear growth) + * - an action has a defined mana heft, i.e. how much power is required and deducted in order to execute it + * - mana states are represented by snapshots, i.e. the amount of power at a certain point in time + * + * @author fenris + */ + async function rate_limit_check(setup, heft) { + if (heft > setup.capacity) { + return Promise.resolve({ + "granted": false, + "seconds": null, + }); + } + else { + // get current value + const current_timestamp = (Date.now() / 1000); + const old_snapshot_raw = (await setup.get_snapshot()); + const old_snapshot = (old_snapshot_raw + ?? + { "timestamp": current_timestamp, "value": setup.capacity }); + const seconds_passed = (current_timestamp - old_snapshot.timestamp); + const current_value = Math.min(setup.capacity, (old_snapshot.value + + + (setup.regeneration_rate + * + seconds_passed))); + // analyze + if (current_value < heft) { + // too less + const seconds_needed = ((setup.regeneration_rate <= 0) + ? null + : ((heft - old_snapshot.value) / setup.regeneration_rate)); + return Promise.resolve({ + "granted": false, + "seconds": ((seconds_needed === null) ? null : (seconds_needed - seconds_passed)), + }); + } + else { + // enough -> update snapshot + const new_value = (current_value - heft); + // set_snapshot + if (old_snapshot_raw === null) { + await setup.set_snapshot({ "timestamp": current_timestamp, "value": new_value }); + } + else { + await setup.update_snapshot(current_timestamp, (new_value - old_snapshot.value)); + } + return Promise.resolve({ + "granted": true, + "seconds": 0, + }); + } + } + } + call.rate_limit_check = rate_limit_check; + })(call = lib_plankton.call || (lib_plankton.call = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:file«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:file« is free software: you can redistribute it and/or modify @@ -2758,6 +3837,23 @@ var lib_plankton; (function (lib_plankton) { var file; (function (file) { + /** + * @author fenris + */ + function exists(path) { + var nm_fs = require("fs"); + return (new Promise(function (resolve, reject) { + nm_fs.stat(path, function (error, stats) { + if (error) { + resolve(false); + } + else { + resolve(true); + } + }); + })); + } + file.exists = exists; /** * @author fenris */ @@ -2766,7 +3862,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); @@ -2785,7 +3881,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); @@ -2822,13 +3918,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); @@ -2849,7 +3945,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); @@ -2892,7 +3988,7 @@ var __extends = (this && this.__extends) || (function () { /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -2925,7 +4021,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -2962,7 +4058,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -2997,7 +4093,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3032,7 +4128,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3067,7 +4163,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3102,7 +4198,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3137,7 +4233,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3174,7 +4270,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3212,7 +4308,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3249,7 +4345,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3284,7 +4380,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3322,7 +4418,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3360,7 +4456,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3395,7 +4491,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3428,7 +4524,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3465,7 +4561,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3502,7 +4598,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3539,7 +4635,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3576,7 +4672,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3621,7 +4717,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3660,7 +4756,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3698,7 +4794,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3736,7 +4832,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3774,7 +4870,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3811,7 +4907,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3849,7 +4945,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3882,7 +4978,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3920,7 +5016,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3957,7 +5053,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -3985,12 +5081,12 @@ var lib_plankton; if (options === void 0) { options = {}; } var _this = this; options = Object.assign({ - "export": false, + "export": false }, options); _this = _super.call(this) || this; _this.name = name; _this.type = type; - _this.export_ = options.export; + _this.export_ = options["export"]; return _this; } return struct_statement_type_definition; @@ -4001,7 +5097,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4029,14 +5125,14 @@ var lib_plankton; if (options === void 0) { options = {}; } var _this = this; options = Object.assign({ - "export": false, + "export": false }, options); _this = _super.call(this) || this; _this.constant = constant; _this.name = name; _this.type = type; _this.value = value; - _this.export_ = options.export; + _this.export_ = options["export"]; return _this; } return struct_statement_declaration; @@ -4047,7 +5143,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4085,7 +5181,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4123,7 +5219,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4169,7 +5265,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4206,7 +5302,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4240,7 +5336,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:prog«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4259,7 +5355,7 @@ along with »bacterio-plankton:prog«. If not, see »bacterio-plankton:prog« is free software: you can redistribute it and/or modify @@ -4294,45 +5390,45 @@ var lib_plankton; if (options === void 0) { options = {}; } options = Object.assign({ "indent": true, - "level": 0, + "level": 0 }, options); if (type instanceof prog.struct_type_literal) { var type_literal = type; return lib_plankton.string.coin("{{indentation}}{{value}}", { "indentation": indentation(options.indent, options.level), "value": render_expression(type_literal.value, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (type instanceof prog.struct_type_any) { var type_any = type; return lib_plankton.string.coin("{{indentation}}any", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_void) { var type_void = type; return lib_plankton.string.coin("{{indentation}}void", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_boolean) { var type_boolean = type; return lib_plankton.string.coin("{{indentation}}boolean", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_integer) { var type_integer = type; return lib_plankton.string.coin("{{indentation}}number", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_string) { var type_string = type; return lib_plankton.string.coin("{{indentation}}string", { - "indentation": indentation(options.indent, options.level), + "indentation": indentation(options.indent, options.level) }); } else if (type instanceof prog.struct_type_list) { @@ -4360,10 +5456,10 @@ var lib_plankton; "assignment": (field.mandatory ? ":" : "?:"), "type": render_type(field.type, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(";\n")), + .join(";\n")) }); } else if (type instanceof prog.struct_type_function) { @@ -4373,12 +5469,12 @@ var lib_plankton; "indentation2": indentation(true, options.level), "arguments": (type_function.arguments .map(function (argument) { return render_type(argument, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) .join(", ")), "target": render_type(type_function.target, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (type instanceof prog.struct_type_construction) { @@ -4392,10 +5488,10 @@ var lib_plankton; "indentation": indentation(true, options.level), "arguments": (type_construction.arguments .map(function (argument) { return render_type(argument, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join(",\n")), - })), + .join(",\n")) + })) }); } else if (type instanceof prog.struct_type_union) { @@ -4405,11 +5501,11 @@ var lib_plankton; "indentation2": indentation(true, options.level), "indentation3": indentation(true, options.level + 1), "left": render_type(type_union.left, { - "level": (options.level + 1), + "level": (options.level + 1) }), "right": render_type(type_union.right, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (type instanceof prog.struct_type_intersection) { @@ -4418,11 +5514,11 @@ var lib_plankton; "indentation1": indentation(options.indent, options.level), "indentation2": indentation(true, options.level + 1), "left": render_type(type_intersection.left, { - "level": (options.level + 1), + "level": (options.level + 1) }), "right": render_type(type_intersection.right, { - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else { @@ -4436,20 +5532,20 @@ var lib_plankton; if (options === void 0) { options = {}; } options = Object.assign({ "indent": false, - "level": 0, + "level": 0 }, options); if (expression instanceof prog.struct_expression_variable) { var expression_variable = expression; return lib_plankton.string.coin("{{indentation}}{{name}}", { "indentation": indentation(options.indent, options.level), - "name": expression.name, + "name": expression.name }); } else if (expression instanceof prog.struct_expression_literal) { var expression_literal = expression; return lib_plankton.string.coin("{{indentation}}{{value}}", { "indentation": indentation(options.indent, options.level), - "value": JSON.stringify(expression_literal.value), + "value": JSON.stringify(expression_literal.value) }); } else if (expression instanceof prog.struct_expression_list) { @@ -4462,10 +5558,10 @@ var lib_plankton; "indentation": indentation(true, options.level + 1), "value": render_expression(element, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (expression instanceof prog.struct_expression_dict) { @@ -4479,10 +5575,10 @@ var lib_plankton; "key": field.key, "value": render_expression(field.value, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (expression instanceof prog.struct_expression_abstraction) { @@ -4500,7 +5596,7 @@ var lib_plankton; ? "" : lib_plankton.string.coin(" : {{type}}", { "type": render_type(argument.type) - })), + })) }); }) .join(", ")), "macro_output_type": ((expression_abstraction.output_type === null) @@ -4508,14 +5604,14 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(expression_abstraction.output_type, { "indent": false, - "level": (options.level + 1), + "level": (options.level + 1) }) })), "body": (expression_abstraction.body .map(function (statement) { return render_statement(statement, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join("")), + .join("")) }); } else if (expression instanceof prog.struct_expression_function_application) { @@ -4525,16 +5621,16 @@ var lib_plankton; "indentation2": indentation(true, options.level), "name": render_expression(expression_function_application.head, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "arguments": (expression_function_application.arguments .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { "argument": render_expression(argument, { "indent": true, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (expression instanceof prog.struct_expression_projection) { @@ -4542,7 +5638,7 @@ var lib_plankton; return lib_plankton.string.coin("{{indentation}}{{source}}[{{index}}]", { "indentation": indentation(options.indent, options.level), "source": render_expression(expression_projection.source), - "index": render_expression(expression_projection.index), + "index": render_expression(expression_projection.index) }); } else if (expression instanceof prog.struct_expression_fieldaccess) { @@ -4550,9 +5646,9 @@ var lib_plankton; return lib_plankton.string.coin("{{indentation}}{{structure}}.{{fieldname}}", { "indentation": indentation(options.indent, options.level), "structure": render_expression(expression_fieldaccess.structure, { - "level": (options.level + 1), + "level": (options.level + 1) }), - "fieldname": expression_fieldaccess.fieldname, + "fieldname": expression_fieldaccess.fieldname }); } else if (expression instanceof prog.struct_expression_operation_comparison) { @@ -4561,12 +5657,12 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "left": render_expression(expression_operation_comparison.left, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "right": render_expression(expression_operation_comparison.right, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else if (expression instanceof prog.struct_expression_await) { @@ -4575,8 +5671,8 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "target": render_expression(expression_await.target, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else if (expression instanceof prog.struct_expression_cast) { @@ -4585,12 +5681,12 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "expression": render_expression(expression_cast.expression, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "type": render_type(expression_cast.type, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else { @@ -4604,7 +5700,7 @@ var lib_plankton; if (options === void 0) { options = {}; } options = Object.assign({ "indent": true, - "level": 0, + "level": 0 }, options); if (statement instanceof prog.struct_statement_comment) { var statement_comment = statement; @@ -4614,17 +5710,17 @@ var lib_plankton; "lines": (statement_comment.lines .map(function (line) { return lib_plankton.string.coin("{{indentation}} * {{line}}\n", { "indentation": indentation(options.indent, options.level), - "line": line, + "line": line }); }) - .join("")), + .join("")) }) : lib_plankton.string.coin("{{lines}}", { "lines": (statement_comment.lines .map(function (line) { return lib_plankton.string.coin("{{indentation}}// {{line}}\n", { "indentation": indentation(options.indent, options.level), - "line": line, + "line": line }); }) - .join("")), + .join("")) })); } else if (statement instanceof prog.struct_statement_block) { @@ -4633,9 +5729,9 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "statements": (statement_block.statements .map(function (statement) { return render_statement(statement, { - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join("")), + .join("")) }); } else if (statement instanceof prog.struct_statement_type_definition) { @@ -4648,8 +5744,8 @@ var lib_plankton; : "export "), "type": render_type(statement_type_definition.type, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else if (statement instanceof prog.struct_statement_declaration) { @@ -4668,17 +5764,17 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(statement_declaration.type, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) })), "macro_value": ((statement_declaration.value === null) ? "" : lib_plankton.string.coin(" = {{value}}", { "value": render_expression(statement_declaration.value, { "indent": false, - "level": (options.level + 0), - }), - })), + "level": (options.level + 0) + }) + })) }); } else if (statement instanceof prog.struct_statement_assignment) { @@ -4688,8 +5784,8 @@ var lib_plankton; "name": statement_assignment.name, "value": render_expression(statement_assignment.value, { "indent": false, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); } else if (statement instanceof prog.struct_statement_procedure_call) { @@ -4699,16 +5795,16 @@ var lib_plankton; "indentation2": indentation(true, options.level), "name": render_expression(statement_procedure_call.head, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }), "arguments": (statement_procedure_call.arguments .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { "argument": render_expression(argument, { "indent": true, - "level": (options.level + 1), - }), + "level": (options.level + 1) + }) }); }) - .join(",\n")), + .join(",\n")) }); } else if (statement instanceof prog.struct_statement_function_definition) { @@ -4729,9 +5825,9 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(argument.type, { "indent": false, - "level": (options.level + 2), + "level": (options.level + 2) }) - })), + })) }); }) .join(",\n")), "macro_output_type": ((statement_function_definition.output_type === null) @@ -4739,15 +5835,15 @@ var lib_plankton; : lib_plankton.string.coin(" : {{type}}", { "type": render_type(statement_function_definition.output_type, { "indent": false, - "level": (options.level + 0), + "level": (options.level + 0) }) })), "body": (statement_function_definition.body .map(function (statement) { return render_statement(statement, { "indent": true, - "level": (options.level + 1), + "level": (options.level + 1) }); }) - .join("")), + .join("")) }); } else if (statement instanceof prog.struct_statement_return) { @@ -4756,8 +5852,8 @@ var lib_plankton; "indentation": indentation(options.indent, options.level), "expression": render_expression(statement_return.expression, { "indent": false, - "level": (options.level + 0), - }), + "level": (options.level + 0) + }) }); } else { @@ -4771,7 +5867,7 @@ var lib_plankton; return (program.statements .map(function (statement) { return render_statement(statement, { "indent": true, - "level": 0, + "level": 0 }); }) .join("\n")); } @@ -4783,7 +5879,7 @@ var lib_plankton; "render_expression": render_expression, "render_type": render_type, "render_statement": render_statement, - "render_program": render_program, + "render_program": render_program }; } typescript.output_typescript = output_typescript; @@ -4793,7 +5889,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -4852,7 +5948,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -4913,8 +6009,8 @@ var lib_plankton; "info": info, "hidden": hidden, "parameters": { - "index": index, - }, + "index": index + } })); }; /** @@ -4932,8 +6028,8 @@ var lib_plankton; "hidden": hidden, "parameters": { "indicators_short": indicators_short, - "indicators_long": indicators_long, - }, + "indicators_long": indicators_long + } })); }; /** @@ -5150,7 +6246,7 @@ var lib_plankton; /* This file is part of »bacterio-plankton:args«. -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' »bacterio-plankton:args« is free software: you can redistribute it and/or modify @@ -5179,17 +6275,17 @@ var lib_plankton; "symbols": { "delimiter": " ", "prefix": "--", - "assignment": "=", - }, + "assignment": "=" + } }, "url": { "symbols": { "delimiter": "&", "prefix": "", - "assignment": "=", + "assignment": "=" } } - }, + } }; /** * @author fenris @@ -5266,14 +6362,14 @@ var lib_plankton; "pattern_from": pattern_from, "pattern_to": pattern_to, "input": input, - "result": result, + "result": result }); input = result; } } } lib_plankton.log.debug("lib_args:read:current_input", { - "input": input, + "input": input }); } // parsing @@ -5284,18 +6380,18 @@ var lib_plankton; var index_expected_1 = 0; parts.forEach(function (part) { lib_plankton.log.debug("lib_args:read:analyzing", { - "part": part, + "part": part }); var found = [ function () { lib_plankton.log.debug("lib_args:read:probing_as_volatile", { - "part": part, + "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 = ""; { @@ -5314,12 +6410,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", { - "pattern": pattern, + "pattern": pattern }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", { - "matching": matching, + "matching": matching }); if (matching == null) { // do nothing @@ -5333,7 +6429,7 @@ var lib_plankton; }, function () { lib_plankton.log.debug("lib_args:read:probing_as_positional", { - "part": part, + "part": part }); var positional = _this.filter(args.enum_kind.positional); for (var _i = 0, _a = Object.entries(positional); _i < _a.length; _i++) { @@ -5344,7 +6440,7 @@ var lib_plankton; else { lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", { "part": part, - "argument": argument.toString(), + "argument": argument.toString() }); var pattern = ""; { @@ -5353,12 +6449,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_positional:pattern", { - "pattern": 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, + "matching": matching }); if (matching == null) { return false; @@ -5375,7 +6471,7 @@ var lib_plankton; ].some(function (x) { return x(); }); if (!found) { lib_plankton.log.warning("lib_args:read:could_not_parse", { - "part": part, + "part": part }); } }); diff --git a/source/outputs/database/postgresql/logic.ts b/source/outputs/database/postgresql/logic.ts index ba7cfa8..38d675e 100644 --- a/source/outputs/database/postgresql/logic.ts +++ b/source/outputs/database/postgresql/logic.ts @@ -56,7 +56,7 @@ namespace _sindri.outputs.database.postgresql : lib_plankton.string.coin( "{{name}} {{parameters}}", { - "name": domain.key_field.name, + "name": ('"' + domain.key_field.name + '"'), "parameters": ( [ "SERIAL", @@ -73,7 +73,7 @@ namespace _sindri.outputs.database.postgresql (data_field) => lib_plankton.string.coin( "{{name}} {{parameters}}", { - "name": data_field.name, + "name": ('"' + data_field.name + '"'), "parameters": ( ( // type @@ -115,6 +115,22 @@ namespace _sindri.outputs.database.postgresql // constraints .concat( domain["constraints"] + .concat( + (domain.key_field === null) + ? + [] + : + [ + { + "kind": "unique", + "parameters": { + "fields": [ + domain.key_field.name, + ] + } + }, + ] + ) .map( (constraint) => { switch (constraint.kind) { @@ -128,13 +144,13 @@ namespace _sindri.outputs.database.postgresql { "fields": ( constraint.parameters["fields"] - .map(x => ('' + x + '')) + .map(x => ('"' + x + '"')) .join(",") ), - "reference_name": constraint.parameters["reference"]["name"], + "reference_name": ('"' + constraint.parameters["reference"]["name"] + '"'), "reference_fields": ( constraint.parameters["reference"]["fields"] - .map(x => ('' + x + '')) + .map(x => ('"' + x + '"')) .join(",") ), } @@ -147,7 +163,7 @@ namespace _sindri.outputs.database.postgresql { "fields": ( constraint.parameters["fields"] - .map(x => ('' + x + '')) + .map(x => ('"' + x + '"')) .join(",") ), } diff --git a/source/outputs/other/jsonschema/logic.ts b/source/outputs/other/jsonschema/logic.ts index 490d0cc..98f8d23 100644 --- a/source/outputs/other/jsonschema/logic.ts +++ b/source/outputs/other/jsonschema/logic.ts @@ -83,7 +83,9 @@ namespace _sindri.outputs.other.jsonschema ]) ) ), - true + { + "formatted": true + } ); } diff --git a/todo.md b/todo.md index 3c4dd20..5d5b8e8 100644 --- a/todo.md +++ b/todo.md @@ -1 +1,3 @@ - Nutzer-Verwaltung +- auf `plankton:database` setzen +