2024-04-22 10:02:34 +02:00
/ *
This file is part of » bacterio - plankton : base « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 {
2025-04-03 06:19:19 +00:00
let message = ` nullpointer dereferencation ` ;
2024-04-22 10:02:34 +02:00
throw ( new Error ( message ) ) ;
}
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _write ( pseudopointer , value ) {
pseudopointer . value = value ;
}
/ *
This file is part of » bacterio - plankton : base « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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
* /
2025-04-03 06:19:19 +00:00
class class _observer {
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
constructor ( ) {
2024-04-22 10:02:34 +02:00
this . counter = 0 ;
this . actions = { } ;
this . buffer = [ ] ;
}
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
empty ( ) {
2024-04-22 10:02:34 +02:00
return ( Object . keys ( this . actions ) . length == 0 ) ;
2025-04-03 06:19:19 +00:00
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
flush ( ) {
2024-04-22 10:02:34 +02:00
this . actions = { } ;
2025-04-03 06:19:19 +00:00
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
set ( id , action ) {
2024-04-22 10:02:34 +02:00
this . actions [ id ] = action ;
2025-04-03 06:19:19 +00:00
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
del ( id ) {
2024-04-22 10:02:34 +02:00
delete this . actions [ id ] ;
2025-04-03 06:19:19 +00:00
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
add ( action ) {
2024-04-22 10:02:34 +02:00
this . set ( ( this . counter ++ ) . toString ( ) , action ) ;
2025-04-03 06:19:19 +00:00
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
notify ( information = { } , delayed = false ) {
2024-04-22 10:02:34 +02:00
if ( delayed ) {
this . buffer . push ( information ) ;
}
else {
2025-04-03 06:19:19 +00:00
Object . keys ( this . actions ) . forEach ( id => this . actions [ id ] ( information ) ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
rollout ( ) {
this . buffer . forEach ( information => this . notify ( information , false ) ) ;
2024-04-22 10:02:34 +02:00
this . buffer = [ ] ;
2025-04-03 06:19:19 +00:00
}
}
2024-04-22 10:02:34 +02:00
/ * *
* @ 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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
* /
2025-04-03 06:19:19 +00:00
class class _error extends Error {
2024-04-22 10:02:34 +02:00
/ * *
* @ author frac
* /
2025-04-03 06:19:19 +00:00
constructor ( message , suberrors = [ ] ) {
super ( message ) ;
this . suberrors = suberrors ;
this . mess = message ;
2024-04-22 10:02:34 +02:00
}
/ * *
* @ override
* @ author frac
* /
2025-04-03 06:19:19 +00:00
toString ( ) {
return ( /*super.toString()*/ this . mess + " " + ( "[" + this . suberrors . map ( x => x . toString ( ) ) . join ( "," ) + "]" ) ) ;
}
}
2024-08-21 15:17:53 +02:00
/ *
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/>.
* /
2024-04-22 10:02:34 +02:00
var lib _plankton ;
( function ( lib _plankton ) {
var base ;
( function ( base ) {
/ * *
* returns the current UNIX timestamp
*
* @ author fenris
* /
2025-04-03 06:19:19 +00:00
function get _current _timestamp ( rounded = false ) {
const x = ( Date . now ( ) / 1000 ) ;
2024-04-22 10:02:34 +02:00
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 ;
2025-04-03 06:19:19 +00:00
/ * *
* /
function buffer _show ( buffer , { "block_size" : option _block _size = 20 , "break_char" : option _break _char = "\n" , } = { } ) {
let output = "" ;
let count = 0 ;
// @ts-ignore
for ( const entry of buffer ) {
count = ( ( count + 1 ) % option _block _size ) ;
output += ( ( typeof ( entry ) === "string" )
?
entry . charCodeAt ( 0 )
:
entry ) . toString ( 16 ) . toUpperCase ( ) . padStart ( 2 , "0" ) ;
output += ( ( count === 0 ) ? option _break _char : " " ) ;
}
return output ;
}
base . buffer _show = buffer _show ;
2024-04-22 10:02:34 +02:00
} ) ( base = lib _plankton . base || ( lib _plankton . base = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : pod « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ; }
2025-04-03 06:19:19 +00:00
tear ( ) { return this . subject ; }
static empty ( ) { return ( new class _pod ( pod . make _empty ( ) ) ) ; }
static filled ( value ) { return ( new class _pod ( pod . make _filled ( value ) ) ) ; }
2024-04-22 10:02:34 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ;
2025-04-03 06:19:19 +00:00
/ * *
* /
class class _value _wrapper {
/ * *
* /
constructor ( value ) {
this . value = value ;
}
/ * *
* /
convey ( function _ ) {
return ( new class _value _wrapper ( function _ ( this . value ) ) ) ;
}
/ * *
* /
cull ( ) {
return this . value ;
}
}
/ * *
* /
function wrap ( value ) {
return ( new class _value _wrapper ( value ) ) ;
}
call . wrap = wrap ;
2024-04-22 10:02:34 +02:00
/ * *
* @ 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 ;
/ * *
* /
2025-04-03 06:19:19 +00:00
function try _catch _wrap ( get _value ) {
try {
return {
"value" : get _value ( ) ,
"error" : null ,
} ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
catch ( error ) {
return {
"value" : null ,
"error" : error ,
} ;
2024-04-22 10:02:34 +02:00
}
}
2025-04-03 06:19:19 +00:00
call . try _catch _wrap = try _catch _wrap ;
/ * *
* /
function try _catch _wrap _async ( get _value ) {
return ( get _value ( )
. then ( ( value ) => Promise . resolve ( {
"value" : value ,
"error" : null ,
} ) )
. catch ( ( reason ) => Promise . resolve ( {
"value" : null ,
"error" : reason ,
} ) ) ) ;
}
call . try _catch _wrap _async = try _catch _wrap _async ;
2024-04-22 10:02:34 +02:00
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : pair « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : pair « 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 : pair « 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 : pair « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : pair « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : pair « 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 : pair « 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 : pair « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var pair ;
( function ( pair _1 ) {
/ * *
* /
function swap ( pair ) {
return {
"first" : pair . second ,
"second" : pair . first
} ;
}
pair _1 . swap = swap ;
/ * *
* /
function show ( pair , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"show_first" : instance _show ,
"show_second" : instance _show
} , options ) ;
return ( "("
+
options . show _first ( pair . first )
+
","
+
options . show _second ( pair . second )
+
")" ) ;
}
pair _1 . show = show ;
} ) ( pair = lib _plankton . pair || ( lib _plankton . pair = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
"use strict" ;
/ *
This file is part of » bacterio - plankton : list « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : list « 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 : list « 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 : list « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : list « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : list « 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 : list « 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 : list « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var list ;
( function ( list _1 ) {
/ * *
2025-04-03 06:19:19 +00:00
* returns a certain list of integer numbers
2024-06-20 15:13:58 +02:00
* /
2025-04-03 06:19:19 +00:00
function range ( from , to , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"step" : 1
} , options ) ;
2024-06-20 15:13:58 +02:00
var list = [ ] ;
2025-04-03 06:19:19 +00:00
for ( var value = from ; value <= to ; value += options . step ) {
2024-06-20 15:13:58 +02:00
list . push ( value ) ;
}
return list ;
}
list _1 . range = range ;
/ * *
2025-04-03 06:19:19 +00:00
* returns a certain list of consecutiv integer numbers , beginning with 0
2024-06-20 15:13:58 +02:00
* /
function sequence ( length ) {
return range ( 0 , length - 1 ) ;
}
list _1 . sequence = sequence ;
/ * *
* /
2025-04-03 06:19:19 +00:00
function from _iterator ( iterator ) {
2024-06-20 15:13:58 +02:00
var list = [ ] ;
2025-04-03 06:19:19 +00:00
// @ts-ignore
2024-06-20 15:13:58 +02:00
for ( var _i = 0 , iterator _1 = iterator ; _i < iterator _1 . length ; _i ++ ) {
var element = iterator _1 [ _i ] ;
list . push ( element ) ;
}
return list ;
}
list _1 . from _iterator = from _iterator ;
/ * *
* /
2025-04-03 06:19:19 +00:00
function is _empty ( list ) {
2024-06-20 15:13:58 +02:00
return ( list . length <= 0 ) ;
}
2025-04-03 06:19:19 +00:00
list _1 . is _empty = is _empty ;
2024-06-20 15:13:58 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* combines two lists into one
*
* @ param { boolean } [ options . cut ] whether the result list will be as long as the shortest input list or an exception is thrown if they have different lengths ; default : true
2024-06-20 15:13:58 +02:00
* /
2025-04-03 06:19:19 +00:00
function zip ( list _first , list _second , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"cut" : true
} , options ) ;
var empty _first = is _empty ( list _first ) ;
var empty _second = is _empty ( list _second ) ;
if ( empty _first || empty _second ) {
if ( options . cut || ( empty _first && empty _second ) ) {
2024-06-20 15:13:58 +02:00
return [ ] ;
}
else {
2025-04-03 06:19:19 +00:00
throw ( new Error ( "lists have different lengths" ) ) ;
2024-06-20 15:13:58 +02:00
}
}
else {
2025-04-03 06:19:19 +00:00
return ( [ { "first" : list _first [ 0 ] , "second" : list _second [ 0 ] } ]
. concat ( zip ( list _first . slice ( 1 ) , list _second . slice ( 1 ) , {
"cut" : options . cut
} ) ) ) ;
2024-06-20 15:13:58 +02:00
}
}
list _1 . zip = zip ;
/ * *
2025-04-03 06:19:19 +00:00
* checks whether two lists are equal
*
2024-06-20 15:13:58 +02:00
* @ todo define common function "equals" and default predicate to
* /
2025-04-03 06:19:19 +00:00
function equals ( list1 , list2 , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"collate_element" : instance _collate
} , options ) ;
2024-06-20 15:13:58 +02:00
if ( list1 . length == list2 . length ) {
2025-04-03 06:19:19 +00:00
return ( zip ( list1 , list2 , { "cut" : true } )
. every ( function ( pair ) { return options . collate _element ( pair . first , pair . second ) ; } ) ) ;
2024-06-20 15:13:58 +02:00
}
else {
return false ;
}
}
list _1 . equals = equals ;
/ * *
2025-04-03 06:19:19 +00:00
* creates a list with the elements from the input list , which fulfil a certain predicate ( ~ filter )
2024-06-20 15:13:58 +02:00
* /
function keep ( list , predicate ) {
2025-04-03 06:19:19 +00:00
return ( list
. filter ( function ( element , index ) { return predicate ( element ) ; } ) ) ;
2024-06-20 15:13:58 +02:00
}
list _1 . keep = keep ;
/ * *
2025-04-03 06:19:19 +00:00
* creates a list with the elements from the input list , which do not fulfil a certain predicate ( ~ dual filter )
2024-06-20 15:13:58 +02:00
* /
function drop ( list , predicate ) {
2025-04-03 06:19:19 +00:00
return ( list
. filter ( function ( element , index ) { return ( ! predicate ( element ) ) ; } ) ) ;
2024-06-20 15:13:58 +02:00
}
list _1 . drop = drop ;
/ * *
* /
2025-04-03 06:19:19 +00:00
function filter _inplace ( list , predicate ) {
var index = 0 ;
while ( index < list . length ) {
var element = list [ index ] ;
if ( predicate ( element ) ) {
index += 1 ;
}
else {
list . splice ( index , 1 ) ;
}
}
}
list _1 . filter _inplace = filter _inplace ;
/ * *
* returns a list with no duplicates ( like unix ' "unique" )
* /
function cleaned ( list , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"collate_element" : instance _collate
} , options ) ;
2024-06-20 15:13:58 +02:00
var list _ = [ ] ;
list . forEach ( function ( element ) {
2025-04-03 06:19:19 +00:00
if ( ! list _ . some ( function ( element _ ) { return options . collate _element ( element , element _ ) ; } ) ) {
2024-06-20 15:13:58 +02:00
list _ . push ( element ) ;
}
2025-04-03 06:19:19 +00:00
else {
// do nothing
}
2024-06-20 15:13:58 +02:00
} ) ;
return list _ ;
}
2025-04-03 06:19:19 +00:00
list _1 . cleaned = cleaned ;
2024-06-20 15:13:58 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* creates a binary partition of the list according to a given predicate
2024-06-20 15:13:58 +02:00
* /
function separate ( list , predicate ) {
2025-04-03 06:19:19 +00:00
return ( list
. reduce ( function ( seperation , element ) {
2024-06-20 15:13:58 +02:00
return ( predicate ( element )
? { "yes" : seperation . yes . concat ( [ element ] ) , "no" : seperation [ "no" ] }
: { "yes" : seperation . yes , "no" : seperation [ "no" ] . concat ( [ element ] ) } ) ;
} , { "yes" : [ ] , "no" : [ ] } ) ) ;
}
list _1 . separate = separate ;
;
/ * *
* /
2025-04-03 06:19:19 +00:00
function clone ( list ) {
return keep ( list , function ( x ) { return true ; } ) ;
}
list _1 . clone = clone ;
/ * *
* /
function reversed ( list ) {
var list _ = clone ( list ) ;
list _ . reverse ( ) ;
return list _ ;
}
list _1 . reversed = reversed ;
/ * *
* @ todo use Array . toSorted ?
* /
function sorted ( list , options ) {
options = Object . assign ( {
"compare_element" : instance _compare
} , options ) ;
var list _ = clone ( list ) ;
list _ . sort ( function ( x , y ) { return ( options . compare _element ( x , y ) ? - 1 : + 1 ) ; } ) ;
return list _ ;
}
list _1 . sorted = sorted ;
/ * *
* die Liste in gleich große Blöcke zerlegen
* /
function chop ( list , chunk _size ) {
2024-06-20 15:13:58 +02:00
var chunks = [ ] ;
var index = 0 ;
while ( index < list . length ) {
var chunk = list . slice ( index , Math . min ( list . length , index + chunk _size ) ) ;
index += chunk _size ;
chunks . push ( chunk ) ;
}
return chunks ;
}
2025-04-03 06:19:19 +00:00
list _1 . chop = chop ;
2024-06-20 15:13:58 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function group ( list , collate _element ) {
2024-06-20 15:13:58 +02:00
var result = [ ] ;
list . forEach ( function ( element ) {
2025-04-03 06:19:19 +00:00
var target = result . find (
// @ts-ignore
function ( group ) { return collate _element ( group [ 0 ] , element ) ; } ) ;
if ( target === undefined ) {
2024-06-20 15:13:58 +02:00
target = [ ] ;
result . push ( target ) ;
}
target . push ( element ) ;
} ) ;
return result ;
}
list _1 . group = group ;
/ * *
* /
function has ( list , predicate ) {
2025-04-03 06:19:19 +00:00
return ( list . find ( predicate ) !== undefined ) ;
2024-06-20 15:13:58 +02:00
}
list _1 . has = has ;
/ * *
2025-04-03 06:19:19 +00:00
* @ deprecate use Array . includes or Array . some
2024-06-20 15:13:58 +02:00
* /
2025-04-03 06:19:19 +00:00
function contains ( list , element , options ) {
options = Object . assign ( {
"collate" : instance _collate
} , options ) ;
return has ( list , function ( element _ ) { return options . collate _element ( element _ , element ) ; } ) ;
2024-06-20 15:13:58 +02:00
}
list _1 . contains = contains ;
2025-04-03 06:19:19 +00:00
/ * *
* retrieves the element and its index of the list , which has the maximum value
* /
function max ( list , target _function , options ) {
options = Object . assign ( {
"compare_value" : instance _compare
} , options ) ;
if ( is _empty ( list ) ) {
throw ( new Error ( "the max-arg of an empty list is not defined" ) ) ;
2024-06-20 15:13:58 +02:00
}
else {
2025-04-03 06:19:19 +00:00
return ( list
. reduce ( function ( result , element , index ) {
var value = target _function ( element ) ;
if ( ( result == null )
||
( ! options . compare _value ( value , result . value ) ) ) {
2024-06-20 15:13:58 +02:00
return { "index" : index , "element" : element , "value" : value } ;
}
else {
return result ;
}
} , null ) ) ;
}
}
list _1 . max = max ;
/ * *
2025-04-03 06:19:19 +00:00
* retrieves the element and its index of the list , which has the mininum value
2024-06-20 15:13:58 +02:00
* /
2025-04-03 06:19:19 +00:00
function min ( list , target _function , options ) {
options = Object . assign ( {
"compare_value" : instance _compare
} , options ) ;
return max ( list , target _function , {
"compare_value" : function ( x , y ) { return options . compare _value ( y , x ) ; }
} ) ;
2024-06-20 15:13:58 +02:00
}
list _1 . min = min ;
/ * *
2025-04-03 06:19:19 +00:00
* implements the idea of arithmetic distribution like in "(a+b)·(c+d) = (a·c)+(a·d)+(b·c)+(b·d)"
2024-06-20 15:13:58 +02:00
* example : distribute ( [ [ 1 , 2 ] , [ 3 ] , [ 4 , 5 , 6 ] ] ) = [ [ 1 , 3 , 4 ] , [ 1 , 3 , 5 ] , [ 1 , 3 , 6 ] , [ 2 , 3 , 4 ] , [ 2 , 3 , 5 ] , [ 2 , 3 , 6 ] ]
* /
function distribute ( lists ) {
2025-04-03 06:19:19 +00:00
if ( is _empty ( lists ) ) {
2024-06-20 15:13:58 +02:00
return [ [ ] ] ;
}
else {
var subresult _1 = distribute ( lists . slice ( 1 ) ) ;
return ( lists [ 0 ]
. map ( function ( element ) { return subresult _1 . map ( function ( list ) { return [ element ] . concat ( list ) ; } ) ; } )
. reduce ( function ( x , y ) { return x . concat ( y ) ; } , [ ] ) ) ;
}
}
list _1 . distribute = distribute ;
/ * *
* /
2025-04-03 06:19:19 +00:00
function contrast ( list _left , extract _key _left , list _right , extract _key _right ) {
var gathering = { } ;
list _left . forEach ( function ( source _left ) {
var _a ;
var key = extract _key _left ( source _left ) ;
gathering [ key ] = Object . assign ( ( ( _a = gathering [ key ] ) !== null && _a !== void 0 ? _a : { } ) , { "left" : source _left } ) ;
} ) ;
list _right . forEach ( function ( source _right ) {
var _a ;
var key = extract _key _right ( source _right ) ;
gathering [ key ] = Object . assign ( ( ( _a = gathering [ key ] ) !== null && _a !== void 0 ? _a : { } ) , { "right" : source _right } ) ;
} ) ;
var result = {
"both" : [ ] ,
"only_left" : [ ] ,
"only_right" : [ ]
} ;
Object . entries ( gathering ) . forEach ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
if ( "left" in value ) {
if ( "right" in value ) {
result . both . push ( { "key" : key , "left" : value . left , "right" : value . right } ) ;
2024-06-20 15:13:58 +02:00
}
2025-04-03 06:19:19 +00:00
else {
result . only _left . push ( { "key" : key , "left" : value . left } ) ;
2024-06-20 15:13:58 +02:00
}
}
else {
2025-04-03 06:19:19 +00:00
if ( "right" in value ) {
result . only _right . push ( { "key" : key , "right" : value . right } ) ;
2024-06-20 15:13:58 +02:00
}
else {
2025-04-03 06:19:19 +00:00
// impossible
// do nothing
2024-06-20 15:13:58 +02:00
}
}
2025-04-03 06:19:19 +00:00
} ) ;
return result ;
2024-06-20 15:13:58 +02:00
}
2025-04-03 06:19:19 +00:00
list _1 . contrast = contrast ;
2024-06-20 15:13:58 +02:00
} ) ( list = lib _plankton . list || ( lib _plankton . list = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-04-22 10:02:34 +02:00
This file is part of » bacterio - plankton : file « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
2024-04-26 11:02:32 +02:00
/ * *
* @ 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 ;
2024-04-22 10:02:34 +02:00
/ * *
* @ 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 = { } ) ) ;
2024-06-23 13:52:59 +02:00
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." ) ;
2024-08-28 07:52:01 +02:00
while ( g && ( g = 0 , op [ 0 ] && ( _ = 0 ) ) , _ ) try {
2024-06-23 13:52:59 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-23 13:52:59 +02:00
< 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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 = { } ) ) ;
;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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
2025-04-03 06:19:19 +00:00
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
2025-04-03 06:19:19 +00:00
function level _order ( level1 , level2 ) {
return ( level1 <= level2 ) ;
}
log . level _order = level _order ;
/ * *
* /
function level _show ( level , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "abbreviated" ] , option _abbreviated = _c === void 0 ? false : _c ;
if ( option _abbreviated ) {
switch ( level ) {
case log . enum _level . debug : return "DBG" ;
case log . enum _level . info : return "INF" ;
case log . enum _level . notice : return "NTC" ;
case log . enum _level . warning : return "WRN" ;
case log . enum _level . error : return "ERR" ;
default : return "(unknown)" ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
}
else {
switch ( level ) {
case log . enum _level . debug : return "debug" ;
case log . enum _level . info : return "info" ;
case log . enum _level . notice : return "notice" ;
case log . enum _level . warning : return "warning" ;
case log . enum _level . error : return "error" ;
default : return "(unknown)" ;
}
}
}
log . level _show = level _show ;
/ * *
* /
function level _decode ( 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 ] ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . level _decode = level _decode ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
2025-04-03 06:19:19 +00:00
/ * *
* @ todo use label
* /
function get _logger _logic ( logger _data ) {
return logger _data . map ( function ( channel _description ) { return lib _plankton . log . get _channel _logic ( channel _description ) ; } ) ;
}
log . get _logger _logic = get _logger _logic ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function format _entry ( format _definition , entry ) {
switch ( format _definition . kind ) {
case "jsonl" : {
var now = Date . now ( ) ;
var timestamp = ( now / 1000 ) ;
var datetime = ( new Date ( now ) ) . toISOString ( ) ;
return ( JSON . stringify ( {
"datetime_timestamp" : Math . round ( timestamp ) ,
"datetime_string" : datetime /*.slice(0, 19)*/ ,
"level_numeric" : entry . level ,
"level_name" : log . level _show ( entry . level , { "abbreviated" : false } ) ,
"tags" : entry . tags ,
"incident" : entry . incident ,
"details" : entry . details
} , undefined , ( format _definition . data . structured
?
"\t"
:
undefined ) ) ) ;
break ;
}
case "human_readable" : {
var parts = [ ] ;
parts . push ( ( "<" + ( new Date ( Date . now ( ) ) ) . toISOString ( ) /*.slice(0, 19)*/ + ">" ) ) ;
parts . push ( ( "[" + log . level _show ( entry . level , { "abbreviated" : true } ) + "]" ) ) ;
for ( var _i = 0 , _a = entry . tags ; _i < _a . length ; _i ++ ) {
var tag = _a [ _i ] ;
parts . push ( ( "{" + tag + "}" ) ) ;
}
parts . push ( entry . incident ) ;
( entry . details !== null ) && parts . push ( ( ": " + JSON . stringify ( entry . details , undefined , undefined ) ) ) ;
return ( parts . join ( " " ) ) ;
break ;
}
default : {
throw ( new Error ( "unhandled format kind: " + format _definition [ "kind" ] ) ) ;
break ;
}
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
}
log . format _entry = format _entry ;
/ * *
* /
function parse _format _definition ( format _definition _raw ) {
return lib _plankton . call . distinguish ( ( format _definition _raw !== null && format _definition _raw !== void 0 ? format _definition _raw : {
"kind" : "human_readable" ,
"data" : { }
} ) , {
"jsonl" : function ( _a ) {
var structured = _a [ "structured" ] ;
return ( {
"kind" : "jsonl" ,
"data" : {
"structured" : ( structured !== null && structured !== void 0 ? structured : false )
}
} ) ;
} ,
"human_readable" : function ( data _ ) { return ( {
"kind" : "human_readable" ,
"data" : { }
} ) ; }
} ) ;
}
log . parse _format _definition = parse _format _definition ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
2025-04-03 06:19:19 +00:00
var channel ;
( function ( channel ) {
var filtered ;
( function ( filtered ) {
/ * *
* /
function predicate _incident ( substring ) {
return ( function ( entry ) { return entry . incident . includes ( substring ) ; } ) ;
}
filtered . predicate _incident = predicate _incident ;
/ * *
* /
function predicate _level ( threshold ) {
return ( function ( entry ) { return log . level _order ( threshold , entry . level ) ; } ) ;
}
filtered . predicate _level = predicate _level ;
/ * *
* /
function predicate _tag ( tag ) {
return ( function ( entry ) { return entry . tags . includes ( tag ) ; } ) ;
}
filtered . predicate _tag = predicate _tag ;
/ * *
* combines other predicates in disjunctive normal form
* /
function predicate _complex ( definition ) {
return ( function ( entry ) { return definition . some ( function ( clause ) { return clause . every ( function ( literal ) { return ( literal . item ( entry )
===
literal . mode ) ; } ) ; } ) ; } ) ;
}
filtered . predicate _complex = predicate _complex ;
/ * *
* /
function send ( subject , entry ) {
if ( ! subject . predicate ( entry ) ) {
// do nothing
}
else {
subject . core . send ( entry ) ;
}
}
filtered . send = send ;
/ * *
* /
function logic ( subject ) {
return {
"send" : function ( entry ) { return send ( subject , entry ) ; }
} ;
}
filtered . logic = logic ;
} ) ( filtered = channel . filtered || ( channel . filtered = { } ) ) ;
} ) ( channel = log . channel || ( log . channel = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
2025-04-03 06:19:19 +00:00
var channel ;
( function ( channel ) {
var minlevel ;
( function ( minlevel ) {
/ * *
* /
function to _filter _subject ( subject ) {
return {
"core" : subject . core ,
"predicate" : lib _plankton . log . channel . filtered . predicate _level ( subject . threshold )
} ;
}
/ * *
* /
function send ( subject , entry ) {
lib _plankton . log . channel . filtered . send ( to _filter _subject ( subject ) , entry ) ;
}
minlevel . send = send ;
/ * *
* /
function logic ( subject ) {
return {
"send" : function ( entry ) { return send ( subject , entry ) ; }
} ;
}
minlevel . logic = logic ;
} ) ( minlevel = channel . minlevel || ( channel . minlevel = { } ) ) ;
} ) ( channel = log . channel || ( log . channel = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 .
2024-06-23 13:52:59 +02:00
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 ) {
2025-04-03 06:19:19 +00:00
var channel ;
( function ( channel ) {
var std ;
( function ( std ) {
/ * *
* /
function send ( subject , entry ) {
var write = lib _plankton . call . distinguish ( {
"kind" : subject . target ,
"data" : null
} , {
"stdout" : function ( ) { return function ( x ) { return process . stdout . write ( x ) ; } ; } ,
"stderr" : function ( ) { return function ( x ) { return process . stderr . write ( x ) ; } ; }
} ) ;
write ( lib _plankton . log . format _entry ( subject . format , entry )
+
"\n" ) ;
}
std . send = send ;
/ * *
* /
function logic ( subject ) {
return {
"send" : function ( entry ) { return send ( subject , entry ) ; }
} ;
}
std . logic = logic ;
} ) ( std = channel . std || ( channel . std = { } ) ) ;
} ) ( channel = log . channel || ( log . channel = { } ) ) ;
2024-06-23 13:52:59 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-23 13:52:59 +02:00
< 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 .
2024-04-22 10:02:34 +02:00
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 ) {
2025-04-03 06:19:19 +00:00
var channel ;
( function ( channel ) {
var file ;
( function ( file ) {
/ * *
* /
function send ( subject , entry ) {
var _this = this ;
var nm _fs = require ( "fs" ) ;
nm _fs . writeFile ( subject . path , ( lib _plankton . log . format _entry ( subject . format , entry )
+
"\n" ) , {
"flag" : "a+"
} , function ( error ) {
if ( error !== null ) {
process . stderr . write ( '-- [plankton] could not add log entry to file ' + _this . path + "\n" ) ;
}
else {
// do nothing
}
} ) ;
}
file . send = send ;
/ * *
* /
function logic ( subject ) {
return {
"send" : function ( entry ) { return send ( subject , entry ) ; }
} ;
}
file . logic = logic ;
} ) ( file = channel . file || ( channel . file = { } ) ) ;
} ) ( channel = log . channel || ( log . channel = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
2025-04-03 06:19:19 +00:00
var channel ;
( function ( channel ) {
var notify ;
( function ( notify ) {
/ * *
* @ todo tags
* /
function send ( subject , entry ) {
var nm _child _process = require ( "child_process" ) ;
var command = ( "notify-send"
+
" "
+
( "'"
+
( "[" + log . level _show ( entry . level ) + "]" )
+
" "
+
entry . incident
+
"'" )
+
" "
+
( "'"
+
JSON . stringify ( entry . details )
+
"'" ) ) ;
nm _child _process . exec ( command , function ( error , stdout , stderr ) {
// do noting
} ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
notify . send = send ;
/ * *
* /
function logic ( subject ) {
return {
"send" : function ( entry ) { return send ( subject , entry ) ; }
} ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
notify . logic = logic ;
} ) ( notify = channel . notify || ( channel . notify = { } ) ) ;
} ) ( channel = log . channel || ( log . 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 ) {
var channel ;
( function ( channel ) {
var email ;
( function ( email ) {
/ * *
* @ todo tags
* /
function send ( subject , entry ) {
var nm _fs = require ( "fs" ) ;
lib _plankton . email . send ( subject . smtp _credentials , subject . sender , subject . receivers , ( ( "[" + log . level _show ( entry . level ) + "]" )
+
" "
+
( "" + entry . incident + "" ) ) , JSON . stringify ( entry . details , undefined , " " ) ) ;
}
email . send = send ;
/ * *
* /
function logic ( subject ) {
return {
"send" : function ( entry ) { return send ( subject , entry ) ; }
} ;
}
email . logic = logic ;
} ) ( email = channel . email || ( channel . email = { } ) ) ;
} ) ( channel = log . channel || ( log . channel = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
/ * *
* /
2025-04-03 06:19:19 +00:00
function get _channel _logic ( channel _description ) {
var _a , _b , _c , _d , _e , _f , _g , _h , _j ;
switch ( channel _description . kind ) {
2024-04-22 10:02:34 +02:00
default : {
2025-04-03 06:19:19 +00:00
throw ( new Error ( "unhandled log channel kind: " + channel _description . kind ) ) ;
2024-04-22 10:02:34 +02:00
break ;
}
2025-04-03 06:19:19 +00:00
case "filtered" : {
return lib _plankton . log . channel . filtered . logic ( {
"core" : get _channel _logic ( channel _description . data . core ) ,
"predicate" : lib _plankton . log . channel . filtered . predicate _complex ( channel _description . data . predicate . map ( function ( clause _raw ) { return clause _raw . map ( function ( literal _raw ) {
var _a ;
return ( {
"mode" : ( ( _a = literal _raw [ "mode" ] ) !== null && _a !== void 0 ? _a : true ) ,
"item" : lib _plankton . call . distinguish ( literal _raw [ "item" ] , {
"incident" : function ( _a ) {
var substring = _a [ "substring" ] ;
if ( substring === undefined ) {
throw ( new Error ( "required parameter missing: substring" ) ) ;
}
else {
return lib _plankton . log . channel . filtered . predicate _incident ( substring ) ;
}
} ,
"level" : function ( _a ) {
var threshold = _a [ "threshold" ] ;
if ( threshold === undefined ) {
throw ( new Error ( "required parameter missing: threshold" ) ) ;
}
else {
return lib _plankton . log . channel . filtered . predicate _level ( log . level _decode ( threshold ) ) ;
}
} ,
"tag" : function ( _a ) {
var value = _a [ "value" ] ;
if ( value === undefined ) {
throw ( new Error ( "required parameter missing: value" ) ) ;
}
else {
return lib _plankton . log . channel . filtered . predicate _tag ( value ) ;
}
}
} , {
"fallback" : function ( ) { return function ( entry ) { return true ; } ; }
} )
} ) ;
} ) ; } ) )
} ) ;
2024-04-22 10:02:34 +02:00
break ;
}
2025-04-03 06:19:19 +00:00
case "minlevel" : {
return lib _plankton . log . channel . minlevel . logic ( {
"core" : get _channel _logic ( channel _description . data . core ) ,
"threshold" : log . level _decode ( channel _description . data . threshold )
} ) ;
2024-06-23 13:52:59 +02:00
break ;
}
2025-04-03 06:19:19 +00:00
case "std" : {
return lib _plankton . log . channel . std . logic ( {
"target" : ( ( _b = ( _a = channel _description === null || channel _description === void 0 ? void 0 : channel _description . data ) === null || _a === void 0 ? void 0 : _a . target ) !== null && _b !== void 0 ? _b : "stdout" ) ,
"format" : log . parse _format _definition ( ( _c = channel _description === null || channel _description === void 0 ? void 0 : channel _description . data ) === null || _c === void 0 ? void 0 : _c . format )
} ) ;
break ;
}
case "file" : {
/ * *
* @ todo exceptions on missing parameters
* /
return lib _plankton . log . channel . file . logic ( {
"path" : ( ( _e = ( _d = channel _description === null || channel _description === void 0 ? void 0 : channel _description . data ) === null || _d === void 0 ? void 0 : _d . path ) !== null && _e !== void 0 ? _e : "log" ) ,
"format" : log . parse _format _definition ( ( _f = channel _description === null || channel _description === void 0 ? void 0 : channel _description . data ) === null || _f === void 0 ? void 0 : _f . format )
} ) ;
2024-04-22 10:02:34 +02:00
break ;
}
case "notify" : {
2025-04-03 06:19:19 +00:00
return lib _plankton . log . channel . notify . logic ( { } ) ;
break ;
}
case "email" : {
/ * *
* @ todo exceptions on missing parameters
* /
return lib _plankton . log . channel . email . logic ( {
"smtp_credentials" : channel _description . data . smtp _credentials ,
"sender" : ( ( _h = ( _g = channel _description . data ) === null || _g === void 0 ? void 0 : _g . sender ) !== null && _h !== void 0 ? _h : "plankton" ) ,
"receivers" : ( _j = channel _description . data ) === null || _j === void 0 ? void 0 : _j . receivers
} ) ;
2024-04-22 10:02:34 +02:00
break ;
}
}
}
2025-04-03 06:19:19 +00:00
log . get _channel _logic = get _channel _logic ;
} ) ( 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 ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function default _logger ( ) {
2024-04-22 10:02:34 +02:00
return [
2025-04-03 06:19:19 +00:00
{
"kind" : "minlevel" ,
"data" : {
"core" : {
"kind" : "std" ,
"data" : {
"target" : "stdout" ,
"format" : {
"kind" : "human_readable" ,
"data" : { }
}
}
} ,
"threshold" : "info"
}
} ,
2024-04-22 10:02:34 +02:00
] ;
}
2025-04-03 06:19:19 +00:00
log . default _logger = default _logger ;
2024-04-22 10:02:34 +02:00
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
/ * *
* /
2025-04-03 06:19:19 +00:00
var _main _logger _data = null ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function set _main _logger ( logger _data ) {
_main _logger _data = logger _data ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . set _main _logger = set _main _logger ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function get _main _logger ( ) {
return ( _main _logger _data !== null && _main _logger _data !== void 0 ? _main _logger _data : log . default _logger ( ) ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2025-04-03 06:19:19 +00:00
function get _main _logger _logic ( ) {
return lib _plankton . log . get _logger _logic ( get _main _logger ( ) ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
2025-04-03 06:19:19 +00:00
* consumes a log entry , i . e . sends it to all channels
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function send _ ( logger , entry ) {
logger . forEach ( function ( channel ) { return channel . send ( entry ) ; } ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . send _ = send _ ;
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* [ convenience ]
*
* @ todo rename to "send"
* /
function debug _ ( logger , incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
send _ ( logger , {
"level" : log . enum _level . debug ,
"incident" : incident ,
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . debug _ = debug _ ;
/ * *
* [ convenience ]
*
* @ todo rename to "info"
* /
function info _ ( logger , incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
send _ ( logger , {
"level" : log . enum _level . info ,
"incident" : incident ,
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . info _ = info _ ;
/ * *
* [ convenience ]
*
* @ todo rename to "notice"
* /
function notice _ ( logger , incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
send _ ( logger , {
"level" : log . enum _level . notice ,
"incident" : incident ,
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . notice _ = notice _ ;
/ * *
* [ convenience ]
*
* @ todo rename to "warning"
* /
function warning _ ( logger , incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
send _ ( logger , {
"level" : log . enum _level . warning ,
"incident" : incident ,
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . warning _ = warning _ ;
/ * *
* [ convenience ]
*
* @ todo rename to "error"
* /
function error _ ( logger , incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
send _ ( logger , {
"level" : log . enum _level . error ,
"incident" : incident ,
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . error _ = error _ ;
/ * *
* [ convenience ]
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function _send ( entry ) {
send _ ( get _main _logger _logic ( ) , entry ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . _send = _send ;
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* [ convenience ]
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function _debug ( incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
debug _ ( get _main _logger _logic ( ) , incident , {
"tags" : option _tags ,
"details" : option _details
} ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . _debug = _debug ;
/ * *
* [ convenience ]
* /
function _info ( incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
info _ ( get _main _logger _logic ( ) , incident , {
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . _info = _info ;
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* [ convenience ]
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function _notice ( incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
notice _ ( get _main _logger _logic ( ) , incident , {
"tags" : option _tags ,
"details" : option _details
} ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . _notice = _notice ;
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* [ convenience ]
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function _warning ( incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
warning _ ( get _main _logger _logic ( ) , incident , {
"tags" : option _tags ,
"details" : option _details
} ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
log . _warning = _warning ;
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* [ convenience ]
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function _error ( incident , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "tags" ] , option _tags = _c === void 0 ? [ ] : _c , _d = _b [ "details" ] , option _details = _d === void 0 ? null : _d ;
error _ ( get _main _logger _logic ( ) , incident , {
"tags" : option _tags ,
"details" : option _details
} ) ;
}
log . _error = _error ;
/ * *
* [ convenience ]
*
* @ deprecated use . _debug instead !
* /
function debug ( incident , details , tags ) {
if ( details === void 0 ) { details = null ; }
if ( tags === void 0 ) { tags = [ ] ; }
_debug ( incident , {
"details" : details ,
"tags" : tags
} ) ;
}
log . debug = debug ;
/ * *
* [ convenience ]
*
* @ deprecated use . _info instead !
* /
function info ( incident , details , tags ) {
if ( details === void 0 ) { details = null ; }
if ( tags === void 0 ) { tags = [ ] ; }
_info ( incident , {
"details" : details ,
"tags" : tags
} ) ;
}
log . info = info ;
/ * *
* [ convenience ]
*
* @ deprecated use . _notice instead !
* /
function notice ( incident , details , tags ) {
if ( details === void 0 ) { details = null ; }
if ( tags === void 0 ) { tags = [ ] ; }
_notice ( incident , {
"details" : details ,
"tags" : tags
} ) ;
}
log . notice = notice ;
/ * *
* [ convenience ]
*
* @ deprecated use . _warning instead !
* /
function warning ( incident , details , tags ) {
if ( details === void 0 ) { details = null ; }
if ( tags === void 0 ) { tags = [ ] ; }
_warning ( incident , {
"details" : details ,
"tags" : tags
} ) ;
}
log . warning = warning ;
/ * *
* [ convenience ]
*
* @ deprecated use . _error instead !
* /
function error ( incident , details , tags ) {
if ( details === void 0 ) { details = null ; }
if ( tags === void 0 ) { tags = [ ] ; }
_error ( incident , {
"details" : details ,
"tags" : tags
} ) ;
2024-04-22 10:02:34 +02:00
}
log . error = error ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : string « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
2025-04-03 06:19:19 +00:00
lib _plankton . log . error ( "plankton.string.generate.out_of_valid_indices" , null ) ;
2024-04-22 10:02:34 +02:00
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
* /
2025-04-03 06:19:19 +00:00
function split ( chain , separator ) {
2024-04-22 10:02:34 +02:00
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" ) ;
2025-04-03 06:19:19 +00:00
/ *
lib _plankton . log . debug (
"lib_plankton.string.coin" ,
{
"key" : key ,
"regex" : regexp _argument . toString ( ) ,
"value" : value ,
}
) ;
* /
2024-04-22 10:02:34 +02:00
str = str . replace ( regexp _argument , value ) ;
}
}
// new syntax
{
const value = args [ key ] ;
const regexp _argument = new RegExp ( options . open + key + options . close , "g" ) ;
2025-04-03 06:19:19 +00:00
/ *
lib _plankton . log . debug (
"lib_plankton.string.coin" ,
{
"key" : key ,
"regex" : regexp _argument . toString ( ) ,
"value" : value ,
}
) ;
* /
2024-04-22 10:02:34 +02:00
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 ;
2025-04-03 06:19:19 +00:00
/ * *
* /
function capitalize ( str ) {
return ( str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ) ;
}
string . capitalize = capitalize ;
2024-04-22 10:02:34 +02:00
} ) ( 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ;
} ) ( ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _1 ) {
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _2 ) {
var any ;
( function ( any ) {
/ * *
* /
function make ( options = { } ) {
return { } ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< 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" ) ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
// all good
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
return inspection ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
/ * *
* /
function show ( sub _show , subject ) {
return "null" ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
/ * *
* /
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _4 ) {
var boolean ;
( function ( boolean ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
} , options ) ;
2024-04-22 10:02:34 +02:00
return {
2024-06-20 15:13:58 +02:00
"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 ) ) ,
} ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
boolean . make = make ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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" ) ;
}
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
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 ,
} ) ) ;
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
return inspection ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
function show ( sub _show , subject ) {
const core = "boolean" ;
return ( subject . soft ? ( "~" + core ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = "boolean" ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
function example ( sub _example , subject ) {
return ( subject . soft ? null : false ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _5 ) {
var integer ;
( function ( integer ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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" ) ;
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _6 ) {
var float ;
( function ( float ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function make ( options = { } ) {
options = Object . assign ( {
"soft" : false ,
"defaultvalue" : undefined ,
"description" : undefined ,
"minimum" : undefined ,
"maximum" : undefined ,
} , options ) ;
2024-04-22 10:02:34 +02:00
return {
2024-06-20 15:13:58 +02:00
"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 ) ) ,
2024-04-22 10:02:34 +02:00
} ;
}
2024-06-20 15:13:58 +02:00
float . make = make ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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" ) ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
// 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
}
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
}
return inspection ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
function show ( sub _show , subject ) {
const core = "float" ;
return ( subject . soft ? ( "~" + core ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
function to _typescript _type ( sub _to _typescript _type , subject ) {
const core = "number" ;
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ,
2024-04-22 10:02:34 +02:00
} ;
2024-06-20 15:13:58 +02:00
return ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
] ,
}
: core ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
/ * *
* /
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _7 ) {
var string ;
( function ( string ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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" ) ;
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 ,
} ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 ) ,
} ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 ) ,
} ) ) ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
// do nothing
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
// 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
}
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
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 ,
}
} ,
} ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< 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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : shape « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : shape « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : shape « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var shape ;
( function ( shape _10 ) {
var map ;
( function ( map ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ;
2024-04-22 10:02:34 +02:00
return {
2024-06-20 15:13:58 +02:00
"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 ) ) ,
2024-04-22 10:02:34 +02:00
} ;
}
2024-06-20 15:13:58 +02:00
map . make = make ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ,
2024-04-22 10:02:34 +02:00
} ) ;
2024-06-20 15:13:58 +02:00
return ( subject . soft ? ( "~" + core ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ,
2024-04-22 10:02:34 +02:00
} ) ;
2024-06-20 15:13:58 +02:00
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< 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 ) ) ,
} ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
record . make = make ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
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 + "'" ) ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
// do nothing
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
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 + "'" ) ;
} ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
}
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 ( "," ) ) ,
2024-04-22 10:02:34 +02:00
} ) ;
2024-06-20 15:13:58 +02:00
return ( subject . soft ? ( "~" + core ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ( ";" ) ) ,
2024-04-22 10:02:34 +02:00
} ) ;
2024-06-20 15:13:58 +02:00
return ( subject . soft ? ( "(null | " + core + ")" ) : core ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2024-06-20 15:13:58 +02:00
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 ) ) ,
2024-04-22 10:02:34 +02:00
} ;
2024-06-20 15:13:58 +02:00
return ( ( subject . soft
? {
"anyOf" : [
Object . assign ( { "type" : "null" } , common ) ,
Object . assign ( core , common ) ,
]
}
: core ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
/ * *
* /
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var code ;
( function ( code ) {
2024-04-22 10:02:34 +02:00
/ * *
* @ author fenris
* /
2024-06-20 15:13:58 +02:00
function inverse _encode ( decode , to ) {
return decode ( to ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
code . inverse _encode = inverse _encode ;
2024-04-22 10:02:34 +02:00
/ * *
* @ author fenris
* /
2024-06-20 15:13:58 +02:00
function inverse _decode ( encode , from ) {
return encode ( from ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
code . inverse _decode = inverse _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _inverse = /** @class */ ( function ( ) {
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
function class _code _inverse ( subject ) {
this . subject = subject ;
2024-04-22 10:02:34 +02:00
}
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
class _code _inverse . prototype . encode = function ( to ) {
var _this = this ;
return code . inverse _encode ( function ( x ) { return _this . subject . decode ( x ) ; } , to ) ;
} ;
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _pair = /** @class */ ( function ( ) {
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
function class _code _pair ( first , second ) {
this . first = first ;
this . second = second ;
2024-04-22 10:02:34 +02:00
}
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
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 ) ;
} ;
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< 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 ( ) {
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
function class _code _chain ( links ) {
this . links = links ;
2024-04-22 10:02:34 +02:00
}
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
class _code _chain . prototype . encode = function ( from ) {
return code . chain _encode ( this . links . map ( function ( link ) { return ( function ( x ) { return link . encode ( x ) ; } ) ; } ) , from ) ;
} ;
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : code « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
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 ] ) ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
throw ( new Error ( "encoding impossible" ) ) ;
2024-04-22 10:02:34 +02:00
}
}
2024-06-20 15:13:58 +02:00
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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< 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 ( ) {
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
function class _code _flatten ( ) {
2024-04-22 10:02:34 +02:00
}
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
class _code _flatten . prototype . encode = function ( x ) {
return code . flatten _encode ( x ) ;
} ;
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : www _form « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2025-04-03 06:19:19 +00:00
» bacterio - plankton : www _form « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2025-04-03 06:19:19 +00:00
» bacterio - plankton : www _form « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2025-04-03 06:19:19 +00:00
along with » bacterio - plankton : www _form « . If not , see < http : //www.gnu.org/licenses/>.
2024-06-20 15:13:58 +02:00
* /
2025-04-03 06:19:19 +00:00
var lib _plankton ;
( function ( lib _plankton ) {
var www _form ;
( function ( www _form ) {
/ * *
* @ author fenris
* /
function encode ( source ) {
return ( Object . entries ( source )
. map ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
return ( key + "=" + encodeURIComponent ( value ) ) ;
} )
. join ( "&" ) ) ;
}
www _form . encode = encode ;
/ * *
* @ author fenris
* /
function decode ( target ) {
return ( Object . fromEntries ( target . split ( "&" )
. map ( function ( part ) {
var components = part . split ( "=" ) ;
var key = components [ 0 ] ;
var value = decodeURIComponent ( components . slice ( 1 ) . join ( "=" ) ) ;
return [ key , value ] ;
} ) ) ) ;
}
www _form . decode = decode ;
} ) ( www _form = lib _plankton . www _form || ( lib _plankton . www _form = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
2024-06-20 15:13:58 +02:00
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : www _form « .
2024-06-20 15:13:58 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
2025-04-03 06:19:19 +00:00
» bacterio - plankton : www _form « 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 : www _form « 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 : www _form « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var www _form ;
( function ( www _form ) {
/ * *
* @ author fenris
* /
var class _www _form = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _www _form ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
class _www _form . prototype . encode = function ( source ) {
return www _form . encode ( source ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _www _form . prototype . decode = function ( target ) {
return www _form . decode ( target ) ;
} ;
return class _www _form ;
} ( ) ) ;
www _form . class _www _form = class _www _form ;
} ) ( www _form = lib _plankton . www _form || ( lib _plankton . www _form = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : url « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : url « 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 : url « 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 : url « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : url « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : url « is free software : you can redistribute it and / or modify
2024-06-20 15:13:58 +02:00
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 : url « 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 : url « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var url ;
( function ( url _1 ) {
/ * *
* @ author fenris
* /
function encode ( url ) {
let result = "" ;
2025-04-03 06:19:19 +00:00
// scheme
2024-06-20 15:13:58 +02:00
{
2025-04-03 06:19:19 +00:00
if ( url . scheme !== null ) {
result += ( url . scheme + ":" ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
// host
{
2025-04-03 06:19:19 +00:00
if ( url . host !== null ) {
2024-06-20 15:13:58 +02:00
result += "//" ;
// username
{
2025-04-03 06:19:19 +00:00
if ( url . username !== null ) {
2024-06-20 15:13:58 +02:00
result += url . username ;
// password
{
2025-04-03 06:19:19 +00:00
if ( url . password !== null ) {
2024-06-20 15:13:58 +02:00
result += ( ":" + url . password ) ;
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
result += "@" ;
2024-04-22 10:02:34 +02:00
}
}
2024-06-20 15:13:58 +02:00
result += url . host ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
// port
{
2025-04-03 06:19:19 +00:00
if ( url . port !== null ) {
2024-06-20 15:13:58 +02:00
result += ( ":" + url . port . toString ( ) ) ;
}
}
// path
{
2025-04-03 06:19:19 +00:00
if ( url . path !== null ) {
result += url . path ;
2024-06-20 15:13:58 +02:00
}
}
2025-04-03 06:19:19 +00:00
// query
2024-06-20 15:13:58 +02:00
{
2025-04-03 06:19:19 +00:00
if ( url . query !== null ) {
result += ( "?" + url . query ) ;
2024-06-20 15:13:58 +02:00
}
}
// hash
{
2025-04-03 06:19:19 +00:00
if ( url . hash !== null ) {
2024-06-20 15:13:58 +02:00
result += ( "#" + url . hash ) ;
}
}
return result ;
}
url _1 . encode = encode ;
/ * *
* @ author fenris
* @ todo arguments
* /
function decode ( url _raw ) {
const builtin _url = new URL ( url _raw ) ;
return {
2025-04-03 06:19:19 +00:00
"scheme" : builtin _url . protocol . slice ( 0 , - 1 ) ,
2024-06-20 15:13:58 +02:00
"host" : builtin _url . hostname ,
2025-04-03 06:19:19 +00:00
"username" : ( ( builtin _url . username !== "" )
?
builtin _url . username
:
null ) ,
"password" : ( ( builtin _url . password !== "" )
?
builtin _url . password
:
null ) ,
"port" : ( ( builtin _url . port !== "" )
?
parseInt ( builtin _url . port )
:
null ) ,
"path" : builtin _url . pathname ,
"query" : builtin _url . search . slice ( 1 ) ,
"hash" : ( ( builtin _url . hash !== "" )
?
builtin _url . hash . slice ( 1 )
:
null ) ,
2024-06-20 15:13:58 +02:00
} ;
}
url _1 . decode = decode ;
/ * *
* @ author fenris
* /
function implementation _code ( ) {
return {
"encode" : encode ,
"decode" : decode ,
} ;
}
url _1 . implementation _code = implementation _code ;
} ) ( url = lib _plankton . url || ( lib _plankton . url = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : url « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : url « 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 : url « 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 : url « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var url ;
( function ( url ) {
/ * *
* @ author fenris
* /
class class _url {
/ * *
* @ author fenris
* /
constructor ( ) {
2024-04-22 10:02:34 +02:00
}
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
encode ( x ) {
return url . encode ( x ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
2024-06-20 15:13:58 +02:00
* @ implementation
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
decode ( x ) {
return url . decode ( x ) ;
}
}
url . class _url = class _url ;
} ) ( url = lib _plankton . url || ( lib _plankton . url = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : random « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : random « 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 : random « 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 : random « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var random ;
( function ( random ) {
/ * *
* @ author fenris
* /
function sequence ( n ) {
return ( ( n <= 0 ) ? [ ] : sequence ( n - 1 ) . concat ( [ n - 1 ] ) ) ;
}
/ * *
* @ author fenris
* /
function interpolate ( x , y , t ) {
return ( ( ( 1 - t ) * x ) + ( t * y ) ) ;
}
/ * *
* @ author fenris
* /
var _statestack = [
{
"builtin" : true ,
"seed" : Date . now ( )
} ,
] ;
/ * *
* @ author fenris
* /
function state _get ( ) {
return _statestack [ _statestack . length - 1 ] ;
}
/ * *
* @ author fenris
* /
function state _push ( state ) {
_statestack . push ( state ) ;
}
random . state _push = state _push ;
/ * *
* @ author fenris
* /
function state _pop ( ) {
if ( _statestack . length <= 1 ) {
throw ( new Error ( "no state to pop" ) ) ;
}
else {
return _statestack . pop ( ) ;
}
}
random . state _pop = state _pop ;
/ * *
* @ author fenris
* /
function seed _tick ( ) {
var state = state _get ( ) ;
state . seed = ( ( state . seed << 8 ) % 99767 ) ;
}
/ * *
* @ author fenris
* /
function seed _get ( tick ) {
if ( tick === void 0 ) { tick = true ; }
if ( tick ) {
seed _tick ( ) ;
}
else {
// do nothing
}
return state _get ( ) . seed ;
}
/ * *
* returns a random floating point number in the interval [ 0 , 1 [
*
* @ author fenris
* /
function generate _unit ( ) {
if ( state _get ( ) . builtin ) {
return Math . random ( ) ;
}
else {
return ( ( Math . sin ( seed _get ( ) << 8 ) + 1 ) / 2 ) ;
}
}
random . generate _unit = generate _unit ;
/ * *
* returns a random boolean value
*
* @ param { float } [ probability ] the probability for the return - value "true" ; default : 0.5
* @ author fenris
* /
function generate _boolean ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"probability" : 0.5
} , options ) ;
return ( generate _unit ( ) < options . probability ) ;
}
random . generate _boolean = generate _boolean ;
/ * *
* returns a random integer number in the interval [ a , b ]
*
* @ param { int } [ minimum ] the left side of the halfopen interval ( i . e . the smallest included value in the range )
* @ param { int } [ minimum ] the right side of the halfopen interval ( i . e . the smallest excluded value in the range )
* @ author fenris
* /
function generate _integer ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"minimum" : 0 ,
"maximum" : ( ( 1 << 16 ) - 1 )
} , options ) ;
return Math . floor ( interpolate ( options . minimum , options . maximum + 1 , generate _unit ( ) ) ) ;
}
random . generate _integer = generate _integer ;
random . generate _int = generate _integer ;
/ * *
* returns a random floating point number in the given interval
*
* @ author fenris
* /
function generate _float ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"minimum" : 0.0 ,
"maximum" : 1.0
} , options ) ;
return interpolate ( options . minimum , options . maximum , generate _unit ( ) ) ;
}
random . generate _float = generate _float ;
/ * *
* returns a random date
*
* @ author fenris
* /
function generate _date ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"minimum" : new Date ( 0 ) ,
"maximum" : new Date ( Date . now ( ) )
} , options ) ;
return ( new Date ( generate _integer ( {
"minimum" : options . minimum . getTime ( ) ,
"maximum" : options . maximum . getTime ( )
} ) ) ) ;
}
random . generate _date = generate _date ;
/ * *
* @ author fenris
* /
function generate _hexdigit ( ) {
return ( this . generate _integer ( { "minimum" : 0 , "maximum" : 15 } ) . toString ( 16 ) . toUpperCase ( ) ) ;
}
random . generate _hexdigit = generate _hexdigit ;
/ * *
* generates a random string with an optional prefix
*
* @ author fenris
* /
function generate _string ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"length" : 8
} , options ) ;
return ( sequence ( options . length )
. map ( function ( x ) { return generate _integer ( { "minimum" : 65 , "maximum" : 90 } ) ; } )
. map ( function ( x ) { return String . fromCharCode ( x ) ; } )
. join ( "" )
. toLowerCase ( ) ) ;
}
random . generate _string = generate _string ;
/ * *
* chooses a value randomly from a list of values with weights ( a higher weight means a higher probability to be chosen )
*
* @ author fenris
* /
function choose _weighted ( sets ) {
var sum = sets . reduce ( function ( sum , set _ ) { return ( sum + set _ . weight ) ; } , 0 ) ;
if ( sum === 0 ) {
throw ( new Error ( "weights sum up to zero; are all zero or are negative weights included?" ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
else {
var position _1 = generate _unit ( ) ;
return ( sets . reduce ( function ( current , set _ ) {
var next = { "index" : null , "value" : null } ;
next . index = ( current . index + ( set _ . weight / sum ) ) ;
next . value = ( ( ( current . index <= position _1 ) && ( position _1 < next . index ) )
? set _ . value
: current . value ) ;
return next ;
} , { "index" : 0 , "value" : null } ) . value ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
random . choose _weighted = choose _weighted ;
/ * *
* chooses a value randomly from a list of values with equal probabilities
*
* @ author fenris
* /
function choose _uniformly ( values ) {
return ( choose _weighted ( values . map ( function ( value ) { return ( { "weight" : 1 , "value" : value } ) ; } ) ) ) ;
}
random . choose _uniformly = choose _uniformly ;
/ * *
* @ author fenris
* /
function shuffle ( list ) {
var list _ = [ ] ;
list . forEach ( function ( element ) {
var index = generate _integer ( { "minimum" : 0 , "maximum" : list _ . length } ) ;
list _ . splice ( index , 0 , element ) ;
} ) ;
return list _ ;
}
random . shuffle = shuffle ;
/ * *
* @ author fenris
* /
function generate _vowel ( ) {
return ( choose _weighted ( [
{ "weight" : 1.0 , "value" : "u" } ,
{ "weight" : 4.0 , "value" : "o" } ,
{ "weight" : 6.0 , "value" : "a" } ,
{ "weight" : 4.0 , "value" : "e" } ,
{ "weight" : 1.0 , "value" : "i" } ,
] ) ) ;
}
random . generate _vowel = generate _vowel ;
/ * *
* @ author fenris
* /
function generate _halfvowel ( ) {
return ( choose _weighted ( [
{ "weight" : 4.0 , "value" : "y" } ,
{ "weight" : 1.0 , "value" : "w" } ,
] ) ) ;
}
random . generate _halfvowel = generate _halfvowel ;
/ * *
* @ author fenris
* /
function generate _consonant ( ) {
return ( choose _weighted ( [
{ "weight" : 5.0 , "value" : "l" } ,
{ "weight" : 5.0 , "value" : "m" } ,
{ "weight" : 5.0 , "value" : "n" } ,
{ "weight" : 4.0 , "value" : "b" } ,
{ "weight" : 4.0 , "value" : "p" } ,
{ "weight" : 4.0 , "value" : "d" } ,
{ "weight" : 2.0 , "value" : "dj" } ,
{ "weight" : 4.0 , "value" : "t" } ,
{ "weight" : 2.0 , "value" : "tc" } ,
{ "weight" : 4.0 , "value" : "g" } ,
{ "weight" : 4.0 , "value" : "k" } ,
{ "weight" : 3.0 , "value" : "v" } ,
{ "weight" : 3.0 , "value" : "f" } ,
{ "weight" : 3.0 , "value" : "z" } ,
{ "weight" : 3.0 , "value" : "s" } ,
{ "weight" : 3.0 , "value" : "j" } ,
{ "weight" : 3.0 , "value" : "c" } ,
{ "weight" : 2.0 , "value" : "r" } ,
{ "weight" : 1.0 , "value" : "h" } ,
{ "weight" : 1.0 , "value" : "x" } ,
] ) ) ;
}
random . generate _consonant = generate _consonant ;
/ * *
* @ author fenris
* /
function generate _letter ( ) {
return choose _uniformly ( [
"a" ,
"b" ,
"c" ,
"d" ,
"e" ,
"f" ,
"g" ,
"h" ,
"i" ,
"j" ,
"k" ,
"l" ,
"m" ,
"n" ,
"o" ,
"p" ,
"q" ,
"r" ,
"s" ,
"t" ,
"u" ,
"v" ,
"w" ,
"x" ,
"y" ,
"z" ,
] ) ;
}
random . generate _letter = generate _letter ;
/ * *
* @ author fenris
* /
function generate _syllable ( ) {
return ( generate _consonant ( )
+
generate _vowel ( )
+
( generate _boolean ( { "probability" : 1 / 8 } )
? generate _halfvowel ( )
: "" )
+
( generate _boolean ( { "probability" : 1 / 4 } )
? generate _consonant ( )
: "" ) ) ;
}
random . generate _syllable = generate _syllable ;
/ * *
* @ author fenris
* /
function generate _word ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"syllable_count_minimum" : 2 ,
"syllable_count_maximum" : 5
} , options ) ;
return ( sequence ( generate _integer ( {
"minimum" : options . syllable _count _minimum ,
"maximum" : options . syllable _count _maximum
} ) )
. map ( function ( x ) { return generate _syllable ( ) ; } )
. join ( "" ) ) ;
}
random . generate _word = generate _word ;
/ * *
* @ author fenris
* /
function generate _text ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"word_count" : generate _integer ( { "minimum" : 20 , "maximum" : 80 } )
} , options ) ;
return sequence ( options . word _count ) . map ( function ( x ) { return generate _word ( ) ; } ) . join ( " " ) ;
}
random . generate _text = generate _text ;
/ * *
* @ author fenris
* /
function generate _city ( ) {
var str = (
// prefix
( generate _boolean ( { "probability" : 0.25 } )
? choose _uniformly ( [
"unter" ,
"ober" ,
"mittel" ,
"groß" ,
"klein" ,
"neu" ,
"alt" ,
] )
: "" )
+
// infix
choose _uniformly ( [
"stein" ,
"frei" ,
"berns" ,
"kirch" ,
"fels" ,
"weiden" ,
"buchen" ,
"eichen" ,
"eiben" ,
"linden" ,
"ulmen" ,
"birken" ,
"eschen" ,
"erlen" ,
"grün" ,
"kreuz" ,
"wald" ,
"reichen" ,
"lieben" ,
"schön" ,
"heinrichs" ,
"friedrichs" ,
"johann" ,
"walters" ,
"günthers" ,
"rupperts" ,
"wilhems" ,
"albert" ,
] )
+
// suffix
choose _uniformly ( [
"feld" ,
"thal" ,
"berg" ,
"burg" ,
"stadt" ,
"dorf" ,
"heim" ,
"bach" ,
"au" ,
"rode" ,
"ing" ,
"nitz" ,
"hausen" ,
] ) ) ;
return ( str [ 0 ] . toUpperCase ( ) + str . substring ( 1 ) ) ;
}
random . generate _city = generate _city ;
/ * *
* @ author fenris
* /
function generate _street ( ) {
var str = (
// prefix
choose _uniformly ( [
"haupt" ,
"neben" ,
"bahnhof" ,
"markt" ,
"augustus" ,
"wilhelm" ,
"albert" ,
"friedrich" ,
"maximilian" ,
"wagner" ,
"linden" ,
"eichen" ,
"buchen" ,
"tannen" ,
"pappel" ,
"ulmen" ,
"eschen" ,
] )
+
// core
choose _uniformly ( [
"straße" ,
"weg" ,
"allee" ,
"pfad" ,
"hain" ,
"anger" ,
"passage" ,
"platz" ,
] )
+
// number
( " " + generate _integer ( { "minimum" : 1 , "maximum" : 80 } ) . toString ( ) ) ) ;
return ( str [ 0 ] . toUpperCase ( ) + str . substring ( 1 ) ) ;
}
random . generate _street = generate _street ;
/ * *
* @ author fenris
* /
function generate _guid ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"with_braces" : false
} , options ) ;
/ *
return (
[ 8 , 4 , 4 , 4 , 12 ]
. map ( length => sequence ( length ) . map ( _ => this . generate _hexdigit ( ) ) . join ( "" ) )
. join ( "-" )
) ;
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
var guid = ( "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" . replace ( new RegExp ( "[xy]" , "g" ) , function ( symbol ) {
var r = generate _integer ( { "minimum" : 0 , "maximum" : 15 } ) ;
var v = ( ( symbol == "y" ) ? ( ( r & 0x3 ) | 0x8 ) : r ) ;
return ( v . toString ( 16 ) . toUpperCase ( ) ) ;
2024-04-22 10:02:34 +02:00
} ) ) ;
2024-06-20 15:13:58 +02:00
return ( options . with _braces
? ( "{" + guid + "}" )
: guid ) ;
}
random . generate _guid = generate _guid ;
/ * *
* @ author fenris
* /
function generate _domain ( options ) {
if ( options === void 0 ) { options = { } ; }
options = lib _plankton . base . object _merge ( {
"steps" : 3
} , options ) ;
return ( sequence ( generate _integer ( { "minimum" : 1 , "maximum" : options . steps } ) )
. map ( function ( ) { return generate _word ( ) ; } )
// tld
. concat ( sequence ( generate _integer ( { "minimum" : 2 , "maximum" : 3 } ) )
. map ( function ( ) { return generate _letter ( ) ; } )
. join ( "" ) ) ) . join ( "." ) ;
}
/ * *
* @ author fenris
* /
function generate _url ( ) {
return ( lib _plankton . url . encode ( {
2025-04-03 06:19:19 +00:00
"scheme" : choose _uniformly ( [
2024-06-20 15:13:58 +02:00
"http" ,
"https" ,
"git" ,
"smb" ,
"ftp" ,
] ) ,
"host" : generate _domain ( ) ,
2025-04-03 06:19:19 +00:00
"username" : null ,
"password" : null ,
2024-06-20 15:13:58 +02:00
"port" : generate _integer ( { "minimum" : 20 , "maximum" : 99999 } ) ,
2025-04-03 06:19:19 +00:00
"path" : ( "/"
+
( sequence ( generate _integer ( { "minimum" : 0 , "maximum" : 3 } ) )
. map ( function ( ) { return generate _word ( ) ; } )
. join ( "/" ) ) ) ,
"query" : choose _uniformly ( [
2024-06-20 15:13:58 +02:00
null ,
2025-04-03 06:19:19 +00:00
lib _plankton . www _form . encode ( Object . fromEntries ( sequence ( generate _integer ( { "minimum" : 0 , "maximum" : 3 } ) )
2024-06-20 15:13:58 +02:00
. map ( function ( ) { return ( [
generate _word ( ) ,
generate _integer ( ) . toFixed ( 0 ) ,
2025-04-03 06:19:19 +00:00
] ) ; } ) ) ) ,
] ) ,
"hash" : null
2024-06-20 15:13:58 +02:00
} ) ) ;
}
random . generate _url = generate _url ;
/ * *
* @ author fenris
* /
function generate _email _address ( ) {
return (
// user
generate _word ( )
+
"@"
+
generate _domain ( { "steps" : 1 } ) ) ;
}
random . generate _email _address = generate _email _address ;
/ * *
* @ author fenris
* /
function generate _telephone _number ( ) {
return (
// country prefix
( "+"
+
generate _integer ( { "minimum" : 1 , "maximum" : 999 } ) . toFixed ( 0 ) )
+
" "
+
// provider
+ ( sequence ( 3 )
. map ( function ( ) { return generate _integer ( { "minimum" : 0 , "maximum" : 9 } ) ; } )
. join ( "" ) )
+
" "
+
// custom
+ ( sequence ( 7 )
. map ( function ( ) { return generate _integer ( { "minimum" : 0 , "maximum" : 9 } ) ; } )
. join ( "" ) ) ) ;
}
random . generate _telephone _number = generate _telephone _number ;
/ * *
* @ author fenris
* /
function generate _time ( ) {
return {
"hour" : generate _integer ( { "minimum" : 0 , "maximum" : 23 } ) ,
"minute" : generate _integer ( { "minimum" : 0 , "maximum" : 59 } ) ,
"second" : generate _integer ( { "minimum" : 0 , "maximum" : 59 } )
} ;
}
random . generate _time = generate _time ;
/ * *
* @ author fenris
* @ deprecated
* @ todo remove
* /
function generate _for _shape ( shape ) {
throw ( new Error ( "deprecated! use lib_shape!" ) ) ;
}
random . generate _for _shape = generate _for _shape ;
/ * *
* @ author fenris
* /
/ *
export function generate _for _shape _ (
shape : lib _plankton . shape . type _shape
) : any
{
switch ( shape . name ) {
case "boolean" : {
return generate _boolean ( ) ;
break ;
}
case "int" : {
const min = shape . parameters [ "min" ] ;
const max = shape . parameters [ "max" ] ;
return generate _integer (
{
"minimum" : ( ( min == null ) ? undefined : min ) ,
"maximum" : ( ( max == null ) ? undefined : max ) ,
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
) ;
break ;
}
case "float" : {
return generate _float (
{
"minimum" : shape . parameters [ "min" ] ,
"maximum" : shape . parameters [ "max" ] ,
}
) ;
break ;
}
case "string" : {
return generate _string ( ) ;
break ;
}
case "url" : {
return generate _url ( ) ;
break ;
}
case "email" : {
return generate _email _address ( ) ;
break ;
}
case "time" : {
return generate _time ( ) ;
break ;
}
case "array" : {
return (
sequence ( generate _integer ( { "minimum" : 2 , "maximum" : 5 } ) )
. map ( ( ) => generate _for _shape _ ( shape . parameters [ "shape_element" ] ) )
) ;
break ;
}
case "object" : {
return Object . fromEntries (
shape . parameters [ "fields" ]
. map (
field => ( [
field [ "name" ] ,
generate _for _shape _ ( field [ "shape" ] ) ,
] )
)
) ;
break ;
}
case "date" : {
return generate _date ( ) ;
break ;
}
case "enumeration" : {
return choose _uniformly < any > ( shape . parameters [ "options" ] ) [ "value" ] ;
break ;
}
default : {
const message : string = ` unhandled shape kind ' ${ shape . name } ' ` ;
// console.warn(message);
// return null;
throw ( new Error ( message ) ) ;
break ;
}
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
}
* /
} ) ( random = lib _plankton . random || ( lib _plankton . random = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : sha256 « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : sha256 « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : sha256 « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : sha256 « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
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 = { } ) ) ;
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 ( ) ) ;
} ) ;
} ;
/ *
This file is part of » bacterio - plankton : database « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : database « 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 : database « 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 : database « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var database ;
( function ( database ) {
/ * *
* /
let enum _type ;
( function ( enum _type ) {
enum _type [ "boolean" ] = "boolean" ;
enum _type [ "integer" ] = "integer" ;
enum _type [ "string_short" ] = "string_short" ;
enum _type [ "string_medium" ] = "string_medium" ;
enum _type [ "string_long" ] = "string_long" ;
enum _type [ "float" ] = "float" ;
} ) ( enum _type = database . enum _type || ( database . enum _type = { } ) ) ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var database ;
( function ( database ) {
/ * *
* @ todo default case ?
* /
function sql _common _value _format ( value ) {
if ( value === undefined ) {
throw ( new Error ( "can not format undefined" ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
else {
2024-04-22 10:02:34 +02:00
if ( value === null ) {
2024-06-20 15:13:58 +02:00
return "NULL" ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
switch ( typeof ( value ) ) {
case "boolean" : {
return ( value ? "TRUE" : "FALSE" ) ;
break ;
}
case "number" : {
return value . toString ( ) ;
break ;
}
case "string" : {
return ( "'" + value + "'" ) ;
break ;
}
2024-04-22 10:02:34 +02:00
}
}
}
2024-06-20 15:13:58 +02:00
}
database . sql _common _value _format = sql _common _value _format ;
/ * *
* /
function sql _common _formulation _create _table ( description _create _table , options = { } ) {
2024-08-28 07:52:01 +02:00
var _a , _b , _c , _d , _e , _f ;
2024-06-20 15:13:58 +02:00
options = Object . assign ( {
"auto_increment_keyword" : "AUTO INCREMENT" ,
2024-08-28 07:52:01 +02:00
"auto_increment_special" : null ,
2024-06-20 15:13:58 +02:00
"omit_comments" : false ,
"type_map" : {
"boolean" : "BOOLEAN" ,
"integer" : "INTEGER" ,
"string_short" : "VARCHAR(63)" ,
"string_medium" : "VARCHAR(255)" ,
"string_long" : "TEXT" ,
"float" : "REAL" ,
} ,
2024-08-28 07:52:01 +02:00
"wrap_name" : ( x => x ) ,
2024-06-20 15:13:58 +02:00
} , options ) ;
return {
2024-08-28 07:52:01 +02:00
"template" : lib _plankton . string . coin ( "CREATE TABLE IF NOT EXISTS\n\t{{name}}(\n{{entries}}\n\t){{comment}}\n;" , {
"name" : options . wrap _name ( description _create _table . name ) ,
2024-06-20 15:13:58 +02:00
"comment" : ( ( options . omit _comments
||
( ( ( _a = description _create _table . description ) !== null && _a !== void 0 ? _a : null ) === null ) )
? ""
: lib _plankton . string . coin ( " COMMENT '{{comment}}'" , {
"comment" : description _create _table . description ,
} ) ) ,
"entries" : ( ( [ ]
// key field
. concat ( ( ( ( _b = description _create _table . key _field ) !== null && _b !== void 0 ? _b : null ) === null )
? [ ]
: lib _plankton . string . coin ( "{{name}} {{parameters}}" , {
2024-08-28 07:52:01 +02:00
"name" : options . wrap _name ( description _create _table . key _field . name ) ,
"parameters" : ( ( ( options . auto _increment _special === null )
?
( [ ]
// type
. concat ( [
options . type _map [ ( _c = description _create _table . key _field . type ) !== null && _c !== void 0 ? _c : "integer" ] ,
] )
// nullability
. concat ( [
"NOT NULL" ,
] )
// primary key
. concat ( [
"PRIMARY KEY" ,
] )
// auto increment
. concat ( ( ( ( _d = description _create _table . key _field . auto _increment ) !== null && _d !== void 0 ? _d : true ) === null )
?
[ ]
:
[
options . auto _increment _keyword ,
] ) )
:
2024-06-20 15:13:58 +02:00
[
2024-08-28 07:52:01 +02:00
options . auto _increment _special
] )
2024-06-20 15:13:58 +02:00
. join ( " " ) ) ,
} ) )
// data fields
2024-08-28 07:52:01 +02:00
. concat ( ( ( _e = description _create _table . data _fields ) !== null && _e !== void 0 ? _e : [ ] )
2024-06-20 15:13:58 +02:00
. map ( ( data _field ) => {
var _a , _b ;
return lib _plankton . string . coin ( "{{name}} {{parameters}}" , {
2024-08-28 07:52:01 +02:00
"name" : options . wrap _name ( data _field . name ) ,
2024-06-20 15:13:58 +02:00
"parameters" : ( ( [ ]
// type
. concat ( [
options . type _map [ data _field . type ] ,
] )
// nullability
. concat ( ( ! ( ( _a = data _field . nullable ) !== null && _a !== void 0 ? _a : false ) )
? [ ]
: [ "NULL" ] )
// default
. concat ( ( ! data _field . hasOwnProperty ( "default" ) )
? [ ]
: [
lib _plankton . string . coin ( " DEFAULT {{value}}" , {
"value" : sql _common _value _format ( data _field . default )
} ) ,
] )
// comment
. concat ( ( options . omit _comments
||
( ( ( _b = data _field . description ) !== null && _b !== void 0 ? _b : null ) === null ) )
? [ ]
: [
lib _plankton . string . coin ( "COMMENT '{{comment}}'" , {
"comment" : data _field . description ,
} ) ,
] ) )
. join ( " " ) )
} ) ;
} ) )
// constraints
2024-08-28 07:52:01 +02:00
. concat ( ( ( _f = description _create _table . constraints ) !== null && _f !== void 0 ? _f : [ ] )
2024-06-20 15:13:58 +02:00
. map ( ( constraint ) => {
switch ( constraint . kind ) {
default : {
throw ( new Error ( "unhandled constraint kind: " + constraint . kind ) ) ;
break ;
}
case "foreign_key" : {
return lib _plankton . string . coin ( "FOREIGN KEY ({{fields}}) REFERENCES {{reference_name}}({{reference_fields}})" , {
"fields" : ( constraint . parameters [ "fields" ]
2024-08-28 07:52:01 +02:00
. map ( x => options . wrap _name ( x ) )
2024-06-20 15:13:58 +02:00
. join ( "," ) ) ,
2024-08-28 07:52:01 +02:00
"reference_name" : options . wrap _name ( constraint . parameters [ "reference" ] [ "name" ] ) ,
2024-06-20 15:13:58 +02:00
"reference_fields" : ( constraint . parameters [ "reference" ] [ "fields" ]
2024-08-28 07:52:01 +02:00
. map ( x => options . wrap _name ( x ) )
2024-06-20 15:13:58 +02:00
. join ( "," ) ) ,
} ) ;
break ;
}
case "unique" : {
return lib _plankton . string . coin ( "UNIQUE ({{fields}})" , {
"fields" : ( constraint . parameters [ "fields" ]
2024-08-28 07:52:01 +02:00
. map ( x => options . wrap _name ( x ) )
2024-06-20 15:13:58 +02:00
. join ( "," ) ) ,
} ) ;
break ;
}
}
} ) ) )
. map ( x => ( "\t\t" + x ) )
. join ( ",\n" ) ) ,
} ) ,
"arguments" : { }
} ;
}
database . sql _common _formulation _create _table = sql _common _formulation _create _table ;
/ * *
* /
function sql _common _formulation _insert ( description _insert , options = { } ) {
options = Object . assign ( {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( x => x ) ,
"set_returning" : false ,
2024-06-20 15:13:58 +02:00
} , options ) ;
const field _names = Object . keys ( description _insert . values ) ;
return {
2024-08-28 07:52:01 +02:00
"template" : lib _plankton . string . coin ( "INSERT INTO {{table_name}}({{schema}}) VALUES ({{values}}){{returning}};" , {
"table_name" : options . wrap _name ( description _insert . table _name ) ,
2024-06-20 15:13:58 +02:00
"schema" : ( field _names
. map ( ( field _name ) => lib _plankton . string . coin ( "{{name}}" , {
2024-08-28 07:52:01 +02:00
"name" : options . wrap _name ( field _name ) ,
2024-06-20 15:13:58 +02:00
} ) )
. join ( "," ) ) ,
"values" : ( field _names
. map ( ( field _name ) => lib _plankton . string . coin ( "$value_{{name}}" , {
"name" : field _name ,
} ) )
. join ( "," ) ) ,
2024-08-28 07:52:01 +02:00
"returning" : ( ( options . set _returning
&&
( ( description _insert . returning !== undefined )
&&
( description _insert . returning !== null ) ) )
?
( " RETURNING " + description _insert . returning )
:
"" ) ,
2024-06-20 15:13:58 +02:00
} ) ,
"arguments" : Object . fromEntries ( Object . entries ( description _insert . values )
. map ( ( [ name , value ] ) => ( [
lib _plankton . string . coin ( "value_{{name}}" , {
"name" : name ,
} ) ,
value
] ) ) ) ,
} ;
}
database . sql _common _formulation _insert = sql _common _formulation _insert ;
/ * *
* /
function sql _common _formulation _update ( description _update , options = { } ) {
var _a , _b ;
options = Object . assign ( {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( x => x ) ,
2024-06-20 15:13:58 +02:00
} , options ) ;
const field _names = Object . keys ( description _update . values ) ;
return {
"template" : lib _plankton . string . coin ( "UPDATE {{table_name}} SET {{assignments}}{{macro_where}};" , {
2024-08-28 07:52:01 +02:00
"table_name" : options . wrap _name ( description _update . table _name ) ,
2024-06-20 15:13:58 +02:00
"assignments" : ( field _names
. map ( ( field _name ) => lib _plankton . string . coin ( "{{name}} = $value_{{suffix}}" , {
2024-08-28 07:52:01 +02:00
"name" : options . wrap _name ( field _name ) ,
2024-06-20 15:13:58 +02:00
"suffix" : field _name ,
} ) )
. join ( ", " ) ) ,
"macro_where" : ( ( ( ( _a = description _update . condition ) !== null && _a !== void 0 ? _a : null ) === null )
? ""
: lib _plankton . string . coin ( " WHERE {{expression}}" , {
"expression" : description _update . condition ,
} ) ) ,
} ) ,
"arguments" : Object . assign ( Object . fromEntries ( Object . entries ( description _update . values )
. map ( ( [ name , value ] ) => ( [
lib _plankton . string . coin ( "value_{{name}}" , {
"name" : name ,
} ) ,
value
] ) ) ) , ( ( _b = description _update . arguments ) !== null && _b !== void 0 ? _b : { } ) )
} ;
}
database . sql _common _formulation _update = sql _common _formulation _update ;
/ * *
* /
function sql _common _formulation _delete ( description _delete , options = { } ) {
var _a , _b ;
options = Object . assign ( {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( x => x ) ,
2024-06-20 15:13:58 +02:00
} , options ) ;
return {
"template" : lib _plankton . string . coin ( "DELETE FROM {{table_name}}{{macro_where}};" , {
2024-08-28 07:52:01 +02:00
"table_name" : options . wrap _name ( description _delete . table _name ) ,
2024-06-20 15:13:58 +02:00
"macro_where" : ( ( ( ( _a = description _delete . condition ) !== null && _a !== void 0 ? _a : null ) === null )
? ""
: lib _plankton . string . coin ( " WHERE {{expression}}" , {
"expression" : description _delete . condition ,
} ) ) ,
} ) ,
"arguments" : Object . assign ( { } , ( ( _b = description _delete . arguments ) !== null && _b !== void 0 ? _b : { } ) ) ,
} ;
}
database . sql _common _formulation _delete = sql _common _formulation _delete ;
/ * *
* /
function sql _common _formulation _select ( description _select , options = { } ) {
var _a , _b , _c , _d , _e , _f , _g ;
options = Object . assign ( {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( x => x ) ,
2024-06-20 15:13:58 +02:00
} , options ) ;
return {
"template" : lib _plankton . string . coin ( "SELECT {{fields}} FROM {{source}}{{macro_where}}{{macro_group_by}}{{macro_having}}{{macro_order_by}}{{macro_limit}};" , {
2024-08-28 07:52:01 +02:00
"source" : options . wrap _name ( description _select . source ) ,
2024-06-20 15:13:58 +02:00
"fields" : ( ( ( ( _a = description _select . fields ) !== null && _a !== void 0 ? _a : null ) === null )
? "*"
: ( description _select . fields
2024-08-28 07:52:01 +02:00
. map ( field _name => lib _plankton . string . coin ( "{{name}}" , { "name" : options . wrap _name ( field _name ) } ) )
2024-06-20 15:13:58 +02:00
. join ( "," ) ) ) ,
"macro_where" : ( ( ( ( _b = description _select . condition ) !== null && _b !== void 0 ? _b : null ) === null )
? ""
: lib _plankton . string . coin ( " WHERE {{expression}}" , {
"expression" : description _select . condition ,
} ) ) ,
"macro_group_by" : ( ( ( ( _c = description _select . group _by ) !== null && _c !== void 0 ? _c : null ) === null )
? ""
: lib _plankton . string . coin ( " GROUP BY {{expression}}" , {
"expression" : description _select . group _by ,
} ) ) ,
"macro_having" : ( ( ( ( _d = description _select . having ) !== null && _d !== void 0 ? _d : null ) === null )
? ""
: lib _plankton . string . coin ( " HAVING {{expression}}" , {
"expression" : description _select . having ,
} ) ) ,
"macro_order_by" : ( ( ( ( _e = description _select . order _by ) !== null && _e !== void 0 ? _e : null ) === null )
? ""
: lib _plankton . string . coin ( " ORDER BY {{expression}}" , {
"expression" : description _select . order _by ,
} ) ) ,
"macro_limit" : ( ( ( ( _f = description _select . limit ) !== null && _f !== void 0 ? _f : null ) === null )
? ""
: lib _plankton . string . coin ( " LIMIT {{expression}}" , {
"expression" : description _select . limit . toFixed ( 0 ) ,
} ) ) ,
} ) ,
"arguments" : Object . assign ( { } , ( ( _g = description _select . arguments ) !== null && _g !== void 0 ? _g : { } ) ) ,
} ;
}
database . sql _common _formulation _select = sql _common _formulation _select ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
( at your option ) any later version .
» bacterio - plankton : database « 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 : database « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var database ;
( function ( database ) {
/ * *
* /
function sqlite _make ( parameters ) {
return {
"path" : parameters . path ,
"handle" : null ,
} ;
}
database . sqlite _make = sqlite _make ;
2024-08-28 07:52:01 +02:00
/ * *
* /
function sqlite _wrap _name ( name ) {
return ( "`" + name + "`" ) ;
}
database . sqlite _wrap _name = sqlite _wrap _name ;
2024-06-20 15:13:58 +02:00
/ * *
* /
function sqlite _init ( subject ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
if ( subject . handle === null ) {
yield new Promise ( ( resolve , reject ) => {
const _nm _sqlite3 = require ( "sqlite3" ) ;
subject . handle = new _nm _sqlite3 . Database ( subject . path , ( _nm _sqlite3 . OPEN _READWRITE | _nm _sqlite3 . OPEN _CREATE | _nm _sqlite3 . OPEN _FULLMUTEX ) , ( ) => { resolve ( undefined ) ; } ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
else {
2024-06-20 15:13:58 +02:00
// do nothing
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
return Promise . resolve ( undefined ) ;
} ) ;
}
/ * *
* @ author fenris
* /
function sqlite _adjust _query ( subject , query ) {
const query _adjusted = {
"template" : query . template ,
"arguments" : Object . fromEntries ( Object . entries ( query . arguments )
. map ( ( [ key , value ] ) => ( [
( "$" + key ) ,
( ( ( value === null )
||
( value === undefined ) )
? null
: ( ( typeof ( value ) === "boolean" )
? ( value ? "1" : "0" )
: value . toString ( ) ) )
] ) ) ) ,
} ;
lib _plankton . log . debug ( "database_sqlite_query" , {
"original" : query ,
"adjusted" : query _adjusted ,
} ) ;
return query _adjusted ;
}
/ * *
* @ author fenris
* /
function sqlite _query _free _get ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield sqlite _init ( subject ) ;
const query _adjusted = sqlite _adjust _query ( subject , query ) ;
return ( new Promise ( ( resolve , reject ) => {
subject . handle . all ( query _adjusted . template , query _adjusted . arguments , ( error , rows ) => {
if ( error !== null ) {
reject ( error ) ;
}
else {
resolve ( rows ) ;
}
} ) ;
} ) ) ;
} ) ;
}
database . sqlite _query _free _get = sqlite _query _free _get ;
/ * *
* @ author fenris
* /
function sqlite _query _free _put ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield sqlite _init ( subject ) ;
const query _adjusted = sqlite _adjust _query ( subject , query ) ;
return ( new Promise ( ( resolve , reject ) => {
subject . handle . run ( query _adjusted . template , query _adjusted . arguments ,
// this MUST be an old style function
function ( error ) {
if ( error ) {
reject ( error ) ;
}
else {
resolve ( this [ "lastID" ] ) ;
}
} ) ;
} ) ) ;
} ) ;
}
database . sqlite _query _free _put = sqlite _query _free _put ;
/ * *
* @ author fenris
* /
function sqlite _query _free _set ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield sqlite _init ( subject ) ;
const query _adjusted = sqlite _adjust _query ( subject , query ) ;
return ( new Promise ( ( resolve , reject ) => {
subject . handle . run ( query _adjusted . template , query _adjusted . arguments ,
// this MUST be an old style function
function ( error ) {
if ( error ) {
reject ( error ) ;
}
else {
resolve ( this [ "changes" ] ) ;
}
} ) ;
} ) ) ;
} ) ;
}
database . sqlite _query _free _set = sqlite _query _free _set ;
/ * *
* /
function sqlite _formulation _create _table ( description _create _table ) {
return database . sql _common _formulation _create _table ( description _create _table , {
2024-08-28 07:52:01 +02:00
"auto_increment_keyword" : "AUTOINCREMENT" ,
"auto_increment_special" : null ,
2024-06-20 15:13:58 +02:00
"omit_comments" : true ,
"type_map" : {
"boolean" : "INTEGER" ,
"integer" : "INTEGER" ,
"string_short" : "TEXT" ,
"string_medium" : "TEXT" ,
"string_long" : "TEXT" ,
"float" : "REAL" ,
} ,
2024-08-28 07:52:01 +02:00
"wrap_name" : sqlite _wrap _name ,
2024-06-20 15:13:58 +02:00
} ) ;
}
database . sqlite _formulation _create _table = sqlite _formulation _create _table ;
/ * *
* /
function sqlite _query _create _table ( subject , description ) {
return ( sqlite _query _free _set ( subject , sqlite _formulation _create _table ( description ) )
. then ( x => Promise . resolve ( undefined ) ) ) ;
}
database . sqlite _query _create _table = sqlite _query _create _table ;
/ * *
* /
function sqlite _formulation _insert ( description _insert ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _insert ( description _insert , {
"wrap_name" : sqlite _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . sqlite _formulation _insert = sqlite _formulation _insert ;
/ * *
* /
function sqlite _query _insert ( subject , description _insert ) {
return sqlite _query _free _put ( subject , sqlite _formulation _insert ( description _insert ) ) ;
}
database . sqlite _query _insert = sqlite _query _insert ;
/ * *
* /
function sqlite _formulation _update ( description _update ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _update ( description _update , {
"wrap_name" : sqlite _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . sqlite _formulation _update = sqlite _formulation _update ;
/ * *
* /
function sqlite _query _update ( subject , description _update ) {
return sqlite _query _free _set ( subject , sqlite _formulation _update ( description _update ) ) ;
}
database . sqlite _query _update = sqlite _query _update ;
/ * *
* /
function sqlite _formulation _delete ( description _delete ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _delete ( description _delete , {
"wrap_name" : sqlite _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . sqlite _formulation _delete = sqlite _formulation _delete ;
/ * *
* /
function sqlite _query _delete ( subject , description _delete ) {
return sqlite _query _free _set ( subject , sqlite _formulation _delete ( description _delete ) ) ;
}
database . sqlite _query _delete = sqlite _query _delete ;
/ * *
* /
function sqlite _formulation _select ( description _select ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _select ( description _select , {
"wrap_name" : sqlite _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . sqlite _formulation _select = sqlite _formulation _select ;
/ * *
* /
function sqlite _query _select ( subject , description _select ) {
return sqlite _query _free _get ( subject , sqlite _formulation _select ( description _select ) ) ;
}
database . sqlite _query _select = sqlite _query _select ;
/ * *
* /
function sqlite _database ( parameters ) {
const subject = sqlite _make ( parameters ) ;
return {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( name ) => sqlite _wrap _name ( name ) ,
2024-06-20 15:13:58 +02:00
"query_free_get" : ( query ) => sqlite _query _free _get ( subject , query ) ,
"query_free_put" : ( query ) => sqlite _query _free _put ( subject , query ) ,
"query_free_set" : ( query ) => sqlite _query _free _set ( subject , query ) ,
"query_create_table" : ( description _create _table ) => sqlite _query _create _table ( subject , description _create _table ) ,
"query_insert" : ( description _insert ) => sqlite _query _insert ( subject , description _insert ) ,
"query_update" : ( description _update ) => sqlite _query _update ( subject , description _update ) ,
"query_delete" : ( description _delete ) => sqlite _query _delete ( subject , description _delete ) ,
"query_select" : ( description _select ) => sqlite _query _select ( subject , description _select ) ,
} ;
}
database . sqlite _database = sqlite _database ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
var lib _plankton ;
( function ( lib _plankton ) {
var database ;
( function ( database ) {
/ * *
* @ author fenris
* /
class class _sqlite {
constructor ( parameters ) { this . subject = database . sqlite _make ( parameters ) ; }
2024-08-28 07:52:01 +02:00
wrap _name ( name ) { return database . sqlite _wrap _name ( name ) ; }
2024-06-20 15:13:58 +02:00
query _free _get ( query ) { return database . sqlite _query _free _get ( this . subject , query ) ; }
query _free _put ( query ) { return database . sqlite _query _free _put ( this . subject , query ) ; }
query _free _set ( query ) { return database . sqlite _query _free _set ( this . subject , query ) ; }
query _create _table ( description _create _table ) { return database . sqlite _query _create _table ( this . subject , description _create _table ) ; }
query _insert ( description _insert ) { return database . sqlite _query _insert ( this . subject , description _insert ) ; }
query _update ( description _update ) { return database . sqlite _query _update ( this . subject , description _update ) ; }
query _delete ( description _delete ) { return database . sqlite _query _delete ( this . subject , description _delete ) ; }
query _select ( description _select ) { return database . sqlite _query _select ( this . subject , description _select ) ; }
}
database . class _sqlite = class _sqlite ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
2024-04-22 10:02:34 +02:00
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var database ;
( function ( database ) {
/ * *
* /
function postgresql _make ( parameters ) {
var _a ;
return {
"host" : parameters . host ,
"port" : ( ( _a = parameters . port ) !== null && _a !== void 0 ? _a : 5432 ) ,
"username" : parameters . username ,
"password" : parameters . password ,
"schema" : parameters . schema ,
2024-08-28 07:52:01 +02:00
"pool" : null ,
2024-06-20 15:13:58 +02:00
} ;
}
database . postgresql _make = postgresql _make ;
/ * *
* /
2024-08-28 07:52:01 +02:00
function postgresql _wrap _name ( name ) {
2025-04-03 06:19:19 +00:00
return ( "\"" + name + "\"" ) ;
2024-08-28 07:52:01 +02:00
}
database . postgresql _wrap _name = postgresql _wrap _name ;
/ * *
* https : //node-postgres.com/apis/pool
* /
2024-06-20 15:13:58 +02:00
function postgresql _init ( subject ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
2024-08-28 07:52:01 +02:00
if ( subject . pool === null ) {
2024-06-20 15:13:58 +02:00
const nm _pg = require ( "pg" ) ;
2024-08-28 07:52:01 +02:00
subject . pool = ( new nm _pg . Pool ( {
2024-06-20 15:13:58 +02:00
"host" : subject . host ,
"port" : subject . port ,
"database" : subject . schema ,
"user" : subject . username ,
"password" : subject . password ,
} ) ) ;
}
else {
// do nothing
}
return Promise . resolve ( undefined ) ;
} ) ;
}
/ * *
* @ author fenris
* /
function postgresql _adjust _query ( subject , query ) {
let query _adjusted = {
"template" : query . template ,
"arguments" : [ ]
} ;
let index = 1 ;
while ( true ) {
const regexp = ( new RegExp ( "\\$([a-zA-Z_][0-9a-zA-Z_]*)" , "g" ) ) ;
const matching = regexp . exec ( query _adjusted . template ) ;
if ( matching === null ) {
break ;
}
else {
const part = matching [ 0 ] ;
const name = matching [ 1 ] ;
query _adjusted . template = ( query _adjusted . template . slice ( 0 , matching . index )
+
( "$" + index . toFixed ( 0 ) )
+
query _adjusted . template . slice ( matching . index + part . length ) ) ;
query _adjusted . arguments . push ( query . arguments [ name ] ) ;
index += 1 ;
}
}
lib _plankton . log . debug ( "database_postgresql_query" , {
"original" : query ,
"adjusted" : query _adjusted ,
} ) ;
return query _adjusted ;
}
/ * *
* @ author fenris
2024-08-28 07:52:01 +02:00
* @ see https : //node-postgres.com/apis/pool#poolquery
2024-06-20 15:13:58 +02:00
* /
function postgresql _query _free _get ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield postgresql _init ( subject ) ;
const query _adjusted = postgresql _adjust _query ( subject , query ) ;
2024-08-28 07:52:01 +02:00
const result = yield subject . pool . query ( {
2024-06-20 15:13:58 +02:00
"text" : query _adjusted . template ,
"values" : query _adjusted . arguments ,
} ) ;
return result [ "rows" ] ;
} ) ;
}
database . postgresql _query _free _get = postgresql _query _free _get ;
/ * *
* @ author fenris
2024-08-28 07:52:01 +02:00
* @ see https : //node-postgres.com/apis/pool#poolquery
2024-06-20 15:13:58 +02:00
* /
function postgresql _query _free _put ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield postgresql _init ( subject ) ;
const query _adjusted = postgresql _adjust _query ( subject , query ) ;
2024-08-28 07:52:01 +02:00
const result = yield subject . pool . query ( query _adjusted . template , query _adjusted . arguments ) ;
if ( result [ "rows" ] . length <= 0 ) {
return null ;
}
else {
const x = result [ "rows" ] [ 0 ] ;
const keys = Object . keys ( x ) ;
if ( keys . length <= 0 ) {
return null ;
}
else {
return x [ Object . keys ( x ) [ 0 ] ] ;
}
}
2024-06-20 15:13:58 +02:00
} ) ;
}
database . postgresql _query _free _put = postgresql _query _free _put ;
/ * *
* @ author fenris
2024-08-28 07:52:01 +02:00
* @ see https : //node-postgres.com/apis/pool#poolquery
2024-06-20 15:13:58 +02:00
* /
function postgresql _query _free _set ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
yield postgresql _init ( subject ) ;
const query _adjusted = postgresql _adjust _query ( subject , query ) ;
2024-08-28 07:52:01 +02:00
const result = yield subject . pool . query ( query _adjusted . template , query _adjusted . arguments ) ;
2024-06-20 15:13:58 +02:00
return result [ "rowCount" ] ;
} ) ;
}
database . postgresql _query _free _set = postgresql _query _free _set ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function postgresql _formulation _create _table ( description _create _table ) {
return database . sql _common _formulation _create _table ( description _create _table , {
2024-08-28 07:52:01 +02:00
"auto_increment_keyword" : "" ,
"auto_increment_special" : "SERIAL" ,
2024-06-20 15:13:58 +02:00
"omit_comments" : false ,
"type_map" : {
"boolean" : "BOOLEAN" ,
"integer" : "INTEGER" ,
"string_short" : "VARCHAR(63)" ,
"string_medium" : "VARCHAR(255)" ,
"string_long" : "TEXT" ,
"float" : "REAL" ,
} ,
2024-08-28 07:52:01 +02:00
"wrap_name" : postgresql _wrap _name ,
2024-06-20 15:13:58 +02:00
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
database . postgresql _formulation _create _table = postgresql _formulation _create _table ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function postgresql _query _create _table ( subject , description ) {
return ( postgresql _query _free _set ( subject , postgresql _formulation _create _table ( description ) )
. then ( x => Promise . resolve ( undefined ) ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
database . postgresql _query _create _table = postgresql _query _create _table ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function postgresql _formulation _insert ( description _insert ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _insert ( description _insert , {
"wrap_name" : postgresql _wrap _name ,
"set_returning" : true
} ) ;
2024-06-20 15:13:58 +02:00
}
database . postgresql _formulation _insert = postgresql _formulation _insert ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function postgresql _query _insert ( subject , description _insert ) {
return postgresql _query _free _put ( subject , postgresql _formulation _insert ( description _insert ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
database . postgresql _query _insert = postgresql _query _insert ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function postgresql _formulation _update ( description _update ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _update ( description _update , {
"wrap_name" : postgresql _wrap _name ,
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
database . postgresql _formulation _update = postgresql _formulation _update ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function postgresql _query _update ( subject , description _update ) {
return postgresql _query _free _set ( subject , postgresql _formulation _update ( description _update ) ) ;
}
database . postgresql _query _update = postgresql _query _update ;
/ * *
* /
function postgresql _formulation _delete ( description _delete ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _delete ( description _delete , {
"wrap_name" : postgresql _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . postgresql _formulation _delete = postgresql _formulation _delete ;
/ * *
* /
function postgresql _query _delete ( subject , description _delete ) {
return postgresql _query _free _set ( subject , postgresql _formulation _delete ( description _delete ) ) ;
}
database . postgresql _query _delete = postgresql _query _delete ;
/ * *
* /
function postgresql _formulation _select ( description _select ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _select ( description _select , {
"wrap_name" : postgresql _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . postgresql _formulation _select = postgresql _formulation _select ;
/ * *
* /
function postgresql _query _select ( subject , description _select ) {
return postgresql _query _free _get ( subject , postgresql _formulation _select ( description _select ) ) ;
}
database . postgresql _query _select = postgresql _query _select ;
/ * *
* /
function postgresql _database ( parameters ) {
const subject = postgresql _make ( parameters ) ;
return {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( name ) => postgresql _wrap _name ( name ) ,
2024-06-20 15:13:58 +02:00
"query_free_get" : ( query ) => postgresql _query _free _get ( subject , query ) ,
"query_free_put" : ( query ) => postgresql _query _free _put ( subject , query ) ,
"query_free_set" : ( query ) => postgresql _query _free _set ( subject , query ) ,
"query_create_table" : ( description _create _table ) => postgresql _query _create _table ( subject , description _create _table ) ,
"query_insert" : ( description _insert ) => postgresql _query _insert ( subject , description _insert ) ,
"query_update" : ( description _update ) => postgresql _query _update ( subject , description _update ) ,
"query_delete" : ( description _delete ) => postgresql _query _delete ( subject , description _delete ) ,
"query_select" : ( description _select ) => postgresql _query _select ( subject , description _select ) ,
2024-04-22 10:02:34 +02:00
} ;
2024-06-20 15:13:58 +02:00
}
database . postgresql _database = postgresql _database ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var database ;
( function ( database ) {
2024-04-22 10:02:34 +02:00
/ * *
* @ author fenris
* /
2024-06-20 15:13:58 +02:00
class class _postgresql {
constructor ( parameters ) { this . subject = database . postgresql _make ( parameters ) ; }
2024-08-28 07:52:01 +02:00
wrap _name ( name ) { return database . postgresql _wrap _name ( name ) ; }
2024-06-20 15:13:58 +02:00
query _free _get ( query ) { return database . postgresql _query _free _get ( this . subject , query ) ; }
query _free _put ( query ) { return database . postgresql _query _free _put ( this . subject , query ) ; }
query _free _set ( query ) { return database . postgresql _query _free _set ( this . subject , query ) ; }
query _create _table ( description _create _table ) { return database . postgresql _query _create _table ( this . subject , description _create _table ) ; }
query _insert ( description _insert ) { return database . postgresql _query _insert ( this . subject , description _insert ) ; }
query _update ( description _update ) { return database . postgresql _query _update ( this . subject , description _update ) ; }
query _delete ( description _delete ) { return database . postgresql _query _delete ( this . subject , description _delete ) ; }
query _select ( description _select ) { return database . postgresql _query _select ( this . subject , description _select ) ; }
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
database . class _postgresql = class _postgresql ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var database ;
( function ( database ) {
/ * *
* /
function mysql _make ( parameters ) {
throw ( new Error ( "not implemented" ) ) ;
}
database . mysql _make = mysql _make ;
2024-08-28 07:52:01 +02:00
/ * *
* /
function mysql _wrap _name ( name ) {
return ( "`" + name + "`" ) ;
}
database . mysql _wrap _name = mysql _wrap _name ;
2024-06-20 15:13:58 +02:00
/ * *
* /
function mysql _init ( subject ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
throw ( new Error ( "not implemented" ) ) ;
} ) ;
}
2024-04-22 10:02:34 +02:00
/ * *
* @ author fenris
* /
2024-06-20 15:13:58 +02:00
function mysql _adjust _query ( subject , query ) {
if ( subject . verbose ) {
console . info ( query ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
throw ( new Error ( "not implemented" ) ) ;
}
/ * *
* @ author fenris
* /
function mysql _query _free _get ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
throw ( new Error ( "not implemented" ) ) ;
} ) ;
}
database . mysql _query _free _get = mysql _query _free _get ;
/ * *
* @ author fenris
* /
function mysql _query _free _put ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
throw ( new Error ( "not implemented" ) ) ;
} ) ;
}
database . mysql _query _free _put = mysql _query _free _put ;
/ * *
* @ author fenris
* /
function mysql _query _free _set ( subject , query ) {
return _ _awaiter ( this , void 0 , void 0 , function * ( ) {
throw ( new Error ( "not implemented" ) ) ;
} ) ;
}
database . mysql _query _free _set = mysql _query _free _set ;
/ * *
* /
function mysql _formulation _create _table ( description _create _table ) {
return database . sql _common _formulation _create _table ( description _create _table , {
"auto_increment_keyword" : "AUTO INCREMENT" ,
"omit_comments" : false ,
"type_map" : {
"boolean" : "BOOLEAN" ,
"integer" : "INTEGER" ,
"string_short" : "VARCHAR(63)" ,
"string_medium" : "VARCHAR(255)" ,
"string_long" : "TEXT" ,
"float" : "REAL" ,
} ,
2024-08-28 07:52:01 +02:00
"wrap_name" : mysql _wrap _name ,
2024-06-20 15:13:58 +02:00
} ) ;
}
database . mysql _formulation _create _table = mysql _formulation _create _table ;
/ * *
* /
function mysql _query _create _table ( subject , description ) {
return ( mysql _query _free _set ( subject , mysql _formulation _create _table ( description ) )
. then ( x => Promise . resolve ( undefined ) ) ) ;
}
database . mysql _query _create _table = mysql _query _create _table ;
/ * *
* /
function mysql _formulation _insert ( description _insert ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _insert ( description _insert , {
"wrap_name" : mysql _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . mysql _formulation _insert = mysql _formulation _insert ;
/ * *
* /
function mysql _query _insert ( subject , description _insert ) {
return mysql _query _free _put ( subject , mysql _formulation _insert ( description _insert ) ) ;
}
database . mysql _query _insert = mysql _query _insert ;
/ * *
* /
function mysql _formulation _update ( description _update ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _update ( description _update , {
"wrap_name" : mysql _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . mysql _formulation _update = mysql _formulation _update ;
/ * *
* /
function mysql _query _update ( subject , description _update ) {
return mysql _query _free _set ( subject , mysql _formulation _update ( description _update ) ) ;
}
database . mysql _query _update = mysql _query _update ;
/ * *
* /
function mysql _formulation _delete ( description _delete ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _delete ( description _delete , {
"wrap_name" : mysql _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . mysql _formulation _delete = mysql _formulation _delete ;
/ * *
* /
function mysql _query _delete ( subject , description _delete ) {
return mysql _query _free _set ( subject , mysql _formulation _delete ( description _delete ) ) ;
}
database . mysql _query _delete = mysql _query _delete ;
/ * *
* /
function mysql _formulation _select ( description _select ) {
2024-08-28 07:52:01 +02:00
return database . sql _common _formulation _select ( description _select , {
"wrap_name" : mysql _wrap _name ,
} ) ;
2024-06-20 15:13:58 +02:00
}
database . mysql _formulation _select = mysql _formulation _select ;
/ * *
* /
function mysql _query _select ( subject , description _select ) {
return mysql _query _free _get ( subject , mysql _formulation _select ( description _select ) ) ;
}
database . mysql _query _select = mysql _query _select ;
/ * *
* /
function mysql _database ( parameters ) {
const subject = mysql _make ( parameters ) ;
return {
2024-08-28 07:52:01 +02:00
"wrap_name" : ( name ) => mysql _wrap _name ( name ) ,
2024-06-20 15:13:58 +02:00
"query_free_get" : ( query ) => mysql _query _free _get ( subject , query ) ,
"query_free_put" : ( query ) => mysql _query _free _put ( subject , query ) ,
"query_free_set" : ( query ) => mysql _query _free _set ( subject , query ) ,
"query_create_table" : ( description _create _table ) => mysql _query _create _table ( subject , description _create _table ) ,
"query_insert" : ( description _insert ) => mysql _query _insert ( subject , description _insert ) ,
"query_update" : ( description _update ) => mysql _query _update ( subject , description _update ) ,
"query_delete" : ( description _delete ) => mysql _query _delete ( subject , description _delete ) ,
"query_select" : ( description _select ) => mysql _query _select ( subject , description _select ) ,
2024-04-22 10:02:34 +02:00
} ;
2024-06-20 15:13:58 +02:00
}
database . mysql _database = mysql _database ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : database « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var database ;
( function ( database ) {
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ author fenris
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
class class _mysql {
constructor ( parameters ) { this . subject = database . mysql _make ( parameters ) ; }
2024-08-28 07:52:01 +02:00
wrap _name ( name ) { return database . mysql _wrap _name ( name ) ; }
2024-06-20 15:13:58 +02:00
query _free _get ( query ) { return database . mysql _query _free _get ( this . subject , query ) ; }
query _free _put ( query ) { return database . mysql _query _free _put ( this . subject , query ) ; }
query _free _set ( query ) { return database . mysql _query _free _set ( this . subject , query ) ; }
query _create _table ( description _create _table ) { return database . mysql _query _create _table ( this . subject , description _create _table ) ; }
query _insert ( description _insert ) { return database . mysql _query _insert ( this . subject , description _insert ) ; }
query _update ( description _update ) { return database . mysql _query _update ( this . subject , description _update ) ; }
query _delete ( description _delete ) { return database . mysql _query _delete ( this . subject , description _delete ) ; }
query _select ( description _select ) { return database . mysql _query _select ( this . subject , description _select ) ; }
}
database . class _mysql = class _mysql ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
} ) ( 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." ) ;
2024-08-28 07:52:01 +02:00
while ( g && ( g = 0 , op [ 0 ] && ( _ = 0 ) ) , _ ) try {
2024-06-20 15:13:58 +02:00
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 ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
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 } ;
}
} ;
2024-04-22 10:02:34 +02:00
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : storage « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : storage « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : storage « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var storage ;
( function ( storage ) {
var memory ;
( function ( memory ) {
/ * *
* @ author fenris
* /
function make ( parameters ) {
return {
"data" : { }
} ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
memory . make = make ;
/ * *
* @ author fenris
* /
function clear ( subject ) {
subject . data = { } ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
memory . clear = clear ;
/ * *
* @ author fenris
* /
function write ( subject , key , value ) {
var exists = ( key in subject . data ) ;
subject . data [ key ] = value ;
return exists ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
memory . write = write ;
/ * *
* @ author fenris
* /
function delete _ ( subject , key ) {
if ( ! ( key in subject . data ) ) {
throw ( new Error ( "no value for key '" + key + "'" ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
else {
delete subject . data [ key ] ;
2024-04-22 10:02:34 +02:00
}
}
2024-06-20 15:13:58 +02:00
memory . delete _ = delete _ ;
/ * *
* @ author fenris
* /
function read ( subject , key ) {
if ( ! ( key in subject . data ) ) {
throw ( new Error ( "no value for key '" + key + "'" ) ) ;
}
else {
return subject . data [ key ] ;
2024-04-22 10:02:34 +02:00
}
}
2024-06-20 15:13:58 +02:00
memory . read = read ;
/ * *
* @ author fenris
* /
function list ( subject ) {
return Object . keys ( subject . data ) ;
}
memory . list = list ;
/ * *
* @ author fenris
* /
function search ( subject , term ) {
return ( list ( subject )
. map ( function ( key ) { return ( { "key" : key , "preview" : key } ) ; } ) ) ;
}
memory . search = search ;
/ * *
* @ author fenris
* /
function implementation _chest ( parameters ) {
function wrap ( core ) {
return ( new Promise ( function ( resolve , reject ) { resolve ( core ( ) ) ; } ) ) ;
}
var subject = make ( parameters ) ;
return {
"setup" : function ( input ) { return Promise . resolve ( undefined ) ; } ,
"clear" : function ( ) { return wrap ( function ( ) { return clear ( subject ) ; } ) ; } ,
"write" : function ( key , value ) { return wrap ( function ( ) { return write ( subject , key , value ) ; } ) ; } ,
"delete" : function ( key ) { return wrap ( function ( ) { return delete _ ( subject , key ) ; } ) ; } ,
"read" : function ( key ) { return wrap ( function ( ) { return read ( subject , key ) ; } ) ; } ,
"search" : function ( term ) { return wrap ( function ( ) { return search ( subject , term ) ; } ) ; }
} ;
}
memory . implementation _chest = implementation _chest ;
} ) ( memory = storage . memory || ( storage . memory = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : storage « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var storage ;
( function ( storage ) {
var memory ;
( function ( memory ) {
2024-04-22 10:02:34 +02:00
/ * *
* @ author fenris
* /
2024-06-20 15:13:58 +02:00
var class _chest = /** @class */ ( function ( ) {
function class _chest ( parameters ) {
this . subject = memory . make ( parameters ) ;
}
class _chest . prototype . setup = function ( input ) { return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . clear = function ( ) { memory . clear ( this . subject ) ; return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . write = function ( key , value ) { return Promise . resolve ( memory . write ( this . subject , key , value ) ) ; } ;
class _chest . prototype [ "delete" ] = function ( key ) { memory . delete _ ( this . subject , key ) ; return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . read = function ( key ) { return Promise . resolve ( memory . read ( this . subject , key ) ) ; } ;
class _chest . prototype . search = function ( term ) { return Promise . resolve ( memory . search ( this . subject , term ) ) ; } ;
return class _chest ;
} ( ) ) ;
memory . class _chest = class _chest ;
} ) ( memory = storage . memory || ( storage . memory = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-06-20 15:13:58 +02:00
This file is part of » bacterio - plankton : storage « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2024-06-20 15:13:58 +02:00
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2024-06-20 15:13:58 +02:00
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2024-06-20 15:13:58 +02:00
var storage ;
( function ( storage ) {
var filesystem ;
( function ( filesystem ) {
/ * *
* @ author fenris
* /
function make ( parameters ) {
return {
"nodemodule" : require ( "fs" )
} ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
filesystem . make = make ;
/ * *
* /
function clear ( subject ) {
return Promise . reject ( new Error ( "nope" ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
filesystem . clear = clear ;
/ * *
* @ author fenris
* /
function write ( subject , path , content ) {
return ( new Promise ( function ( resolve , reject ) {
var exists = subject . nodemodule . existsSync ( path ) ;
subject . nodemodule . writeFile ( path , content , { } , function ( error ) {
if ( error === null ) {
resolve ( exists ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
filesystem . write = write ;
/ * *
* @ author fenris
* /
function delete _ ( subject , path ) {
return ( new Promise ( function ( resolve , reject ) {
subject . nodemodule . unlink ( path , function ( error ) {
if ( error === null ) {
resolve ( undefined ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
filesystem . delete _ = delete _ ;
/ * *
* @ author fenris
* /
function read ( subject , path ) {
return ( new Promise ( function ( resolve , reject ) {
subject . nodemodule . readFile ( path , { } , function ( error , content ) {
if ( error === null ) {
resolve ( content ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
}
filesystem . read = read ;
/ * *
* /
function implementation _chest ( parameters ) {
var subject = make ( parameters ) ;
return {
"setup" : function ( input ) { return Promise . resolve ( undefined ) ; } ,
"clear" : function ( ) { return clear ( subject ) ; } ,
"write" : function ( key , value ) { return write ( subject , key , value ) ; } ,
"delete" : function ( key ) { return delete _ ( subject , key ) ; } ,
"read" : function ( key ) { return read ( subject , key ) ; } ,
"search" : function ( term ) { return Promise . reject ( "not available" ) ; }
} ;
}
filesystem . implementation _chest = implementation _chest ;
} ) ( filesystem = storage . filesystem || ( storage . filesystem = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : storage « 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 : storage « 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 : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var filesystem ;
( function ( filesystem ) {
/ * *
* @ author fenris
* /
var class _chest = /** @class */ ( function ( ) {
function class _chest ( parameters ) {
this . subject = filesystem . make ( parameters ) ;
}
class _chest . prototype . setup = function ( input ) { return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . clear = function ( ) { return filesystem . clear ( this . subject ) ; } ;
class _chest . prototype . write = function ( key , value ) { return filesystem . write ( this . subject , key , value ) ; } ;
class _chest . prototype [ "delete" ] = function ( key ) { return filesystem . delete _ ( this . subject , key ) ; } ;
class _chest . prototype . read = function ( key ) { return filesystem . read ( this . subject , key ) ; } ;
class _chest . prototype . search = function ( searchterm ) { return Promise . reject ( new Error ( "not available" ) ) ; } ;
return class _chest ;
} ( ) ) ;
filesystem . class _chest = class _chest ;
} ) ( filesystem = storage . filesystem || ( storage . filesystem = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : storage « 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 : storage « 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 : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _make ( parameters ) {
return {
"database_implementation" : parameters . database _implementation ,
"table_name" : parameters . table _name ,
"key_name" : parameters . key _name
} ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _make = sql _table _autokey _make ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _setup ( subject , description _create _table ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
return [ 2 /*return*/ , subject . database _implementation . query _create _table ( description _create _table ) ] ;
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _setup = sql _table _autokey _setup ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _create ( subject , value ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
return [ 2 /*return*/ , subject . database _implementation . query _insert ( {
"table_name" : subject . table _name ,
2024-08-28 07:52:01 +02:00
"values" : value ,
"returning" : subject . key _name
2024-06-20 15:13:58 +02:00
} ) ] ;
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _create = sql _table _autokey _create ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _update ( subject , key , value ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
return [ 2 /*return*/ , ( subject . database _implementation . query _update ( {
"table_name" : subject . table _name ,
"values" : value ,
2024-08-28 07:52:01 +02:00
"condition" : lib _plankton . string . coin ( "{{key_name}} = $key" , {
"key_name" : subject . database _implementation . wrap _name ( subject . key _name )
2024-06-20 15:13:58 +02:00
} ) ,
"arguments" : {
"key" : key
}
} )
. then ( function ( x ) { return Promise . resolve ( undefined ) ; } ) ) ] ;
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _update = sql _table _autokey _update ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _delete ( subject , key ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 : return [ 4 /*yield*/ , subject . database _implementation . query _delete ( {
"table_name" : subject . table _name ,
2024-08-28 07:52:01 +02:00
"condition" : lib _plankton . string . coin ( "{{key_name}} = $key" , {
"key_name" : subject . database _implementation . wrap _name ( subject . key _name )
2024-06-20 15:13:58 +02:00
} ) ,
"arguments" : {
"key" : key
}
} ) ] ;
case 1 :
_a . sent ( ) ;
return [ 2 /*return*/ , Promise . resolve ( undefined ) ] ;
}
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _delete = sql _table _autokey _delete ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _read ( subject , key ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var rows ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 : return [ 4 /*yield*/ , subject . database _implementation . query _select ( {
"source" : subject . table _name ,
"fields" : null ,
2024-08-28 07:52:01 +02:00
"condition" : lib _plankton . string . coin ( "{{key_name}} = $key" , {
"key_name" : subject . database _implementation . wrap _name ( subject . key _name )
2024-06-20 15:13:58 +02:00
} ) ,
"arguments" : {
"key" : key
}
} ) ] ;
case 1 :
rows = _a . sent ( ) ;
if ( rows . length < 1 ) {
return [ 2 /*return*/ , Promise . reject ( "not found" ) ] ;
}
else if ( rows . length > 1 ) {
return [ 2 /*return*/ , Promise . reject ( "ambiguous" ) ] ;
}
else {
delete rows [ 0 ] [ subject . key _name ] ;
return [ 2 /*return*/ , Promise . resolve ( rows [ 0 ] ) ] ;
}
return [ 2 /*return*/ ] ;
}
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _read = sql _table _autokey _read ;
2024-04-22 10:02:34 +02:00
/ * *
2024-06-20 15:13:58 +02:00
* @ todo correct preview
2024-04-22 10:02:34 +02:00
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _search ( subject , term ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var rows ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 : return [ 4 /*yield*/ , subject . database _implementation . query _select ( {
"source" : subject . table _name ,
"fields" : null ,
"condition" : ( ( term === null ) ? null : term . expression ) ,
"arguments" : ( ( term === null ) ? null : term . arguments )
} ) ] ;
case 1 :
rows = _a . sent ( ) ;
return [ 2 /*return*/ , Promise . resolve ( rows
. map ( function ( row ) { return ( {
"key" : row [ subject . key _name ] ,
"preview" : row
} ) ; } ) ) ] ;
}
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _search = sql _table _autokey _search ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2024-06-20 15:13:58 +02:00
function sql _table _autokey _store ( parameters ) {
var subject = sql _table _autokey _make ( parameters ) ;
2024-04-22 10:02:34 +02:00
return {
2024-06-20 15:13:58 +02:00
"setup" : function ( input ) { return sql _table _autokey _setup ( subject , input ) ; } ,
"create" : function ( value ) { return sql _table _autokey _create ( subject , value ) ; } ,
"update" : function ( key , value ) { return sql _table _autokey _update ( subject , key , value ) ; } ,
"delete" : function ( key ) { return sql _table _autokey _delete ( subject , key ) ; } ,
"read" : function ( key ) { return sql _table _autokey _read ( subject , key ) ; } ,
"search" : function ( term ) { return sql _table _autokey _search ( subject , term ) ; }
2024-04-22 10:02:34 +02:00
} ;
}
2024-06-20 15:13:58 +02:00
storage . sql _table _autokey _store = sql _table _autokey _store ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : storage « 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 : storage « 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 : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
2024-04-22 10:02:34 +02:00
/ * *
* @ author fenris
* /
2024-06-20 15:13:58 +02:00
var class _sql _table _autokey = /** @class */ ( function ( ) {
function class _sql _table _autokey ( parameters ) {
this . subject = storage . sql _table _autokey _make ( parameters ) ;
}
class _sql _table _autokey . prototype . setup = function ( input ) { return storage . sql _table _autokey _setup ( this . subject , input ) ; } ;
class _sql _table _autokey . prototype . create = function ( value ) { return storage . sql _table _autokey _create ( this . subject , value ) ; } ;
class _sql _table _autokey . prototype . update = function ( key , value ) { return storage . sql _table _autokey _update ( this . subject , key , value ) ; } ;
class _sql _table _autokey . prototype [ "delete" ] = function ( key ) { return storage . sql _table _autokey _delete ( this . subject , key ) ; } ;
class _sql _table _autokey . prototype . read = function ( key ) { return storage . sql _table _autokey _read ( this . subject , key ) ; } ;
class _sql _table _autokey . prototype . search = function ( term ) { return storage . sql _table _autokey _search ( this . subject , term ) ; } ;
return class _sql _table _autokey ;
} ( ) ) ;
storage . class _sql _table _autokey = class _sql _table _autokey ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : storage « 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 : storage « 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 : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var sql _table _common ;
( function ( sql _table _common ) {
/ * *
* /
function make ( parameters ) {
return {
"database_implementation" : parameters . database _implementation ,
"table_name" : parameters . table _name ,
"key_names" : parameters . key _names
} ;
}
sql _table _common . make = make ;
/ * *
* /
function key _condition ( subject , key ) {
return {
"condition" : lib _string . coin ( "({{clauses}})" , {
"clauses" : ( subject . key _names
2024-08-28 07:52:01 +02:00
. map ( function ( key _name ) { return lib _plankton . string . coin ( "({{name1}} = $key_{{name2}})" , {
"name1" : subject . database _implementation . wrap _name ( key _name ) ,
"name2" : key _name
2024-06-20 15:13:58 +02:00
} ) ; } )
. join ( " AND " ) )
} ) ,
"arguments" : Object . fromEntries ( subject . key _names
. map ( function ( key _name , index ) { return ( [
lib _plankton . string . coin ( "key_{{name}}" , {
"name" : key _name
} ) ,
key [ index ]
] ) ; } ) )
} ;
}
/ * *
* /
function setup ( subject , description _create _table ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
return [ 2 /*return*/ , subject . database _implementation . query _create _table ( description _create _table ) ] ;
} ) ;
} ) ;
}
sql _table _common . setup = setup ;
/ * *
* /
function clear ( subject ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 : return [ 4 /*yield*/ , subject . database _implementation . query _delete ( {
"table_name" : subject . table _name ,
"condition" : "TRUE" ,
"arguments" : { }
} ) ] ;
case 1 :
_a . sent ( ) ;
return [ 2 /*return*/ , Promise . resolve ( undefined ) ] ;
}
} ) ;
} ) ;
}
sql _table _common . clear = clear ;
/ * *
* @ todo optimize : avoid read
* /
function write ( subject , key , value ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var exists , error _1 , field _names , condition ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 :
_a . trys . push ( [ 0 , 2 , , 3 ] ) ;
return [ 4 /*yield*/ , read ( subject , key ) ] ;
case 1 :
_a . sent ( ) ;
exists = true ;
return [ 3 /*break*/ , 3 ] ;
case 2 :
error _1 = _a . sent ( ) ;
exists = false ;
return [ 3 /*break*/ , 3 ] ;
case 3 :
field _names = Object . keys ( value ) ;
if ( ! ! exists ) return [ 3 /*break*/ , 5 ] ;
return [ 4 /*yield*/ , subject . database _implementation . query _insert ( {
"table_name" : subject . table _name ,
"values" : Object . assign (
// key
Object . fromEntries ( subject . key _names . map ( function ( key _name , index ) { return ( [ key _name , key [ index ] ] ) ; } ) ) ,
// value
value )
} ) ] ;
case 4 :
_a . sent ( ) ;
return [ 3 /*break*/ , 7 ] ;
case 5 :
condition = key _condition ( subject , key ) ;
return [ 4 /*yield*/ , subject . database _implementation . query _update ( {
"table_name" : subject . table _name ,
"values" : value ,
"condition" : condition . condition ,
"arguments" : condition . arguments
} ) ] ;
case 6 :
_a . sent ( ) ;
_a . label = 7 ;
case 7 : return [ 2 /*return*/ , Promise . resolve ( exists ) ] ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
} ) ;
} ) ;
}
sql _table _common . write = write ;
/ * *
* /
function delete _ ( subject , key ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var condition ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 :
condition = key _condition ( subject , key ) ;
return [ 4 /*yield*/ , subject . database _implementation . query _delete ( {
"table_name" : subject . table _name ,
"condition" : condition . condition ,
"arguments" : condition . arguments
} ) ] ;
case 1 :
_a . sent ( ) ;
return [ 2 /*return*/ , Promise . resolve ( undefined ) ] ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
} ) ;
} ) ;
2024-04-22 10:02:34 +02:00
}
2024-06-20 15:13:58 +02:00
sql _table _common . delete _ = delete _ ;
/ * *
* /
function read ( subject , key ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var condition , rows ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 :
condition = key _condition ( subject , key ) ;
return [ 4 /*yield*/ , subject . database _implementation . query _select ( {
"source" : subject . table _name ,
"fields" : null ,
"condition" : condition . condition ,
"arguments" : condition . arguments
} ) ] ;
case 1 :
rows = _a . sent ( ) ;
if ( rows . length < 1 ) {
return [ 2 /*return*/ , Promise . reject ( "not found" ) ] ;
}
else if ( rows . length > 1 ) {
return [ 2 /*return*/ , Promise . reject ( "ambiguous" ) ] ;
}
else {
subject . key _names . forEach ( function ( key _name ) { delete rows [ 0 ] [ key _name ] ; } ) ;
return [ 2 /*return*/ , Promise . resolve ( rows [ 0 ] ) ] ;
}
return [ 2 /*return*/ ] ;
}
} ) ;
} ) ;
}
sql _table _common . read = read ;
/ * *
* @ todo correct preview
* /
function search ( subject , term ) {
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var rows ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 : return [ 4 /*yield*/ , subject . database _implementation . query _select ( {
"source" : subject . table _name ,
"fields" : null ,
"condition" : ( ( term === null ) ? null : term . expression ) ,
"arguments" : ( ( term === null ) ? null : term . arguments )
} ) ] ;
case 1 :
rows = _a . sent ( ) ;
return [ 2 /*return*/ , Promise . resolve ( rows
. map ( function ( row ) { return ( {
"key" : subject . key _names . map ( function ( name ) { return row [ name ] ; } ) ,
"preview" : row
} ) ; } ) ) ] ;
}
} ) ;
} ) ;
}
sql _table _common . search = search ;
/ * *
* /
function chest ( parameters ) {
var subject = make ( parameters ) ;
return {
"setup" : function ( input ) { return setup ( subject , input ) ; } ,
"clear" : function ( ) { return clear ( subject ) ; } ,
"write" : function ( key , value ) { return write ( subject , key , value ) ; } ,
"delete" : function ( key ) { return delete _ ( subject , key ) ; } ,
"read" : function ( key ) { return read ( subject , key ) ; } ,
"search" : function ( term ) { return search ( subject , term ) ; }
} ;
}
sql _table _common . chest = chest ;
} ) ( sql _table _common = storage . sql _table _common || ( storage . sql _table _common = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-20 15:13:58 +02:00
< info @ greenscale . de >
» bacterio - plankton : storage « 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 : storage « 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 : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var sql _table _common ;
( function ( sql _table _common ) {
/ * *
* @ author fenris
* /
var class _chest = /** @class */ ( function ( ) {
function class _chest ( parameters ) {
this . subject = sql _table _common . make ( parameters ) ;
}
class _chest . prototype . setup = function ( input ) { return sql _table _common . setup ( this . subject , input ) ; } ;
class _chest . prototype . clear = function ( ) { return sql _table _common . clear ( this . subject ) ; } ;
class _chest . prototype . write = function ( key , value ) { return sql _table _common . write ( this . subject , key , value ) ; } ;
class _chest . prototype [ "delete" ] = function ( key ) { return sql _table _common . delete _ ( this . subject , key ) ; } ;
class _chest . prototype . read = function ( key ) { return sql _table _common . read ( this . subject , key ) ; } ;
class _chest . prototype . search = function ( term ) { return sql _table _common . search ( this . subject , term ) ; } ;
return class _chest ;
} ( ) ) ;
sql _table _common . class _chest = class _chest ;
} ) ( sql _table _common = storage . sql _table _common || ( storage . sql _table _common = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( 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." ) ;
2024-08-28 07:52:01 +02:00
while ( g && ( g = 0 , op [ 0 ] && ( _ = 0 ) ) , _ ) try {
2024-04-22 10:02:34 +02:00
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 : storage « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
» bacterio - plankton : session « 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 : session « 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 : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var session ;
( function ( session _1 ) {
/ * *
* /
var _conf = null ;
/ * *
* /
function check _conf ( ) {
if ( _conf === null ) {
throw ( new Error ( "session system not set up yet" ) ) ;
}
else {
// do nothing
}
}
/ * *
* /
function begin ( name , options ) {
if ( options === void 0 ) { options = { } ; }
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
var key , attempts , session _old , error _1 , session _2 , session _raw ;
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 :
options = Object . assign ( {
"lifetime" : _conf . default _lifetime ,
"data" : null
} , options ) ;
check _conf ( ) ;
key = null ;
attempts = 0 ;
_a . label = 1 ;
case 1 :
if ( ! true ) return [ 3 /*break*/ , 6 ] ;
attempts += 1 ;
key = lib _plankton . call . convey ( _conf . key _length , [
function ( x ) { return ( new Array ( x ) ) . fill ( null ) ; } ,
function ( x ) { return x . map ( function ( ) { return lib _plankton . random . generate _hexdigit ( ) ; } ) ; } ,
function ( x ) { return x . join ( "" ) ; } ,
] ) ;
session _old = null ;
_a . label = 2 ;
case 2 :
_a . trys . push ( [ 2 , 4 , , 5 ] ) ;
return [ 4 /*yield*/ , _conf . data _chest . read ( key ) ] ;
case 3 :
session _old = _a . sent ( ) ;
return [ 3 /*break*/ , 5 ] ;
case 4 :
error _1 = _a . sent ( ) ;
session _old = null ;
return [ 3 /*break*/ , 5 ] ;
case 5 :
if ( session _old !== null ) {
key = null ;
if ( attempts >= _conf . key _max _attempts ) {
// fail
return [ 3 /*break*/ , 6 ] ;
}
else {
// retry
}
}
else {
// suuccess
return [ 3 /*break*/ , 6 ] ;
}
return [ 3 /*break*/ , 1 ] ;
case 6 :
if ( ! ( key === null ) ) return [ 3 /*break*/ , 7 ] ;
throw ( new Error ( "failed to generate unique session key" ) ) ;
case 7 :
session _2 = {
"key" : key ,
"name" : name ,
"expiry" : ( lib _plankton . base . get _current _timestamp ( ) + options . lifetime ) ,
"data" : options . data
} ;
session _raw = {
"key" : session _2 . key ,
"name" : session _2 . name ,
"expiry" : Math . floor ( session _2 . expiry ) ,
"data" : JSON . stringify ( session _2 . data )
} ;
lib _plankton . call . timeout ( function ( ) {
lib _plankton . log . info ( "session_dropping_due_to_being_expired" , {
"key" : key ,
"name" : name ,
"lifetime" : options . lifetime
} ) ;
end ( key ) ;
} , options . lifetime ) ;
return [ 4 /*yield*/ , _conf . data _chest . write ( key , session _raw ) ] ;
case 8 :
_a . sent ( ) ;
return [ 2 /*return*/ , Promise . resolve ( key ) ] ;
}
} ) ;
} ) ;
}
session _1 . begin = begin ;
/ * *
* /
function get ( key ) {
check _conf ( ) ;
return ( _conf . data _chest . read ( key )
. then ( function ( session _raw ) {
var session = {
"key" : session _raw [ "key" ] ,
"name" : session _raw [ "name" ] ,
"expiry" : session _raw [ "expiry" ] ,
"data" : JSON . parse ( session _raw [ "data" ] )
} ;
var now = lib _plankton . base . get _current _timestamp ( ) ;
if ( now > session . expiry ) {
lib _plankton . log . info ( "session_dropping_due_to_being_stale" , {
"key" : session . key ,
"name" : session . name
} ) ;
end ( key ) ;
return Promise . reject ( ) ;
}
else {
return Promise . resolve ( session ) ;
}
} ) ) ;
}
session _1 . get = get ;
/ * *
* /
function end ( key ) {
check _conf ( ) ;
return _conf . data _chest [ "delete" ] ( key ) ;
}
session _1 . end = end ;
/ * *
* /
function setup ( options ) {
if ( options === void 0 ) { options = { } ; }
return _ _awaiter ( this , void 0 , void 0 , function ( ) {
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
case 0 :
options = Object . assign ( {
"key_length" : 16 ,
"key_max_attempts" : 3 ,
"default_lifetime" : 900 ,
"data_chest" : lib _plankton . storage . memory . implementation _chest ( { } ) ,
"clear" : false
} , options ) ;
_conf = {
"key_length" : options . key _length ,
"key_max_attempts" : options . key _max _attempts ,
"default_lifetime" : options . default _lifetime ,
"data_chest" : options . data _chest
} ;
if ( ! options . clear ) return [ 3 /*break*/ , 2 ] ;
return [ 4 /*yield*/ , _conf . data _chest . clear ( ) ] ;
case 1 :
_a . sent ( ) ;
return [ 3 /*break*/ , 2 ] ;
case 2 : return [ 2 /*return*/ , Promise . resolve ( undefined ) ] ;
}
} ) ;
} ) ;
}
session _1 . setup = setup ;
} ) ( session = lib _plankton . session || ( lib _plankton . session = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : json « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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
* /
2025-04-03 06:19:19 +00:00
function encode ( source , options = { } ) {
options = Object . assign ( {
"formatted" : false ,
} , options ) ;
return JSON . stringify ( source , undefined , ( options . formatted ? "\t" : undefined ) ) ;
2024-04-22 10:02:34 +02:00
}
json . encode = encode ;
/ * *
* @ author fenris
* /
2025-04-03 06:19:19 +00:00
function decode ( target ) {
return JSON . parse ( target ) ;
2024-04-22 10:02:34 +02:00
}
json . decode = decode ;
2025-04-03 06:19:19 +00:00
/ * *
* @ author fenris
* /
function implementation _code ( ) {
return {
"encode" : x => encode ( x ) ,
"decode" : decode ,
} ;
}
json . implementation _code = implementation _code ;
2024-04-22 10:02:34 +02:00
} ) ( json = lib _plankton . json || ( lib _plankton . json = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : json « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 = { } ) ) ;
/ *
This file is part of » bacterio - plankton : object « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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
2025-04-03 06:19:19 +00:00
* @ deprecated use the "??" operator instead
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function fetch ( object , fieldname , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"fallback" : null ,
"escalation" : 1
} , options ) ;
if ( ( fieldname in object )
&&
( object [ fieldname ] !== undefined ) ) {
2024-04-22 10:02:34 +02:00
return object [ fieldname ] ;
}
else {
2025-04-03 06:19:19 +00:00
if ( ! options . escalate ) {
return options . fallback ;
}
else {
throw ( new Error ( "field '" + fieldname + "' not in structure" ) ) ;
2024-04-22 10:02:34 +02:00
}
}
}
object _1 . fetch = fetch ;
/ * *
* /
function map ( object _from , transformator ) {
2025-04-03 06:19:19 +00:00
return ( Object . fromEntries ( Object . entries ( object _from )
. map ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
return ( [ key , transformator ( value , key ) ] ) ;
} ) ) ) ;
2024-04-22 10:02:34 +02:00
}
object _1 . map = map ;
/ * *
2025-04-03 06:19:19 +00:00
* gibt ein Objekt mit bestimmten Einträgen des Eingabe - Objekts zurück
2024-04-22 10:02:34 +02:00
* /
function filter ( object _from , predicate ) {
2025-04-03 06:19:19 +00:00
return ( Object . fromEntries ( Object . entries ( object _from )
. filter ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
return predicate ( value , key ) ;
} ) ) ) ;
2024-04-22 10:02:34 +02:00
}
object _1 . filter = filter ;
/ * *
2025-04-03 06:19:19 +00:00
* wandelt ein Array mit Einträgen der Form { key , value } in ein entsprechendes Objekt um
*
* @ deprecated use Object . fromEntries instead !
2024-04-22 10:02:34 +02:00
* /
function from _array ( array ) {
2025-04-03 06:19:19 +00:00
return ( Object . fromEntries ( array
. map ( function ( _a ) {
var key = _a [ "key" ] , value = _a [ "value" ] ;
return ( [ key , value ] ) ;
} ) ) ) ;
2024-04-22 10:02:34 +02:00
}
object _1 . from _array = from _array ;
/ * *
2025-04-03 06:19:19 +00:00
* wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form { key , value } um
*
* @ deprecated use Object . entries insetad !
2024-04-22 10:02:34 +02:00
* /
function to _array ( object ) {
2025-04-03 06:19:19 +00:00
return ( Object . entries ( object )
. map ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
return ( { "key" : key , "value" : value } ) ;
} ) ) ;
2024-04-22 10:02:34 +02:00
}
object _1 . to _array = to _array ;
/ * *
2025-04-03 06:19:19 +00:00
* gibt eine Liste von Schlüsseln eines Objekts zurück
*
* @ deprecated use Object . keys instead !
2024-04-22 10:02:34 +02:00
* /
function keys ( object ) {
return Object . keys ( object ) ;
}
object _1 . keys = keys ;
/ * *
2025-04-03 06:19:19 +00:00
* gibt eine Liste von Werten eines Objekts zurück
*
* @ deprecated use Object . values instead !
2024-04-22 10:02:34 +02:00
* /
function values ( object ) {
2025-04-03 06:19:19 +00:00
return Object . values ( object ) ;
2024-04-22 10:02:34 +02:00
}
object _1 . values = values ;
/ * *
2025-04-03 06:19:19 +00:00
* liest ein Baum - artiges Objekt an einer bestimmten Stelle aus
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function path _read ( object , path , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"fallback" : null ,
"escalate" : false
} , options ) ;
2024-04-22 10:02:34 +02:00
var steps = ( ( path . length == 0 ) ? [ ] : path . split ( "." ) ) ;
if ( steps . length == 0 ) {
throw ( new Error ( "empty path" ) ) ;
}
else {
var position _1 = object ;
2025-04-03 06:19:19 +00:00
var reachable = ( ( position _1 != null )
&&
( steps . slice ( 0 , steps . length - 1 )
. every ( function ( step ) {
position _1 = lib _plankton . object . fetch ( position _1 , step , {
"fallback" : null ,
"escalate" : false
} ) ;
return ( position _1 != null ) ;
} ) ) ) ;
2024-04-22 10:02:34 +02:00
if ( reachable ) {
2025-04-03 06:19:19 +00:00
return lib _plankton . object . fetch ( position _1 , steps [ steps . length - 1 ] , {
"fallback" : options . fallback ,
"escalate" : options . escalate
} ) ;
2024-04-22 10:02:34 +02:00
}
else {
2025-04-03 06:19:19 +00:00
return lib _plankton . object . fetch ( { } , "_dummy_" , {
"fallback" : options . fallback ,
"escalate" : options . escalate
} ) ;
2024-04-22 10:02:34 +02:00
}
}
}
object _1 . path _read = path _read ;
/ * *
2025-04-03 06:19:19 +00:00
* schreibt einen Wert an eine bestimmte Stelle in einem Baum - artigen Objekt
2024-04-22 10:02:34 +02:00
* /
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 ) {
2025-04-03 06:19:19 +00:00
var position _ = lib _plankton . object . fetch ( position _2 , step , {
"fallback" : null ,
"escalate" : false
} ) ;
2024-04-22 10:02:34 +02:00
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 {
2025-04-03 06:19:19 +00:00
throw ( new Error ( "path '" + path + "' does not exist and may not be constructed" ) ) ;
2024-04-22 10:02:34 +02:00
}
}
}
object _1 . path _write = path _write ;
/ * *
2025-04-03 06:19:19 +00:00
* prüft ob ein Objekt einem bestimmten Muster entspricht
*
* @ deprecated not very useful
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function matches ( object , pattern , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"collate" : instance _collate
} , options ) ;
return ( Object . entries ( pattern )
. every ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
return options . collate ( value , object [ key ] ) ;
} ) ) ;
2024-04-22 10:02:34 +02:00
}
object _1 . matches = matches ;
/ * *
2025-04-03 06:19:19 +00:00
* erzeugt eine Projektion eines Baum - artigen Objekts in ein Listen - artiges Objekt
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function flatten ( value , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"separator" : "." ,
"key_for_array_element" : ( function ( index ) { return ( "element_" + index . toFixed ( 0 ) ) ; } )
} , options ) ;
var integrate = function ( result , key , value ) {
if ( value == null ) {
result [ key ] = value ;
2024-04-22 10:02:34 +02:00
}
else {
// primitive Werte direkt übernehmen
2025-04-03 06:19:19 +00:00
if ( typeof ( value ) != "object" ) {
result [ key ] = value ;
2024-04-22 10:02:34 +02:00
}
// sonst durch rekursiven Aufruf die flache Variante des Wertes ermitteln und einarbeiten
else {
2025-04-03 06:19:19 +00:00
var result _ = flatten ( value , {
"separator" : options . separator ,
"key_for_array_element" : options . key _for _array _element
} ) ;
Object . entries ( result _ ) . forEach ( function ( _a ) {
var key _ = _a [ 0 ] , value _ = _a [ 1 ] ;
result [ ( key + options . separator + key _ ) ] = value _ ;
2024-04-22 10:02:34 +02:00
} ) ;
}
}
} ;
2025-04-03 06:19:19 +00:00
if ( ( value === null )
||
( value === undefined ) ) {
2024-04-22 10:02:34 +02:00
return null ;
}
else {
2025-04-03 06:19:19 +00:00
var result _1 = { } ;
2024-04-22 10:02:34 +02:00
if ( typeof ( value ) != "object" ) {
2025-04-03 06:19:19 +00:00
result _1 [ "value" ] = value ;
2024-04-22 10:02:34 +02:00
}
else {
if ( value instanceof Array ) {
2025-04-03 06:19:19 +00:00
value . forEach ( function ( element , index ) {
integrate ( result _1 , options . key _for _array _element ( index ) , element ) ;
2024-04-22 10:02:34 +02:00
} ) ;
}
else {
2025-04-03 06:19:19 +00:00
Object . entries ( value ) . forEach ( function ( _a ) {
var key = _a [ 0 ] , value = _a [ 1 ] ;
integrate ( result _1 , key , value ) ;
2024-04-22 10:02:34 +02:00
} ) ;
}
}
2025-04-03 06:19:19 +00:00
return result _1 ;
2024-04-22 10:02:34 +02:00
}
}
object _1 . flatten = flatten ;
/ * *
2025-04-03 06:19:19 +00:00
* @ deprecated use Object . assign instead !
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function clash ( x , y , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"overwrite" : true ,
"hooks" : {
"existing" : function ( key , value _old , value _new ) {
lib _plankton . log . warning ( "object_clash_field_already_defined" , {
"key" : key
} ) ;
}
}
} , options ) ;
2024-04-22 10:02:34 +02:00
var z = { } ;
Object . keys ( x ) . forEach ( function ( key ) {
z [ key ] = x [ key ] ;
} ) ;
Object . keys ( y ) . forEach ( function ( key ) {
if ( key in z ) {
2025-04-03 06:19:19 +00:00
if ( options . hooks . existing != null ) {
options . hooks . existing ( key , z [ key ] , y [ key ] ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
if ( options . overwrite ) {
2024-04-22 10:02:34 +02:00
z [ key ] = y [ key ] ;
}
}
else {
z [ key ] = y [ key ] ;
}
} ) ;
return z ;
}
object _1 . clash = clash ;
/ * *
2025-04-03 06:19:19 +00:00
* @ deprecated use Object . assign instead !
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function patch ( core , mantle , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"deep" : true ,
"path" : null
} , options ) ;
2024-04-22 10:02:34 +02:00
if ( mantle == null ) {
2025-04-03 06:19:19 +00:00
lib _plankton . log . warning ( "object_patch_mantle_is_null" , {
"core" : core
} ) ;
2024-04-22 10:02:34 +02:00
}
else {
Object . keys ( mantle ) . forEach ( function ( key ) {
2025-04-03 06:19:19 +00:00
var path _ = ( ( options . path == null )
?
key
:
( options . path + "." + key ) ) ;
2024-04-22 10:02:34 +02:00
var value _mantle = mantle [ key ] ;
if ( ! ( key in core ) ) {
2025-04-03 06:19:19 +00:00
if ( ( typeof ( value _mantle ) == "object" )
&&
( value _mantle != null )
&&
options . deep ) {
2024-04-22 10:02:34 +02:00
if ( value _mantle instanceof Array ) {
core [ key ] = [ ] ;
value _mantle . forEach ( function ( element ) {
2025-04-03 06:19:19 +00:00
if ( ( typeof ( element ) == "object" )
&&
( element != null ) ) {
2024-04-22 10:02:34 +02:00
var element _ = { } ;
patch ( element _ , element ) ;
core [ key ] . push ( element _ ) ;
}
else {
core [ key ] . push ( element ) ;
}
} ) ;
}
else {
core [ key ] = { } ;
2025-04-03 06:19:19 +00:00
patch ( core [ key ] , value _mantle , {
"deep" : options . deep ,
"path" : path _
} ) ;
2024-04-22 10:02:34 +02:00
}
}
else {
core [ key ] = value _mantle ;
}
}
else {
var value _core = core [ key ] ;
if ( typeof ( value _core ) == typeof ( value _mantle ) ) {
2025-04-03 06:19:19 +00:00
if ( ( typeof ( value _mantle ) == "object" )
&&
( value _mantle != null )
&&
options . deep ) {
patch ( core [ key ] , value _mantle , {
"deep" : options . deep ,
"path" : path _
} ) ;
2024-04-22 10:02:34 +02:00
}
else {
core [ key ] = value _mantle ;
}
}
else {
2025-04-03 06:19:19 +00:00
if ( ( value _core != null )
&&
( value _mantle != null ) ) {
lib _plankton . log . warning ( "object_path_different_shapes" , {
"path" : path _ ,
"core_type" : typeof ( value _core ) ,
"mantle_type" : typeof ( value _mantle )
} ) ;
2024-04-22 10:02:34 +02:00
}
core [ key ] = value _mantle ;
// throw (new Error(message));
}
}
} ) ;
}
}
object _1 . patch = patch ;
/ * *
2025-04-03 06:19:19 +00:00
* @ deprecated use Object . assign instead !
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function patched ( core , mantle , options ) {
if ( options === void 0 ) { options = { } ; }
options = Object . assign ( {
"deep" : true
} , options ) ;
2024-04-22 10:02:34 +02:00
var result = { } ;
2025-04-03 06:19:19 +00:00
patch ( result , core , { "deep" : options . deep } ) ;
patch ( result , mantle , { "deep" : options . deep } ) ;
2024-04-22 10:02:34 +02:00
return result ;
}
object _1 . patched = patched ;
/ * *
2025-04-03 06:19:19 +00:00
* @ deprecated use Object . assign instead !
2024-04-22 10:02:34 +02:00
* /
function attached ( object , key , value ) {
var mantle = { } ;
mantle [ key ] = value ;
2025-04-03 06:19:19 +00:00
return patched ( object , mantle , { "deep" : false } ) ;
2024-04-22 10:02:34 +02:00
}
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 : markdown « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 = { } ) ) ;
2025-04-03 06:19:19 +00:00
"use strict" ;
2024-04-22 10:02:34 +02:00
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : http _base « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2025-04-03 06:19:19 +00:00
» bacterio - plankton : http _base « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2025-04-03 06:19:19 +00:00
» bacterio - plankton : http _base « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2025-04-03 06:19:19 +00:00
along with » bacterio - plankton : http _base « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : http _base « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2025-04-03 06:19:19 +00:00
» bacterio - plankton : http _base « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2025-04-03 06:19:19 +00:00
» bacterio - plankton : http _base « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2025-04-03 06:19:19 +00:00
along with » bacterio - plankton : http _base « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2025-04-03 06:19:19 +00:00
var http _base ;
( function ( http _base ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
const linebreak = "\r\n" ;
/ * *
* /
function capitalize _all ( str ) {
2025-04-03 06:19:19 +00:00
return str . split ( "-" ) . map ( x => lib _plankton . string . capitalize ( x ) ) . join ( "-" ) ;
2024-04-22 10:02:34 +02:00
}
/ * *
* /
2025-04-03 06:19:19 +00:00
function encode _request ( encode _method , request ) {
2024-04-22 10:02:34 +02:00
let request _raw = "" ;
2025-04-03 06:19:19 +00:00
request _raw += lib _plankton . string . coin ( "{{method}} {{path}}{{query}} {{version}}{{linebreak}}" , {
"method" : encode _method ( request . method ) ,
"path" : request . path ,
"query" : ( ( request . query === null ) ? "" : request . query ) ,
"version" : request . version ,
"linebreak" : linebreak ,
} ) ;
2024-04-22 10:02:34 +02:00
if ( request . host === null ) {
// do nothing
}
else {
2025-04-03 06:19:19 +00:00
request _raw += lib _plankton . string . coin ( "Host: {{host}}{{linebreak}}" , {
"host" : request . host ,
"linebreak" : linebreak ,
} ) ;
2024-04-22 10:02:34 +02:00
}
for ( const [ key , value ] of Object . entries ( request . headers ) ) {
2025-04-03 06:19:19 +00:00
request _raw += lib _plankton . string . coin ( "{{key}}: {{value}}{{linebreak}}" , {
"key" : capitalize _all ( key ) ,
"value" : value ,
"linebreak" : linebreak ,
} ) ;
2024-04-22 10:02:34 +02:00
}
request _raw += linebreak ;
if ( request . body === null ) {
// do nothing
}
else {
request _raw += request . body . toString ( ) ;
}
return request _raw ;
}
2025-04-03 06:19:19 +00:00
http _base . encode _request = encode _request ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function decode _request ( decode _method , has _body , request _raw ) {
const lines = lib _plankton . string . split ( request _raw , linebreak ) ;
if ( lines . length <= 0 ) {
throw ( new Error ( "malformed request" ) ) ;
}
else {
const first = lines [ 0 ] ;
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 [ 0 ] ;
lines . shift ( ) ;
if ( line === "" ) {
break ;
}
else {
const [ key , value ] = line . split ( ": " , 2 ) ;
headers [ key . toLowerCase ( ) ] = value ;
}
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
const body = ( has _body ( method )
// @ts-ignore
? Buffer . from ( lines . join ( linebreak ) )
: null ) ;
const request = {
// TODO
"scheme" : "http" ,
"host" : ( headers [ "host" ] ? ? null ) ,
"path" : path ,
"version" : version ,
"method" : method ,
"query" : query ,
"headers" : headers ,
"body" : body ,
} ;
return request ;
2024-04-22 10:02:34 +02:00
}
}
2025-04-03 06:19:19 +00:00
http _base . decode _request = decode _request ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function encode _response ( encode _status _code , get _status _text , response ) {
2024-04-22 10:02:34 +02:00
let response _raw = "" ;
2025-04-03 06:19:19 +00:00
response _raw += lib _plankton . string . coin ( "{{version}} {{status_code}} {{status_text}}{{linebreak}}" , {
"version" : ( response . version ? ? "" ) ,
"status_code" : encode _status _code ( response . status _code ) ,
"status_text" : get _status _text ( response . status _code ) ,
"linebreak" : linebreak ,
} ) ;
2024-04-22 10:02:34 +02:00
for ( const [ key , value ] of Object . entries ( response . headers ) ) {
2025-04-03 06:19:19 +00:00
response _raw += lib _plankton . string . coin ( "{{key}}: {{value}}{{linebreak}}" , {
"key" : capitalize _all ( key ) ,
"value" : value ,
"linebreak" : linebreak ,
} ) ;
2024-04-22 10:02:34 +02:00
}
response _raw += linebreak ;
2025-04-03 06:19:19 +00:00
if ( response . body === null ) {
// do nothing
}
else {
response _raw += response . body . toString ( ) ;
}
2024-04-22 10:02:34 +02:00
return response _raw ;
}
2025-04-03 06:19:19 +00:00
http _base . encode _response = encode _response ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function decode _response ( decode _status _code , response _raw ) {
2024-04-22 10:02:34 +02:00
const lines = response _raw . split ( linebreak ) ;
2025-04-03 06:19:19 +00:00
const first = lines [ 0 ] ;
lines . shift ( ) ;
2024-04-22 10:02:34 +02:00
const first _parts = first . split ( " " ) ;
const version = first _parts [ 0 ] ;
2025-04-03 06:19:19 +00:00
const status _code = decode _status _code ( first _parts [ 1 ] ) ;
2024-04-22 10:02:34 +02:00
// first_parts.slice(2) ? probably irrelevant
let headers = { } ;
while ( true ) {
2025-04-03 06:19:19 +00:00
const line = lines [ 0 ] ;
lines . shift ( ) ;
2024-04-22 10:02:34 +02:00
if ( line === "" ) {
break ;
}
else {
const [ key , value ] = line . split ( ": " , 2 ) ;
headers [ key . toLowerCase ( ) ] = value ;
}
}
2024-08-28 07:52:01 +02:00
// @ts-ignore
const body = Buffer . from ( lines . join ( linebreak ) ) ;
2024-04-22 10:02:34 +02:00
const response = {
// TODO
"version" : version ,
"status_code" : status _code ,
"headers" : headers ,
"body" : body ,
} ;
return response ;
}
2025-04-03 06:19:19 +00:00
http _base . decode _response = decode _response ;
2024-04-22 10:02:34 +02:00
/ * *
* executes an HTTP request
*
* @ todo define type _signal
* /
2025-04-03 06:19:19 +00:00
async function call ( has _body , encode _method , decode _status _code , request , { "timeout" : option _timeout = 5.0 , "follow_redirects" : option _follow _redirects = false , "implementation" : option _implementation = "fetch" , } = { } ) {
const target = lib _plankton . string . coin ( "{{scheme}}://{{host}}{{path}}{{query}}" , {
"scheme" : request . scheme ,
"host" : ( request . host ? ? "" ) ,
"path" : request . path ,
"query" : ( request . query ? ? "" ) ,
} ) ;
switch ( option _implementation ) {
2024-04-22 10:02:34 +02:00
default : {
2025-04-03 06:19:19 +00:00
return Promise . reject ( new Error ( "invalid implementation: " + option _implementation ) ) ;
2024-04-22 10:02:34 +02:00
break ;
}
case "fetch" : {
function core ( signal ) {
2024-08-21 15:17:53 +02:00
return ( fetch ( target , Object . assign ( {
2025-04-03 06:19:19 +00:00
"method" : encode _method ( request . method ) ,
2024-04-22 10:02:34 +02:00
"headers" : request . headers ,
2024-08-21 15:17:53 +02:00
/ *
"redirect" : (
2025-04-03 06:19:19 +00:00
option _follow _redirects
2024-08-21 15:17:53 +02:00
?
"follow"
:
"manual"
) ,
* /
"signal" : ( signal
? ?
undefined ) ,
// "keepalive": false,
2025-04-03 06:19:19 +00:00
} , ( ( has _body ( request . method )
2024-08-21 15:17:53 +02:00
&&
( request . body !== null ) )
? {
"body" : request . body . toString ( ) ,
}
: { } ) ) )
2024-04-22 10:02:34 +02:00
. catch ( ( reason ) => {
2024-08-21 15:17:53 +02:00
// console.info(reason);
2024-04-22 10:02:34 +02:00
return Promise . reject ( reason ) ;
} )
. then ( ( response _raw ) => ( response _raw . text ( )
. then ( ( body ) => Promise . resolve ( {
// TODO
"version" : null ,
2025-04-03 06:19:19 +00:00
"status_code" : decode _status _code ( response _raw . status . toFixed ( 0 ) ) ,
2024-04-22 10:02:34 +02:00
"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 ) => {
2025-04-03 06:19:19 +00:00
if ( option _timeout === null ) {
2024-04-22 10:02:34 +02:00
// do nothing (neither resolve nor reject ever)
}
else {
setTimeout ( ( ) => {
controller . abort ( ) ;
resolve ( null ) ;
2025-04-03 06:19:19 +00:00
} , ( option _timeout * 1000 ) ) ;
2024-04-22 10:02:34 +02:00
}
} ) ) ;
}
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:17:53 +02:00
// @ts-ignore
2024-04-22 10:02:34 +02:00
const nm _http = require ( "http" ) ;
2024-08-21 15:17:53 +02:00
// @ts-ignore
2024-04-22 10:02:34 +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 ,
2025-04-03 06:19:19 +00:00
} ,
// @ts-ignore
( res ) => {
2024-04-22 10:02:34 +02:00
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 ;
}
}
}
2025-04-03 06:19:19 +00:00
http _base . call = call ;
} ) ( http _base = lib _plankton . http _base || ( lib _plankton . http _base = { } ) ) ;
} ) ( 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 ) {
enum _method [ "options" ] = "options" ;
enum _method [ "head" ] = "head" ;
enum _method [ "get" ] = "get" ;
enum _method [ "delete" ] = "delete" ;
enum _method [ "post" ] = "post" ;
enum _method [ "put" ] = "put" ;
enum _method [ "patch" ] = "patch" ;
} ) ( enum _method = http . enum _method || ( http . enum _method = { } ) ) ;
/ * *
* /
let enum _status _code ;
( function ( enum _status _code ) {
enum _status _code [ enum _status _code [ "continue_" ] = 100 ] = "continue_" ;
enum _status _code [ enum _status _code [ "switching_protocols" ] = 101 ] = "switching_protocols" ;
enum _status _code [ enum _status _code [ "early_hints" ] = 103 ] = "early_hints" ;
enum _status _code [ enum _status _code [ "ok" ] = 200 ] = "ok" ;
enum _status _code [ enum _status _code [ "created" ] = 201 ] = "created" ;
enum _status _code [ enum _status _code [ "accepted" ] = 202 ] = "accepted" ;
enum _status _code [ enum _status _code [ "non_authoritative_information" ] = 203 ] = "non_authoritative_information" ;
enum _status _code [ enum _status _code [ "no_content" ] = 204 ] = "no_content" ;
enum _status _code [ enum _status _code [ "reset_content" ] = 205 ] = "reset_content" ;
enum _status _code [ enum _status _code [ "partial_coentent" ] = 206 ] = "partial_coentent" ;
enum _status _code [ enum _status _code [ "multiple_choices" ] = 300 ] = "multiple_choices" ;
enum _status _code [ enum _status _code [ "moved_permanently" ] = 301 ] = "moved_permanently" ;
enum _status _code [ enum _status _code [ "found" ] = 302 ] = "found" ;
enum _status _code [ enum _status _code [ "see_other" ] = 303 ] = "see_other" ;
enum _status _code [ enum _status _code [ "not_modified" ] = 304 ] = "not_modified" ;
enum _status _code [ enum _status _code [ "temporary_redirect" ] = 307 ] = "temporary_redirect" ;
enum _status _code [ enum _status _code [ "permanent_redirect" ] = 308 ] = "permanent_redirect" ;
enum _status _code [ enum _status _code [ "bad_request" ] = 400 ] = "bad_request" ;
enum _status _code [ enum _status _code [ "unauthorized" ] = 401 ] = "unauthorized" ;
enum _status _code [ enum _status _code [ "payment_required" ] = 402 ] = "payment_required" ;
enum _status _code [ enum _status _code [ "forbidden" ] = 403 ] = "forbidden" ;
enum _status _code [ enum _status _code [ "not_found" ] = 404 ] = "not_found" ;
enum _status _code [ enum _status _code [ "method_not_allowed" ] = 405 ] = "method_not_allowed" ;
enum _status _code [ enum _status _code [ "not_acceptable" ] = 406 ] = "not_acceptable" ;
enum _status _code [ enum _status _code [ "proxy_authentication_required" ] = 407 ] = "proxy_authentication_required" ;
enum _status _code [ enum _status _code [ "request_timeout" ] = 408 ] = "request_timeout" ;
enum _status _code [ enum _status _code [ "conflict" ] = 409 ] = "conflict" ;
enum _status _code [ enum _status _code [ "gone" ] = 410 ] = "gone" ;
enum _status _code [ enum _status _code [ "length_required" ] = 411 ] = "length_required" ;
enum _status _code [ enum _status _code [ "precondition_failed" ] = 412 ] = "precondition_failed" ;
enum _status _code [ enum _status _code [ "payload_too_large" ] = 413 ] = "payload_too_large" ;
enum _status _code [ enum _status _code [ "uri_too_long" ] = 414 ] = "uri_too_long" ;
enum _status _code [ enum _status _code [ "unsupported_media_type" ] = 415 ] = "unsupported_media_type" ;
enum _status _code [ enum _status _code [ "range_not_satisfiable" ] = 416 ] = "range_not_satisfiable" ;
enum _status _code [ enum _status _code [ "expectation_failed" ] = 417 ] = "expectation_failed" ;
enum _status _code [ enum _status _code [ "i_m_a_teapot" ] = 418 ] = "i_m_a_teapot" ;
enum _status _code [ enum _status _code [ "unprocessable_entity" ] = 422 ] = "unprocessable_entity" ;
enum _status _code [ enum _status _code [ "too_early" ] = 425 ] = "too_early" ;
enum _status _code [ enum _status _code [ "upgrade_required" ] = 426 ] = "upgrade_required" ;
enum _status _code [ enum _status _code [ "precondition_required" ] = 428 ] = "precondition_required" ;
enum _status _code [ enum _status _code [ "too_many_requests" ] = 429 ] = "too_many_requests" ;
enum _status _code [ enum _status _code [ "request_header_fields_too_large" ] = 431 ] = "request_header_fields_too_large" ;
enum _status _code [ enum _status _code [ "unavailable_for_legal_reasons" ] = 451 ] = "unavailable_for_legal_reasons" ;
enum _status _code [ enum _status _code [ "internal_server_error" ] = 500 ] = "internal_server_error" ;
enum _status _code [ enum _status _code [ "not_implemented" ] = 501 ] = "not_implemented" ;
enum _status _code [ enum _status _code [ "bad_gateway" ] = 502 ] = "bad_gateway" ;
enum _status _code [ enum _status _code [ "service_unavailable" ] = 503 ] = "service_unavailable" ;
enum _status _code [ enum _status _code [ "gateway_timeout" ] = 504 ] = "gateway_timeout" ;
enum _status _code [ enum _status _code [ "http_version_not_supported" ] = 505 ] = "http_version_not_supported" ;
enum _status _code [ enum _status _code [ "variant_also_negotiates" ] = 506 ] = "variant_also_negotiates" ;
enum _status _code [ enum _status _code [ "insufficient_storage" ] = 507 ] = "insufficient_storage" ;
enum _status _code [ enum _status _code [ "loop_detected" ] = 508 ] = "loop_detected" ;
enum _status _code [ enum _status _code [ "not_extended" ] = 510 ] = "not_extended" ;
enum _status _code [ enum _status _code [ "network_authentication" ] = 511 ] = "network_authentication" ;
} ) ( enum _status _code = http . enum _status _code || ( http . enum _status _code = { } ) ) ;
} ) ( 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 >
* /
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 ) ) ;
}
}
http . decode _method = decode _method ;
/ * *
* /
function encode _status _code ( status _code ) {
return status _code . toFixed ( 0 ) ;
}
/ * *
* @ todo check for existance
* /
function decode _status _code ( status _code _raw ) {
return parseInt ( status _code _raw ) ;
}
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function get _status _text ( 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 ) ) ) ;
}
}
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* @ author fenris < frass @ greenscale . de >
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function has _body ( method ) {
return [
http . enum _method . post ,
http . enum _method . put ,
http . enum _method . patch
] . includes ( method ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
http . has _body = has _body ;
2024-04-22 10:02:34 +02:00
/ * *
2025-04-03 06:19:19 +00:00
* @ author fenris < frass @ greenscale . de >
2024-04-22 10:02:34 +02:00
* /
2025-04-03 06:19:19 +00:00
function encode _request ( request ) {
return lib _plankton . http _base . encode _request ( encode _method , request ) ;
}
http . encode _request = encode _request ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function decode _request ( request _raw ) {
return lib _plankton . http _base . decode _request ( decode _method , has _body , request _raw ) ;
}
http . decode _request = decode _request ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function encode _response ( response ) {
return lib _plankton . http _base . encode _response ( encode _status _code , get _status _text , response ) ;
}
http . encode _response = encode _response ;
/ * *
* @ author fenris < frass @ greenscale . de >
* /
function decode _response ( response _raw ) {
return lib _plankton . http _base . decode _response ( decode _status _code , response _raw ) ;
}
http . decode _response = decode _response ;
/ * *
* executes an HTTP request
*
* @ todo define type _signal
* /
async function call ( request , { "timeout" : option _timeout = 5.0 , "follow_redirects" : option _follow _redirects = false , "implementation" : option _implementation = "fetch" , } = { } ) {
return lib _plankton . http _base . call ( has _body , encode _method , decode _status _code , request , {
"timeout" : option _timeout ,
"follow_redirects" : option _follow _redirects ,
"implementation" : option _implementation ,
} ) ;
2024-04-22 10:02:34 +02:00
}
2025-04-03 06:19:19 +00:00
http . call = call ;
2024-04-22 10:02:34 +02:00
} ) ( http = lib _plankton . http || ( lib _plankton . http = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
2025-04-03 06:19:19 +00:00
"use strict" ;
2024-04-22 10:02:34 +02:00
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : rest _base « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2025-04-03 06:19:19 +00:00
» bacterio - plankton : rest _base « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2025-04-03 06:19:19 +00:00
» bacterio - plankton : rest _base « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2025-04-03 06:19:19 +00:00
along with » bacterio - plankton : rest _base « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
/ *
2025-04-03 06:19:19 +00:00
This file is part of » bacterio - plankton : rest _base « .
2024-04-22 10:02:34 +02:00
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< info @ greenscale . de >
2025-04-03 06:19:19 +00:00
» bacterio - plankton : rest _base « is free software : you can redistribute it and / or modify
2024-04-22 10:02:34 +02:00
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 .
2025-04-03 06:19:19 +00:00
» bacterio - plankton : rest _base « is distributed in the hope that it will be useful ,
2024-04-22 10:02:34 +02:00
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
2025-04-03 06:19:19 +00:00
along with » bacterio - plankton : rest _base « . If not , see < http : //www.gnu.org/licenses/>.
2024-04-22 10:02:34 +02:00
* /
var lib _plankton ;
( function ( lib _plankton ) {
2025-04-03 06:19:19 +00:00
var rest _base ;
( function ( rest _base ) {
2024-04-22 10:02:34 +02:00
/ * *
* /
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 ;
}
/ * *
* /
2025-04-03 06:19:19 +00:00
function routenode _spawn ( encode _http _method , steps , http _method , operation ) {
2024-04-22 10:02:34 +02:00
let routenode ;
if ( steps . length <= 0 ) {
routenode = {
2025-04-03 06:19:19 +00:00
"operations" : Object . fromEntries ( [ [ encode _http _method ( http _method ) . toLowerCase ( ) , operation ] ] ) ,
2024-04-22 10:02:34 +02:00
"sub_branch" : { } ,
"sub_wildcard" : null ,
} ;
}
else {
const steps _head = steps [ 0 ] ;
const steps _tail = steps . slice ( 1 ) ;
2025-04-03 06:19:19 +00:00
const sub = routenode _spawn ( encode _http _method , steps _tail , http _method , operation ) ;
2024-04-22 10:02:34 +02:00
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 {
2025-04-03 06:19:19 +00:00
lib _plankton . log . warning ( "plankton.rest_base.overwriting_path_parameter" , {
2024-04-22 10:02:34 +02:00
"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" : { } ,
} ;
}
}
}
}
/ * *
* /
2025-04-03 06:19:19 +00:00
function routenode _path _write ( encode _http _method , routenode , steps , http _method , operation , options = { } ) {
2024-04-22 10:02:34 +02:00
options = lib _plankton . object . patched ( {
"create" : false ,
} , options ) ;
2025-04-03 06:19:19 +00:00
const http _method _encoded = encode _http _method ( http _method ) . toLowerCase ( ) ;
2024-04-22 10:02:34 +02:00
if ( steps . length <= 0 ) {
2025-04-03 06:19:19 +00:00
if ( ! ( http _method _encoded in routenode . operations ) ) {
2024-04-22 10:02:34 +02:00
// do nothing
}
else {
2025-04-03 06:19:19 +00:00
lib _plankton . log . warning ( "plankton.rest_base.overwriting_action" , {
2024-04-22 10:02:34 +02:00
"http_method" : http _method ,
"steps" : steps ,
} ) ;
}
2025-04-03 06:19:19 +00:00
routenode . operations [ http _method _encoded ] = operation ;
2024-04-22 10:02:34 +02:00
}
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 ,
2025-04-03 06:19:19 +00:00
"node" : routenode _spawn ( encode _http _method , steps _tail , http _method , operation ) ,
2024-04-22 10:02:34 +02:00
} ;
}
}
else {
if ( ! ( routenode . sub _wildcard . name === wildcard _name ) ) {
/ *
lib _plankton . log . warning (
2025-04-03 06:19:19 +00:00
"plankton.rest_base.overwriting_wildcard_node" ,
2024-04-22 10:02:34 +02:00
{
"wildcard_name" : wildcard _name ,
}
) ;
* /
throw ( new Error ( "inconsistent wildcard name: '" + routenode . sub _wildcard . name + "' vs. '" + wildcard _name + "'" ) ) ;
}
else {
// walk
2025-04-03 06:19:19 +00:00
routenode _path _write ( encode _http _method , routenode . sub _wildcard . node , steps _tail , http _method , operation , options ) ;
2024-04-22 10:02:34 +02:00
}
}
}
else {
if ( steps _head in routenode . sub _branch ) {
// walk branch
2025-04-03 06:19:19 +00:00
routenode _path _write ( encode _http _method , routenode . sub _branch [ steps _head ] , steps _tail , http _method , operation , options ) ;
2024-04-22 10:02:34 +02:00
}
else {
// add branch
if ( ! options . create ) {
throw ( new Error ( "may not create missing route" ) ) ;
}
else {
2025-04-03 06:19:19 +00:00
routenode . sub _branch [ steps _head ] = routenode _spawn ( encode _http _method , steps _tail , http _method , operation ) ;
2024-04-22 10:02:34 +02:00
}
}
}
}
}
/ * *
* /
2025-04-03 06:19:19 +00:00
function make ( encode _http _method , { "title" : option _title = "REST-API" , "versioning_method" : option _versioning _method = "none" , "versioning_header_name" : option _versioning _header _name = "X-Api-Version" , "versioning_query_key" : option _versioning _query _key = "version" , "header_parameters" : option _header _parameters = [ ] , "set_access_control_headers" : option _set _access _control _headers = false , "authentication" : option _authentication = {
"kind" : "none" ,
"data" : { } ,
} , "actions" : option _actions = [ ] , } = { } ) {
2024-04-22 10:02:34 +02:00
const subject = {
2025-04-03 06:19:19 +00:00
"api" : lib _plankton . api . make ( option _title ? ? "" ) ,
"versioning_method" : option _versioning _method ,
"versioning_header_name" : option _versioning _header _name ,
"versioning_query_key" : option _versioning _query _key ,
2024-04-22 10:02:34 +02:00
"routetree" : {
"operations" : { } ,
"sub_branch" : { } ,
"sub_wildcard" : null ,
} ,
2025-04-03 06:19:19 +00:00
"header_parameters" : option _header _parameters ,
"set_access_control_headers" : option _set _access _control _headers ,
"authentication" : option _authentication ,
2024-04-22 10:02:34 +02:00
} ;
2025-04-03 06:19:19 +00:00
option _actions . forEach ( ( action _definition ) => {
register ( encode _http _method , subject , action _definition . http _method , action _definition . path , action _definition . options ) ;
2024-04-22 10:02:34 +02:00
} ) ;
return subject ;
}
2025-04-03 06:19:19 +00:00
rest _base . make = make ;
2024-04-22 10:02:34 +02:00
/ * *
* /
2025-04-03 06:19:19 +00:00
function register ( encode _http _method , rest , http _method , path , { "active" : option _active = ( version ) => true , "execution" : option _execution = ( version ) => ( stuff ) => Promise . resolve ( { "status_code" : 501 , "data" : null } ) , "restriction" : option _restriction = ( version ) => ( stuff ) => Promise . resolve ( true ) , "title" : option _title = ( version ) => null , "description" : option _description = ( version ) => null , "query_parameters" : option _query _parameters = ( version ) => ( [ ] ) , "input_schema" : option _input _schema = ( version ) => ( { } ) , "output_schema" : option _output _schema = ( version ) => ( { } ) , "request_body_mimetype" : option _request _body _mimetype = ( version ) => "application/json" , "request_body_decode" : option _request _body _decode = ( version ) => ( http _request _body , http _request _header _content _type ) => Promise . resolve ( ( ( 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" : option _response _body _mimetype = ( version ) => "application/json" ,
/ * *
* @ todo no "from" ?
* /
"response_body_encode" : option _response _body _encode = ( version ) => ( output ) => Promise . resolve ( Buffer [ "from" ] ( JSON . stringify ( output ) ) ) , } = { } ) {
2024-04-22 10:02:34 +02:00
const steps = lib _plankton . string . split ( path , "/" ) . slice ( 1 ) ;
const steps _enriched = ( ( rest . versioning _method === "path" )
2025-04-03 06:19:19 +00:00
?
[ "{version}" ] . concat ( steps )
:
steps ) ;
const http _method _encoded = encode _http _method ( http _method ) . toLowerCase ( ) ;
const action _name = ( steps . concat ( [ http _method _encoded ] )
2024-04-22 10:02:34 +02:00
. join ( "_" ) ) ;
const operation = {
"action_name" : action _name ,
2025-04-03 06:19:19 +00:00
"query_parameters" : option _query _parameters ,
"request_body_mimetype" : option _request _body _mimetype ,
"request_body_decode" : option _request _body _decode ,
"response_body_mimetype" : option _response _body _mimetype ,
"response_body_encode" : option _response _body _encode ,
"input_schema" : option _input _schema ,
"output_schema" : option _output _schema ,
2024-04-22 10:02:34 +02:00
} ;
2025-04-03 06:19:19 +00:00
routenode _path _write ( encode _http _method , rest . routetree , steps _enriched , http _method , operation , {
2024-04-22 10:02:34 +02:00
"create" : true ,
} ) ;
lib _plankton . api . register ( rest . api , action _name , {
2025-04-03 06:19:19 +00:00
"active" : option _active ,
"execution" : ( version , environment , input ) => option _execution ( version ) ( {
2024-04-22 10:02:34 +02:00
"path_parameters" : environment . path _parameters ,
"query_parameters" : environment . query _parameters ,
"headers" : environment . headers ,
"input" : input
} ) ,
2025-04-03 06:19:19 +00:00
"restriction" : ( version , environment ) => option _restriction ( version ) ( {
2024-04-22 10:02:34 +02:00
"path_parameters" : environment . path _parameters ,
"query_parameters" : environment . query _parameters ,
"headers" : environment . headers ,
} ) ,
2025-04-03 06:19:19 +00:00
/ * *
* @ todo heed version
* /
"title" : option _title ( null ) ,
/ * *
* @ todo heed version
* /
"description" : option _description ( null ) ,
2024-04-22 10:02:34 +02:00
// TODO
2025-04-03 06:19:19 +00:00
// "input_shape": option_input_type,
// "output_shape": option_output_type,
2024-04-22 10:02:34 +02:00
} ) ;
2025-04-03 06:19:19 +00:00
lib _plankton . log . debug ( "plankton.rest_base.route_added" , {
2024-04-22 10:02:34 +02:00
"http_method" : http _method ,
"path" : path ,
// "routetree": rest.routetree,
} ) ;
}
2025-04-03 06:19:19 +00:00
rest _base . register = register ;
2024-04-22 10:02:34 +02:00
/ * *
* @ todo check request body mimetype ?
* @ todo check query paramater validity
* /
2025-04-03 06:19:19 +00:00
async function call ( encode _http _method , is _options _request , decode _status _code , rest , http _request , { "checklevel_restriction" : option _checklevel _restriction = lib _plankton . api . enum _checklevel . hard , "checklevel_input" : option _checklevel _input = lib _plankton . api . enum _checklevel . soft , "checklevel_output" : option _checklevel _output = lib _plankton . api . enum _checklevel . soft , "set_content_length" : option _set _content _length = false , } = { } ) {
lib _plankton . log . info ( "plankton.rest_base.call_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" : ( ( http _request . body === null )
?
null
:
lib _plankton . string . limit ( http _request . body . toString ( ) , {
"length" : 2047 ,
} ) ) ,
2024-04-22 10:02:34 +02:00
} ) ;
// parse target and query parameters
// const url_stuff : URL = new URL("http://dummy" + http_request.target);
const path = http _request . path ;
2025-04-03 06:19:19 +00:00
const query _parameters _raw = new URLSearchParams ( http _request . query ? ? "" ) ;
2024-04-22 10:02:34 +02:00
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 )
2025-04-03 06:19:19 +00:00
. map ( x => x . toUpperCase ( ) )
2024-04-22 10:02:34 +02:00
. 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" : {
2025-04-03 06:19:19 +00:00
if ( rest . versioning _header _name === null ) {
throw ( new Error ( "versioning_header_name not set" ) ) ;
}
else {
version = http _request . headers [ rest . versioning _header _name ] ;
// delete http_request.headers[rest.versioning_header_name];
}
2024-04-22 10:02:34 +02:00
break ;
}
case "query" : {
2025-04-03 06:19:19 +00:00
if ( rest . versioning _query _key === null ) {
throw ( new Error ( "versioning_query_key not set" ) ) ;
}
else {
version = query _parameters [ rest . versioning _query _key ] ;
// delete query_parameters[rest.versioning_query_key];
}
2024-04-22 10:02:34 +02:00
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" )
2025-04-03 06:19:19 +00:00
? [ rest . authentication . data [ "name" ] ]
2024-04-22 10:02:34 +02:00
: [ ] ) )
. join ( ", " ) ) ,
"Access-Control-Allow-Origin" : "*" ,
"Access-Control-Allow-Methods" : allowed _methods ,
}
: { } ) ;
2025-04-03 06:19:19 +00:00
let response ;
2024-04-22 10:02:34 +02:00
if ( stuff . rest . length > 0 ) {
2025-04-03 06:19:19 +00:00
response = {
"version" : http _request . version ,
"status_code" : decode _status _code ( 404 ) ,
2024-04-22 10:02:34 +02:00
"headers" : { } ,
"body" : null ,
} ;
}
else {
2025-04-03 06:19:19 +00:00
/ * i f ( i s _ o p t i o n s _ r e q u e s t ( h t t p _ r e q u e s t . m e t h o d ) ) {
response = {
"version" : http _request . version ,
"status_code" : decode _status _code ( option _options _response _status _code ) ,
"headers" : Object . assign (
{
} ,
additional _response _headers
) ,
2024-04-22 10:02:34 +02:00
"body" : null ,
} ;
}
2025-04-03 06:19:19 +00:00
else * / {
const http _method _encoded = encode _http _method ( http _request . method ) . toLowerCase ( ) ;
if ( ! ( http _method _encoded in stuff . routenode . operations ) ) {
// fallback OPTIONS response
if ( is _options _request ( http _request . method ) ) {
response = {
"version" : http _request . version ,
"status_code" : decode _status _code ( 200 ) ,
2024-04-22 10:02:34 +02:00
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : null ,
} ;
}
else {
2025-04-03 06:19:19 +00:00
if ( Object . keys ( stuff . routenode . operations ) . length <= 0 ) {
return {
"version" : http _request . version ,
"status_code" : decode _status _code ( 404 ) ,
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : null ,
} ;
}
else {
return {
"version" : http _request . version ,
"status_code" : decode _status _code ( 405 ) ,
"headers" : Object . assign ( {
"Allow" : allowed _methods ,
} , additional _response _headers ) ,
"body" : null ,
} ;
}
2024-04-22 10:02:34 +02:00
}
}
else {
// call
let result ;
let error ;
2025-04-03 06:19:19 +00:00
const operation = stuff . routenode . operations [ http _method _encoded ] ;
2024-04-22 10:02:34 +02:00
const stuff _ = {
"version" : version ,
"headers" : http _request . headers ,
"path_parameters" : stuff . parameters ,
"query_parameters" : query _parameters ,
"input" : ( ( http _request . body === null )
2025-04-03 06:19:19 +00:00
?
null
:
await operation . request _body _decode ( version ) ( http _request . body , ( http _request . headers [ "Content-Type" ]
? ?
http _request . headers [ "content-type" ]
? ?
null ) ) ) ,
2024-04-22 10:02:34 +02:00
} ;
2025-04-03 06:19:19 +00:00
/ * c o n s t a l l o w e d : b o o l e a n = (
2024-04-22 10:02:34 +02:00
( operation . restriction === null )
? true
: operation . restriction ( stuff _ )
) ;
2025-04-03 06:19:19 +00:00
2024-04-22 10:02:34 +02:00
if ( ! allowed ) {
lib _plankton . log . error (
2025-04-03 06:19:19 +00:00
"plankton.rest_base.access_denied" ,
2024-04-22 10:02:34 +02:00
{
"http_request" : {
"target" : http _request . target ,
"method" : http _request . method ,
"headers" : http _request . headers ,
"body" : (
( http _request . body === null )
2025-04-03 06:19:19 +00:00
?
null
:
lib _plankton . string . limit (
http _request . body . toString ( ) ,
{
"length" : 2047 ,
}
)
2024-04-22 10:02:34 +02:00
) ,
} ,
}
) ;
response = {
2025-04-03 06:19:19 +00:00
"version" : http _request . version ,
2024-04-22 10:02:34 +02:00
"status_code" : 403 ,
"headers" : Object . assign (
{
} ,
additional _response _headers
) ,
"body" : Buffer [ "from" ] ( "forbidden" ) ,
} ;
}
else * / {
2025-04-03 06:19:19 +00:00
const { "value" : result , "error" : error } = await lib _plankton . call . try _catch _wrap _async ( ( ) => 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" : option _checklevel _restriction ,
"checklevel_input" : option _checklevel _input ,
"checklevel_output" : option _checklevel _output ,
} ) ) ;
2024-04-22 10:02:34 +02:00
if ( ( result === null ) || ( error !== null ) ) {
if ( error instanceof lib _plankton . api . class _error _permission _denied ) {
response = {
2025-04-03 06:19:19 +00:00
"version" : http _request . version ,
"status_code" : decode _status _code ( 403 ) ,
2024-04-22 10:02:34 +02:00
"headers" : Object . assign ( { } , additional _response _headers ) ,
"body" : null ,
} ;
}
else {
2025-04-03 06:19:19 +00:00
lib _plankton . log . error ( "plankton.rest_base.execution_failed" , {
2024-04-22 10:02:34 +02:00
"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 )
2025-04-03 06:19:19 +00:00
?
null
:
lib _plankton . string . limit ( http _request . body . toString ( ) , {
"length" : 2047
} ) ) ,
2024-04-22 10:02:34 +02:00
} ,
2025-04-03 06:19:19 +00:00
"error" : ( ( error === null )
?
null
:
{
"message" : error . toString ( ) ,
"file_name" : error . fileName ,
"line_number" : error . lineNumber ,
"stack" : error . stack ,
} ) ,
2024-04-22 10:02:34 +02:00
} ) ;
response = {
2025-04-03 06:19:19 +00:00
"version" : http _request . version ,
"status_code" : decode _status _code ( 500 ) ,
2024-04-22 10:02:34 +02:00
"headers" : Object . assign ( { } , additional _response _headers ) ,
2025-04-03 06:19:19 +00:00
// @ts-ignore
"body" : Buffer . from ( "internal error" ) ,
2024-04-22 10:02:34 +02:00
} ;
}
}
else {
// encode
2025-04-03 06:19:19 +00:00
const body = await operation . response _body _encode ( version ) ( result . data ) ;
2024-04-22 10:02:34 +02:00
response = {
2025-04-03 06:19:19 +00:00
"version" : http _request . version ,
"status_code" : decode _status _code ( result . status _code ) ,
"headers" : Object . assign ( { } , additional _response _headers , ( ( body !== null )
?
{
"Content-Type" : operation . response _body _mimetype ( version ) ,
}
:
{ } ) , ( ( option _set _content _length
&&
( body !== null ) )
?
// @ts-ignore Buffer HAS a length
{ "Content-Length" : body . length }
:
{ } ) , ( result . extra _headers ? ? { } ) ) ,
"body" : body ,
2024-04-22 10:02:34 +02:00
} ;
}
}
}
}
}
2025-04-03 06:19:19 +00:00
lib _plankton . log . info ( "plankton.rest_base.call_response" , {
"version" : response . version ,
"status_code" : response . status _code ,
"headers" : response . headers ,
"body" : ( ( response . body === null )
?
null
:
lib _plankton . string . limit ( response . body . toString ( ) , {
"length" : 2047 ,
} ) ) ,
} ) ;
return response ;
2024-04-22 10:02:34 +02:00
}
}
2025-04-03 06:19:19 +00:00
rest _base . call = call ;
2024-04-22 10:02:34 +02:00
/ * *
* @ see https : //swagger.io/specification/#openrest-object
* /
2025-04-03 06:19:19 +00:00
function to _oas ( http _request _method _to _oas , has _body , rest , { "version" : option _version = null , "servers" : option _servers = [ ] , } = { } ) {
2024-04-22 10:02:34 +02:00
const subject = rest ;
2025-04-03 06:19:19 +00:00
const version = ( option _version ? ? "-" ) ;
2024-04-22 10:02:34 +02:00
return {
"openapi" : "3.0.3" ,
"info" : {
"version" : version ,
"title" : ( rest . api . title ? ? "API" ) ,
// "description": (rest.api.description ?? undefined),
} ,
2025-04-03 06:19:19 +00:00
"servers" : option _servers . map ( url => ( { "url" : url } ) ) ,
2024-04-22 10:02:34 +02:00
"components" : {
2025-04-03 06:19:19 +00:00
"securitySchemes" : lib _plankton . call . distinguish ( rest . authentication , {
"none" : ( { } ) => ( { } ) ,
"key_header" : ( { "name" : name } ) => ( {
2024-04-22 10:02:34 +02:00
"default_security_schema" : {
"type" : "restKey" ,
"in" : "header" ,
2025-04-03 06:19:19 +00:00
"name" : name ,
2024-04-22 10:02:34 +02:00
} ,
2025-04-03 06:19:19 +00:00
} ) ,
} ) ,
2024-04-22 10:02:34 +02:00
} ,
"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 , [
2025-04-03 06:19:19 +00:00
( x ) => Object . entries ( x ) ,
2024-04-22 10:02:34 +02:00
( pairs ) => pairs . map ( ( [ http _method , operation ] ) => ( [
2025-04-03 06:19:19 +00:00
/ * *
* @ todo rectify type argument
* /
2024-04-22 10:02:34 +02:00
http _request _method _to _oas ( http _method ) ,
{
2025-04-03 06:19:19 +00:00
/ * *
* @ todo rectify type argument
* /
2024-04-22 10:02:34 +02:00
"operationId" : ( http _request _method _to _oas ( http _method )
+
"_"
+
path ) ,
2025-04-03 06:19:19 +00:00
"summary" : ( operation . action _name
2024-04-22 10:02:34 +02:00
? ?
[ "" ] . concat ( steps _ ) . join ( " " ) ) ,
"description" : ( lib _plankton . api . get _action ( rest . api , operation . action _name ) . description
? ?
"(missing)" ) ,
2025-04-03 06:19:19 +00:00
"parameters" : ( ( new Array ( ) )
// header parameters
. concat ( rest . header _parameters
. map ( header _parameter => ( {
2024-04-22 10:02:34 +02:00
"name" : header _parameter . name ,
"in" : "header" ,
"required" : header _parameter . required ,
"schema" : {
"type" : "string" ,
} ,
"description" : ( header _parameter . description ? ? undefined ) ,
2025-04-03 06:19:19 +00:00
} ) ) )
// path parameters
. concat ( lib _plankton . call . convey ( steps _ , [
( x ) => x . map ( y => wildcard _step _decode ( y ) ) ,
( x ) => x . filter ( y => ( ! ( y === null ) ) ) ,
( x ) => x . map ( y => ( {
2024-04-22 10:02:34 +02:00
"name" : y ,
"in" : "path" ,
"required" : true ,
"schema" : {
"type" : "string" ,
} ,
} ) ) ,
2025-04-03 06:19:19 +00:00
] ) )
// query parameters
. concat ( operation . query _parameters ( option _version )
. map ( ( query _parameter ) => ( {
2024-04-22 10:02:34 +02:00
"name" : query _parameter . name ,
"in" : "query" ,
"required" : query _parameter . required ,
"schema" : {
"type" : "string" ,
} ,
"description" : ( query _parameter . description ? ? undefined ) ,
2025-04-03 06:19:19 +00:00
} ) ) ) ) ,
"requestBody" : ( ( ! has _body ( http _method ) )
2024-04-22 10:02:34 +02:00
? undefined
: {
"content" : Object . fromEntries ( [
[
operation . request _body _mimetype ,
{
2025-04-03 06:19:19 +00:00
"schema" : operation . input _schema ( option _version ) ,
2024-04-22 10:02:34 +02:00
}
]
] )
} ) ,
"responses" : {
"default" : {
"description" : "" ,
"content" : Object . fromEntries ( [
[
operation . response _body _mimetype ,
{
2025-04-03 06:19:19 +00:00
"schema" : operation . output _schema ( option _version ) ,
2024-04-22 10:02:34 +02:00
}
]
] ) ,
}
} ,
}
] ) ) ,
( pairs ) => Object . fromEntries ( pairs ) ,
] ) ,
] ;
} ) ,
2025-04-03 06:19:19 +00:00
( x ) => x . filter ( y => ( Object . keys ( y [ 1 ] ) . length > 0 ) ) ,
( x ) => Object . fromEntries ( x ) ,
2024-04-22 10:02:34 +02:00
] )
} ;
}
2025-04-03 06:19:19 +00:00
rest _base . to _oas = to _oas ;
} ) ( rest _base = lib _plankton . rest _base || ( lib _plankton . rest _base = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : rest _http « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : rest _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 : rest _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 : rest _http « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : rest _http « .
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : rest _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 : rest _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 : rest _http « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var rest _http ;
( function ( rest _http ) {
/ * *
* /
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 make ( options = { } ) {
return lib _plankton . rest _base . make ( lib _plankton . http . encode _method , options ) ;
}
rest _http . make = make ;
/ * *
* /
function register ( rest , http _method , path , options ) {
lib _plankton . rest _base . register ( lib _plankton . http . encode _method , rest , http _method , path , options ) ;
}
rest _http . register = register ;
/ * *
* @ todo check request body mimetype ?
* @ todo check query paramater validity
* @ todo improve status code mapping
* /
async function call ( rest , http _request , { "checklevel_restriction" : option _checklevel _restriction = lib _plankton . api . enum _checklevel . hard , "checklevel_input" : option _checklevel _input = lib _plankton . api . enum _checklevel . soft , "checklevel_output" : option _checklevel _output = lib _plankton . api . enum _checklevel . soft , "set_content_length" : option _set _content _length = false , } = { } ) {
return lib _plankton . rest _base . call ( lib _plankton . http . encode _method , ( x => ( x === lib _plankton . http . enum _method . options ) ) , ( x => x ) , rest , http _request , {
"checklevel_restriction" : option _checklevel _restriction ,
"checklevel_input" : option _checklevel _input ,
"checklevel_output" : option _checklevel _output ,
"set_content_length" : option _set _content _length ,
} ) ;
}
rest _http . call = call ;
/ * *
* @ see https : //swagger.io/specification/#openrest-object
* /
function to _oas ( rest , options = { } ) {
return lib _plankton . rest _base . to _oas ( http _request _method _to _oas , lib _plankton . http . has _body , rest , options ) ;
}
rest _http . to _oas = to _oas ;
} ) ( rest _http = lib _plankton . rest _http || ( lib _plankton . rest _http = { } ) ) ;
2024-04-22 10:02:34 +02:00
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : server « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 ) {
/ * *
* /
2024-08-21 15:17:53 +02:00
function make ( handle , options = { } ) {
options = Object . assign ( {
"host" : "::" ,
"port" : 9999 ,
"threshold" : 0.25 ,
} , options ) ;
2024-04-22 10:02:34 +02:00
return {
2024-08-21 15:17:53 +02:00
"host" : options . host ,
"port" : options . port ,
"threshold" : options . threshold ,
2024-04-22 10:02:34 +02:00
"handle" : handle ,
"serverobj" : undefined ,
} ;
}
server . make = make ;
/ * *
2024-08-21 15:17:53 +02:00
* @ deprecated
* /
function make _old ( port , handle ) {
return make ( handle , {
"host" : "::" ,
"port" : port ,
"threshold" : 0.25 ,
} ) ;
}
server . make _old = make _old ;
/ * *
* @ see https : //nodejs.org/api/net.html#serverlistenport-host-backlog-callback
2024-04-22 10:02:34 +02:00
* /
function start ( subject ) {
const net = require ( "net" ) ;
return ( new Promise ( ( resolve , reject ) => {
2024-08-21 15:17:53 +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 ,
} ;
* /
2025-04-03 06:19:19 +00:00
lib _plankton . log . debug ( "plankton.server.process_input" , {
"input" : lib _plankton . base . buffer _show ( input , { "break_char" : "|" } ) ,
2024-08-21 15:17:53 +02:00
} ) ;
( subject . handle ( input /*, metadata*/ )
. then ( ( output ) => {
2025-04-03 06:19:19 +00:00
lib _plankton . log . debug ( "plankton.server.writing" , {
"output" : lib _plankton . base . buffer _show ( output , { "break_char" : "|" } ) ,
2024-04-22 10:02:34 +02:00
} ) ;
2024-08-21 15:17:53 +02:00
socket . write ( output ) ;
socket . end ( ) ;
} )
. catch ( ( error ) => {
2025-04-03 06:19:19 +00:00
lib _plankton . log . warning ( "plankton.server.handle_failed" , {
2024-08-21 15:17:53 +02:00
"error" : error . toString ( ) ,
2025-04-03 06:19:19 +00:00
"stack_trace" : error . stack ,
2024-04-22 10:02:34 +02:00
} ) ;
2024-08-21 15:17:53 +02:00
// socket.write("");
socket . end ( ) ;
} )
. then ( ( ) => {
input _chunks = [ ] ;
} ) ) ;
} ;
const timeout _stop = function ( ) {
if ( timeout _handler === null ) {
// do nothing
2024-04-22 10:02:34 +02:00
}
2024-08-21 15:17:53 +02:00
else {
2025-04-03 06:19:19 +00:00
lib _plankton . log . debug ( "plankton.server.timeout_cancelling" ) ;
2024-08-21 15:17:53 +02:00
clearTimeout ( timeout _handler ) ;
timeout _handler = null ;
}
} ;
const timeout _start = function ( ) {
if ( subject . threshold === null ) {
process _input ( ) ;
}
else {
if ( timeout _handler === null ) {
timeout _handler = setTimeout ( ( ) => {
2025-04-03 06:19:19 +00:00
lib _plankton . log . debug ( "plankton.server.timeout_reached" ) ;
2024-08-21 15:17:53 +02:00
timeout _handler = null ;
process _input ( ) ;
} , ( subject . threshold * 1000 ) ) ;
}
else {
2025-04-03 06:19:19 +00:00
lib _plankton . log . warning ( "plankton.server.timeout_already_started" ) ;
2024-08-21 15:17:53 +02:00
// do nothing
}
}
} ;
2025-04-03 06:19:19 +00:00
lib _plankton . log . info ( "plankton.server.client_connected" ) ;
2024-08-21 15:17:53 +02:00
socket . on ( "data" , ( input _chunk _raw ) => {
2025-04-03 06:19:19 +00:00
lib _plankton . log . debug ( "plankton.server.reading_chunk" , {
"chunk_raw" : ( ( input _chunk _raw instanceof Buffer )
?
lib _plankton . base . buffer _show ( input _chunk _raw , { "break_char" : "|" } )
:
input _chunk _raw ) ,
2024-08-21 15:17:53 +02:00
} ) ;
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-04-22 10:02:34 +02:00
} ) ;
socket . on ( "end" , ( ) => {
2024-08-21 15:17:53 +02:00
if ( ! ended ) {
2025-04-03 06:19:19 +00:00
lib _plankton . log . info ( "plankton.server.client_disconnected" ) ;
2024-08-21 15:17:53 +02:00
ended = true ;
timeout _stop ( ) ;
}
else {
2025-04-03 06:19:19 +00:00
lib _plankton . log . info ( "plankton.server.socket_already_ended" ) ;
2024-08-21 15:17:53 +02:00
// do nothing
}
2024-04-22 10:02:34 +02:00
} ) ;
} ) ;
subject . serverobj . on ( "error" , ( error ) => {
2024-05-20 22:15:07 +02:00
// throw error;
process . stderr . write ( "net_error: " + String ( error ) + "\n\n" ) ;
2024-04-22 10:02:34 +02:00
} ) ;
2024-08-21 15:17:53 +02:00
subject . serverobj . listen ( subject . port , subject . host , 511 , ( ) => {
2025-04-03 06:19:19 +00:00
lib _plankton . log . info ( "plankton.server.listenting" , {
2024-08-21 15:17:53 +02:00
"host" : subject . host ,
2024-04-22 10:02:34 +02:00
"port" : subject . port ,
} ) ;
resolve ( undefined ) ;
} ) ;
} ) ) ;
}
server . start = start ;
/ * *
* /
function kill ( subject ) {
subject . serverobj . close ( ) ;
2025-04-03 06:19:19 +00:00
lib _plankton . log . info ( "plankton.server.stopped" ) ;
2024-04-22 10:02:34 +02:00
}
server . kill = kill ;
} ) ( server = lib _plankton . server || ( lib _plankton . server = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : server « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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:17:53 +02:00
constructor ( handle , options = { } ) {
options = Object . assign ( {
"host" : "::" ,
"port" : 9999 ,
} , options ) ;
this . subject = server . make ( handle , {
"host" : options . host ,
"port" : options . port ,
} ) ;
2024-04-22 10:02:34 +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 : args « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-04-22 10:02:34 +02:00
< 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 = { } ) ) ;
2024-06-03 12:32:49 +02:00
/ *
This file is part of » bacterio - plankton : translate « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-03 12:32:49 +02:00
< info @ greenscale . de >
» bacterio - plankton : translate « 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 : translate « 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 : translate « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var translate ;
( function ( translate ) {
/ * *
* @ desc contains the sets of strings
* @ author fenris
* /
var _packages = { } ;
/ * *
* @ desc specifies in which order the languages shall be queried ; if getting a string from language # 0 fails , the
* system tries to get it from language # 1 , and so on
* @ author fenris
* /
var _order = [ ] ;
/ * *
* @ desc whether to automatically promote the language of a newly added package
* @ author fenris
* /
var _autopromote = false ;
/ * *
* @ desc the level of verbosity , specifiying how much output the system shall provide about its actions
* @ author fenris
* /
translate . _verbosity = 1 ;
/ * *
* @ desc which initial string to use for log - outputs
* @ author fenris
* /
var _logprefix = "[lib_translate]" ;
/ * *
* @ desc moves a language to the top of the order , making it the primary one
* @ author fenris
* /
function promote ( identifier ) {
if ( Object . keys ( _packages ) . indexOf ( identifier ) < 0 ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } package ' ${ identifier } ' doesn't exist yet ` ) ;
}
}
let position = _order . indexOf ( identifier ) ;
if ( position >= 0 ) {
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } ' ${ identifier } ' already in order; will promote it ` ) ;
}
_order . splice ( position , 1 ) ;
}
_order . unshift ( identifier ) ;
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } order is now ${ _order . toString ( ) } ` ) ;
}
}
translate . promote = promote ;
/ * *
* @ desc adds a package to the sytem
* @ author fenris
* /
function add ( package _ ) {
let identifier = package _ . meta . identifier ;
if ( identifier in _packages ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } package ' ${ identifier } ' has already been added; will overwrite ` ) ;
}
}
else {
if ( translate . _verbosity >= 2 ) {
console . log ( ` ${ _logprefix } got package ' ${ identifier } ' ` ) ;
}
}
_packages [ identifier ] = package _ ;
if ( _autopromote ) {
promote ( identifier ) ;
}
}
translate . add = add ;
/ * *
* @ desc integrates a package to the system , i . e . creates a new one if none existed so far or merges with an existing one
* @ author fenris
* /
function feed ( package _ ) {
let identifier = package _ . meta . identifier ;
if ( identifier in _packages ) {
2025-04-03 06:19:19 +00:00
lib _plankton . object . patch ( _packages [ identifier ] . tree , package _ . tree , {
"deep" : true ,
} ) ;
2024-06-03 12:32:49 +02:00
}
else {
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } package ' ${ identifier } ' didn't exist so far; will create it now ` ) ;
}
add ( package _ ) ;
}
}
translate . feed = feed ;
/ * *
* @ desc tries to retrieve a translation for a specific package identifier
* @ author fenris
* /
function fetch ( identifier , path , args = { } ) {
if ( ! ( identifier in _packages ) ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } no package ' ${ identifier } ' ` ) ;
}
return ( lib _plankton . pod . make _empty ( ) ) ;
}
else {
// let str : string = lib_plankton.object.path_read<string>(_packages[identifier].tree, path);
let str = _packages [ identifier ] . tree [ path ] ;
if ( str == undefined ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } string ' ${ path } ' missing in package ' ${ identifier } ' ` ) ;
}
return ( lib _plankton . pod . make _empty ( ) ) ;
}
else {
// resolve references
{
let regexp _reference = new RegExp ( "#\\(([\\w\\.]*)(?:\\?(\\w+)=(\\w+)(?:&(\\w+)=(\\w+))*)?\\)" ) ;
while ( true ) {
let matching = regexp _reference . exec ( str ) ;
if ( matching != null ) {
let path _ = matching [ 1 ] ;
let args _ = { } ;
if ( translate . _verbosity >= 2 ) {
// console.info(`${_logprefix} found reference to '${path_}' with args ${JSON.stringify(args_)}`);
console . info ( ` ${ _logprefix } found reference to ' ${ path _ } ' ` ) ;
}
// parse args
{
for ( let index = 2 ; index <= matching . length - 1 ; index += 2 ) {
let id = matching [ index + 0 ] ;
let value = matching [ index + 1 ] ;
if ( id != undefined ) {
args _ [ id ] = value ;
}
}
}
// fetch referenced string
{
let result _ = fetch ( identifier , path _ , args _ ) ;
if ( lib _plankton . pod . is _filled ( result _ ) ) {
let front = str . slice ( 0 , matching . index ) ;
let back = str . slice ( matching . index + matching [ 0 ] . length ) ;
str = ( front + lib _plankton . pod . cull ( result _ ) + back ) ;
}
else {
return ( lib _plankton . pod . make _empty ( ) ) ;
break ;
}
}
}
else {
break ;
}
}
}
// insert arguments
{
str = lib _plankton . string . coin ( str , args ) ;
}
return ( lib _plankton . pod . make _filled ( str ) ) ;
}
}
}
translate . fetch = fetch ;
/ * *
* @ desc retrieves a string by going through the order and trying to fetch it for the current entry
* @ author fenris
* /
function get ( path , args = { } , fallback = null ) {
if ( fallback == null ) {
fallback = ` { ${ path } } ` ;
}
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } getting translation for string ' ${ path } ' with arguments ${ JSON . stringify ( args ) } … ` ) ;
}
let result = lib _plankton . pod . make _empty ( ) ;
let found = _order . some ( identifier => {
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } trying package ' ${ identifier } ' … ` ) ;
}
let result _ = fetch ( identifier , path , args ) ;
if ( lib _plankton . pod . is _filled ( result _ ) ) {
result = result _ ;
return true ;
}
else {
return false ;
}
} ) ;
if ( found ) {
let str = lib _plankton . pod . cull ( result ) ;
if ( translate . _verbosity >= 3 ) {
console . info ( ` ${ _logprefix } found translation: ' ${ str } ' ` ) ;
}
return str ;
}
else {
let str = fallback ;
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } no package provides a translation for string ' ${ path } '; will use the fallback translation ' ${ str } ' ` ) ;
}
return str ;
}
}
translate . get = get ;
/ * *
* @ author fenris
* /
function list ( ) {
return lib _plankton . object . to _array ( _packages ) . map ( x => x . value . meta ) ;
}
translate . list = list ;
/ * *
* @ author fenris
* @ todo get rid of this ; it ' s currenly needed only for the cdh - internal lib _completion
* /
function paths ( ) {
return lib _plankton . object . keys ( lib _plankton . object . flatten ( _packages [ _order [ 0 ] ] . tree ) ) ;
}
translate . paths = paths ;
/ * *
* @ author fenris
* /
function initialize ( { "logprefix" : logprefix = undefined , "verbosity" : verbosity = undefined , "packages" : packages = [ ] , "order" : order = undefined , "autopromote" : autopromote = undefined , } = { } ) {
return ( Promise . resolve ( undefined )
// set variables
. then ( _ => {
if ( logprefix != undefined )
_logprefix = logprefix ;
if ( verbosity != undefined )
translate . _verbosity = verbosity ;
// _packages = {};
if ( order != undefined )
_order = order ;
if ( autopromote != undefined )
_autopromote = autopromote ;
return Promise . resolve ( undefined ) ;
} )
// feed
. then ( _ => {
packages . forEach ( feed ) ;
return Promise . resolve ( undefined ) ;
} ) ) ;
}
translate . initialize = initialize ;
} ) ( translate = lib _plankton . translate || ( lib _plankton . translate = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : translate « .
2024-08-21 15:17:53 +02:00
Copyright 2016 - 2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
2024-06-03 12:32:49 +02:00
< info @ greenscale . de >
» bacterio - plankton : translate « 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 : translate « 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 : translate « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var translate ;
( function ( translate ) {
/ * *
* @ author fenris
* /
function iso _639 _1 _to _iso _639 _2 ( iso6391 ) {
let mapping = {
"af" : "afr" ,
"ar" : "ara" ,
"bg" : "bul" ,
"cs" : "ces" ,
"da" : "dan" ,
"de" : "deu" ,
"el" : "ell" ,
"en" : "eng" ,
"eo" : "epo" ,
"es" : "esp" ,
"fa" : "fas" ,
"fi" : "fin" ,
"fr" : "fra" ,
"hi" : "hin" ,
"hr" : "hrv" ,
"hu" : "hun" ,
"is" : "isl" ,
"it" : "ita" ,
"ja" : "jpn" ,
"ko" : "kor" ,
"nb" : "nob" ,
"nl" : "nld" ,
"nn" : "nno" ,
"pt" : "por" ,
"pl" : "pol" ,
"ro" : "ron" ,
"ru" : "rus" ,
"sk" : "slk" ,
"sv" : "swe" ,
"zh" : "zho" ,
} ;
return mapping [ iso6391 ] ;
}
translate . iso _639 _1 _to _iso _639 _2 = iso _639 _1 _to _iso _639 _2 ;
/ * *
* @ author fenris
* /
function stance ( str ) {
let regexp = new RegExp ( "^translate:(.*)$" ) ;
let matching = regexp . exec ( str ) ;
if ( matching != null ) {
return translate . get ( matching [ 1 ] ) ;
}
else {
return str ;
}
}
translate . stance = stance ;
} ) ( translate = lib _plankton . translate || ( lib _plankton . translate = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;