2024-08-18 13:57:55 +02:00
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
if ( typeof b !== "function" && b !== null )
throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
// }
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
;
var lib _plankton ;
( function ( lib _plankton ) {
var base ;
( function ( base ) {
/ * *
* @ author fenris
* /
function environment ( ) {
return "node" ;
}
base . environment = environment ;
} ) ( base = lib _plankton . base || ( lib _plankton . base = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _null ( ) {
return {
"value" : null
} ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _make ( value ) {
return {
"value" : value
} ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _isset ( pseudopointer ) {
return ( pseudopointer . value != null ) ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _read ( pseudopointer ) {
if ( pseudopointer . value != null ) {
return pseudopointer . value ;
}
else {
var message = "nullpointer dereferencation" ;
throw ( new Error ( message ) ) ;
}
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _write ( pseudopointer , value ) {
pseudopointer . value = value ;
}
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author fenris
* /
var instance _verbosity = 0 ;
/ * *
* @ author fenris
* /
function instance _collate ( value1 , value2 ) {
if ( typeof ( value1 ) === "object" ) {
if ( value1 == null ) {
return ( value2 == null ) ;
}
else {
if ( "_collate" in value1 ) {
return value1 [ "_collate" ] ( value2 ) ;
}
else {
throw ( new Error ( "[collate]" + " " + "object has no such method" ) ) ;
}
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[collate]" + " " + "primitive value; using default implementation");
}
return ( value1 === value2 ) ;
}
}
/ * *
* @ author fenris
* /
function instance _compare ( value1 , value2 ) {
if ( typeof ( value1 ) === "object" ) {
if ( "_compare" in value1 ) {
return value1 [ "_compare" ] ( value2 ) ;
}
else {
throw ( new Error ( "[compare]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[compare]" + " " + "primitive value; using default implementation");
}
return ( value1 <= value2 ) ;
}
}
/ * *
* @ author fenris
* /
function instance _clone ( value ) {
if ( typeof ( value ) === "object" ) {
if ( "_clone" in value ) {
return value [ "_clone" ] ( ) ;
}
else {
throw ( new Error ( "[clone]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[clone]" + " " + "primitive value; using default implementation");
}
return value ;
}
}
/ * *
* @ desc the ability to generate a string out of the element , which identifies it to a high degree
* @ author fenris
* /
function instance _hash ( value ) {
if ( typeof ( value ) === "object" ) {
if ( "_hash" in value ) {
return value [ "_hash" ] ( ) ;
}
else {
throw ( new Error ( "[hash]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[hash]" + " " + "primitive value; using default implementation");
}
return String ( value ) ;
}
}
/ * *
* @ desc the ability to map the element to a textual representation ( most likely not injective )
* @ author fenris
* /
function instance _show ( value ) {
if ( typeof ( value ) === "object" ) {
if ( value == null ) {
return "NULL" ;
}
else {
if ( "_show" in value ) {
return value [ "_show" ] ( ) ;
}
else {
// throw (new Error("[show]" + " " + "object has no such method"));
return JSON . stringify ( value ) ;
}
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[show]" + " " + "primitive value; using default implementation");
}
return String ( value ) ;
}
}
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author frac
* /
var class _observer = /** @class */ ( function ( ) {
/ * *
* @ author frac
* /
function class _observer ( ) {
this . counter = 0 ;
this . actions = { } ;
this . buffer = [ ] ;
}
/ * *
* @ author frac
* /
class _observer . prototype . empty = function ( ) {
return ( Object . keys ( this . actions ) . length == 0 ) ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . flush = function ( ) {
this . actions = { } ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . set = function ( id , action ) {
this . actions [ id ] = action ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . del = function ( id ) {
delete this . actions [ id ] ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . add = function ( action ) {
this . set ( ( this . counter ++ ) . toString ( ) , action ) ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . notify = function ( information , delayed ) {
var _this = this ;
if ( information === void 0 ) { information = { } ; }
if ( delayed === void 0 ) { delayed = false ; }
if ( delayed ) {
this . buffer . push ( information ) ;
}
else {
Object . keys ( this . actions ) . forEach ( function ( id ) { return _this . actions [ id ] ( information ) ; } ) ;
}
} ;
/ * *
* @ author frac
* /
class _observer . prototype . rollout = function ( ) {
var _this = this ;
this . buffer . forEach ( function ( information ) { return _this . notify ( information , false ) ; } ) ;
this . buffer = [ ] ;
} ;
return class _observer ;
} ( ) ) ;
/ * *
* @ author frac
* /
/ *
export interface interface _readable < type _value > {
| * *
* @ author frac
* |
read ( ) : type _executor < type _value , Error > ;
}
* /
/ * *
* @ author frac
* /
/ *
export interface interface _writeable < type _value > {
| * *
* @ author frac
* |
write ( value : type _value ) : type _executor < void , Error > ;
}
* /
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author frac
* /
var class _error = /** @class */ ( function ( _super ) {
_ _extends ( class _error , _super ) ;
/ * *
* @ author frac
* /
function class _error ( message , suberrors ) {
if ( suberrors === void 0 ) { suberrors = [ ] ; }
var _this = _super . call ( this , message ) || this ;
_this . suberrors = suberrors ;
_this . mess = message ;
return _this ;
}
/ * *
* @ override
* @ author frac
* /
class _error . prototype . toString = function ( ) {
return ( /*super.toString()*/ this . mess + " " + ( "[" + this . suberrors . map ( function ( x ) { return x . toString ( ) ; } ) . join ( "," ) + "]" ) ) ;
} ;
return class _error ;
} ( Error ) ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var base ;
( function ( base ) {
/ * *
* returns the current UNIX timestamp
*
* @ author fenris
* /
function get _current _timestamp ( rounded ) {
if ( rounded === void 0 ) { rounded = false ; }
var x = ( Date . now ( ) / 1000 ) ;
return ( rounded ? Math . round ( x ) : x ) ;
;
}
base . get _current _timestamp = get _current _timestamp ;
/ * *
* /
function object _merge ( core , mantle ) {
return Object . assign ( core , mantle ) ;
}
base . object _merge = object _merge ;
} ) ( base = lib _plankton . base || ( lib _plankton . base = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
var _ _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 ( _ ) 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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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 ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
if ( typeof b !== "function" && b !== null )
throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var enum _level ;
( function ( enum _level ) {
enum _level [ enum _level [ "debug" ] = 0 ] = "debug" ;
enum _level [ enum _level [ "info" ] = 1 ] = "info" ;
enum _level [ enum _level [ "notice" ] = 2 ] = "notice" ;
enum _level [ enum _level [ "warning" ] = 3 ] = "warning" ;
enum _level [ enum _level [ "error" ] = 4 ] = "error" ;
} ) ( enum _level = log . enum _level || ( log . enum _level = { } ) ) ;
;
/ * *
* /
function level _order ( level1 , level2 ) {
return ( level1 <= level2 ) ;
}
log . level _order = level _order ;
/ * *
* /
function level _show ( level ) {
switch ( level ) {
case enum _level . debug : return "debug" ;
case enum _level . info : return "info" ;
case enum _level . notice : return "notice" ;
case enum _level . warning : return "warning" ;
case enum _level . error : return "error" ;
default : return "(unknown)" ;
}
}
log . level _show = level _show ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ deprecated
* @ todo remove
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* @ author fenris
* /
/*export*/ var level _stack = [ 0 ] ;
function level _push ( level ) { level _stack . push ( level ) ; }
log . level _push = level _push ;
function level _pop ( ) { if ( level _stack . length > 1 ) {
level _stack . pop ( ) ;
} }
log . level _pop = level _pop ;
function level _get ( ) { return level _stack . slice ( - 1 ) [ 0 ] ; }
/ *
export function level _inc ( ) : void { level _push ( level _get ( ) + 1 ) ; }
export function level _dec ( ) : void { level _push ( level _get ( ) - 1 ) ; }
* /
/ * *
* @ author fenris
* /
var indent _stack = [ 0 ] ;
function indent _push ( indent ) { indent _stack . push ( indent ) ; }
log . indent _push = indent _push ;
function indent _pop ( ) { if ( indent _stack . length > 1 ) {
indent _stack . pop ( ) ;
} }
log . indent _pop = indent _pop ;
function indent _get ( ) { return level _stack . slice ( - 1 ) [ 0 ] ; }
function indent _inc ( ) { level _push ( level _get ( ) + 1 ) ; }
log . indent _inc = indent _inc ;
function indent _dec ( ) { level _push ( level _get ( ) - 1 ) ; }
log . indent _dec = indent _dec ;
/ * *
* @ author fenris
* /
function write ( _a ) {
var message = _a [ "message" ] , _b = _a [ "type" ] , type = _b === void 0 ? null : _b , _c = _a [ "prefix" ] , prefix = _c === void 0 ? null : _c , _d = _a [ "level" ] , level = _d === void 0 ? 0 : _d , _e = _a [ "indent" ] , indent = _e === void 0 ? 0 : _e ;
var entry = {
"level" : ( ( type === null )
? lib _plankton . log . enum _level . info
: {
"debug" : lib _plankton . log . enum _level . debug ,
"info" : lib _plankton . log . enum _level . info ,
"notice" : lib _plankton . log . enum _level . notice ,
"warning" : lib _plankton . log . enum _level . warning ,
"error" : lib _plankton . log . enum _level . error
} [ type ] ) ,
"incident" : message ,
"details" : {
"prefix" : prefix ,
"level" : level ,
"indent" : indent
}
} ;
lib _plankton . log . add ( entry ) ;
}
log . write = write ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel = /** @class */ ( function ( ) {
function class _channel ( ) {
}
return class _channel ;
} ( ) ) ;
log . class _channel = class _channel ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* output for writing log entries to stdout
* /
var class _channel _stdout = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _stdout , _super ) ;
function class _channel _stdout ( ) {
return _super !== null && _super . apply ( this , arguments ) || this ;
}
/ * *
* /
class _channel _stdout . prototype . add = function ( entry ) {
process . stdout . write ( ( "<" + ( new Date ( Date . now ( ) ) ) . toISOString ( ) . slice ( 0 , 19 ) + ">" )
+
" "
+
( "[" + log . level _show ( entry . level ) + "]" )
+
" "
+
( "" + entry . incident + "" )
+
": "
+
JSON . stringify ( entry . details , undefined , " " )
+
"\n" ) ;
} ;
return class _channel _stdout ;
} ( log . class _channel ) ) ;
log . class _channel _stdout = class _channel _stdout ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel _file = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _file , _super ) ;
/ * *
* [ constructor ]
* /
function class _channel _file ( path , human _readable ) {
var _this = _super . call ( this ) || this ;
_this . path = path ;
_this . human _readable = human _readable ;
return _this ;
}
/ * *
* /
class _channel _file . prototype . add = function ( entry ) {
var _this = this ;
var nm _fs = require ( "fs" ) ;
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+"
} , 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 ;
} ( log . class _channel ) ) ;
log . class _channel _file = class _channel _file ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* output for desktop notifications via "libnotify"
* /
var class _channel _notify = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _notify , _super ) ;
function class _channel _notify ( ) {
return _super !== null && _super . apply ( this , arguments ) || this ;
}
/ * *
* /
class _channel _notify . prototype . add = function ( entry ) {
var nm _child _process = require ( "child_process" ) ;
var command = ( "notify-send"
+
" "
+
( "'"
+
( "[" + log . level _show ( entry . level ) + "]" )
+
" "
+
entry . incident
+
"'" )
+
" "
+
( "'"
+
( Object . keys ( entry . details )
. map ( function ( key ) { return ( key + ": " + JSON . stringify ( entry . details [ key ] ) ) ; } )
. join ( "\n" ) )
+
"'" ) ) ;
nm _child _process . exec ( command , function ( error , stdout , stderr ) {
// do noting
} ) ;
} ;
return class _channel _notify ;
} ( log . class _channel ) ) ;
log . class _channel _notify = class _channel _notify ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* decorator for filtering out log entries below a certain level threshold
* /
var class _channel _minlevel = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _minlevel , _super ) ;
/ * *
* /
function class _channel _minlevel ( core , threshold ) {
var _this = _super . call ( this ) || this ;
_this . core = core ;
_this . threshold = threshold ;
return _this ;
}
/ * *
* /
class _channel _minlevel . prototype . add = function ( entry ) {
if ( ! log . level _order ( this . threshold , entry . level ) ) {
// do nothing
}
else {
this . core . add ( entry ) ;
}
} ;
return class _channel _minlevel ;
} ( log . class _channel ) ) ;
log . class _channel _minlevel = class _channel _minlevel ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
function translate _level ( level _string ) {
return {
"debug" : log . enum _level . debug ,
"info" : log . enum _level . info ,
"notice" : log . enum _level . notice ,
"warning" : log . enum _level . warning ,
"error" : log . enum _level . error
} [ level _string ] ;
}
/ * *
* /
function channel _make ( description ) {
var _a , _b , _c , _d , _e ;
switch ( description . kind ) {
default : {
throw ( new Error ( "unhandled log channel kind: " + description . kind ) ) ;
break ;
}
case "stdout" : {
return ( new log . class _channel _minlevel ( new log . class _channel _stdout ( ) , translate _level ( ( _a = description . data [ "threshold" ] ) !== null && _a !== void 0 ? _a : "debug" ) ) ) ;
break ;
}
case "file" : {
return ( new log . class _channel _minlevel ( new log . class _channel _file ( ( ( _b = description . data [ "path" ] ) !== null && _b !== void 0 ? _b : "/tmp/plankton.log" ) , 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 ( ( _e = description . data [ "threshold" ] ) !== null && _e !== void 0 ? _e : "debug" ) ) ) ;
break ;
}
}
}
log . channel _make = channel _make ;
/ * *
* /
function conf _default ( ) {
return [
new log . class _channel _minlevel ( new log . class _channel _stdout ( ) , log . enum _level . notice ) ,
new log . class _channel _minlevel ( new log . class _channel _notify ( ) , log . enum _level . error ) ,
] ;
}
log . conf _default = conf _default ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var _channel _stack = null ;
/ * *
* pushes a new configuration on the stack and activates it
* /
function conf _push ( channels ) {
if ( _channel _stack === null ) {
_channel _stack = [ ] ;
}
_channel _stack . push ( channels ) ;
}
log . conf _push = conf _push ;
/ * *
* pops the current active configuration from the stack
* /
function conf _pop ( ) {
if ( _channel _stack . length > 0 ) {
_channel _stack . pop ( ) ;
}
else {
// do nothing
}
}
log . conf _pop = conf _pop ;
/ * *
* makes the logging system ready
* /
function setup ( ) {
if ( _channel _stack === null ) {
_channel _stack = [ ] ;
conf _push ( log . conf _default ( ) ) ;
}
else {
// do nothing
}
}
/ * *
* consumes a log entry , i . e . sends it to the currently active outputs
* /
function add ( entry ) {
setup ( ) ;
_channel _stack . slice ( - 1 ) [ 0 ] . forEach ( function ( channel ) { return channel . add ( entry ) ; } ) ;
}
log . add = add ;
/ * *
* /
function debug ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . debug , "incident" : incident , "details" : details } ) ;
}
log . debug = debug ;
/ * *
* /
function info ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . info , "incident" : incident , "details" : details } ) ;
}
log . info = info ;
/ * *
* /
function notice ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . notice , "incident" : incident , "details" : details } ) ;
}
log . notice = notice ;
/ * *
* /
function warning ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . warning , "incident" : incident , "details" : details } ) ;
}
log . warning = warning ;
/ * *
* /
function error ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . error , "incident" : incident , "details" : details } ) ;
}
log . error = error ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
function inverse _encode ( decode , to ) {
return decode ( to ) ;
}
code . inverse _encode = inverse _encode ;
/ * *
* @ author fenris
* /
function inverse _decode ( encode , from ) {
return encode ( from ) ;
}
code . inverse _decode = inverse _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _inverse = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _inverse ( subject ) {
this . subject = subject ;
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _inverse . prototype . encode = function ( to ) {
var _this = this ;
return code . inverse _encode ( function ( x ) { return _this . subject . decode ( x ) ; } , to ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _inverse . prototype . decode = function ( from ) {
var _this = this ;
return code . inverse _decode ( function ( x ) { return _this . subject . encode ( x ) ; } , from ) ;
} ;
return class _code _inverse ;
} ( ) ) ;
code . class _code _inverse = class _code _inverse ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
function pair _encode ( encode _first , encode _second , from ) {
var between = encode _first ( from ) ;
var to = encode _second ( between ) ;
return to ;
}
code . pair _encode = pair _encode ;
/ * *
* @ author fenris
* /
function pair _decode ( decode _first , decode _second , to ) {
var between = decode _second ( to ) ;
var from = decode _first ( between ) ;
return from ;
}
code . pair _decode = pair _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _pair = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _pair ( first , second ) {
this . first = first ;
this . second = second ;
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _pair . prototype . encode = function ( from ) {
var _this = this ;
return code . pair _encode ( function ( x ) { return _this . first . encode ( x ) ; } , function ( x ) { return _this . second . encode ( x ) ; } , from ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _pair . prototype . decode = function ( to ) {
var _this = this ;
return code . pair _decode ( function ( x ) { return _this . first . decode ( x ) ; } , function ( x ) { return _this . second . decode ( x ) ; } , to ) ;
} ;
return class _code _pair ;
} ( ) ) ;
code . class _code _pair = class _code _pair ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
function chain _encode ( encode _links , from ) {
var value = from ;
encode _links
. forEach ( function ( link ) {
value = link ( value ) ;
} ) ;
return value ;
}
code . chain _encode = chain _encode ;
/ * *
* @ author fenris
* /
function chain _decode ( decode _links , to ) {
var value = to ;
decode _links
. reverse ( )
. forEach ( function ( link ) {
value = link ( value ) ;
} ) ;
return value ;
}
code . chain _decode = chain _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _chain = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _chain ( links ) {
this . links = links ;
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _chain . prototype . encode = function ( from ) {
return code . chain _encode ( this . links . map ( function ( link ) { return ( function ( x ) { return link . encode ( x ) ; } ) ; } ) , from ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _chain . prototype . decode = function ( to ) {
return code . chain _decode ( this . links . map ( function ( link ) { return ( function ( x ) { return link . decode ( x ) ; } ) ; } ) , to ) ;
} ;
return class _code _chain ;
} ( ) ) ;
code . class _code _chain = class _code _chain ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author Christian Fraß < frass @ greenscale . de >
* /
function flatten _encode ( from , keys ) {
if ( keys === void 0 ) { keys = null ; }
if ( keys === null ) {
if ( from . length > 0 ) {
keys = Object . keys ( from [ 0 ] ) ;
}
else {
throw ( new Error ( "encoding impossible" ) ) ;
}
}
return {
"keys" : keys ,
"data" : from . map ( function ( line ) { return keys . map ( function ( name ) { return line [ name ] ; } ) ; } )
} ;
}
code . flatten _encode = flatten _encode ;
/ * *
* @ author Christian Fraß < frass @ greenscale . de >
* /
function flatten _decode ( to ) {
return ( to . data
. map ( function ( dataset ) {
var dataset _ = { } ;
dataset
. forEach ( function ( value , index ) {
var name = to . keys [ index ] ;
dataset _ [ name ] = value ;
} ) ;
return dataset _ ;
} ) ) ;
}
code . flatten _decode = flatten _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _flatten = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _flatten ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _flatten . prototype . encode = function ( x ) {
return code . flatten _encode ( x ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _flatten . prototype . decode = function ( x ) {
return code . flatten _decode ( x ) ;
} ;
return class _code _flatten ;
} ( ) ) ;
code . class _code _flatten = class _code _flatten ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : http « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : http « 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 : http « 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 : http « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var http ;
( function ( http ) {
/ * *
* @ author fenris < frass @ greenscale . de >
* /
let enum _method ;
( function ( enum _method ) {
2024-08-21 15:06:49 +02:00
enum _method [ "options" ] = "options" ;
enum _method [ "head" ] = "head" ;
2024-08-18 13:57:55 +02:00
enum _method [ "get" ] = "get" ;
2024-08-21 15:06:49 +02:00
enum _method [ "delete" ] = "delete" ;
2024-08-18 13:57:55 +02:00
enum _method [ "post" ] = "post" ;
enum _method [ "put" ] = "put" ;
2024-08-21 15:06:49 +02:00
enum _method [ "patch" ] = "patch" ;
2024-08-18 13:57:55 +02:00
} ) ( enum _method = http . enum _method || ( http . enum _method = { } ) ) ;
} ) ( http = lib _plankton . http || ( lib _plankton . http = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : http « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : http « 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 : http « 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 : http « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var http ;
( function ( http ) {
/ * *
* @ author fenris < frass @ greenscale . de >
* /
const linebreak = "\r\n" ;
/ * *
* @ todo outsource to string module
* /
function capitalize ( str ) {
return ( str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ) ;
}
/ * *
* @ todo outsource to string module
* /
function capitalize _all ( str ) {
return str . split ( "-" ) . map ( x => capitalize ( x ) ) . join ( "-" ) ;
}
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function encode _method ( method ) {
switch ( method ) {
case http . enum _method . get : return "GET" ;
case http . enum _method . post : return "POST" ;
case http . enum _method . patch : return "PATCH" ;
case http . enum _method . put : return "PUT" ;
case http . enum _method . delete : return "DELETE" ;
case http . enum _method . options : return "OPTIONS" ;
case http . enum _method . head : return "HEAD" ;
default : throw ( new Error ( "impossible" ) ) ;
}
}
http . encode _method = encode _method ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function decode _method ( method _raw ) {
switch ( method _raw ) {
case "GET" : return http . enum _method . get ;
case "POST" : return http . enum _method . post ;
case "PATCH" : return http . enum _method . patch ;
case "PUT" : return http . enum _method . put ;
case "DELETE" : return http . enum _method . delete ;
case "OPTIONS" : return http . enum _method . options ;
case "HEAD" : return http . enum _method . head ;
default : throw ( new Error ( "unhandled method: " + method _raw ) ) ;
}
}
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function get _statustext ( statuscode ) {
switch ( statuscode ) {
case 100 : return "Continue" ;
case 101 : return "Switching Protocols" ;
case 103 : return "Early Hints" ;
case 200 : return "OK" ;
case 201 : return "Created" ;
case 202 : return "Accepted" ;
case 203 : return "Non-Authoritative Information" ;
case 204 : return "No Content" ;
case 205 : return "Reset Content" ;
case 206 : return "Partial Content" ;
case 300 : return "Multiple Choices" ;
case 301 : return "Moved Permanently" ;
case 302 : return "Found" ;
case 303 : return "See Other" ;
case 304 : return "Not Modified" ;
case 307 : return "Temporary Redirect" ;
case 308 : return "Permanent Redirect" ;
case 400 : return "Bad Request" ;
case 401 : return "Unauthorized" ;
case 402 : return "Payment Required" ;
case 403 : return "Forbidden" ;
case 404 : return "Not Found" ;
case 405 : return "Method Not Allowed" ;
case 406 : return "Not Acceptable" ;
case 407 : return "Proxy Authentication Required" ;
case 408 : return "Request Timeout" ;
case 409 : return "Conflict" ;
case 410 : return "Gone" ;
case 411 : return "Length Required" ;
case 412 : return "Precondition Failed" ;
case 413 : return "Payload Too Large" ;
case 414 : return "URI Too Long" ;
case 415 : return "Unsupported Media Type" ;
case 416 : return "Range Not Satisfiable" ;
case 417 : return "Expectation Failed" ;
case 418 : return "I'm a teapot" ;
case 422 : return "Unprocessable Entity" ;
case 425 : return "Too Early" ;
case 426 : return "Upgrade Required" ;
case 428 : return "Precondition Required" ;
case 429 : return "Too Many Requests" ;
case 431 : return "Request Header Fields Too Large" ;
case 451 : return "Unavailable For Legal Reasons" ;
case 500 : return "Internal Server Error" ;
case 501 : return "Not Implemented" ;
case 502 : return "Bad Gateway" ;
case 503 : return "Service Unavailable" ;
case 504 : return "Gateway Timeout" ;
case 505 : return "HTTP Version Not Supported" ;
case 506 : return "Variant Also Negotiates" ;
case 507 : return "Insufficient Storage" ;
case 508 : return "Loop Detected" ;
case 510 : return "Not Extended" ;
case 511 : return "Network Authentication" ;
default : throw ( new Error ( "unhandled statuscode: " + statuscode . toFixed ( 0 ) ) ) ;
}
}
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function encode _request ( request ) {
let request _raw = "" ;
request _raw += ( encode _method ( request . method )
+
" "
+
request . path
+
( ( request . query === null ) ? "" : request . query )
+
" "
+
request . version
+
linebreak ) ;
if ( request . host === null ) {
// do nothing
}
else {
request _raw += ( "Host: " + request . host + linebreak ) ;
}
for ( const [ key , value ] of Object . entries ( request . headers ) ) {
request _raw += ( capitalize _all ( key ) + ": " + value + linebreak ) ;
}
request _raw += linebreak ;
if ( request . body === null ) {
// do nothing
}
else {
request _raw += request . body . toString ( ) ;
}
return request _raw ;
}
http . encode _request = encode _request ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function decode _request ( request _raw ) {
const lines = request _raw . split ( linebreak ) ;
const first = lines . shift ( ) ;
const parts = first . split ( " " ) ;
const method = decode _method ( parts [ 0 ] ) ;
const path _and _query = parts [ 1 ] ;
const parts _ = path _and _query . split ( "?" ) ;
const path = parts _ [ 0 ] ;
const query = ( ( parts _ . length <= 1 ) ? null : ( "?" + parts _ . slice ( 1 ) . join ( "?" ) ) ) ;
const version = parts [ 2 ] ;
let headers = { } ;
while ( true ) {
const line = lines . shift ( ) ;
if ( line === "" ) {
break ;
}
else {
const [ key , value ] = line . split ( ": " , 2 ) ;
headers [ key . toLowerCase ( ) ] = value ;
}
}
2024-08-21 15:06:49 +02:00
const body = ( [ http . enum _method . post , http . enum _method . put , http . enum _method . patch ] . includes ( method )
? Buffer [ "from" ] ( lines . join ( linebreak ) )
: null ) ;
2024-08-18 13:57:55 +02:00
const request = {
// TODO
"scheme" : "http" ,
"host" : ( headers [ "host" ] ? ? null ) ,
"path" : path ,
"version" : version ,
"method" : method ,
"query" : query ,
"headers" : headers ,
"body" : body ,
} ;
return request ;
}
http . decode _request = decode _request ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function encode _response ( response ) {
let response _raw = "" ;
response _raw += ( response . version
+
" "
+
response . status _code . toFixed ( 0 )
+
" "
+
get _statustext ( response . status _code )
+
linebreak ) ;
for ( const [ key , value ] of Object . entries ( response . headers ) ) {
response _raw += ( capitalize _all ( key ) + ": " + value + linebreak ) ;
}
response _raw += linebreak ;
response _raw += response . body ;
return response _raw ;
}
http . encode _response = encode _response ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function decode _response ( response _raw ) {
const lines = response _raw . split ( linebreak ) ;
const first = lines . shift ( ) ;
const first _parts = first . split ( " " ) ;
const version = first _parts [ 0 ] ;
const status _code = parseInt ( first _parts [ 1 ] ) ;
// first_parts.slice(2) ? probably irrelevant
let headers = { } ;
while ( true ) {
const line = lines . shift ( ) ;
if ( line === "" ) {
break ;
}
else {
const [ key , value ] = line . split ( ": " , 2 ) ;
headers [ key . toLowerCase ( ) ] = value ;
}
}
const body = Buffer [ "from" ] ( lines . join ( linebreak ) ) ;
const response = {
// TODO
"version" : version ,
"status_code" : status _code ,
"headers" : headers ,
"body" : body ,
} ;
return response ;
}
http . decode _response = decode _response ;
/ * *
* executes an HTTP request
*
* @ todo define type _signal
* /
async function call ( request , options = { } ) {
options = Object . assign ( {
"timeout" : 5.0 ,
"follow_redirects" : false ,
"implementation" : "fetch" ,
} , options ) ;
const target = ( request . scheme
+
"://"
+
request . host
+
request . path
+
( ( request . query === null )
? ""
: request . query ) ) ;
switch ( options . implementation ) {
default : {
return Promise . reject ( "invalid implementation: " + options . implementation ) ;
break ;
}
case "fetch" : {
function core ( signal ) {
2024-08-21 15:06:49 +02:00
return ( fetch ( target , Object . assign ( {
2024-08-18 13:57:55 +02:00
"method" : ( ( method => {
switch ( method ) {
2024-08-21 15:06:49 +02:00
case http . enum _method . head : return "HEAD" ;
case http . enum _method . options : return "OPTIONS" ;
2024-08-18 13:57:55 +02:00
case http . enum _method . get : return "GET" ;
2024-08-21 15:06:49 +02:00
case http . enum _method . delete : return "DELETE" ;
2024-08-18 13:57:55 +02:00
case http . enum _method . post : return "POST" ;
case http . enum _method . put : return "PUT" ;
2024-08-21 15:06:49 +02:00
case http . enum _method . patch : return "PATCH" ;
2024-08-18 13:57:55 +02:00
}
} ) ( request . method ) ) ,
"headers" : request . headers ,
2024-08-21 15:06:49 +02:00
/ *
"redirect" : (
options . follow _redirects
?
"follow"
:
"manual"
) ,
* /
"signal" : ( signal
? ?
undefined ) ,
// "keepalive": false,
} , ( ( ( ( method => {
switch ( method ) {
case http . enum _method . head : return false ;
case http . enum _method . options : return false ;
case http . enum _method . get : return false ;
case http . enum _method . delete : return false ;
case http . enum _method . post : return true ;
case http . enum _method . put : return true ;
case http . enum _method . patch : return true ;
}
} ) ( request . method ) )
&&
( request . body !== null ) )
? {
"body" : request . body . toString ( ) ,
}
: { } ) ) )
2024-08-18 13:57:55 +02:00
. catch ( ( reason ) => {
2024-08-21 15:06:49 +02:00
// console.info(reason);
2024-08-18 13:57:55 +02:00
return Promise . reject ( reason ) ;
} )
. then ( ( response _raw ) => ( response _raw . text ( )
. then ( ( body ) => Promise . resolve ( {
// TODO
"version" : null ,
"status_code" : response _raw . status ,
"headers" : ( ( headers _raw => {
let headers = { } ;
headers _raw . forEach ( ( value , key ) => {
headers [ key ] = value ;
} ) ;
return headers ;
} ) ( response _raw . headers ) ) ,
"body" : body ,
} ) ) ) ) ) ;
}
function timeout ( controller ) {
return ( new Promise ( ( resolve , reject ) => {
if ( options . timeout === null ) {
// do nothing (neither resolve nor reject ever)
}
else {
setTimeout ( ( ) => {
controller . abort ( ) ;
resolve ( null ) ;
} , ( options . timeout * 1000 ) ) ;
}
} ) ) ;
}
const controller = new AbortController ( ) ;
const signal = controller . signal ;
const response = await Promise . race ( [
timeout ( controller ) ,
core ( signal ) ,
] ) ;
if ( response === null ) {
throw ( new Error ( "http_request_timeout" ) ) ;
}
else {
return response ;
}
break ;
}
case "http_module" : {
2024-08-21 15:06:49 +02:00
// @ts-ignore
2024-08-18 13:57:55 +02:00
const nm _http = require ( "http" ) ;
2024-08-21 15:06:49 +02:00
// @ts-ignore
2024-08-18 13:57:55 +02:00
const nm _https = require ( "https" ) ;
return ( new Promise ( ( resolve , reject ) => {
const req = ( ( request . scheme === "https" )
? nm _https
: nm _http )
. request ( target , {
"method" : request . method ,
"headers" : request . headers ,
} , ( res ) => {
try {
let response _body = "" ;
res . setEncoding ( "utf8" ) ;
res . on ( "data" , ( chunk ) => {
response _body += chunk ;
} ) ;
res . on ( "end" , ( ) => {
resolve ( {
// TODO
"version" : null ,
"status_code" : res . statusCode ,
"headers" : res . headers ,
"body" : response _body ,
} ) ;
} ) ;
}
catch ( error ) {
reject ( error ) ;
}
} ) ;
req . on ( "error" , ( error ) => {
reject ( error ) ;
} ) ;
req . write ( request . body ) ;
req . end ( ) ;
} ) ) ;
break ;
}
}
}
http . call = call ;
} ) ( http = lib _plankton . http || ( lib _plankton . http = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : http « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : http « 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 : http « 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 : http « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var http ;
( function ( http ) {
/ * *
* @ author fenris
* /
class class _http _request {
/ * *
* @ author fenris
* /
constructor ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
encode ( x ) {
return http . encode _request ( x ) ;
}
/ * *
* @ implementation
* @ author fenris
* /
decode ( x ) {
return http . decode _request ( x ) ;
}
}
http . class _http _request = class _http _request ;
/ * *
* @ author fenris
* /
class class _http _response {
/ * *
* @ author fenris
* /
constructor ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
encode ( x ) {
return http . encode _response ( x ) ;
}
/ * *
* @ implementation
* @ author fenris
* /
decode ( x ) {
return http . decode _response ( x ) ;
}
}
http . class _http _response = class _http _response ;
} ) ( http = lib _plankton . http || ( lib _plankton . http = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : server « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : server « 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 : server « 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 : server « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var server ;
( function ( server ) {
/ * *
* @ author fenris
* /
2024-08-21 15:06:49 +02:00
function make ( handle , options = { } ) {
options = Object . assign ( {
"host" : "::" ,
"port" : 9999 ,
"threshold" : 0.25 ,
} , options ) ;
2024-08-18 13:57:55 +02:00
return {
2024-08-21 15:06:49 +02:00
"host" : options . host ,
"port" : options . port ,
"threshold" : options . threshold ,
2024-08-18 13:57:55 +02:00
"handle" : handle ,
"serverobj" : undefined ,
} ;
}
server . make = make ;
/ * *
* @ author fenris
2024-08-21 15:06:49 +02:00
* @ deprecated
* /
function make _old ( port , handle ) {
return make ( handle , {
"host" : "::" ,
"port" : port ,
"threshold" : 0.25 ,
} ) ;
}
server . make _old = make _old ;
/ * *
* @ author fenris
* @ see https : //nodejs.org/api/net.html#serverlistenport-host-backlog-callback
2024-08-18 13:57:55 +02:00
* /
function start ( subject ) {
const net = require ( "net" ) ;
return ( new Promise ( ( resolve , reject ) => {
2024-08-21 15:06:49 +02:00
// @ts-ignore
let input _chunks = [ ] ;
subject . serverobj = net . createServer ( {
"allowHalfOpen" : false ,
} , ( socket ) => {
let timeout _handler = null ;
let ended = false ;
const process _input = function ( ) {
// @ts-ignore
const input = Buffer . concat ( input _chunks ) ;
/ *
const metadata : type _metadata = {
"ip_address" : socket . remoteAddress ,
} ;
* /
lib _plankton . log . debug ( "server_process_input" , {
"input" : input ,
} ) ;
( subject . handle ( input /*, metadata*/ )
. then ( ( output ) => {
lib _plankton . log . debug ( "server_writing" , {
"output" : output ,
2024-08-18 13:57:55 +02:00
} ) ;
2024-08-21 15:06:49 +02:00
socket . write ( output ) ;
socket . end ( ) ;
} )
. catch ( ( error ) => {
lib _plankton . log . warning ( "server_handle_failed" , {
"error" : error . toString ( ) ,
2024-08-18 13:57:55 +02:00
} ) ;
2024-08-21 15:06:49 +02:00
// socket.write("");
socket . end ( ) ;
} )
. then ( ( ) => {
input _chunks = [ ] ;
} ) ) ;
} ;
const timeout _stop = function ( ) {
if ( timeout _handler === null ) {
// do nothing
2024-08-18 13:57:55 +02:00
}
2024-08-21 15:06:49 +02:00
else {
lib _plankton . log . debug ( "server_timeout_cancelling" ) ;
clearTimeout ( timeout _handler ) ;
timeout _handler = null ;
}
} ;
const timeout _start = function ( ) {
if ( subject . threshold === null ) {
process _input ( ) ;
}
else {
if ( timeout _handler === null ) {
timeout _handler = setTimeout ( ( ) => {
lib _plankton . log . debug ( "server_timeout_reached" ) ;
timeout _handler = null ;
process _input ( ) ;
} , ( subject . threshold * 1000 ) ) ;
}
else {
lib _plankton . log . warning ( "server_timeout_already_started" ) ;
// do nothing
}
}
} ;
lib _plankton . log . info ( "server_client connected" , { } ) ;
socket . on ( "data" , ( input _chunk _raw ) => {
lib _plankton . log . debug ( "server_reading_chunk" , {
"chunk_raw" : input _chunk _raw ,
} ) ;
timeout _stop ( ) ;
const input _chunk = ( ( input _chunk _raw instanceof Buffer )
?
input _chunk _raw
:
// @ts-ignore
Buffer . from ( input _chunk _raw ) ) ;
input _chunks . push ( input _chunk ) ;
timeout _start ( ) ;
2024-08-18 13:57:55 +02:00
} ) ;
socket . on ( "end" , ( ) => {
2024-08-21 15:06:49 +02:00
if ( ! ended ) {
lib _plankton . log . info ( "server_client_disconnected" , { } ) ;
ended = true ;
timeout _stop ( ) ;
}
else {
lib _plankton . log . info ( "server_socket_already_ended" ) ;
// do nothing
}
2024-08-18 13:57:55 +02:00
} ) ;
} ) ;
subject . serverobj . on ( "error" , ( error ) => {
// throw error;
process . stderr . write ( "net_error: " + String ( error ) + "\n\n" ) ;
} ) ;
2024-08-21 15:06:49 +02:00
subject . serverobj . listen ( subject . port , subject . host , 511 , ( ) => {
2024-08-18 13:57:55 +02:00
lib _plankton . log . info ( "server_listenting" , {
2024-08-21 15:06:49 +02:00
"host" : subject . host ,
2024-08-18 13:57:55 +02:00
"port" : subject . port ,
} ) ;
resolve ( undefined ) ;
} ) ;
} ) ) ;
}
server . start = start ;
/ * *
* @ author fenris
* /
function kill ( subject ) {
subject . serverobj . close ( ) ;
lib _plankton . log . info ( "server_stopped" , { } ) ;
}
server . kill = kill ;
} ) ( server = lib _plankton . server || ( lib _plankton . server = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : server « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : server « 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 : server « 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 : server « . If not , see < common : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var server ;
( function ( server ) {
/ * *
* @ author fenris
* /
class class _server {
/ * *
* @ author fenris
* /
2024-08-21 15:06:49 +02:00
constructor ( handle , options = { } ) {
options = Object . assign ( {
"host" : "::" ,
"port" : 9999 ,
} , options ) ;
this . subject = server . make ( handle , {
"host" : options . host ,
"port" : options . port ,
} ) ;
2024-08-18 13:57:55 +02:00
}
/ * *
* @ author fenris
* /
start ( ) {
return server . start ( this . subject ) ;
}
/ * *
* @ author fenris
* /
kill ( ) {
return server . kill ( this . subject ) ;
}
}
server . class _server = class _server ;
} ) ( server = lib _plankton . server || ( lib _plankton . server = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
var lib _server = lib _plankton . server ;
/ *
This file is part of » bacterio - plankton : object « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : object « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : object « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : object « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var object ;
( function ( object _1 ) {
/ * *
* @ author fenris
* /
function fetch ( object , fieldname , fallback , escalation ) {
if ( fallback === void 0 ) { fallback = null ; }
if ( escalation === void 0 ) { escalation = 1 ; }
if ( ( fieldname in object ) && ( object [ fieldname ] !== undefined ) ) {
return object [ fieldname ] ;
}
else {
switch ( escalation ) {
case 0 : {
return fallback ;
break ;
}
case 1 : {
var message = ( "field '" . concat ( fieldname , "' not in structure" ) ) ;
message += ( "; using fallback value '" . concat ( String ( fallback ) , "'" ) ) ;
// console.warn(message);
return fallback ;
break ;
}
case 2 : {
var message = ( "field '" . concat ( fieldname , "' not in structure" ) ) ;
throw ( new Error ( message ) ) ;
break ;
}
default : {
throw ( new Error ( "invalid escalation level " . concat ( escalation ) ) ) ;
break ;
}
}
}
}
object _1 . fetch = fetch ;
/ * *
* @ author fenris
* /
function map ( object _from , transformator ) {
var object _to = { } ;
Object . keys ( object _from ) . forEach ( function ( key ) { return ( object _to [ key ] = transformator ( object _from [ key ] , key ) ) ; } ) ;
return object _to ;
}
object _1 . map = map ;
/ * *
* @ desc gibt ein Objekt mit bestimmten Einträgen des Eingabe - Objekts zurück
* @ author fenris
* /
function filter ( object _from , predicate ) {
var object _to = { } ;
Object . keys ( object _from ) . forEach ( function ( key ) {
var value = object _from [ key ] ;
if ( predicate ( value , key ) ) {
object _to [ key ] = value ;
}
} ) ;
return object _to ;
}
object _1 . filter = filter ;
/ * *
* @ desc wandelt ein Array mit Einträgen der Form { key , value } in ein entsprechendes Objekt um
* @ author fenris
* /
function from _array ( array ) {
var object = { } ;
array . forEach ( function ( entry ) { return ( object [ entry . key ] = entry . value ) ; } ) ;
return object ;
}
object _1 . from _array = from _array ;
/ * *
* @ desc wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form { key , value } um
* @ author fenris
* /
function to _array ( object ) {
var array = [ ] ;
Object . keys ( object ) . forEach ( function ( key ) { return array . push ( { "key" : key , "value" : object [ key ] } ) ; } ) ;
return array ;
}
object _1 . to _array = to _array ;
/ * *
* @ desc gibt eine Liste von Schlüsseln eines Objekts zurück
* @ author fenris
* /
function keys ( object ) {
return Object . keys ( object ) ;
}
object _1 . keys = keys ;
/ * *
* @ desc gibt eine Liste von Werten eines Objekts zurück
* @ author fenris
* /
function values ( object ) {
return to _array ( object ) . map ( function ( entry ) { return entry . value ; } ) ;
}
object _1 . values = values ;
/ * *
* @ desc liest ein Baum - artiges Objekt an einer bestimmten Stelle aus
* @ author fenris
* /
function path _read ( object , path , fallback , escalation ) {
if ( fallback === void 0 ) { fallback = null ; }
if ( escalation === void 0 ) { escalation = 1 ; }
var steps = ( ( path . length == 0 ) ? [ ] : path . split ( "." ) ) ;
if ( steps . length == 0 ) {
throw ( new Error ( "empty path" ) ) ;
}
else {
var position _1 = object ;
var reachable = ( position _1 != null ) && steps . slice ( 0 , steps . length - 1 ) . every ( function ( step ) {
position _1 = lib _plankton . object . fetch ( position _1 , step , null , 0 ) ;
return ( position _1 != null ) ;
} ) ;
if ( reachable ) {
return lib _plankton . object . fetch ( position _1 , steps [ steps . length - 1 ] , fallback , escalation ) ;
}
else {
return lib _plankton . object . fetch ( { } , "_dummy_" , fallback , escalation ) ;
}
}
}
object _1 . path _read = path _read ;
/ * *
* @ desc schreibt einen Wert an eine bestimmte Stelle in einem Baum - artigen Objekt
* @ author fenris
* /
function path _write ( object , path , value , construct ) {
if ( construct === void 0 ) { construct = true ; }
var steps = ( ( path . length == 0 ) ? [ ] : path . split ( "." ) ) ;
if ( steps . length == 0 ) {
throw ( new Error ( "empty path" ) ) ;
}
else {
var position _2 = object ;
var reachable = steps . slice ( 0 , steps . length - 1 ) . every ( function ( step ) {
var position _ = lib _plankton . object . fetch ( position _2 , step , null , 0 ) ;
if ( position _ == null ) {
if ( construct ) {
position _2 [ step ] = { } ;
position _2 = position _2 [ step ] ;
return true ;
}
else {
return false ;
}
}
else {
position _2 = position _ ;
return true ;
}
} ) ;
if ( reachable ) {
position _2 [ steps [ steps . length - 1 ] ] = value ;
}
else {
var message = ( "path '" . concat ( path , "' does not exist and may not be constructed" ) ) ;
throw ( new Error ( message ) ) ;
}
}
}
object _1 . path _write = path _write ;
/ * *
* @ desc prüft ob ein Objekt einem bestimmten Muster entspricht
* @ param { Object } object das zu prüfende Objekt
* @ param { Object } pattern das einzuhaltende Muster
* @ param { Function } connlate eine Funktion zum Feststellen der Gleichheit von Einzelwerten
* @ author fenris
* /
function matches ( object , pattern , collate ) {
if ( collate === void 0 ) { collate = instance _collate ; }
return Object . keys ( pattern ) . every ( function ( key ) { return collate ( pattern [ key ] , object [ key ] ) ; } ) ;
}
object _1 . matches = matches ;
/ * *
* @ desc erzeugt eine Projektion eines Baum - artigen Objekts in ein Listen - artiges Objekt
* @ param { string } [ separator ] welches Zeichen als Trenner zwischen zwei Pfad - Schritten verwendet werden soll
* @ author fenris
* /
function flatten ( value , separator , key _for _element ) {
if ( separator === void 0 ) { separator = "." ; }
if ( key _for _element === void 0 ) { key _for _element = ( function ( index ) { return ( "element_" + index . toFixed ( 0 ) ) ; } ) ; }
var integrate = function ( result , key _ , value _ ) {
if ( value _ == null ) {
result [ key _ ] = value _ ;
}
else {
// primitive Werte direkt übernehmen
if ( typeof ( value _ ) != "object" ) {
result [ key _ ] = value _ ;
}
// sonst durch rekursiven Aufruf die flache Variante des Wertes ermitteln und einarbeiten
else {
var result _1 = flatten ( value _ ) ;
Object . keys ( result _1 )
. forEach ( function ( key _ _ ) {
var value _ _ = result _1 [ key _ _ ] ;
var key _new = ( key _ + separator + key _ _ ) ;
result [ key _new ] = value _ _ ;
} ) ;
}
}
} ;
if ( ( value === null ) || ( value === undefined ) ) {
return null ;
}
else {
var result _2 = { } ;
if ( typeof ( value ) != "object" ) {
result _2 [ "value" ] = value ;
}
else {
if ( value instanceof Array ) {
var array = ( value ) ;
array
. forEach ( function ( element , index ) {
integrate ( result _2 , key _for _element ( index ) , element ) ;
} ) ;
}
else {
var object _2 = ( value ) ;
Object . keys ( object _2 )
. forEach ( function ( key ) {
integrate ( result _2 , key , object _2 [ key ] ) ;
} ) ;
}
}
return result _2 ;
}
}
object _1 . flatten = flatten ;
/ * *
* @ author fenris
* /
function clash ( x , y , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "overwrite" ] , overwrite = _c === void 0 ? true : _c , _d = _b [ "hooks" ] , _e = _d === void 0 ? { } : _d , _f = _e [ "existing" ] , hook _existing = _f === void 0 ? null : _f ;
if ( hook _existing == null ) {
( function ( key , value _old , value _new ) { return console . warn ( "field " . concat ( key , " already defined" ) ) ; } ) ;
}
var z = { } ;
Object . keys ( x ) . forEach ( function ( key ) {
z [ key ] = x [ key ] ;
} ) ;
Object . keys ( y ) . forEach ( function ( key ) {
if ( key in z ) {
if ( hook _existing != null ) {
hook _existing ( key , z [ key ] , y [ key ] ) ;
}
if ( overwrite ) {
z [ key ] = y [ key ] ;
}
}
else {
z [ key ] = y [ key ] ;
}
} ) ;
return z ;
}
object _1 . clash = clash ;
/ * *
* @ author fenris
* /
function patch ( core , mantle , deep , path ) {
if ( deep === void 0 ) { deep = true ; }
if ( path === void 0 ) { path = null ; }
if ( mantle == null ) {
console . warn ( "mantle is null; core was" , core ) ;
}
else {
Object . keys ( mantle ) . forEach ( function ( key ) {
var path _ = ( ( path == null ) ? key : "" . concat ( path , "." ) . concat ( key ) ) ;
var value _mantle = mantle [ key ] ;
if ( ! ( key in core ) ) {
if ( ( typeof ( value _mantle ) == "object" ) && ( value _mantle != null ) && deep ) {
if ( value _mantle instanceof Array ) {
core [ key ] = [ ] ;
value _mantle . forEach ( function ( element ) {
if ( ( typeof ( element ) == "object" ) && ( element != null ) ) {
var element _ = { } ;
patch ( element _ , element ) ;
core [ key ] . push ( element _ ) ;
}
else {
core [ key ] . push ( element ) ;
}
} ) ;
}
else {
core [ key ] = { } ;
patch ( core [ key ] , value _mantle , deep , path _ ) ;
}
}
else {
core [ key ] = value _mantle ;
}
}
else {
var value _core = core [ key ] ;
if ( typeof ( value _core ) == typeof ( value _mantle ) ) {
if ( ( typeof ( value _mantle ) == "object" ) && ( value _mantle != null ) && deep ) {
patch ( core [ key ] , value _mantle , deep , path _ ) ;
}
else {
core [ key ] = value _mantle ;
}
}
else {
if ( ( value _core != null ) && ( value _mantle != null ) ) {
var message = "objects have different shapes at path '" . concat ( path _ , "'; core has type '" ) . concat ( typeof ( value _core ) , "' and mantle has type '" ) . concat ( typeof ( value _mantle ) , "'" ) ;
console . warn ( message ) ;
}
core [ key ] = value _mantle ;
// throw (new Error(message));
}
}
} ) ;
}
}
object _1 . patch = patch ;
/ * *
* @ author fenris
* /
function patched ( core , mantle , deep ) {
if ( deep === void 0 ) { deep = undefined ; }
var result = { } ;
patch ( result , core , deep ) ;
patch ( result , mantle , deep ) ;
return result ;
}
object _1 . patched = patched ;
/ * *
* @ author fenris
* /
function attached ( object , key , value ) {
var mantle = { } ;
mantle [ key ] = value ;
return patched ( object , mantle , false ) ;
}
object _1 . attached = attached ;
/ * *
* @ author fenris
* /
function copy ( object ) {
return patched ( { } , object ) ;
}
object _1 . copy = copy ;
} ) ( object = lib _plankton . object || ( lib _plankton . object = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : pod « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var pod ;
( function ( pod ) {
/ * *
* /
class class _pod {
constructor ( subject ) { this . subject = subject ; }
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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
/ * *
* 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 < type _result , type _reason > ( label : string ) : ( result : type _result ) => type _promise < type _result , type _reason > {
return (
result => promise _make < type _result , type _reason > (
( 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 < type _result , type _reason > ( result : type _result ) : ( result : type _result ) => type _promise < type _result , type _reason > {
return promise _show < type _result , type _reason > ( "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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
/ * *
* 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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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 < 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 ( 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<type_value, type_value, type_value>(result, current),
deferral _compose _serial , deferral _id ( ) ) ) ;
}
call . deferral _chain = deferral _chain ;
/ * *
* @ author fenris
* /
/ *
export function deferral _bunch < type _input , type _output > (
members : { [ name : string ] : type _deferral < type _input , type _output > }
) : type _deferral < type _input , { [ name : string ] : type _output } > {
}
* /
} ) ( 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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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'
< info @ greenscale . de >
» 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 < http : //www.gnu.org/licenses/>.
* /
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 : string « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « 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 : string « 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 : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var plain _text _to _html = function ( text ) {
let ret = text ;
ret = ret . replace ( / /g , " " ) ; // convert multiple whitespace to forced ones
ret = ret . split ( "\n" ) . join ( "<br/>" ) ;
return ret ;
} ;
/ * *
* @ desc makes a valid
* /
var format _sentence = function ( str , rtl = false , caseSense = true ) {
if ( str === "" ) {
return str ;
}
else {
let marks = {
"." : true ,
"?" : true ,
"!" : true
} ;
let default _mark = "." ;
let ret = str . split ( "" ) ;
if ( ! rtl ) {
ret [ 0 ] = ret [ 0 ] . toLocaleUpperCase ( ) ;
if ( ! ( ret [ ret . length - 1 ] in marks ) ) {
ret . push ( default _mark ) ;
}
}
else {
ret [ ret . length - 1 ] = ret [ ret . length - 1 ] . toLocaleUpperCase ( ) ;
if ( ! ( ret [ 0 ] in marks ) ) {
ret . unshift ( default _mark ) ;
}
}
return ret . join ( "" ) ;
}
} ;
var fill _string _template = function ( template _string , object , fabric = function ( object , key ) { return object [ key ] ; } , delimiter = "%" , default _string = null , sloppy ) {
function get _tags ( str ) {
let r = new RegExp ( delimiter + "[^\\s^" + delimiter + "]+" + delimiter , "gi" ) ;
return ( ( str . match ( r ) || [ ] ) . map ( function ( e ) {
return e . slice ( delimiter . length , e . length - delimiter . length ) ;
} ) ) ;
}
function replace _tag ( str , tag , value ) {
let r = new RegExp ( delimiter + tag + delimiter , "gi" ) ;
return str . replace ( r , value ) ;
}
function replace _tags ( str , obj ) {
return ( get _tags ( str ) . reduce ( function ( ret , key ) {
let value = "" ;
try {
value = fabric ( obj , key ) ;
if ( ( ! sloppy && ( value === void 0 ) ) || ( sloppy && ( value == void 0 ) ) ) {
value = default _string ;
}
}
catch ( e ) {
console . warn ( "invalid placeholder " + key ) ;
value = default _string ;
}
return replace _tag ( ret , key , value ) ;
} , str ) ) ;
}
return replace _tags ( template _string , object ) ;
} ;
var make _string _template = function ( _template , _fabrics = { } ) {
function replace _tag ( str , tag , value ) {
var r = new RegExp ( "%" + tag + "%" , "gi" ) ;
return str . replace ( r , value ) ;
}
function replace _tags ( str , obj ) {
return ( Object . keys ( obj ) . reduce ( function ( ret , key ) {
return replace _tag ( ret , key , _fabrics [ key ] || obj [ key ] ) ;
} , str ) ) ;
}
return ( function ( tags ) {
return replace _tags ( _template , tags ) ;
} ) ;
} ;
var make _eml _header = ( function ( ) {
let _template = "" ;
_template += "From: %from%\n" ;
_template += "To: %recipient%\n" ;
_template += "Subject: %subject%\n" ;
_template += "X-Mailer: greenscale-plankton.emlgen\n" ;
return make _string _template ( _template ) ;
} ) ( ) ;
var make _eml _body = ( function ( ) {
let exports = { } ;
exports [ "simple_body" ] = make _string _template ( "Content-Type: %contenttype%\n\n%body%\n\n" ) ;
// very basic implementation
// parts = [{contenttype:"text/html; charset=UTF-8", body: "<h1>foo</h1>" }, {...}]
exports [ "body_boundrary" ] = function ( parts , boundrary ) {
let _template = "" ;
_template += "--%boundrary%\n" ;
_template += "Content-Type: %contenttype%\n\n%body%\n\n" ;
//_template += "--%boundrary%--\n\n";
let maker = make _string _template ( _template ) ;
return ( parts . reduce ( function ( prev , curr ) {
curr . boundrary = boundrary ;
return [ prev , maker ( curr ) ] . join ( "" ) ;
} , "" ) ) ;
} ;
// body must be base64 encoded!
exports [ "attachment_boundrary" ] = function ( parts , boundrary ) {
let _template = "" ;
_template += "--%boundrary%\n" ;
_template += "Content-Type: %contenttype%\n" ;
_template += "Content-Transfer-Encoding: base64\n" ;
_template += "Content-Disposition: %disposition%; filename=\"%name%\"\n\n" ;
_template += "%body%\n\n" ;
//_template += "--%boundrary%--\n\n";
let maker = make _string _template ( _template ) ;
return ( parts . reduce ( function ( prev , curr ) {
curr . boundrary = boundrary ;
if ( curr . disposition === void 0 )
curr . disposition = "inline" ;
return [ prev , maker ( curr ) ] . join ( "" ) ;
} , "" ) ) ;
} ;
exports [ "gen_boundrary" ] = function ( ) {
return ( "xxxxxxxxxxxxxxxxxxxxxx" . replace ( /[xy]/g , function ( c ) {
let r = crypto . getRandomValues ( new Uint8Array ( 1 ) ) [ 0 ] % 16 | 0 , v = c == "x" ? r : ( r & 0x3 | 0x8 ) ;
return v . toString ( 16 ) ;
} ) ) ;
} ;
// simple implementation without alternatives (old rfc)
exports [ "complete_boundrary" ] = function ( bodyparts , attachments ) {
let ret = "" ;
let boundrary = exports [ "gen_boundrary" ] ( ) ;
ret += exports [ "body_boundrary" ] ( bodyparts , boundrary ) ;
ret += exports [ "attachment_boundrary" ] ( attachments , boundrary ) ;
ret += "--" + boundrary + "--\n\nINVISIBLE!!!!" ;
return ( exports [ "simple_body" ] ( {
"contenttype" : sprintf ( "multipart/mixed; boundary=%s" , [ boundrary ] ) ,
"body" : ret
} ) ) ;
} ;
return exports ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « 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 : string « 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 : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var string ;
( function ( string ) {
/ * *
* @ author fenris
* /
const hexdigits = 4 ;
/ * *
* @ author fenris
* /
const index _max = ( 1 << ( 4 * hexdigits ) ) ;
/ * *
* @ author fenris
* /
var index _is = 0 ;
/ * *
* @ author neuc , frac
* /
function empty ( str ) {
return ( str . trim ( ) === "" ) ;
}
string . empty = empty ;
/ * *
* @ desc returns a unique string
* @ param { string } prefix an optional prefix for the generated string
* @ return { string }
* @ author fenris
* /
function generate ( prefix = "string_" ) {
if ( index _is > index _max ) {
throw ( new Error ( "[string_generate] out of valid indices" ) ) ;
}
else {
return string . sprintf ( prefix + "%0" + hexdigits . toString ( ) + "X" , [ index _is ++ ] ) ;
}
}
string . generate = generate ;
/ * *
* @ author fenris
* /
function join ( parts , glue = " " ) {
if ( parts . length == 0 ) {
return "" ;
}
else {
return parts . join ( glue ) ;
}
}
string . join = join ;
/ * *
* @ desc splits a string , but returns an empty list , if the string is empty
* @ param { string } chain
* @ param { string } separator
* @ return { Array < string > }
* @ author fenris
* /
function split ( chain , separator = " " ) {
if ( chain . length == 0 ) {
return [ ] ;
}
else {
return chain . split ( separator ) ;
}
}
string . split = split ;
/ * *
* @ author neu3no
* /
function explode ( str , needle , max ) {
let temp = str . split ( needle ) ;
const right = temp . splice ( max - 1 ) ;
temp . push ( right . join ( needle ) ) ;
return temp ;
}
string . explode = explode ;
/ * *
* @ desc concats a given word with itself n times
* @ param { string } word
* @ param { int }
* @ return { string }
* @ author fenris
* /
function repeat ( word , count ) {
// return ((count == 0) ? "" : (word + repeat(word, count-1)));
let result = "" ;
for ( let n = 0 ; n < count ; n += 1 ) {
result += word ;
}
return result ;
}
string . repeat = repeat ;
/ * *
* @ desc lengthens a string by repeatedly appending or prepending another string
* @ param { string } word the string to pad
* @ param { int } length the length , which the result shall have
* @ param { string } symbol the string , which will be added ( multiple times )
* @ param { boolean } [ prepend ] ; whether to prepend ( ~ true ) or append ( ~ false ) ; default : false
* @ return { string } the padded string
* @ author fenris
* /
function pad ( word , length , symbol = " " , mode = "append" ) {
switch ( mode ) {
case "prepend" : {
// insert symbols only at the beginning
while ( word . length < length )
word = symbol + word ;
return word . substring ( word . length - length ) ;
break ;
}
case "append" : {
// insert symbols only at the end
while ( word . length < length )
word = word + symbol ;
return word . substring ( 0 , length ) ;
break ;
}
case "widen" : {
// insert symbols at both sides
let left = ( ( ( length - word . length ) & 1 ) === 0 ) ;
while ( word . length < length ) {
word = ( left
? ( symbol + word )
: ( word + symbol ) ) ;
left = ( ! left ) ;
}
return word . substring ( 0 , length ) ;
break ;
}
default : {
const message = ( "unhandled mode '" + mode + "'" ) ;
console . warn ( message ) ;
return word ;
break ;
}
}
}
string . pad = pad ;
/ * *
* @ desc checks if a given string conttains a certain substring
* @ param { string } string
* @ param { string } part
* @ return { boolean }
* @ author fenris
* /
function contains ( chain , part ) {
if ( typeof ( chain ) !== "string" ) {
return false ;
}
return ( chain . indexOf ( part ) >= 0 ) ;
}
string . contains = contains ;
/ * *
* @ desc checks if a given string starts with a certain substring
* @ param { string } string
* @ param { string } part
* @ return { boolean }
* @ author fenris
* /
function startsWith ( chain , part ) {
if ( typeof ( chain ) !== "string" ) {
return false ;
}
// return (string.indexOf(part) === 0);
return ( ( function ( m , n ) {
if ( n === 0 ) {
return true ;
}
else {
if ( m === 0 ) {
return false ;
}
else {
return ( ( chain [ 0 ] == part [ 0 ] )
&&
startsWith ( chain . substring ( 1 ) , part . substring ( 1 ) ) ) ;
}
}
} ) ( chain . length , part . length ) ) ;
}
string . startsWith = startsWith ;
/ * *
* @ desc checks if a given string ends with a certain substring
* @ param { string } string
* @ param { string } part
* @ return { boolean }
* @ author fenris
* /
function endsWith ( chain , part ) {
if ( typeof ( chain ) !== "string" ) {
return false ;
}
// return (string.lastIndexOf(part) === string.length-part.length);
return ( ( function ( m , n ) {
if ( n === 0 ) {
return true ;
}
else {
if ( m === 0 ) {
return false ;
}
else {
// console.info(("(" + string[m-1] + " == " + part[n-1] + ")") + " = " + String(string[m-1] == part[n-1]));
return ( ( chain [ m - 1 ] === part [ n - 1 ] )
&&
endsWith ( chain . substring ( 0 , m - 1 ) , part . substring ( 0 , n - 1 ) ) ) ;
}
}
} ) ( chain . length , part . length ) ) ;
}
string . endsWith = endsWith ;
/ * *
* @ desc count the occourrences of a string in a string
* @ param string haystack _string the string wich should be examined
* @ param string needle _string the string which should be counted
* @ author neuc
* /
function count _occourrences ( haystack _string , needle _string , check _escape ) {
let cnt = 0 ;
let pos = - 1 ;
do {
pos = haystack _string . indexOf ( needle _string , pos + 1 ) ;
if ( ( ! check _escape ) || ( haystack _string [ pos - 1 ] != "\\" ) ) {
cnt ++ ;
}
} while ( pos >= 0 ) ;
return ( cnt - 1 ) ;
}
string . count _occourrences = count _occourrences ;
/ * *
* @ author fenris
* /
function replace ( str , replacements , options = { } ) {
options = Object . assign ( { } , options ) ;
let result = str ;
replacements . forEach ( replacement => {
lib _plankton . log . debug ( "lib_plankton.string.replace" , {
"from" : replacement . from ,
"to" : replacement . to ,
} ) ;
result = result . replace ( new RegExp ( replacement . from , "g" ) , replacement . to ) ;
} ) ;
return result ;
}
string . replace = replace ;
/ * *
* @ desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object
* @ author fenris
* /
function coin ( str , args , options = { } ) {
options = Object . assign ( {
"legacy" : false ,
"open" : "{{" ,
"close" : "}}" ,
} , options ) ;
Object . keys ( args ) . forEach ( ( key ) => {
// old syntax
{
if ( options . legacy ) {
const value = args [ key ] ;
const regexp _argument = new RegExp ( "\\${" + key + "}" , "g" ) ;
lib _plankton . log . debug ( "lib_plankton.string.coin" , {
"key" : key ,
"regex" : regexp _argument . toString ( ) ,
"value" : value ,
} ) ;
str = str . replace ( regexp _argument , value ) ;
}
}
// new syntax
{
const value = args [ key ] ;
const regexp _argument = new RegExp ( options . open + key + options . close , "g" ) ;
lib _plankton . log . debug ( "lib_plankton.string.coin" , {
"key" : key ,
"regex" : regexp _argument . toString ( ) ,
"value" : value ,
} ) ;
str = str . replace ( regexp _argument , value ) ;
}
} ) ;
return str ;
}
string . coin = coin ;
/ * *
* @ author fenris
* @ deprecated use limit
* /
function cut ( str , length , delimiter = "…" ) {
if ( str . length <= length ) {
return str ;
}
else {
return ( str . slice ( 0 , length - delimiter . length ) + delimiter ) ;
}
}
string . cut = cut ;
/ * *
* /
function limit ( str , options = { } ) {
options = Object . assign ( {
"length" : 120 ,
"indicator" : "…" ,
} , options ) ;
return ( ( str . length <= options . length )
? str
: ( str . slice ( 0 , options . length - options . indicator . length ) + options . indicator ) ) ;
}
string . limit = limit ;
/ * *
* /
function slice ( str , size ) {
let slices = [ ] ;
let rest = str ;
while ( rest . length > 0 ) {
slices . push ( rest . slice ( 0 , size ) ) ;
rest = rest . slice ( size ) ;
}
return slices ;
}
string . slice = slice ;
} ) ( string = lib _plankton . string || ( lib _plankton . string = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ * *
* @ deprecated
* /
var lib _string ;
( function ( lib _string ) {
lib _string . empty = lib _plankton . string . empty ;
lib _string . generate = lib _plankton . string . generate ;
lib _string . split = lib _plankton . string . split ;
lib _string . explode = lib _plankton . string . repeat ;
lib _string . repeat = lib _plankton . string . repeat ;
lib _string . pad = lib _plankton . string . pad ;
lib _string . contains = lib _plankton . string . contains ;
lib _string . startsWith = lib _plankton . string . startsWith ;
lib _string . endsWith = lib _plankton . string . endsWith ;
lib _string . count _occourrences = lib _plankton . string . count _occourrences ;
lib _string . coin = lib _plankton . string . coin ;
lib _string . stance = lib _plankton . string . coin ;
lib _string . cut = lib _plankton . string . cut ;
} ) ( lib _string || ( lib _string = { } ) ) ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « 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 : string « 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 : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var string ;
( function ( string ) {
var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/ ;
var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g ;
function split _format ( format ) {
var tmp = format . match ( pattern ) ;
if ( tmp === null )
return null ;
return {
'flags' : tmp [ 1 ] . split ( "" ) ,
'width' : Number ( tmp [ 2 ] ) ,
'precision' : tmp [ 3 ] === '' ? null : Number ( tmp [ 3 ] ) ,
'specifier' : tmp [ 4 ] ,
'string' : format
} ;
}
function make _err ( format , arg , should ) {
return ( "[sprintf]" + " " + "argument for '" + format . string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!" ) ;
}
function test _arg ( format , arg , should ) {
if ( typeof arg !== should ) {
console . warn ( make _err ( format , arg , should ) ) ;
return false ;
}
return true ;
}
function string _fill ( str , char , len , left ) {
while ( str . length < len ) {
if ( left ) {
str += char ;
}
else {
str = char + str ;
}
}
return str ;
}
/ * *
* the known _parameters are used to parse the different identifiers for the welln known syntax :
* flag width precision identifier
* % { [ 0 # + - ] } { [ 0 - 9 ] * } . { [ 0 - 9 ] * } [ fFdiueEgGsoxXaAsn ]
* flags :
* 0 - fill with '0' instead of ' ' if the string length < width
* # - not implemented
* - - left - justified - > fill on the right side to reach width
* + - force using '+' on positive numbers
* ' ' - add a single space before positive numbers
*
* identifiers
* % f , % F - interpret given number as float , width : the minimal total width ( fill with ' ' or '0' if the
* resulting string is too short , precision : cut more then given decimal places
* % d , % i , % u - interpret number as integer , decimal places will be cut . width : like float , precision :
* fill with '0' on right side until length given in precision is reached
* % e - interpret as float and write as scientifical number , width & precision like in float
* % E - same es % e but uppercase 'E'
* % g - use the shortest string of % f or % e
* % G - use the shortest string of % E or % E
* % s - simply print a string
* % o - print the given number in octal notation
* % x - print the given number in hex notation
* % X - same as % x but with uppercase characters
* % a - alias to % x
* % A - alias to % X
* % n - just print nothing
* @ type { { } }
* /
var known _params = { } ;
known _params [ "f" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , "number" ) )
return "Ø" ;
var tmp = Math . abs ( arg ) ;
var sign = ( arg < 0 ) ? - 1 : 1 ;
var tmp _result = null ;
if ( format . precision !== null ) {
tmp = Math . floor ( Math . pow ( 10 , format . precision ) * tmp ) / Math . pow ( 10 , format . precision ) ;
var tmp _ = ( tmp * sign ) . toString ( ) . split ( "." ) ;
if ( tmp _ . length === 1 )
tmp _ . push ( "" ) ;
tmp _ [ 1 ] = string _fill ( tmp _ [ 1 ] , "0" , format . precision , true ) ;
tmp _result = tmp _ . join ( "." ) ;
}
else {
tmp _result = ( sign * tmp ) . toString ( ) ;
}
if ( ( format . flags . indexOf ( " " ) >= 0 ) && ( arg >= 0 ) ) {
tmp _result = " " + tmp ;
}
else if ( ( format . flags . indexOf ( "+" ) >= 0 ) && ( arg >= 0 ) ) {
tmp _result = "+" + tmp ;
}
tmp _result = string _fill ( tmp , ( format . flags . indexOf ( "0" ) >= 0 ) ? "0" : " " , format . width , ( format . flags . indexOf ( "-" ) >= 0 ) ) ;
return tmp _result ;
} ;
known _params [ "F" ] = known _params [ "f" ] ;
known _params [ "d" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = ( ( ( arg < 0 && format . specifier !== 'u' ) ? - 1 : 1 ) * Math . floor ( Math . abs ( arg ) ) ) . toString ( ) ;
if ( ( format . specifier === 'd' || format . specifier === 'i' ) && format . flags . indexOf ( ' ' ) >= 0 && arg >= 0 ) {
tmp = ' ' + tmp ;
}
else if ( ( format . specifier === 'd' || format . specifier === 'i' ) && format . flags . indexOf ( '+' ) >= 0 && arg >= 0 ) {
tmp = '+' + tmp ;
}
tmp = string _fill ( tmp , format . flags . indexOf ( '0' ) >= 0 ? '0' : ' ' , format . width , format . flags . indexOf ( '-' ) >= 0 ) ;
tmp = string _fill ( tmp , '0' , format . precision === null ? 0 : format . precision , false ) ;
return tmp ;
} ;
known _params [ "i" ] = known _params [ "d" ] ;
known _params [ "u" ] = known _params [ "d" ] ;
known _params [ "e" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = arg . toExponential ( format . precision === null ? undefined : format . precision ) . toString ( ) ;
if ( format . flags . indexOf ( ' ' ) >= 0 && arg >= 0 ) {
tmp = ' ' + tmp ;
}
else if ( format . flags . indexOf ( '+' ) >= 0 && arg >= 0 ) {
tmp = '+' + tmp ;
}
tmp = string _fill ( tmp , format . flags . indexOf ( '0' ) >= 0 ? '0' : ' ' , format . width , format . flags . indexOf ( '-' ) >= 0 ) ;
return tmp ;
} ;
known _params [ "E" ] = function ( format , arg ) {
return known _params [ "e" ] ( format , arg ) . toUpperCase ( ) ;
} ;
known _params [ "g" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmpf = known _params [ "f" ] ( format , arg ) ;
var tmpe = known _params [ "e" ] ( format , arg ) ;
if ( tmpf . length < tmpe . length ) {
return tmpf ;
}
else {
return tmpe ;
}
} ;
known _params [ "G" ] = function ( format , arg ) {
return known _params [ "g" ] ( format , arg ) . toUpperCase ( ) ;
} ;
known _params [ "s" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'string' ) )
return 'o.O' ;
var tmp = format . precision !== null ? arg . substr ( 0 , format . precision ) : arg ;
tmp = string _fill ( tmp , format . flags . indexOf ( '0' ) >= 0 ? '0' : ' ' , format . width , format . flags . indexOf ( '-' ) >= 0 ) ;
return tmp ;
} ;
known _params [ "o" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = Math . floor ( Math . round ( Math . abs ( arg ) ) ) * ( ( arg < 0 ) ? - 1 : 1 ) ;
return known _params [ "s" ] ( format , tmp . toString ( 8 ) ) ;
} ;
known _params [ "x" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = Math . floor ( Math . round ( Math . abs ( arg ) ) ) * ( ( arg < 0 ) ? - 1 : 1 ) ;
return known _params [ "s" ] ( format , tmp . toString ( 16 ) ) ;
} ;
known _params [ "a" ] = known _params [ "x" ] ;
known _params [ "X" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
return known _params [ "x" ] ( format , arg ) . toUpperCase ( ) ;
} ;
known _params [ "A" ] = known _params [ "X" ] ;
known _params [ "c" ] = function ( format , arg ) {
var tmp = "" ;
if ( typeof arg === "number" ) {
tmp = String . fromCharCode ( arg ) ;
}
else if ( ( typeof arg === "string" ) && ( arg . length === 1 ) ) {
tmp = arg [ 0 ] ;
}
else {
console . warn ( make _err ( format , arg , "number|string" ) + " and if string it needs to have the length of 1!" ) ;
}
return known _params [ "s" ] ( format , tmp ) ;
} ;
known _params [ "n" ] = function ( ) {
return "" ;
} ;
var decompose = function ( chain , regexp ) {
var result = regexp . exec ( chain ) ;
if ( result == null ) {
return null ;
}
else {
var front = chain . substring ( 0 , result . index ) ;
var back = chain . substring ( result . index + result [ 0 ] . length ) ;
return { "front" : front , "match" : result [ 0 ] , "back" : back } ;
}
} ;
/ * *
* an implementation of c sprintf
* @ param { string } string format string
* @ param { array } args arguments which should be filled into
* @ returns { string }
* /
string . sprintf = function ( input , args = [ ] , original = null ) {
if ( original == null )
original = input ;
var components = decompose ( input , pattern ) ;
if ( components == null ) {
if ( args . length > 0 ) {
console . warn ( "[sprintf] superfluous arguments while formatting '" + original + "': " , args ) ;
}
return input ;
}
else {
var arg ;
var rest ;
if ( args . length > 0 ) {
arg = args [ 0 ] ;
rest = args . slice ( 1 ) ;
}
else {
console . warn ( "[sprintf] out of arguments while formatting '" + original + "'" ) ;
arg = null ;
rest = [ ] ;
return input ;
}
var fmt = split _format ( components [ "match" ] ) ;
return ( components [ "front" ]
+ known _params [ fmt . specifier ] ( fmt , arg )
+ string . sprintf ( components [ "back" ] , rest , original ) ) ;
}
} ;
/ * *
* an implementation of c printf
* @ param { string } string format string
* @ param { array } args arguments which should be filled into
* @ returns { string }
* /
function printf ( format , args ) {
console . log ( string . sprintf ( format , args ) ) ;
}
string . printf = printf ;
} ) ( string = lib _plankton . string || ( lib _plankton . string = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
var sprintf = lib _plankton . string . sprintf ;
var printf = lib _plankton . string . printf ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « 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 : string « 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 : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var make _logger = ( function ( ) {
var _loggers = { } ;
var make _logger = function ( prefix , current _loglevel ) {
var log = [ ] ;
var level = [
"LOG" , "INFO" , "WARNING" , "DEBUG"
] ;
var logger = function ( obj , lvl ) {
var txt = obj . txt || obj ;
if ( lvl == void 0 )
lvl = 0 ;
var date = new Date ( ) ;
log . push ( {
"message" : sprintf ( "%s [%s:%s] %s" , [ date . toString ( ) , level [ lvl ] , prefix , txt ] ) ,
"timeStamp" : + ( date )
} ) ;
if ( lvl <= current _loglevel ) {
var msg = [ "[" + prefix + "]" , txt ] ;
if ( obj . arg )
msg = [ "[" + prefix + "]" ] . concat ( Array . prototype . slice . call ( obj . arg ) ) ;
if ( lvl === 0 )
console [ "_log" ] . apply ( console , msg ) ;
else if ( lvl === 1 )
console [ "_info" ] . apply ( console , msg ) ;
else if ( lvl === 2 )
console [ "_warn" ] . apply ( console , msg ) ;
else if ( lvl >= 3 )
console [ "_log" ] . apply ( console , msg ) ;
}
} ;
_loggers [ prefix ] = {
"logger" : logger ,
"log" : log
} ;
return logger ;
} ;
make _logger [ "loggers" ] = _loggers ;
make _logger [ "complete_log" ] = function ( ) {
var logs = Object . keys ( _loggers )
. reduce ( function ( p , c ) {
return [ ] . concat ( p , _loggers [ c ] . log ) ;
} , [ ] ) ;
logs . sort ( function ( x , y ) {
return ( ( x . timeStamp > y . timeStamp ) ? - 1 : + 1 ) ;
} ) ;
return logs . map ( function ( x , i , a ) {
return x . message ;
} ) ;
} ;
if ( /*!track_exports*/ true ) {
var _log _all = function ( log , lvl , next = function ( ) { } ) {
return function ( ) {
var msg = [ ] ;
for ( var i = 0 ; i < arguments . length ; i ++ ) {
if ( typeof arguments [ i ] === "string" ) {
msg . push ( arguments [ i ] ) ;
}
else {
msg . push ( JSON . stringify ( arguments [ i ] ) ) ;
}
}
var obj = {
txt : msg . join ( "\t" ) ,
arg : arguments
} ;
log ( obj , lvl ) ;
next ( ) ;
} ;
} ;
{
var _ _warn = make _logger ( "deprecated console.warn" , 99 ) ;
var _ _error = make _logger ( "deprecated console.error" , 99 ) ;
var _ _log = make _logger ( "deprecated console.log" , 99 ) ;
var _ _info = make _logger ( "deprecated console.info" , 99 ) ;
// bad ass
console [ "_log" ] = console . log ;
console [ "_error" ] = console . error ;
console [ "_warn" ] = console . warn ;
console [ "_info" ] = console . info ;
/ *
console [ "log" ] = _log _all ( _ _log , 0 ) ;
console [ "error" ] = _log _all ( _ _error , 2 ) ;
console [ "warn" ] = _log _all ( _ _warn , 2 ) ;
console [ "info" ] = _log _all ( _ _info , 0 ) ;
* /
}
/ *
{
make _logger [ "send_log" ] = function ( ) {
eml _log (
function ( ) {
alert ( "fehlerbericht wurde gesendet!" ) ;
}
) ;
} ;
var error _log = make _logger ( "global.error" , 99 ) ;
window . onerror = _log _all (
error _log ,
1 ,
function ( ) {
if ( global _config == undefined ) {
return false ;
}
if ( global _config . report _error ) {
make _logger [ "send_log" ] ( ) ;
}
}
) ;
}
* /
}
return make _logger ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _1 ) {
/ * *
* @ author fenris
* /
function inspection _create ( ) {
return {
"flaws" : [ ] ,
"sub" : [ ]
} ;
}
shape _1 . inspection _create = inspection _create ;
/ * *
* @ author fenris
* /
function inspection _add ( main , flaw ) {
main . flaws . push ( flaw ) ;
}
shape _1 . inspection _add = inspection _add ;
/ * *
* @ author fenris
* /
function inspection _extend ( main , prefix , sub ) {
if ( ( sub . flaws . length <= 0 )
&&
( sub . sub . length <= 0 ) ) {
// do nothing
}
else {
main . sub . push ( { "position" : prefix , "inspection" : sub } ) ;
}
}
shape _1 . inspection _extend = inspection _extend ;
/ * *
* /
function inspection _flatten ( inspection ) {
return ( inspection . flaws
. concat ( inspection . sub
. map ( ( entry ) => ( inspection _flatten ( entry . inspection )
. map ( rest => lib _plankton . string . coin ( "[{{position}}] {{rest}}" , {
"position" : entry . position ,
"rest" : rest
} ) ) ) )
. reduce ( ( x , y ) => x . concat ( y ) , [ ] ) ) ) ;
}
/ * *
* /
var _pool = { } ;
/ * *
* @ todo cache
* /
function construct ( shape ) {
return _pool [ shape . kind ] . construct ( shape . parameters ) ;
}
/ * *
* /
function get _logic ( shape ) {
if ( ! ( shape . kind in _pool ) ) {
throw ( new Error ( "missing shape: " + shape . kind ) ) ;
}
else {
return _pool [ shape . kind ] . logic ( construct ( shape ) ) ;
}
}
/ * *
* /
function inspect ( shape , value ) {
return get _logic ( shape ) . inspect ( inspect , value ) ;
}
shape _1 . inspect = inspect ;
/ * *
* /
function inspect _flat ( shape , value ) {
return inspection _flatten ( inspect ( shape , value ) ) ;
}
shape _1 . inspect _flat = inspect _flat ;
/ * *
* /
function show ( shape ) {
return get _logic ( shape ) . show ( show ) ;
}
shape _1 . show = show ;
/ * *
* /
function to _typescript _type ( shape ) {
return get _logic ( shape ) . to _typescript _type ( to _typescript _type ) ;
}
shape _1 . to _typescript _type = to _typescript _type ;
/ * *
* /
function to _jsonschema ( shape ) {
return get _logic ( shape ) . to _jsonschema ( to _jsonschema ) ;
}
shape _1 . to _jsonschema = to _jsonschema ;
/ * *
* /
function to _oas _schema ( shape ) {
return get _logic ( shape ) . to _oas _schema ( to _oas _schema ) ;
}
shape _1 . to _oas _schema = to _oas _schema ;
/ * *
* /
function example ( shape ) {
return get _logic ( shape ) . example ( example ) ;
}
shape _1 . example = example ;
/ * *
* /
function register ( name , construct , logic ) {
_pool [ name ] = {
"construct" : construct ,
"logic" : logic ,
} ;
}
shape _1 . register = register ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _2 ) {
var any ;
( function ( any ) {
/ * *
* /
function make ( options = { } ) {
return { } ;
}
any . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _2 . inspection _create ( ) ;
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
return "any" ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
return "any" ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
return { } ;
}
/ * *
* /
function example ( sub _example , subject ) {
return null ;
}
shape _2 . register ( "any" , ( parameters ) => make ( { } ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( any = shape _2 . any || ( shape _2 . any = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _3 ) {
var null _ ;
( function ( null _ ) {
/ * *
* /
function make ( options = { } ) {
return { } ;
}
null _ . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _3 . inspection _create ( ) ;
if ( ! ( value === null ) ) {
shape _3 . inspection _add ( inspection , "null expected" ) ;
}
else {
// all good
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
return "null" ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
return "null" ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
return {
"type" : "null" ,
} ;
}
/ * *
* /
function example ( sub _example , subject ) {
return null ;
}
shape _3 . register ( "null" , ( parameters ) => make ( { } ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( null _ = shape _3 . null _ || ( shape _3 . null _ = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _4 ) {
var boolean ;
( function ( boolean ) {
/ * *
* /
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
} , options ) ;
return {
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
} ;
}
boolean . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _4 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _4 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "boolean" ;
if ( jstype _actual === jstype _expected ) {
// all good
}
else {
shape _4 . inspection _add ( inspection , lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ) ;
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = "boolean" ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = "boolean" ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "boolean" ,
} ;
return ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
] ,
}
: core ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft ? null : false ) ;
}
shape _4 . register ( "boolean" , ( parameters ) => make ( {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( boolean = shape _4 . boolean || ( shape _4 . boolean = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _5 ) {
var integer ;
( function ( integer ) {
/ * *
* /
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
"minimum" : undefined ,
"maximum" : undefined ,
} , options ) ;
return {
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
"minimum" : ( ( options . minimum === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . minimum ) ) ,
"maximum" : ( ( options . minimum === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . maximum ) ) ,
} ;
}
integer . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _5 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _5 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "number" ;
if ( ! ( jstype _actual === jstype _expected ) ) {
shape _5 . inspection _add ( inspection , lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ) ;
}
else {
if ( isNaN ( parseInt ( value ) ) ) {
shape _5 . inspection _add ( inspection , "value is not parsable to a valid int" ) ;
}
else {
// minimum
{
if ( ! lib _plankton . pod . distinguish ( subject . minimum , ( ) => true , x => ( value >= x ) ) ) {
shape _5 . inspection _add ( inspection , lib _plankton . string . coin ( "value is below the minimum of '{{minimum}}'" , {
"minimum" : lib _plankton . pod . cull ( subject . minimum ) . toFixed ( 0 ) ,
} ) ) ;
}
else {
// do nothing
}
}
// maximum
{
if ( ! lib _plankton . pod . distinguish ( subject . maximum , ( ) => true , x => ( value <= x ) ) ) {
shape _5 . inspection _add ( inspection , lib _plankton . string . coin ( "value is beyond the maximum of '{{maximum}}'" , {
"maximum" : lib _plankton . pod . cull ( subject . maximum ) . toFixed ( 0 ) ,
} ) ) ;
}
else {
// do nothing
}
}
}
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = "integer" ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = "number" ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "integer" ,
"minimum" : lib _plankton . pod . distinguish ( subject . minimum , ( ) => undefined , x => x ) ,
"maximum" : lib _plankton . pod . distinguish ( subject . maximum , ( ) => undefined , x => x ) ,
} ;
return ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
] ,
}
: core ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft ? null : 0 ) ;
}
shape _5 . register ( "integer" , ( parameters ) => make ( {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
"minimum" : parameters . minimum ,
"maximum" : parameters . maximum ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( integer = shape _5 . integer || ( shape _5 . integer = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _6 ) {
var float ;
( function ( float ) {
/ * *
* /
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
"minimum" : undefined ,
"maximum" : undefined ,
} , options ) ;
return {
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
"minimum" : ( ( options . minimum === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . minimum ) ) ,
"maximum" : ( ( options . minimum === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . maximum ) ) ,
} ;
}
float . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _6 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _6 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "number" ;
if ( ! ( jstype _actual === jstype _expected ) ) {
shape _6 . inspection _add ( inspection , lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ) ;
}
else {
if ( isNaN ( parseInt ( value ) ) ) {
shape _6 . inspection _add ( inspection , "value is not parsable to a valid float" ) ;
}
else {
// minimum
{
if ( ! lib _plankton . pod . distinguish ( subject . minimum , ( ) => true , x => ( value >= x ) ) ) {
shape _6 . inspection _add ( inspection , lib _plankton . string . coin ( "value is below the minimum of '{{minimum}}'" , {
"minimum" : lib _plankton . pod . cull ( subject . minimum ) . toFixed ( 0 ) ,
} ) ) ;
}
else {
// do nothing
}
}
// maximum
{
if ( ! lib _plankton . pod . distinguish ( subject . maximum , ( ) => true , x => ( value <= x ) ) ) {
shape _6 . inspection _add ( inspection , lib _plankton . string . coin ( "value is beyond the maximum of '{{maximum}}'" , {
"maximum" : lib _plankton . pod . cull ( subject . maximum ) . toFixed ( 0 ) ,
} ) ) ;
}
else {
// do nothing
}
}
}
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = "float" ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = "number" ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "float" ,
"minimum" : lib _plankton . pod . distinguish ( subject . minimum , ( ) => undefined , x => x ) ,
"maximum" : lib _plankton . pod . distinguish ( subject . maximum , ( ) => undefined , x => x ) ,
} ;
return ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
] ,
}
: core ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft ? null : 0 ) ;
}
shape _6 . register ( "float" , ( parameters ) => make ( {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
"minimum" : parameters . minimum ,
"maximum" : parameters . maximum ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( float = shape _6 . float || ( shape _6 . float = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _7 ) {
var string ;
( function ( string ) {
/ * *
* /
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
"pattern" : undefined ,
"min_length" : undefined ,
"max_lenth" : undefined ,
} , options ) ;
return {
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
"pattern" : ( ( options . pattern === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . pattern ) ) ,
"min_length" : ( ( options . min _length === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . min _length ) ) ,
"max_length" : ( ( options . max _length === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . max _length ) ) ,
} ;
}
string . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _7 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _7 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "string" ;
if ( ! ( jstype _actual === jstype _expected ) ) {
shape _7 . inspection _add ( inspection , lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ) ;
}
else {
const value _ = value ;
// pattern
{
if ( ! lib _plankton . pod . distinguish ( subject . pattern , ( ) => true , x => ( new RegExp ( x ) ) . test ( value _ ) ) ) {
shape _7 . inspection _add ( inspection , lib _plankton . string . coin ( "string does not match the pattern '{{pattern}}'" , {
"pattern" : lib _plankton . pod . cull ( subject . pattern ) ,
} ) ) ;
}
else {
// do nothing
}
}
// min_length
{
if ( ! lib _plankton . pod . distinguish ( subject . min _length , ( ) => true , x => ( value _ . length >= x ) ) ) {
shape _7 . inspection _add ( inspection , lib _plankton . string . coin ( "string is shorter than '{{min_length}}'" , {
"min_length" : lib _plankton . pod . cull ( subject . min _length ) . toFixed ( 0 ) ,
} ) ) ;
}
else {
// do nothing
}
}
// max_length
{
if ( ! lib _plankton . pod . distinguish ( subject . max _length , ( ) => true , x => ( value _ . length <= x ) ) ) {
shape _7 . inspection _add ( inspection , lib _plankton . string . coin ( "string is longer than '{{max_length}}'" , {
"min_length" : lib _plankton . pod . cull ( subject . max _length ) . toFixed ( 0 ) ,
} ) ) ;
}
else {
// do nothing
}
}
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = "string" ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = "string" ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "string" ,
// TODO: transform?
"pattern" : lib _plankton . pod . distinguish ( subject . pattern , ( ) => undefined , x => x ) ,
"minLength" : lib _plankton . pod . distinguish ( subject . min _length , ( ) => undefined , x => x ) ,
"maxLenth" : lib _plankton . pod . distinguish ( subject . max _length , ( ) => undefined , x => x ) ,
} ;
return ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
] ,
}
: core ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft ? null : "" ) ;
}
shape _7 . register ( "string" , ( parameters ) => make ( {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
"pattern" : parameters . pattern ,
"min_length" : parameters . min _length ,
"max_length" : parameters . max _length ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _chema ) => to _jsonschema ( sub _to _oas _chema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( string = shape _7 . string || ( shape _7 . string = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _8 ) {
var email ;
( function ( email ) {
/ * *
* /
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
} , options ) ;
return {
"core" : {
"kind" : "string" ,
"parameters" : {
"soft" : options . soft ,
"defaultvalue" : options . defaultvalue ,
"description" : options . description ,
"pattern" : "[^@]*@[^@]*" ,
"min_length" : 0 ,
"max_length" : 255 ,
}
} ,
} ;
}
email . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
return sub _inspect ( subject . core , value ) ;
}
/ * *
* /
function show ( sub _show , subject ) {
return sub _show ( subject . core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
return sub _to _typescript _type ( subject . core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
return sub _to _jsonschema ( subject . core ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return sub _example ( subject . core ) ;
}
shape _8 . register ( "email" , ( parameters ) => make ( {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _chema ) => to _jsonschema ( sub _to _oas _chema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( email = shape _8 . email || ( shape _8 . email = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _9 ) {
var list _ ;
( function ( list _ ) {
/ * *
* /
function make ( shape _element , options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : lib _plankton . pod . make _empty ( ) ,
"description" : lib _plankton . pod . make _empty ( ) ,
} , options ) ;
return {
"shape_element" : shape _element ,
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
} ;
}
list _ . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _9 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _9 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "object" ;
if ( ! ( jstype _actual === jstype _expected ) ) {
lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ;
}
else {
if ( ! ( value instanceof Array ) ) {
shape _9 . inspection _add ( inspection , "value does not seem to be an array-instance" ) ;
}
else {
value . forEach ( ( element , index ) => {
shape _9 . inspection _extend ( inspection , lib _plankton . string . coin ( "element #{{index}}" , {
"index" : index . toFixed ( 0 ) ,
} ) ,
// subject.shape_element.inspect(element)
sub _inspect ( subject . shape _element , element ) ) ;
} ) ;
}
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = lib _plankton . string . coin ( "list<{{element}}>" , {
"element" : sub _show ( subject . shape _element ) ,
} ) ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = lib _plankton . string . coin ( "Array<{{element}}>" , {
"element" : sub _to _typescript _type ( subject . shape _element ) ,
} ) ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "array" ,
"items" : sub _to _jsonschema ( subject . shape _element ) ,
} ;
return ( ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
]
}
: core ) ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft
? null
: [
sub _example ( subject . shape _element )
] ) ;
}
shape _9 . register ( "list" , ( parameters ) => make ( parameters . shape _element , {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( list _ = shape _9 . list _ || ( shape _9 . list _ = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _10 ) {
var map ;
( function ( map ) {
/ * *
* /
function make ( shape _key , shape _value , options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : lib _plankton . pod . make _empty ( ) ,
"description" : lib _plankton . pod . make _empty ( ) ,
} , options ) ;
return {
"shape_key" : shape _key ,
"shape_value" : shape _value ,
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
} ;
}
map . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _10 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _10 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "object" ;
if ( ! ( jstype _actual === jstype _expected ) ) {
lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ;
}
else {
Object . entries ( value )
. forEach ( ( [ key , value ] ) => {
shape _10 . inspection _extend ( inspection , lib _plankton . string . coin ( "key '{{key}}'" , {
"key" : String ( key ) ,
} ) , sub _inspect ( subject . shape _key , key ) ) ;
shape _10 . inspection _extend ( inspection , lib _plankton . string . coin ( "value for '{{key}}'" , {
"key" : String ( key ) ,
} ) , sub _inspect ( subject . shape _value , value ) ) ;
} ) ;
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = lib _plankton . string . coin ( "map<{{key}},{{value}}>" , {
"key" : sub _show ( subject . shape _key ) ,
"value" : sub _show ( subject . shape _value ) ,
} ) ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = lib _plankton . string . coin ( "Record<{{key}},{{value}}>" , {
"key" : sub _to _typescript _type ( subject . shape _key ) ,
"value" : sub _to _typescript _type ( subject . shape _key ) ,
} ) ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "object" ,
"additionalProperties" : sub _to _jsonschema ( subject . shape _value ) ,
"properties" : { } ,
"required" : [ ] ,
} ;
return ( ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
]
}
: core ) ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft
? null
: { } ) ;
}
shape _10 . register ( "map" , ( parameters ) => make ( parameters . shape _key , parameters . shape _value , {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( map = shape _10 . map || ( shape _10 . map = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : shape « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : shape « 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 : shape « 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 : shape « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var shape ;
( function ( shape _11 ) {
var record ;
( function ( record ) {
/ * *
* /
function make ( fields _raw , options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : lib _plankton . pod . make _empty ( ) ,
"description" : lib _plankton . pod . make _empty ( ) ,
} , options ) ;
return {
"fields" : fields _raw . map ( field _raw => ( {
"name" : field _raw . name ,
"shape" : field _raw . shape ,
"required" : ( field _raw . required ? ? true )
} ) ) ,
"soft" : options . soft ,
"defaultvalue" : ( ( options . defaultvalue === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . defaultvalue ) ) ,
"description" : ( ( options . description === undefined )
? lib _plankton . pod . make _empty ( )
: lib _plankton . pod . make _filled ( options . description ) ) ,
} ;
}
record . make = make ;
/ * *
* /
function inspect ( sub _inspect , subject , value ) {
let inspection = shape _11 . inspection _create ( ) ;
if ( value === null ) {
if ( subject . soft ) {
// all good
}
else {
shape _11 . inspection _add ( inspection , "null is not allowed" ) ;
}
}
else {
const jstype _actual = typeof ( value ) ;
const jstype _expected = "object" ;
if ( ! ( jstype _actual === jstype _expected ) ) {
shape _11 . inspection _add ( inspection , lib _plankton . string . coin ( "expected JS-type '{{expected}}' but got '{{actual}}'" , {
"expected" : jstype _expected ,
"actual" : jstype _actual ,
} ) ) ;
}
else {
subject . fields . forEach ( field => {
if ( ! ( field . name in value ) ) {
if ( field . required ) {
shape _11 . inspection _add ( inspection , "missing field '" + field . name + "'" ) ;
}
else {
// do nothing
}
}
else {
const value _ = value [ field . name ] ;
shape _11 . inspection _extend ( inspection , ( "field '" + field . name + "'" ) , sub _inspect ( field . shape , value _ ) ) ;
}
} ) ;
// extra fields
{
const allowed = subject . fields . map ( field => field . name ) ;
( Object . keys ( value )
. filter ( name => ( ! allowed . includes ( name ) ) )
. forEach ( name => {
shape _11 . inspection _add ( inspection , "extra field '" + name + "'" ) ;
} ) ) ;
}
}
}
return inspection ;
}
/ * *
* /
function show ( sub _show , subject ) {
const core = lib _plankton . string . coin ( "record<{{fields}}>" , {
"fields" : ( subject . fields
. map ( field => lib _plankton . string . coin ( "{{prefix}}{{name}}:{{shape}}" , {
"prefix" : ( field . required ? "" : "?" ) ,
"name" : field . name ,
"shape" : sub _show ( field . shape ) ,
} ) )
. join ( "," ) ) ,
} ) ;
return ( subject . soft ? ( "~" + core ) : core ) ;
}
/ * *
* /
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = lib _plankton . string . coin ( "{{{fields}}}" , {
"fields" : ( subject . fields
. map ( field => lib _plankton . string . coin ( "{{name}}{{infix}}{{shape}}" , {
"name" : field . name ,
"infix" : ( field . required ? ":" : "?:" ) ,
"shape" : sub _to _typescript _type ( field . shape ) ,
} ) )
. join ( ";" ) ) ,
} ) ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
}
/ * *
* /
function to _jsonschema ( sub _to _jsonschema , subject ) {
const common = {
"description" : lib _plankton . pod . distinguish ( subject . description , ( ) => undefined , x => x ) ,
"default" : lib _plankton . pod . distinguish ( subject . defaultvalue , ( ) => undefined , x => x ) ,
} ;
const core = {
"type" : "object" ,
"additionalProperties" : false ,
"properties" : ( Object . fromEntries ( subject . fields
. map ( field => ( [
field . name ,
sub _to _jsonschema ( field . shape )
] ) ) ) ) ,
"required" : ( subject . fields
. filter ( field => field . required )
. map ( field => field . name ) ) ,
} ;
return ( ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
]
}
: core ) ) ;
}
/ * *
* /
function example ( sub _example , subject ) {
return ( subject . soft
? null
: ( Object . fromEntries ( subject . fields
. filter ( field => field . required )
. map ( field => ( [
field . name ,
sub _example ( field . shape )
] ) ) ) ) ) ;
}
shape _11 . register ( "record" , ( parameters ) => make ( ( parameters . fields
. map ( field _raw => ( {
"name" : field _raw . name ,
"shape" : field _raw . shape ,
"required" : field _raw . required ,
} ) ) ) , {
"soft" : parameters . soft ,
"description" : parameters . description ,
"defaultvalue" : parameters . defaultvalue ,
} ) , ( subject ) => ( {
"inspect" : ( sub _inspect , value ) => inspect ( sub _inspect , subject , value ) ,
"show" : ( sub _show ) => show ( sub _show , subject ) ,
"to_typescript_type" : ( sub _to _typescript _type ) => to _typescript _type ( sub _to _typescript _type , subject ) ,
"to_jsonschema" : ( sub _to _jsonschema ) => to _jsonschema ( sub _to _jsonschema , subject ) ,
"to_oas_schema" : ( sub _to _oas _schema ) => to _jsonschema ( sub _to _oas _schema , subject ) ,
"example" : ( sub _example ) => example ( sub _example , subject ) ,
} ) ) ;
} ) ( record = shape _11 . record || ( shape _11 . record = { } ) ) ;
} ) ( shape = lib _plankton . shape || ( lib _plankton . shape = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : markdown « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : markdown « 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 : markdown « 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 : markdown « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var markdown ;
( function ( markdown ) {
/ * *
* @ author fenris
* /
function code ( content ) {
return lib _plankton . string . coin ( "`{{content}}`" , {
"content" : content
} ) ;
}
markdown . code = code ;
/ * *
* @ author fenris
* /
function paragraph ( content ) {
return lib _plankton . string . coin ( "{{content}}\n\n" , {
"content" : content
} ) ;
}
markdown . paragraph = paragraph ;
/ * *
* @ author fenris
* /
function sectionhead ( level , content ) {
return lib _plankton . string . coin ( "{{grids}} {{content}}\n\n" , {
"grids" : lib _plankton . string . repeat ( "#" , level ) ,
"content" : content
} ) ;
}
markdown . sectionhead = sectionhead ;
} ) ( markdown = lib _plankton . markdown || ( lib _plankton . markdown = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : api « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : api « 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 : api « 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 : api « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var api ;
( function ( api ) {
/ * *
* /
let enum _checklevel ;
( function ( enum _checklevel ) {
enum _checklevel [ "none" ] = "none" ;
enum _checklevel [ "soft" ] = "soft" ;
enum _checklevel [ "hard" ] = "hard" ;
} ) ( enum _checklevel = api . enum _checklevel || ( api . enum _checklevel = { } ) ) ;
/ * *
* /
class class _error _permission _denied extends Error {
}
api . class _error _permission _denied = class _error _permission _denied ;
} ) ( api = lib _plankton . api || ( lib _plankton . api = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : api « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : api « 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 : api « 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 : api « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var api ;
( function ( api _1 ) {
/ * *
* @ throws Error if the inspection had foundings and the level is high enough
* @ author fenris
* /
function validate ( level , shape , value , options = { } ) {
options = lib _plankton . object . patched ( {
"kind" : "value" ,
"message_factory" : ( ( kind , findings ) => ( "malformed " + kind + ": " + findings . join ( "; " ) ) ) ,
} , options ) ;
if ( level === api _1 . enum _checklevel . none ) {
return value ;
}
else {
const inspection = lib _plankton . shape . inspect _flat ( shape , value ) ;
if ( inspection . length === 0 ) {
return value ;
}
else {
const message = options . message _factory ( options . kind , inspection ) ;
switch ( level ) {
case api _1 . enum _checklevel . soft : {
console . warn ( message ) ;
return value ;
break ;
}
case api _1 . enum _checklevel . hard :
default :
{
throw ( new Error ( message ) ) ;
break ;
}
}
}
}
}
/ * *
* @ author fenris
* /
function make ( title ) {
const api = {
"title" : title ,
"actions" : { } ,
} ;
return api ;
}
api _1 . make = make ;
/ * *
* @ throws Error if a action with the given name has already been registered
* @ author fenris
* /
function register ( api , name , options = { } ) {
options = /*lib_plankton.object.patched*/ Object . assign ( {
"active" : ( version ) => true ,
"execution" : ( version , environment , input ) => lib _plankton . call . promise _reject ( "not implemented" ) ,
"restriction" : ( version , environment ) => true ,
"input_shape" : ( version ) => ( { "kind" : "any" } ) ,
"output_shape" : ( version ) => ( { "kind" : "any" } ) ,
"title" : null ,
"description" : null ,
} , options ) ;
if ( api . actions . hasOwnProperty ( name ) ) {
throw ( new Error ( "an action with the name '" + name + "' has already been registered" ) ) ;
}
else {
const action = {
"name" : name ,
"active" : options . active ,
"execution" : options . execution ,
"restriction" : options . restriction ,
"input_shape" : options . input _shape ,
"output_shape" : options . output _shape ,
"title" : options . title ,
"description" : options . description ,
} ;
api . actions [ name ] = action ;
}
}
api _1 . register = register ;
/ * *
* @ throws Error if not found
* @ author fenris
* /
function get _action ( api , name ) {
if ( api . actions . hasOwnProperty ( name ) ) {
const action = api . actions [ name ] ;
return action ;
}
else {
throw ( new Error ( "no action with name '" + name + "'" ) ) ;
}
}
api _1 . get _action = get _action ;
/ * *
* @ author fenris
* /
function call ( api , name , options = { } ) {
options = /*lib_plankton.object.patched*/ Object . assign ( {
"version" : null ,
"input" : null ,
"environment" : { } ,
"checklevel_restriction" : api _1 . enum _checklevel . hard ,
"checklevel_input" : api _1 . enum _checklevel . soft ,
"checklevel_output" : api _1 . enum _checklevel . soft ,
} , options ) ;
return ( lib _plankton . call . promise _resolve ( undefined )
// get action
. then ( ( ) => lib _plankton . call . promise _resolve ( get _action ( api , name ) ) )
. then ( ( action ) => ( lib _plankton . call . promise _resolve ( undefined )
// check permission
. then ( ( ) => {
let conf ;
switch ( options . checklevel _restriction ) {
case api _1 . enum _checklevel . none : {
conf = {
"actual_check" : false ,
"escalate" : false ,
} ;
break ;
}
case api _1 . enum _checklevel . soft : {
conf = {
"actual_check" : true ,
"escalate" : false ,
} ;
break ;
}
default :
case api _1 . enum _checklevel . hard : {
conf = {
"actual_check" : true ,
"escalate" : true ,
} ;
break ;
}
}
return ( ( conf . actual _check
? action . restriction ( options . version , options . environment )
: Promise . resolve ( true ) )
. then ( ( valid ) => {
if ( ! valid ) {
if ( conf . escalate ) {
return Promise . reject ( new api _1 . class _error _permission _denied ( ) ) ;
}
else {
lib _plankton . log . warning ( "api_permission_missing" , {
"version" : options . version ,
"environment" : options . environment ,
"action_name" : action . name ,
} ) ;
return Promise . resolve ( null ) ;
}
}
else {
return Promise . resolve ( null ) ;
}
} ) ) ;
} )
// validate and adjust input
. then ( ( ) => lib _plankton . call . promise _resolve ( validate ( options . checklevel _input , action . input _shape ( options . version ) , options . input , {
"kind" : "input" ,
} ) ) )
// execute
. then ( ( input ) => action . execution ( options . version , options . environment , options . input ) )
// validate output
. then ( ( output ) => lib _plankton . call . promise _resolve ( validate ( options . checklevel _output , action . output _shape ( options . version ) , output , {
"kind" : "output" ,
} ) ) ) ) ) ) ;
}
api _1 . call = call ;
/ * *
* @ author fenris
* /
function generate _documentation _for _action ( api , name , options = { } ) {
options = Object . assign ( {
"version" : null ,
} , options ) ;
const action = get _action ( api , name ) ;
let result = "" ;
if ( ! action . active ( options . version ) ) {
// do nothing
}
else {
// name
{
result += lib _plankton . markdown . sectionhead ( 2 , lib _plankton . markdown . code ( action . name ) ) ;
}
// description
{
result += lib _plankton . markdown . sectionhead ( 3 , "Description" ) ;
result += lib _plankton . markdown . paragraph ( action . description ? ? "-" ) ;
}
// input shape
{
result += lib _plankton . markdown . sectionhead ( 3 , "Input" ) ;
result += lib _plankton . markdown . paragraph ( lib _plankton . markdown . code ( lib _plankton . shape . show ( action . input _shape ( options . version ) ) ) ) ;
}
// output shape
{
result += lib _plankton . markdown . sectionhead ( 3 , "Output" ) ;
result += lib _plankton . markdown . paragraph ( lib _plankton . markdown . code ( lib _plankton . shape . show ( action . output _shape ( options . version ) ) ) ) ;
}
}
return result ;
}
api _1 . generate _documentation _for _action = generate _documentation _for _action ;
/ * *
* @ author fenris
* /
function generate _documentation ( api , options = { } ) {
options = Object . assign ( {
"version" : null ,
} , options ) ;
let result = "" ;
result += lib _plankton . markdown . paragraph ( api . title ) ;
result += lib _plankton . markdown . sectionhead ( 1 , "Actions" ) ;
// iterate through actions and use "generate_documentation_for_action"
Object . entries ( api . actions )
. forEach ( ( [ action _name , action ] ) => {
result += generate _documentation _for _action ( api , action _name , {
"version" : options . version ,
} ) ;
} ) ;
return result ;
}
api _1 . generate _documentation = generate _documentation ;
} ) ( api = lib _plankton . api || ( lib _plankton . api = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : api « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : api « 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 : api « 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 : api « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var api ;
( function ( api ) {
/ * *
* @ author fenris
* /
class class _api {
/ * *
* @ author fenris
* /
constructor ( subject ) {
this . subject = subject ;
}
/ * *
* @ author fenris
* /
static create ( name ) {
const subject = api . make ( name ) ;
return ( new class _api ( subject ) ) ;
}
/ * *
* @ author fenris
* /
register ( name , options = { } ) {
return api . register ( this . subject , name , options ) ;
}
/ * *
* @ author fenris
* /
call ( name , options = { } ) {
return api . call ( this . subject , name , options ) ;
}
/ * *
* @ author fenris
* /
generate _documentation _for _action ( name ) {
return api . generate _documentation _for _action ( this . subject , name ) ;
}
/ * *
* @ author fenris
* /
generate _documentation ( ) {
return api . generate _documentation ( this . subject ) ;
}
}
api . class _api = class _api ;
} ) ( api = lib _plankton . api || ( lib _plankton . api = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : rest « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : rest « 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 : rest « 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 : rest « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : rest « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : rest « 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 : rest « 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 : rest « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var rest ;
( function ( rest _1 ) {
/ * *
* /
function http _request _method _to _oas ( http _request _method ) {
switch ( http _request _method ) {
case lib _plankton . http . enum _method . get : return "get" ;
case lib _plankton . http . enum _method . post : return "post" ;
case lib _plankton . http . enum _method . patch : return "patch" ;
case lib _plankton . http . enum _method . head : return "head" ;
case lib _plankton . http . enum _method . delete : return "delete" ;
case lib _plankton . http . enum _method . options : return "options" ;
case lib _plankton . http . enum _method . put : return "put" ;
default : throw ( new Error ( "impossible" ) ) ;
}
}
/ * *
* /
function wildcard _step _decode ( step ) {
const matches = ( new RegExp ( "^:(.*)$" ) ) . exec ( step ) ;
if ( ( matches === null ) || ( matches . length < 2 ) ) {
return null ;
}
else {
return matches [ 1 ] ;
}
}
/ * *
* /
function wildcard _step _encode ( name ) {
return ( ":" + name ) ;
}
/ * *
* /
function routenode _iterate ( routenode , procedure , steps ) {
procedure ( routenode , steps ) ;
Object . entries ( routenode . sub _branch ) . forEach ( ( [ key , value ] ) => {
routenode _iterate ( value , procedure , steps . concat ( [ key ] ) ) ;
} ) ;
if ( ! ( routenode . sub _wildcard === null ) ) {
routenode _iterate ( routenode . sub _wildcard . node , procedure , steps . concat ( [ wildcard _step _encode ( routenode . sub _wildcard . name ) ] ) ) ;
}
}
/ * *
* /
function routenode _flatten ( routenode ) {
let list = [ ] ;
routenode _iterate ( routenode , ( routenode _ , steps ) => {
list . push ( { "steps" : steps , "node" : routenode _ } ) ;
} , [ ] ) ;
return list ;
}
/ * *
* /
function routenode _spawn ( steps , http _method , operation ) {
let routenode ;
if ( steps . length <= 0 ) {
routenode = {
"operations" : Object . fromEntries ( [ [ http _method , operation ] ] ) ,
"sub_branch" : { } ,
"sub_wildcard" : null ,
} ;
}
else {
const steps _head = steps [ 0 ] ;
const steps _tail = steps . slice ( 1 ) ;
const sub = routenode _spawn ( steps _tail , http _method , operation ) ;
const wildcard _name = wildcard _step _decode ( steps _head ) ;
if ( wildcard _name === null ) {
// branch
routenode = {
"operations" : { } ,
"sub_branch" : Object . fromEntries ( [ [ steps _head , sub ] ] ) ,
"sub_wildcard" : null ,
} ;
}
else {
// wildcard
routenode = {
"operations" : { } ,
"sub_branch" : { } ,
"sub_wildcard" : { "name" : wildcard _name , "node" : sub } ,
} ;
}
}
return routenode ;
}
/ * *
* /
function routenode _path _read ( routenode , steps ) {
if ( steps . length <= 0 ) {
return {
"steps" : [ ] ,
"rest" : [ ] ,
"routenode" : routenode ,
"parameters" : { } ,
} ;
}
else {
const path _head = steps [ 0 ] ;
const path _tail = steps . slice ( 1 ) ;
if ( path _head in routenode . sub _branch ) {
const result = routenode _path _read ( routenode . sub _branch [ path _head ] , path _tail ) ;
return {
"steps" : [ path _head ] . concat ( result . steps ) ,
"rest" : result . rest ,
"routenode" : result . routenode ,
"parameters" : result . parameters ,
} ;
}
else {
if ( ! ( routenode . sub _wildcard === null ) ) {
const result = routenode _path _read ( routenode . sub _wildcard . node , path _tail ) ;
if ( ! ( routenode . sub _wildcard . name in result . parameters ) ) {
// do nothing
}
else {
lib _plankton . log . warning ( "rest_overwriting_path_parameter" , {
"key" : routenode . sub _wildcard . name ,
"value_old" : result . parameters [ routenode . sub _wildcard . name ] ,
"value_new" : path _head ,
} ) ;
}
return {
"steps" : [ path _head ] . concat ( result . steps ) ,
"rest" : result . rest ,
"routenode" : result . routenode ,
"parameters" : lib _plankton . object . patched ( Object . fromEntries ( [ [ routenode . sub _wildcard . name , path _head ] ] ) , result . parameters ) ,
} ;
}
else {
return {
"steps" : [ path _head ] ,
"rest" : path _tail ,
"routenode" : routenode ,
"parameters" : { } ,
} ;
}
}
}
}
/ * *
* /
function routenode _path _write ( routenode , steps , http _method , operation , options = { } ) {
options = lib _plankton . object . patched ( {
"create" : false ,
} , options ) ;
if ( steps . length <= 0 ) {
if ( ! ( http _method in routenode . operations ) ) {
// do nothing
}
else {
lib _plankton . log . warning ( "rest_overwriting_action" , {
"http_method" : http _method ,
"steps" : steps ,
} ) ;
}
routenode . operations [ http _method ] = operation ;
}
else {
const steps _head = steps [ 0 ] ;
const steps _tail = steps . slice ( 1 ) ;
const wildcard _name = wildcard _step _decode ( steps _head ) ;
if ( ! ( wildcard _name === null ) ) {
// wildcard
if ( routenode . sub _wildcard === null ) {
if ( ! options . create ) {
throw ( new Error ( "may not create missing route" ) ) ;
}
else {
routenode . sub _wildcard = {
"name" : wildcard _name ,
"node" : routenode _spawn ( steps _tail , http _method , operation ) ,
} ;
}
}
else {
if ( ! ( routenode . sub _wildcard . name === wildcard _name ) ) {
/ *
lib _plankton . log . warning (
"rest_overwriting_wildcard_node" ,
{
"wildcard_name" : wildcard _name ,
}
) ;
* /
throw ( new Error ( "inconsistent wildcard name: '" + routenode . sub _wildcard . name + "' vs. '" + wildcard _name + "'" ) ) ;
}
else {
// walk
routenode _path _write ( routenode . sub _wildcard . node , steps _tail , http _method , operation , options ) ;
}
}
}
else {
if ( steps _head in routenode . sub _branch ) {
// walk branch
routenode _path _write ( routenode . sub _branch [ steps _head ] , steps _tail , http _method , operation , options ) ;
}
else {
// add branch
if ( ! options . create ) {
throw ( new Error ( "may not create missing route" ) ) ;
}
else {
routenode . sub _branch [ steps _head ] = routenode _spawn ( steps _tail , http _method , operation ) ;
}
}
}
}
}
/ * *
* /
function make ( options = { } ) {
options = lib _plankton . object . patched ( {
"title" : "REST-API" ,
"versioning_method" : "none" ,
"versioning_header_name" : "X-Api-Version" ,
"versioning_query_key" : "version" ,
"header_parameters" : [ ] ,
"set_access_control_headers" : false ,
"authentication" : {
"kind" : "none" ,
"parameters" : { } ,
} ,
"actions" : [ ] ,
} , options ) ;
const subject = {
"api" : lib _plankton . api . make ( options . title ) ,
"versioning_method" : options . versioning _method ,
"versioning_header_name" : options . versioning _header _name ,
"versioning_query_key" : options . versioning _query _key ,
"routetree" : {
"operations" : { } ,
"sub_branch" : { } ,
"sub_wildcard" : null ,
} ,
"header_parameters" : options . header _parameters ,
"set_access_control_headers" : options . set _access _control _headers ,
"authentication" : options . authentication ,
} ;
options . actions . forEach ( action _definition => {
rest . register ( subject , action _definition . http _method , action _definition . path , action _definition . options ) ;
} ) ;
return subject ;
}
rest _1 . make = make ;
/ * *
* /
function register ( rest , http _method , path , options ) {
options = lib _plankton . object . patched ( {
"active" : ( ( version ) => true ) ,
"execution" : ( ( stuff ) => Promise . resolve ( { "status_code" : 501 , "data" : null } ) ) ,
"restriction" : ( ( stuff ) => Promise . resolve ( true ) ) ,
"input_schema" : ( ( version ) => ( { } ) ) ,
"output_schema" : ( ( version ) => ( { } ) ) ,
"title" : null ,
"description" : null ,
"query_parameters" : [ ] ,
"request_body_mimetype" : "application/json" ,
"request_body_decode" : ( ( http _request _body , http _request _header _content _type ) => ( ( ( http _request _header _content _type !== null )
&&
( http _request _header _content _type . startsWith ( "application/json" ) )
&&
( http _request _body !== null )
&&
( http _request _body . toString ( ) !== "" ) )
? JSON . parse ( http _request _body . toString ( ) )
: ( ( http _request _body !== null )
? http _request _body . toString ( )
: null ) ) ) ,
"response_body_mimetype" : "application/json" ,
// TODO: no "from"?
"response_body_encode" : ( ( output ) => Buffer [ "from" ] ( JSON . stringify ( output ) ) ) ,
} , options ) ;
const steps = lib _plankton . string . split ( path , "/" ) . slice ( 1 ) ;
const steps _enriched = ( ( rest . versioning _method === "path" )
? [ "{version}" ] . concat ( steps )
: steps ) ;
const action _name = ( steps . concat ( [ lib _plankton . http . encode _method ( http _method ) . toLowerCase ( ) ] )
. join ( "_" ) ) ;
const operation = {
"action_name" : action _name ,
"query_parameters" : options . query _parameters ,
"request_body_mimetype" : options . request _body _mimetype ,
"request_body_decode" : options . request _body _decode ,
"response_body_mimetype" : options . response _body _mimetype ,
"response_body_encode" : options . response _body _encode ,
"input_schema" : options . input _schema ,
"output_schema" : options . output _schema ,
} ;
routenode _path _write ( rest . routetree , steps _enriched , http _method , operation , {
"create" : true ,
} ) ;
lib _plankton . api . register ( rest . api , action _name , {
"active" : options . active ,
"execution" : ( version , environment , input ) => options . execution ( {
"version" : version ,
"path_parameters" : environment . path _parameters ,
"query_parameters" : environment . query _parameters ,
"headers" : environment . headers ,
"input" : input
} ) ,
"restriction" : ( version , environment ) => options . restriction ( {
"version" : version ,
"path_parameters" : environment . path _parameters ,
"query_parameters" : environment . query _parameters ,
"headers" : environment . headers ,
} ) ,
"title" : options . title ,
"description" : options . description ,
// TODO
// "input_shape": options.input_type,
// "output_shape": options.output_type,
} ) ;
lib _plankton . log . debug ( "rest_route_added" , {
"http_method" : http _method ,
"path" : path ,
// "routetree": rest.routetree,
} ) ;
}
rest _1 . register = register ;
/ * *
* @ todo check request body mimetype ?
* @ todo check query paramater validity
* /
async function call ( rest , http _request , options = { } ) {
options = /*lib_plankton.object.patched*/ Object . assign ( {
"checklevel_restriction" : lib _plankton . api . enum _checklevel . hard ,
"checklevel_input" : lib _plankton . api . enum _checklevel . soft ,
"checklevel_output" : lib _plankton . api . enum _checklevel . soft ,
} , options ) ;
lib _plankton . log . info ( "rest_call" , {
"http_request" : {
"scheme" : http _request . scheme ,
"host" : http _request . host ,
"path" : http _request . path ,
"version" : http _request . version ,
"method" : http _request . method ,
"query" : http _request . query ,
"headers" : http _request . headers ,
"body" : String ( http _request . body ) ,
}
} ) ;
// parse target and query parameters
// const url_stuff : URL = new URL("http://dummy" + http_request.target);
const path = http _request . path ;
const query _parameters _raw = new URLSearchParams ( http _request . query ) ;
let query _parameters = { } ;
for ( const [ key , value ] of query _parameters _raw ) {
query _parameters [ key ] = value ;
}
const steps = lib _plankton . string . split ( path , "/" ) . slice ( 1 ) ;
if ( steps . length <= 0 ) {
throw ( new Error ( "empty path" ) ) ;
}
else {
// resolve
const stuff = routenode _path _read ( rest . routetree , steps ) ;
const allowed _methods = ( Object . keys ( stuff . routenode . operations )
. map ( x => lib _plankton . http . encode _method ( x ) )
. join ( ", " ) ) ;
// get version
let version ;
switch ( rest . versioning _method ) {
case "none" : {
version = null ;
break ;
}
case "path" : {
version = stuff . parameters [ "version" ] ;
// delete stuff.parameters["version"];
break ;
}
case "header" : {
version = http _request . headers [ rest . versioning _header _name ] ;
// delete http_request.headers[rest.versioning_header_name];
break ;
}
case "query" : {
version = query _parameters [ rest . versioning _query _key ] ;
// delete query_parameters[rest.versioning_query_key];
break ;
}
default : {
throw ( new Error ( "unhandled versioning method: " + rest . versioning _method ) ) ;
break ;
}
}
const additional _response _headers = ( rest . set _access _control _headers
? {
"Access-Control-Allow-Headers" : ( ( [
"Content-Type" ,
"X-Api-Key" ,
]
. concat ( ( rest . versioning _header _name !== null )
? [ rest . versioning _header _name ]
: [ ] )
. concat ( ( rest . authentication . kind === "key_header" )
? [ rest . authentication . parameters [ "name" ] ]
: [ ] ) )
. join ( ", " ) ) ,
"Access-Control-Allow-Origin" : "*" ,
"Access-Control-Allow-Methods" : allowed _methods ,
}
: { } ) ;
if ( stuff . rest . length > 0 ) {
return {
"version" : "HTTP/1.1" ,
"status_code" : 404 ,
"headers" : { } ,
"body" : null ,
} ;
}
else {
if ( http _request . method === lib _plankton . http . enum _method . options ) {
return {
"version" : "HTTP/1.1" ,
"status_code" : 200 ,
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : null ,
} ;
}
else {
if ( ! ( http _request . method in stuff . routenode . operations ) ) {
if ( Object . keys ( stuff . routenode . operations ) . length <= 0 ) {
return {
"version" : "HTTP/1.1" ,
"status_code" : 404 ,
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : null ,
} ;
}
else {
return {
"version" : "HTTP/1.1" ,
"status_code" : 405 ,
"headers" : Object . assign ( {
"Allow" : allowed _methods ,
} , additional _response _headers ) ,
"body" : null ,
} ;
}
}
else {
// call
let result ;
let error ;
const operation = stuff . routenode . operations [ http _request . method ] ;
const stuff _ = {
"version" : version ,
"headers" : http _request . headers ,
"path_parameters" : stuff . parameters ,
"query_parameters" : query _parameters ,
"input" : ( ( http _request . body === null )
? null
: operation . request _body _decode ( http _request . body , ( http _request . headers [ "Content-Type" ]
? ?
http _request . headers [ "content-type" ]
? ?
null ) ) ) ,
} ;
/ *
const allowed : boolean = (
( operation . restriction === null )
? true
: operation . restriction ( stuff _ )
) ;
* /
let response ;
/ *
if ( ! allowed ) {
lib _plankton . log . error (
"rest_access_denied" ,
{
"http_request" : {
"target" : http _request . target ,
"method" : http _request . method ,
"headers" : http _request . headers ,
"body" : (
( http _request . body === null )
? null
: lib _plankton . string . limit ( http _request . body . toString ( ) , { "length" : 200 } )
) ,
} ,
}
) ;
response = {
"version" : "HTTP/1.1" ,
"status_code" : 403 ,
"headers" : Object . assign (
{
} ,
additional _response _headers
) ,
"body" : Buffer [ "from" ] ( "forbidden" ) ,
} ;
}
else * / {
try {
result = await lib _plankton . api . call ( rest . api , operation . action _name , {
"version" : stuff _ . version ,
"environment" : {
"headers" : stuff _ . headers ,
"path_parameters" : stuff _ . path _parameters ,
"query_parameters" : stuff _ . query _parameters ,
} ,
"input" : stuff _ . input ,
"checklevel_restriction" : options . checklevel _restriction ,
"checklevel_input" : options . checklevel _input ,
"checklevel_output" : options . checklevel _output ,
} ) ;
error = null ;
}
catch ( error _ ) {
result = null ;
error = error _ ;
}
if ( ( result === null ) || ( error !== null ) ) {
if ( error instanceof lib _plankton . api . class _error _permission _denied ) {
response = {
"version" : "HTTP/1.1" ,
"status_code" : 403 ,
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : null ,
} ;
}
else {
lib _plankton . log . error ( "rest_execution_failed" , {
"http_request" : {
"version" : http _request . version ,
"scheme" : http _request . scheme ,
"method" : http _request . method ,
"path" : http _request . path ,
"query" : http _request . query ,
"headers" : http _request . headers ,
"body" : ( ( http _request . body === null )
? null
: lib _plankton . string . limit ( http _request . body . toString ( ) , { "length" : 200 } ) ) ,
} ,
"error" : {
"message" : error . toString ( ) ,
"file_name" : error . fileName ,
"line_number" : error . lineNumber ,
"stack" : error . stack ,
} ,
} ) ;
response = {
"version" : "HTTP/1.1" ,
"status_code" : 500 ,
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : Buffer [ "from" ] ( "internal error" ) ,
} ;
}
}
else {
// encode
response = {
"version" : "HTTP/1.1" ,
"status_code" : result . status _code ,
"headers" : Object . assign ( {
"Content-Type" : operation . response _body _mimetype ,
} , additional _response _headers ) ,
"body" : operation . response _body _encode ( result . data ) ,
} ;
}
}
return response ;
}
}
}
}
}
rest _1 . call = call ;
/ * *
* @ see https : //swagger.io/specification/#openrest-object
* /
function to _oas ( rest , options = { } ) {
options = lib _plankton . object . patched ( {
"version" : null ,
"servers" : [ ] ,
} , options ) ;
const subject = rest ;
const version = ( options . version ? ? "-" ) ;
return {
"openapi" : "3.0.3" ,
"info" : {
"version" : version ,
"title" : ( rest . api . title ? ? "API" ) ,
// "description": (rest.api.description ?? undefined),
} ,
"servers" : options . servers . map ( url => ( { "url" : url } ) ) ,
"components" : {
"securitySchemes" : ( ( ( description ) => ( {
"none" : { } ,
"key_header" : {
"default_security_schema" : {
"type" : "restKey" ,
"in" : "header" ,
"name" : description . parameters [ "name" ] ,
} ,
} ,
} [ description . kind ] ) ) ( rest . authentication ) ) ,
} ,
"security" : [
{
"default_security_schema" : [ ] ,
}
] ,
"paths" : lib _plankton . call . convey ( rest . routetree , [
routenode _flatten ,
( x ) => x . map ( ( entry ) => {
const steps _ = entry . steps ;
const path = lib _plankton . string . join ( steps _ , "_" ) ;
const key = ( ( steps _ . length <= 0 )
? "/"
: lib _plankton . string . join ( [ "" ] . concat ( steps _
. map ( step => ( ( wildcard _step _decode ( step ) !== null )
? ( "{" + wildcard _step _decode ( step ) + "}" )
: step ) ) ) , "/" ) ) ;
return [
key ,
lib _plankton . call . convey ( entry . node . operations , [
x => Object . entries ( x ) ,
( pairs ) => pairs . map ( ( [ http _method , operation ] ) => ( [
http _request _method _to _oas ( http _method ) ,
{
"operationId" : ( http _request _method _to _oas ( http _method )
+
"_"
+
path ) ,
"summary" : ( operation . title
? ?
[ "" ] . concat ( steps _ ) . join ( " " ) ) ,
"description" : ( lib _plankton . api . get _action ( rest . api , operation . action _name ) . description
? ?
"(missing)" ) ,
"parameters" : [ ] . concat (
// header parameters
rest . header _parameters . map ( header _parameter => ( {
"name" : header _parameter . name ,
"in" : "header" ,
"required" : header _parameter . required ,
"schema" : {
"type" : "string" ,
} ,
"description" : ( header _parameter . description ? ? undefined ) ,
} ) ) ,
// path parameters
lib _plankton . call . convey ( steps _ , [
x => x . map ( y => wildcard _step _decode ( y ) ) ,
x => x . filter ( y => ( ! ( y === null ) ) ) ,
x => x . map ( y => ( {
"name" : y ,
"in" : "path" ,
"required" : true ,
"schema" : {
"type" : "string" ,
} ,
} ) ) ,
] ) ,
// query parameters
operation . query _parameters . map ( ( query _parameter ) => ( {
"name" : query _parameter . name ,
"in" : "query" ,
"required" : query _parameter . required ,
"schema" : {
"type" : "string" ,
} ,
"description" : ( query _parameter . description ? ? undefined ) ,
} ) ) ) ,
"requestBody" : ( ( [
lib _plankton . http . enum _method . get ,
lib _plankton . http . enum _method . head ,
lib _plankton . http . enum _method . delete ,
] . includes ( http _method ) )
? undefined
: {
"content" : Object . fromEntries ( [
[
operation . request _body _mimetype ,
{
"schema" : operation . input _schema ( options . version ) ,
}
]
] )
} ) ,
"responses" : {
"default" : {
"description" : "" ,
"content" : Object . fromEntries ( [
[
operation . response _body _mimetype ,
{
"schema" : operation . output _schema ( options . version ) ,
}
]
] ) ,
}
} ,
}
] ) ) ,
( pairs ) => Object . fromEntries ( pairs ) ,
] ) ,
] ;
} ) ,
x => x . filter ( y => ( Object . keys ( y [ 1 ] ) . length > 0 ) ) ,
x => Object . fromEntries ( x ) ,
] )
} ;
}
rest _1 . to _oas = to _oas ;
} ) ( rest = lib _plankton . rest || ( lib _plankton . rest = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : file « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : file « 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 : file « 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 : file « . If not , see < http : //www.gnu.org/licenses/>.
* /
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
* /
function read ( path ) {
var nm _fs = require ( "fs" ) ;
return ( new Promise ( function ( resolve , reject ) {
nm _fs . readFile ( path , {
"encoding" : "utf8" ,
"flag" : "r"
} , function ( error , content ) {
if ( error == null ) {
resolve ( content ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
}
file . read = read ;
/ * *
* @ author fenris
* /
function read _buffer ( path ) {
var nm _fs = require ( "fs" ) ;
return ( new Promise ( function ( resolve , reject ) {
nm _fs . readFile ( path , {
"flag" : "r"
} , function ( error , content ) {
if ( error == null ) {
resolve ( content ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
}
file . read _buffer = read _buffer ;
/ * *
* @ author fenris
* /
function read _stdin ( ) {
return ( new Promise ( function ( resolve , reject ) {
var input _raw = "" ;
process . stdin . setEncoding ( "utf8" ) ;
process . stdin . on ( "readable" , function ( ) {
var chunk ;
while ( ( chunk = process . stdin . read ( ) ) !== null ) {
input _raw += chunk ;
}
} ) ;
process . stdin . on ( "end" , function ( ) {
resolve ( input _raw ) ;
} ) ;
} ) ) ;
}
file . read _stdin = read _stdin ;
/ * *
* @ author fenris
* /
function write ( path , content , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"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"
} , function ( error ) {
if ( error == null ) {
resolve ( undefined ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
}
file . write = write ;
/ * *
* @ author fenris
* /
function write _buffer ( path , content , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( { } , options ) ;
var nm _fs = require ( "fs" ) ;
return ( new Promise ( function ( resolve , reject ) {
nm _fs . writeFile ( path , content , {
"flag" : "w"
} , function ( error ) {
if ( error == null ) {
resolve ( undefined ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
}
file . write _buffer = write _buffer ;
/ * *
* /
function delete _ ( path ) {
var nm _fs = require ( "fs" ) ;
return ( new Promise ( function ( resolve , reject ) {
nm _fs . unlink ( path , function ( ) {
resolve ( undefined ) ;
} ) ;
} ) ) ;
}
file . delete _ = delete _ ;
} ) ( file = lib _plankton . file || ( lib _plankton . file = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : sha256 « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : sha256 « 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 : sha256 « 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 : sha256 « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var sha256 ;
( function ( sha256 ) {
/ * *
* @ author fenris
* /
function get ( value , secret = "" ) {
const nm _crypto = require ( "crypto" ) ;
const sha256Hasher = nm _crypto . createHmac ( "sha256" , secret ) ;
const hash = sha256Hasher . update ( value ) . digest ( "hex" ) ;
return hash ;
}
sha256 . get = get ;
} ) ( sha256 = lib _plankton . sha256 || ( lib _plankton . sha256 = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : args « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : args « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : args « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : args « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var args ;
( function ( args ) {
/ * *
* /
var enum _environment ;
( function ( enum _environment ) {
enum _environment [ "cli" ] = "cli" ;
enum _environment [ "url" ] = "url" ;
} ) ( enum _environment = args . enum _environment || ( args . enum _environment = { } ) ) ;
;
/ * *
* /
var enum _kind ;
( function ( enum _kind ) {
enum _kind [ "positional" ] = "positional" ;
enum _kind [ "volatile" ] = "volatile" ;
} ) ( enum _kind = args . enum _kind || ( args . enum _kind = { } ) ) ;
;
/ * *
* /
var enum _type ;
( function ( enum _type ) {
enum _type [ "boolean" ] = "boolean" ;
enum _type [ "integer" ] = "int" ;
enum _type [ "float" ] = "float" ;
enum _type [ "string" ] = "string" ;
} ) ( enum _type = args . enum _type || ( args . enum _type = { } ) ) ;
;
/ * *
* /
var enum _mode ;
( function ( enum _mode ) {
enum _mode [ "replace" ] = "replace" ;
enum _mode [ "accumulate" ] = "accumulate" ;
} ) ( enum _mode = args . enum _mode || ( args . enum _mode = { } ) ) ;
;
} ) ( args = lib _plankton . args || ( lib _plankton . args = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : args « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : args « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : args « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : args « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var args ;
( function ( args ) {
/ *
export enum _mode {
replace = "replace" ,
accumulate = "accumulate" ,
} ;
* /
/ * *
* @ author fenris
* /
var class _argument = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _argument ( _a ) {
var name = _a [ "name" ] , _b = _a [ "type" ] , type = _b === void 0 ? args . enum _type . string : _b , _c = _a [ "kind" ] , kind = _c === void 0 ? args . enum _kind . positional : _c , _d = _a [ "mode" ] , mode = _d === void 0 ? args . enum _mode . replace : _d , _e = _a [ "default" ] , default _ = _e === void 0 ? null : _e , _f = _a [ "info" ] , info = _f === void 0 ? null : _f , _g = _a [ "parameters" ] , parameters = _g === void 0 ? { } : _g , _h = _a [ "hidden" ] , hidden = _h === void 0 ? false : _h ;
this . name = name ;
this . type = type ;
this . kind = kind ;
this . mode = mode ;
this . default _ = default _ ;
this . info = info ;
this . parameters = parameters ;
this . hidden = hidden ;
if ( ! this . check ( ) ) {
throw ( new Error ( "invalid argument-setup" ) ) ;
}
}
/ * *
* @ author fenris
* /
class _argument . positional = function ( _a ) {
var name = _a [ "name" ] , _b = _a [ "type" ] , type = _b === void 0 ? args . enum _type . string : _b , _c = _a [ "mode" ] , mode = _c === void 0 ? args . enum _mode . replace : _c , _d = _a [ "default" ] , default _ = _d === void 0 ? null : _d , _e = _a [ "info" ] , info = _e === void 0 ? null : _e , _f = _a [ "hidden" ] , hidden = _f === void 0 ? false : _f , index = _a [ "index" ] ;
return ( new class _argument ( {
"name" : name ,
"kind" : args . enum _kind . positional ,
"type" : type ,
"mode" : mode ,
"default" : default _ ,
"info" : info ,
"hidden" : hidden ,
"parameters" : {
"index" : index
}
} ) ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . volatile = function ( _a ) {
var name = _a [ "name" ] , _b = _a [ "type" ] , type = _b === void 0 ? args . enum _type . string : _b , _c = _a [ "mode" ] , mode = _c === void 0 ? args . enum _mode . replace : _c , _d = _a [ "default" ] , default _ = _d === void 0 ? null : _d , _e = _a [ "info" ] , info = _e === void 0 ? null : _e , _f = _a [ "hidden" ] , hidden = _f === void 0 ? false : _f , indicators _short = _a [ "indicators_short" ] , indicators _long = _a [ "indicators_long" ] ;
return ( new class _argument ( {
"name" : name ,
"kind" : args . enum _kind . volatile ,
"type" : type ,
"mode" : mode ,
"default" : default _ ,
"info" : info ,
"hidden" : hidden ,
"parameters" : {
"indicators_short" : indicators _short ,
"indicators_long" : indicators _long
}
} ) ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . check = function ( ) {
var _this = this ;
return [
function ( ) { return ( ( ! ( _this . kind == args . enum _kind . volatile ) )
||
( ( "indicators_long" in _this . parameters )
&&
( _this . parameters [ "indicators_long" ] [ "length" ] >= 0 ) ) ) ; } ,
] . every ( function ( condition ) { return condition ( ) ; } ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . name _get = function ( ) {
return this . name ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . kind _get = function ( ) {
return this . kind ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . type _get = function ( ) {
return this . type ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . mode _get = function ( ) {
return this . mode ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . default _get = function ( ) {
return this . default _ ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . parameters _get = function ( ) {
return this . parameters ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . hidden _get = function ( ) {
return this . hidden ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . toString = function ( ) {
return "<" . concat ( this . name , ">" ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . indicator _main = function ( ) {
if ( this . kind === args . enum _kind . volatile ) {
return this . parameters [ "indicators_long" ] [ 0 ] ;
}
else {
return null ;
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . pattern _value = function ( ) {
switch ( this . type ) {
case args . enum _type . boolean : {
return "false|true" ;
break ;
}
case args . enum _type . integer : {
return "[0-9]+" ;
break ;
}
case args . enum _type . float : {
return "\\d*(?:\\.\\d+)?" ;
break ;
}
case args . enum _type . string : {
return "\\S+" ;
break ;
}
default : {
throw ( new Error ( "unhandled type " . concat ( this . type ) ) ) ;
break ;
}
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . extract = function ( raw ) {
switch ( this . type ) {
case args . enum _type . boolean : {
return ( raw != "false" ) ;
break ;
}
case args . enum _type . integer : {
return parseInt ( raw ) ;
break ;
}
case args . enum _type . float : {
return parseFloat ( raw ) ;
break ;
}
case args . enum _type . string : {
return raw ;
break ;
}
default : {
throw ( new Error ( "unhandled type " . concat ( this . type ) ) ) ;
break ;
}
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . assign = function ( data , target , raw ) {
var value = this . extract ( raw ) ;
switch ( this . mode ) {
case args . enum _mode . replace : {
data [ target ] = value ;
break ;
}
case args . enum _mode . accumulate : {
/ *
if ( ! ( this . name in data ) ) {
data [ this . name ] = [ ] ;
}
* /
data [ target ] . push ( value ) ;
break ;
}
default : {
throw ( new Error ( "unhandled mode " . concat ( this . mode ) ) ) ;
}
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . make = function ( data , target ) {
var value = data [ target ] ;
return value . toString ( ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . generate _help = function ( ) {
var _this = this ;
var _a , _b , _c , _d ;
var output = "" ;
{
switch ( this . kind ) {
case args . enum _kind . positional : {
var line = "" ;
line += "\t" ;
line += "<" . concat ( this . name , ">" ) ;
line += "\n" ;
output += line ;
}
case args . enum _kind . volatile : {
var line = "" ;
line += "\t" ;
if ( this . type === args . enum _type . boolean ) {
line += ( [ ]
. concat ( ( ( _a = this . parameters [ "indicators_short" ] ) !== null && _a !== void 0 ? _a : [ ] ) . map ( function ( indicator ) { return ( "-" + indicator ) ; } ) )
. concat ( ( ( _b = this . parameters [ "indicators_long" ] ) !== null && _b !== void 0 ? _b : [ ] ) . map ( function ( indicator ) { return ( "--" + indicator ) ; } ) )
. join ( " | " ) ) ;
}
else {
line += ( [ ]
. concat ( ( ( _c = this . parameters [ "indicators_short" ] ) !== null && _c !== void 0 ? _c : [ ] ) . map ( function ( indicator ) { return ( "-" + indicator + " " + ( "<" + _this . name + ">" ) ) ; } ) )
. concat ( ( ( _d = this . parameters [ "indicators_long" ] ) !== null && _d !== void 0 ? _d : [ ] ) . map ( function ( indicator ) { return ( "--" + indicator + "=" + ( "<" + _this . name + ">" ) ) ; } ) )
. join ( " | " ) ) ;
}
line += "\n" ;
output += line ;
}
}
}
{
var line = "" ;
line += "\t\t" ;
var infotext = ( ( this . info == null ) ? "(no info available)" : this . info ) ;
line += infotext ;
if ( ( this . type != "boolean" ) && ( this . default _ != null ) ) {
line += "; default: " . concat ( this . default _ . toString ( ) ) ;
}
line += "\n" ;
output += line ;
}
return output ;
} ;
return class _argument ;
} ( ) ) ;
args . class _argument = class _argument ;
} ) ( args = lib _plankton . args || ( lib _plankton . args = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : args « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : args « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : args « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : args « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var args ;
( function ( args ) {
/ * *
* @ author fenris
* /
var settings = {
"environment" : {
"cli" : {
"symbols" : {
"delimiter" : " " ,
"prefix" : "--" ,
"assignment" : "="
}
} ,
"url" : {
"symbols" : {
"delimiter" : "&" ,
"prefix" : "" ,
"assignment" : "="
}
}
}
} ;
/ * *
* @ author fenris
* /
args . verbosity = 0 ;
/ * *
* @ author fenris
* @ todo check validity
* /
var class _handler = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _handler ( arguments _ ) {
this . arguments _ = arguments _ ;
}
/ * *
* @ author fenris
* /
class _handler . prototype . filter = function ( kind ) {
var arguments _ = { } ;
for ( var _i = 0 , _a = Object . entries ( this . arguments _ ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
if ( argument . kind _get ( ) == kind ) {
arguments _ [ name ] = argument ;
}
}
return arguments _ ;
} ;
/ * *
* @ author fenris
* /
class _handler . prototype . read = function ( environment , input , data ) {
var _this = this ;
if ( data === void 0 ) { data = { } ; }
switch ( environment ) {
case args . enum _environment . cli :
case args . enum _environment . url : {
// default values
{
for ( var _i = 0 , _a = Object . entries ( this . arguments _ ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
data [ name ] = argument . default _get ( ) ;
}
}
// preprocessing
{
// short indicators (lil hacky ...)
{
if ( environment == args . enum _environment . cli ) {
for ( var _c = 0 , _d = Object . entries ( this . filter ( args . enum _kind . volatile ) ) ; _c < _d . length ; _c ++ ) {
var _e = _d [ _c ] , name = _e [ 0 ] , argument = _e [ 1 ] ;
// console.info(argument.parameters_get()["indicators_short"].join("|"));
var pattern _from = "" ;
{
pattern _from += "(?:^|" . concat ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] , ")" ) ;
pattern _from += "-" . concat ( argument . parameters _get ( ) [ "indicators_short" ] . join ( "|" ) ) ;
pattern _from += "(?:$|" . concat ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] , ")" ) ;
}
var pattern _to = "" ;
{
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "prefix" ] ;
pattern _to += argument . indicator _main ( ) ;
if ( argument . type _get ( ) == args . enum _type . boolean ) {
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
}
else {
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ] ;
}
}
var result = input . replace ( new RegExp ( pattern _from , "g" ) , pattern _to ) ;
lib _plankton . log . debug ( "lib_args:read:replacing" , {
"pattern_from" : pattern _from ,
"pattern_to" : pattern _to ,
"input" : input ,
"result" : result
} ) ;
input = result ;
}
}
}
lib _plankton . log . debug ( "lib_args:read:current_input" , {
"input" : input
} ) ;
}
// parsing
{
var parts = input
. split ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] )
. filter ( function ( x ) { return ( x != "" ) ; } ) ;
var index _expected _1 = 0 ;
parts . forEach ( function ( part ) {
lib _plankton . log . debug ( "lib_args:read:analyzing" , {
"part" : part
} ) ;
var found = [
function ( ) {
lib _plankton . log . debug ( "lib_args:read:probing_as_volatile" , {
"part" : part
} ) ;
for ( var _i = 0 , _a = Object . entries ( _this . filter ( args . enum _kind . volatile ) ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
lib _plankton . log . debug ( "lib_args:read:probing_as_volatile:trying" , {
"part" : part ,
"argument" : argument . toString ( )
} ) ;
var pattern = "" ;
{
var pattern _front = "" ;
pattern _front += "" . concat ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "prefix" ] ) ;
pattern _front += "(?:" . concat ( argument . parameters _get ( ) [ "indicators_long" ] . join ( "|" ) , ")" ) ;
pattern += pattern _front ;
}
{
var pattern _back = "" ;
pattern _back += "" . concat ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ] ) ;
pattern _back += "(" . concat ( argument . pattern _value ( ) , ")" ) ;
if ( argument . type _get ( ) == args . enum _type . boolean ) {
pattern _back = "(?:" . concat ( pattern _back , ")?" ) ;
}
pattern += pattern _back ;
}
lib _plankton . log . debug ( "lib_args:read:probing_as_volatile:pattern" , {
"pattern" : pattern
} ) ;
var regexp = new RegExp ( pattern ) ;
var matching = regexp . exec ( part ) ;
lib _plankton . log . debug ( "lib_args:read:probing_as_volatile:matching" , {
"matching" : matching
} ) ;
if ( matching == null ) {
// do nothing
}
else {
argument . assign ( data , name , matching [ 1 ] ) ;
return true ;
}
}
return false ;
} ,
function ( ) {
lib _plankton . log . debug ( "lib_args:read:probing_as_positional" , {
"part" : part
} ) ;
var positional = _this . filter ( args . enum _kind . positional ) ;
for ( var _i = 0 , _a = Object . entries ( positional ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
if ( argument . parameters _get ( ) [ 'index' ] !== index _expected _1 ) {
// do nothing
}
else {
lib _plankton . log . debug ( "lib_args:read:probing_as_positional:trying" , {
"part" : part ,
"argument" : argument . toString ( )
} ) ;
var pattern = "" ;
{
var pattern _back = "" ;
pattern _back += "(" . concat ( argument . pattern _value ( ) , ")" ) ;
pattern += pattern _back ;
}
lib _plankton . log . debug ( "lib_args:read:probing_as_positional:pattern" , {
"pattern" : pattern
} ) ;
var regexp = new RegExp ( pattern ) ;
var matching = regexp . exec ( part ) ;
lib _plankton . log . debug ( "lib_args:read:probing_as_positional:matching" , {
"matching" : matching
} ) ;
if ( matching == null ) {
return false ;
}
else {
argument . assign ( data , name , matching [ 1 ] ) ;
index _expected _1 += 1 ;
return true ;
}
}
}
return false ;
} ,
] . some ( function ( x ) { return x ( ) ; } ) ;
if ( ! found ) {
lib _plankton . log . warning ( "lib_args:read:could_not_parse" , {
"part" : part
} ) ;
}
} ) ;
}
return data ;
break ;
}
default : {
throw ( new Error ( "unhandled environment " . concat ( environment ) ) ) ;
break ;
}
}
} ;
/ * *
* @ author fenris
* @ todo handle if the data object doesn ' t have the required field or the type is wrong or sth .
* /
class _handler . prototype . write = function ( environment , data ) {
switch ( environment ) {
case args . enum _environment . cli : {
return ( ( [ ]
. concat ( Object . entries ( this . filter ( args . enum _kind . volatile ) ) . map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var values ;
switch ( argument . mode _get ( ) ) {
case args . enum _mode . replace : {
values = [ data [ argument . name _get ( ) ] ] ;
break ;
}
case args . enum _mode . accumulate : {
values = data [ argument . name _get ( ) ] ;
break ;
}
}
return ( values
. map ( function ( value ) { return ( ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "prefix" ]
+
argument . parameters _get ( ) [ "indicators_long" ] [ 0 ] )
+
( settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ]
+
value . toString ( ) ) ) ; } )
. join ( " " ) ) ;
} ) )
. concat ( Object . entries ( this . filter ( args . enum _kind . positional ) ) . map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var raw = "" ;
{
var raw _back = "" ;
raw _back += argument . make ( data , name ) ;
raw += raw _back ;
}
return raw ;
} ) ) )
. join ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ) ) ;
break ;
}
default : {
throw ( new Error ( "unhandled environment " . concat ( environment ) ) ) ;
break ;
}
}
} ;
/ * *
* @ desc manpage - like info - sheet
* @ author fenris
* /
class _handler . prototype . generate _help = function ( _a ) {
var _b = _a [ "programname" ] , programname = _b === void 0 ? null : _b , _c = _a [ "author" ] , author = _c === void 0 ? null : _c , _d = _a [ "description" ] , description = _d === void 0 ? null : _d , _e = _a [ "executable" ] , executable = _e === void 0 ? null : _e ;
var environment = args . enum _environment . cli ;
var output = "" ;
{
var section = "" ;
{
var line = "" ;
line += "" ;
line += "INFO" ;
line += "\n" ;
section += line ;
}
{
var line = "" ;
line += "\t" ;
line += "" . concat ( programname , " -- " ) . concat ( description ) ;
line += "\n" ;
section += line ;
}
section += "\n" ;
output += section ;
}
{
if ( author != null ) {
var section = "" ;
{
var line = "" ;
line += "" ;
line += "AUTHOR" ;
line += "\n" ;
section += line ;
}
{
var line = "" ;
line += "\t" ;
line += "" . concat ( author ) ;
line += "\n" ;
section += line ;
}
section += "\n" ;
output += section ;
}
}
{
var section = "" ;
{
var line = "" ;
line += "" ;
line += "SYNOPSIS" ;
line += "\n" ;
section += line ;
}
{
var line = "" ;
line += "\t" ;
line += executable ;
line += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
line += Object . entries ( this . filter ( args . enum _kind . positional ) )
. map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var part = "" ;
part += "<" . concat ( argument . name _get ( ) , ">" ) ;
return part ;
} )
. join ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ) ;
line += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
line += Object . entries ( this . filter ( args . enum _kind . volatile ) )
. filter ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
return ( ! argument . hidden _get ( ) ) ;
} )
. map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var part = "" ;
// part += settings["environment"][environment]["symbols"]["prefix"];
part += "-" ;
part += argument . parameters _get ( ) [ "indicators_short" ] [ 0 ] ;
if ( argument . type _get ( ) != "boolean" ) {
/ *
part += settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ] ;
part += ` < ${ argument . name _get ( ) } > ` ;
* /
part += " " ;
part += "<" . concat ( argument . name _get ( ) , ">" ) ;
}
part = "[" . concat ( part , "]" ) ;
return part ;
} )
. join ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ) ;
line += "\n" ;
section += line ;
}
section += "\n" ;
output += section ;
}
{
var section = "" ;
{
var line = "" ;
line += "" ;
line += "OPTIONS" ;
line += "\n" ;
section += line ;
}
{
section += ( Object . entries ( this . arguments _ )
. filter ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
return ( ! argument . hidden _get ( ) ) ;
} )
. map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
return argument . generate _help ( ) ;
} )
. join ( "\n" ) ) ;
}
section += "\n" ;
output += section ;
}
return output ;
} ;
return class _handler ;
} ( ) ) ;
args . class _handler = class _handler ;
} ) ( args = lib _plankton . args || ( lib _plankton . args = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : json « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : json « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : json « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : json « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var json ;
( function ( json ) {
/ * *
* @ author fenris
* /
function encode ( x , formatted = false ) {
return JSON . stringify ( x , undefined , formatted ? "\t" : undefined ) ;
}
json . encode = encode ;
/ * *
* @ author fenris
* /
function decode ( x ) {
return JSON . parse ( x ) ;
}
json . decode = decode ;
} ) ( json = lib _plankton . json || ( lib _plankton . json = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : json « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : json « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : json « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : json « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var json ;
( function ( json ) {
/ * *
* @ author fenris
* /
class class _json {
/ * *
* @ author fenris
* /
constructor ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
encode ( x ) {
return json . encode ( x ) ;
}
/ * *
* @ implementation
* @ author fenris
* /
decode ( x ) {
return json . decode ( x ) ;
}
}
json . class _json = class _json ;
} ) ( json = lib _plankton . json || ( lib _plankton . json = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;