736 lines
24 KiB
TypeScript
736 lines
24 KiB
TypeScript
/**
|
|
* @author fenris
|
|
*/
|
|
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);
|
|
toString(modifier?: string): string;
|
|
}
|
|
declare namespace lib_plankton.base {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function environment(): string;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_pseudopointer<type_value> = {
|
|
value: type_value;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_null<type_value>(): type_pseudopointer<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_make<type_value>(value: type_value): type_pseudopointer<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_isset<type_value>(pseudopointer: type_pseudopointer<type_value>): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_read<type_value>(pseudopointer: type_pseudopointer<type_value>): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_write<type_value>(pseudopointer: type_pseudopointer<type_value>, value: type_value): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare var instance_verbosity: int;
|
|
/**
|
|
* @desc the ability to check for equality with another element of the same domain
|
|
* @author fenris
|
|
*/
|
|
interface interface_collatable<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_collate(value: type_value): boolean;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function instance_collate<type_value>(value1: (type_value & {
|
|
_collate?: ((value: type_value) => boolean);
|
|
}), value2: type_value): boolean;
|
|
/**
|
|
* @desc the ability to compare with another element of the same domain for determining if the first is "smaller than or equal to" the latter
|
|
* @author fenris
|
|
*/
|
|
interface interface_comparable<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_compare(value: type_value): boolean;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function instance_compare<type_value>(value1: (type_value & {
|
|
_compare: ((value: type_value) => boolean);
|
|
}), value2: type_value): boolean;
|
|
/**
|
|
* @desc the ability to create an exact copy
|
|
* @author fenris
|
|
*/
|
|
interface interface_cloneable<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_clone(): type_value;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function instance_clone<type_value>(value: (type_value & {
|
|
_clone?: (() => type_value);
|
|
})): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_hashable {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_hash(): string;
|
|
}
|
|
/**
|
|
* @desc the ability to generate a string out of the element, which identifies it to a high degree
|
|
* @author fenris
|
|
*/
|
|
declare function instance_hash<type_value>(value: (type_value & {
|
|
_hash?: (() => string);
|
|
})): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_showable {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_show(): string;
|
|
}
|
|
/**
|
|
* @desc the ability to map the element to a textual representation (most likely not injective)
|
|
* @author fenris
|
|
*/
|
|
declare function instance_show<type_value>(value: (type_value & {
|
|
_show?: (() => string);
|
|
})): string;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
interface interface_decorator<type_core> {
|
|
/**
|
|
* @author frac
|
|
*/
|
|
core: type_core;
|
|
}
|
|
/**
|
|
* @author frac
|
|
*/
|
|
declare class class_observer {
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected counter: int;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected actions: {
|
|
[id: string]: (information: Object) => void;
|
|
};
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected buffer: Array<Object>;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
constructor();
|
|
/**
|
|
* @author frac
|
|
*/
|
|
empty(): boolean;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
flush(): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
set(id: string, action: (information: Object) => void): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
del(id: string): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
add(action: (information: Object) => void): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
notify(information?: Object, delayed?: boolean): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
rollout(): void;
|
|
}
|
|
/**
|
|
* @author frac
|
|
*/
|
|
/**
|
|
* @author frac
|
|
*/
|
|
/**
|
|
* @author frac
|
|
*/
|
|
declare class class_error extends Error {
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected suberrors: Array<Error>;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected mess: string;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
constructor(message: string, suberrors?: Array<Error>);
|
|
/**
|
|
* @override
|
|
* @author frac
|
|
*/
|
|
toString(): string;
|
|
}
|
|
declare namespace lib_plankton.base {
|
|
/**
|
|
* returns the current UNIX timestamp
|
|
*
|
|
* @author fenris
|
|
*/
|
|
function get_current_timestamp(rounded?: boolean): int;
|
|
/**
|
|
*/
|
|
function object_merge(core: Record<string, any>, mantle: Record<string, any>): Record<string, any>;
|
|
}
|
|
declare namespace 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 namespace lib_plankton.pod {
|
|
/**
|
|
*/
|
|
class class_pod<type_value> {
|
|
private subject;
|
|
private constructor();
|
|
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;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_executor<type_result, type_reason> = ((resolve: (result?: type_result) => any, reject?: (reason?: type_reason) => void) => void);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_resolve<type_result, type_reason>(result: type_result): type_executor<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_reject<type_result, type_reason>(reason: type_reason): type_executor<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_transform<type_result_from, type_error_from, type_result_to, type_error_to>(executor: type_executor<type_result_from, type_error_from>, transform_result: (result_from: type_result_from) => type_result_to, transform_reason: (error_from: type_error_from) => type_error_to): type_executor<type_result_to, type_error_to>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_transform_default<type_result_from, type_result_to>(executor: type_executor<type_result_from, Error>, transform_result: (result_from: type_result_from) => type_result_to, wrap_string?: string): type_executor<type_result_to, Error>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_compose_sequential<type_result_first, type_result_second, type_reason>(first: type_executor<type_result_first, type_reason>, second: (result: type_result_first) => type_executor<type_result_second, type_reason>): type_executor<type_result_second, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_chain<type_state, type_error>(state: type_state, executors: Array<(state: type_state) => type_executor<type_state, type_error>>): type_executor<type_state, type_error>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_first<type_result, type_reason>(executors: Array<type_executor<type_result, type_reason>>): type_executor<type_result, Array<type_reason>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_condense<type_element>(executors: Array<type_executor<type_element, Error>>): type_executor<Array<type_element>, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use condense
|
|
*/
|
|
function executor_filter<type_element>(executors: Array<type_executor<type_element, Error>>, predicate: (element: type_element) => boolean): type_executor<Array<type_element>, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use condense
|
|
*/
|
|
function executor_map<type_element1, type_element2>(executors: Array<type_executor<type_element1, Error>>, transformator: (element1: type_element1) => type_element2): type_executor<Array<type_element2>, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use condense
|
|
*/
|
|
function executor_reduce<type_element, type_result>(executors: Array<type_executor<type_element, Error>>, initial: type_result, accumulator: (result: type_result, element: type_element) => type_result): type_executor<type_result, Error>;
|
|
}
|
|
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: {
|
|
[name: string]: () => type_promise<any, type_reason>;
|
|
}, serial?: boolean): type_promise<{
|
|
[name: 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: {
|
|
[name: string]: any;
|
|
}, promise: type_promise<any, type_reason>, name: string): type_promise<{
|
|
[name: 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>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_to_executor<type_result, type_reason>(promise: type_promise<type_result, type_reason>): type_executor<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;
|
|
}
|
|
}
|
|
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 into 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: int): int;
|
|
/**
|
|
* 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;
|
|
/**
|
|
* Promise version of "setTimeout"
|
|
*
|
|
* @author fenris
|
|
*/
|
|
function defer<type_result>(seconds: float, action: (() => type_result)): Promise<type_result>;
|
|
/**
|
|
* 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);
|
|
}>;
|
|
}
|