[fix] postgresql

This commit is contained in:
Christian Fraß 2024-10-25 11:26:43 +02:00
parent 5e928f8cab
commit 8b121af099
5 changed files with 2094 additions and 630 deletions

View file

@ -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<type_value> = {
kind: string;
parameters: Object;
};
/**
* @author fenris
*/
function make_nothing<type_value>(): type_maybe<type_value>;
/**
* @author fenris
*/
function make_just<type_value>(value: type_value): type_maybe<type_value>;
/**
* @author fenris
*/
function is_nothing<type_value>(maybe: type_maybe<type_value>): boolean;
/**
* @author fenris
*/
function is_just<type_value>(maybe: type_maybe<type_value>): boolean;
/**
* @author fenris
*/
function cull<type_value>(maybe: type_maybe<type_value>): type_value;
/**
* @author fenris
*/
function propagate<type_value, type_value_>(maybe: type_maybe<type_value>, function_: (value: type_value) => type_maybe<type_value_>): type_maybe<type_value_>;
}
/**
* @author fenris
*/
declare class class_maybe<type_value> 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<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
/**
* @desc [implementation]
* @author fenris
*/
_show(): string;
}
/**
* @author fenris
*/
declare class class_nothing<type_value> extends class_maybe<type_value> {
/**
* @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<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
}
/**
* @author fenris
*/
declare class class_just<type_value> extends class_maybe<type_value> {
/**
* @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<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
}
/**
* @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<string, any>, mantle: Record<string, any>): Record<string, any>;
}
declare namespace lib_plankton.email {
/**
*/
function send(smtp_credentials: {
host: string;
port: int;
username: string;
password: string;
}, sender: string, receivers: Array<string>, subject: string, content: string): Promise<void>;
}
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<string>);
/**
*/
add(entry: type_entry): void;
@ -539,6 +424,8 @@ declare namespace lib_plankton.log {
*/
function error(incident: string, details?: Record<string, any>): 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<type_source, type_target>;
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<type_value> = {
kind: ("empty" | "filled");
value?: type_value;
};
/**
* @author fenris
*/
function make_empty<type_value>(): type_pod<type_value>;
/**
* @author fenris
*/
function make_filled<type_value>(value: type_value): type_pod<type_value>;
/**
* whether the pod is filled
*
* @author fenris
*/
function is_filled<type_value>(pod: type_pod<type_value>): boolean;
/**
* return the value, stored in the pod-wrapper
*
* @author fenris
*/
function cull<type_value>(pod: type_pod<type_value>): type_value;
/**
* to pass on a empty-pod or to use a filled-pod
*
* @author fenris
*/
function propagate<type_value, type_value_>(pod: type_pod<type_value>, function_: ((value: type_value) => type_value_)): type_pod<type_value_>;
/**
* @author fenris
*/
function distinguish<type_value, type_result>(pod: type_pod<type_value>, function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result;
/**
*/
function show<type_value>(pod: type_pod<type_value>, options?: {
show_value?: ((value: type_value) => string);
}): string;
}
declare module lib_plankton.pod {
/**
*/
class class_pod<type_value> {
private subject;
constructor(subject: type_pod<type_value>);
tear(): type_pod<type_value>;
static empty<type_value>(): class_pod<type_value>;
static filled<type_value>(value: type_value): class_pod<type_value>;
is_empty(): boolean;
is_filled(): boolean;
cull(): type_value;
show(show_value?: any): string;
toString(): string;
propagate<type_value_>(function_: ((value: type_value) => type_value_)): class_pod<type_value_>;
distinguish<type_result>(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<type_result, type_reason> = Promise<type_result>;
/**
* @author fenris
*/
function promise_reject<type_result, type_reason>(reason: type_reason): type_promise<type_result, type_reason>;
/**
* @author fenris
*/
function promise_resolve<type_result, type_reason>(result: type_result): type_promise<type_result, type_reason>;
/**
* @author fenris
*/
function promise_make<type_result, type_reason>(executor: (resolve: ((result?: type_result) => void), reject: ((reason?: type_reason) => void)) => void): type_promise<type_result, type_reason>;
/**
* @author fenris
*/
function promise_then_close<type_result, type_reason>(promise: type_promise<type_result, type_reason>, resolver: ((result: type_result) => void), rejector: ((reason: type_reason) => void)): void;
/**
* @author fenris
*/
function promise_then_append<type_result, type_reason, type_result_>(promise: type_promise<type_result, type_reason>, resolver: ((result: type_result) => type_promise<type_result_, type_reason>), rejector?: ((reason: type_reason) => type_promise<type_result_, type_reason>)): type_promise<type_result_, type_result>;
/**
* @author fenris
*/
function promise_all<type_result, type_reason>(promises: Array<type_promise<type_result, type_reason>>): type_promise<Array<type_result>, type_reason>;
/**
* @author fenris
*/
function promise_chain<type_result, type_reason>(promises: (Array<(input: type_result) => type_promise<type_result, type_reason>>), start?: type_result): type_promise<type_result, type_reason>;
/**
* @author fenris
*/
function promise_condense<type_element, type_reason>(promises: Array<() => type_promise<type_element, type_reason>>): type_promise<Array<type_element>, type_reason>;
/**
* @author fenris
*/
function promise_group<type_reason>(promises: Record<string, (() => type_promise<any, type_reason>)>, options?: {
serial?: boolean;
}): type_promise<Record<string, any>, type_reason>;
/**
* @author fenris
*/
function promise_wrap<type_result_inner, type_result_outer, type_reason>(promise: type_promise<type_result_inner, type_reason>, transformator_result: ((reason: type_result_inner) => type_result_outer), transformator_reason?: ((reason: type_reason) => type_reason)): type_promise<type_result_outer, type_reason>;
/**
* @author fenris
*/
/**
* @author fenris
*/
/**
* @author fenris
*/
function promise_attach<type_reason>(state: Record<string, any>, promise: type_promise<any, type_reason>, name: string): type_promise<Record<string, any>, type_reason>;
/**
* @author fenris
*/
function promise_delay<type_result, type_reason>(promise: type_promise<type_result, type_reason>, delay: int): type_promise<type_result, type_reason>;
}
declare namespace lib_plankton.call {
/**
*/
class CancellablePromise<type_result> extends Promise<type_result> {
/**
*/
private cancelled;
/**
*/
private interval;
/**
*/
private subject;
/**
*/
constructor(executor: ((resolve: any, reject: any) => void));
/**
*/
private clear;
/**
*/
then<type_next_resolved, type_next_rejected>(onfulfilled?: ((value: type_result) => (type_next_resolved | PromiseLike<type_next_resolved>)), onrejected?: ((reason: any) => (type_next_rejected | PromiseLike<type_next_rejected>))): Promise<type_next_resolved | type_next_rejected>;
/**
*/
catch(x: any): Promise<type_result>;
/**
*/
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<type_result, type_reason> = {
fetcher: (() => type_promise<type_result, type_reason>);
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<type_result, type_reason>(fetcher: (() => type_promise<type_result, type_reason>)): type_initializer<type_result, type_reason>;
/**
* @author fenris
*/
function initializer_reset<type_result, type_reason>(subject: type_initializer<type_result, type_reason>): void;
/**
* @author fenris
*/
function initializer_state<type_result, type_reason>(subject: type_initializer<type_result, type_reason>): enum_initializer_state;
/**
* @author fenris
*/
function initializer_get<type_result, type_reason>(subject: type_initializer<type_result, type_reason>): type_promise<type_result, type_reason>;
}
declare namespace lib_plankton.call {
/**
* @author fenris
*/
type type_deferral<type_input, type_output> = {
representation: (input: type_input) => Promise<type_output>;
};
/**
* @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<type_input, type_output>(deferral: type_deferral<type_input, type_output>, 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<type_input, type_output>(handler: (input: type_input, convey: (output: type_output) => void) => void): type_deferral<type_input, type_output>;
/**
* @author fenris
* @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject")
*/
function deferral_wrap<type_input, type_output>(function_: (input: type_input) => type_output): type_deferral<type_input, type_output>;
/**
* @author fenris
*/
function deferral_id<type_value>(): type_deferral<type_value, type_value>;
/**
* @author fenris
*/
function deferral_const<type_value>(value: type_value): type_deferral<type_value, type_value>;
/**
* @author fenris
*/
function deferral_delay<type_output>(output: type_output, delay: int): type_deferral<any, type_output>;
/**
* @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<type_value1>} first a simple deferral
* @param {(value1 : type_value1)=>type_deferral<type_value2>} second a function depending from a value returning a deferral
*/
function deferral_compose_serial<type_input, type_between, type_output>(first: type_deferral<type_input, type_between>, second: type_deferral<type_between, type_output>): type_deferral<type_input, type_output>;
/**
* @author fenris
*/
function deferral_compose_parallel<type_input, type_output_left, type_output_right>({ "left": deferral_left, "right": deferral_right, }: {
left: type_deferral<type_input, type_output_left>;
right: type_deferral<type_input, type_output_right>;
}): type_deferral<type_input, {
left: type_output_left;
right: type_output_right;
}>;
/**
* @author fenris
* @desc repeatedly applied serial composition
*/
function deferral_chain<type_value>(members: Array<type_deferral<type_value, type_value>>): type_deferral<type_value, type_value>;
/**
* @author fenris
*/
}
declare namespace lib_plankton.call {
/**
* @author fenris
*/
class class_deferral<type_input, type_output> {
/**
* @author fenris
*/
private subject;
/**
* @author fenris
*/
private constructor();
/**
* @author fenris
*/
private static _cram;
/**
* @author fenris
*/
private static _tear;
/**
* @author fenris
*/
static make<type_input, type_output>(handler: (input: type_input, convey: (value: type_output) => void) => void): class_deferral<type_input, type_output>;
/**
* @author fenris
*/
use(input: type_input, procedure: (value: type_output) => void): void;
/**
* @author fenris
*/
compose_serial<type_output_>(second: class_deferral<type_output, type_output_>): class_deferral<type_input, type_output_>;
/**
* @author fenris
*/
static chain<type_value>(members: Array<class_deferral<type_value, type_value>>): class_deferral<type_value, type_value>;
/**
* @author fenris
*/
static wrap<type_input, type_output>(function_: (input: type_input) => type_output): class_deferral<type_input, type_output>;
/**
* @author fenris
*/
static const_<type_value>(value: type_value): class_deferral<type_value, type_value>;
/**
* @author fenris
*/
static delay<type_output>(output: type_output, delay: int): class_deferral<any, type_output>;
}
}
declare namespace lib_plankton.call {
/**
* converts the "arguments"-map into an array
*
* @param {Object} args
* @author fenris
*/
function args2list(args: any): Array<any>;
/**
* 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<type_value>(x: type_value): type_value;
/**
* just the identity; useful for some callbacks etc.
*
* @author fenris
*/
function const_<type_value>(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<type_x, type_y, type_z>(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<Function>): any;
/**
* @author fenris
*/
function timeout(procedure: (() => void), delay_in_seconds: float): int;
/**
* Promise version of "setTimeout"
*
* @author fenris
*/
function defer<type_result>(seconds: float, action: (() => type_result)): Promise<type_result>;
/**
* a definition for a value being "defined"
*
* @author neuc
*/
function is_def<type_value>(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<type_object, type_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<type_object, type_output>(name: string): ((object: type_object) => type_output);
/**
* @author fenris
*/
type type_coproduct = {
kind: string;
data?: any;
};
/**
* @author fenris
*/
function distinguish<type_output>(coproduct: type_coproduct, handlers: Record<string, ((data?: any) => 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<void>);
update_snapshot: ((timestamp: float, value_increment: float) => Promise<void>);
}, heft: float): Promise<{
granted: boolean;
seconds: (null | float);
}>;
}
declare namespace lib_plankton.file {
/**
* @author fenris
*/
function exists(path: string): Promise<boolean>;
/**
* @author fenris
*/

File diff suppressed because it is too large Load diff

View file

@ -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(",")
),
}

View file

@ -83,7 +83,9 @@ namespace _sindri.outputs.other.jsonschema
])
)
),
true
{
"formatted": true
}
);
}

View file

@ -1 +1,3 @@
- Nutzer-Verwaltung
- auf `plankton:database` setzen