From 43c1cda10146a541481a1f1a2b33883a5aa25c88 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 16:29:29 +0200 Subject: [PATCH 1/5] [sty] main --- source/main.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/main.ts b/source/main.ts index f30557d..80f959a 100644 --- a/source/main.ts +++ b/source/main.ts @@ -68,7 +68,8 @@ async function data_init( "user": {}, "calendar": {}, }; - for await (const user_raw of data.users) { + for await (const user_raw of data.users) + { const user_object : _zeitbild.type_user_object = { "name": user_raw.name, "email_address": user_raw.email_address, @@ -82,11 +83,14 @@ async function data_init( ); track.user[user_raw.id] = user_id; } - for await (const calendar_raw of data.calendars) { + for await (const calendar_raw of data.calendars) + { let resource_object : _zeitbild.type_resource_object; let resource_id : _zeitbild.type_resource_id; - switch (calendar_raw.resource.kind) { - case "local": { + switch (calendar_raw.resource.kind) + { + case "local": + { resource_object = { "kind": "local", "data": { @@ -104,7 +108,8 @@ async function data_init( ); break; } - case "caldav": { + case "caldav": + { resource_object = { "kind": "caldav", "data": { @@ -119,7 +124,8 @@ async function data_init( break; } } - const calendar_object : _zeitbild.type_calendar_object = { + const calendar_object : _zeitbild.type_calendar_object = + { "name": calendar_raw.name, "access": { "public": (calendar_raw.access.public ?? false), From 834953b6355cd5f24470afd8f5cd77a4d46c4e1d Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 16:35:22 +0200 Subject: [PATCH 2/5] [mod] logging --- source/conf.ts | 12 +++++++++- source/main.ts | 64 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/source/conf.ts b/source/conf.ts index 537d357..f984923 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -41,7 +41,17 @@ namespace _zeitbild.conf "error" ], "default": "info" - } + }, + "format": { + "nullable": false, + "type": "string", + "enum": [ + "human_readable", + "jsonl", + "jsonl_structured", + ], + "default": "human_readable", + }, }, "required": [ ] diff --git a/source/main.ts b/source/main.ts index 80f959a..85464ed 100644 --- a/source/main.ts +++ b/source/main.ts @@ -165,11 +165,17 @@ async function main( ) : Promise { // init1 - lib_plankton.log.conf_push( + /* + lib_plankton.log.set_main_logger( [ - lib_plankton.log.channel_make({"kind": "stdout", "data": {"threshold": "info"}}), + { + "kind": "std", + "data": { + } + } ] ); + */ // args const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler({ @@ -258,12 +264,54 @@ async function main( await _zeitbild.conf.init( args["conf_path"] ); - lib_plankton.log.conf_push( + lib_plankton.log.set_main_logger( _zeitbild.conf.get().log.map( - (log_output : any) => lib_plankton.log.channel_make( - { - "kind": log_output.kind, - "data": log_output.data + (log_output : any) => { + switch (log_output.kind) { + case "stdout": { + return { + "kind": "minlevel", + "data": { + "core": { + "kind": "std", + "data": { + "target": "stdout", + "format": lib_plankton.call.distinguish( + { + "kind": log_output.data.format, + "data": null, + }, + { + "jsonl": () => ({ + "kind": "jsonl", + "data": { + "structured": false, + } + }), + "jsonl_structured": () => ({ + "kind": "jsonl", + "data": { + "structured": true, + } + }), + "human_readable": () => ({ + "kind": "human_readable", + "data": { + } + }), + } + ), + } + }, + "threshold": log_output.data.threshold, + } + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } } ) ) @@ -327,7 +375,7 @@ async function main( break; } case "api-doc": { - lib_plankton.log.conf_push([]); + lib_plankton.log.set_main_logger([]); const rest_subject : lib_plankton.rest.type_rest = _zeitbild.api.make(); lib_plankton.log.conf_pop(); process.stdout.write( From c96a0aef4a26084f79771124022ffc619845ea7d Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 16:41:17 +0200 Subject: [PATCH 3/5] [mod] caching --- source/base.ts | 12 +++++++++++- source/helpers.ts | 40 ++++++++++++++++------------------------ source/main.ts | 26 +++++++++++++++++--------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/source/base.ts b/source/base.ts index 4aa10be..8a9f23c 100644 --- a/source/base.ts +++ b/source/base.ts @@ -3,6 +3,16 @@ namespace _zeitbild /** */ - export var cache : lib_plankton.cache.type_cache; + export var cache_regular : lib_plankton.cache.type_subject; + + + /** + */ + export var cache_external_resources : lib_plankton.cache.type_subject; + + + /** + */ + export var cache_templates : lib_plankton.cache.type_subject; } diff --git a/source/helpers.ts b/source/helpers.ts index d5b929d..97dc5fa 100644 --- a/source/helpers.ts +++ b/source/helpers.ts @@ -60,37 +60,29 @@ namespace _zeitbild.helpers /** */ - var _template_cache : Record = {}; - - - /** - * @todo caching - */ export async function template_coin( name : string, data : Record ) : Promise { - let content : string; - if (! (name in _template_cache)) { - content = ( - ( - await lib_plankton.file.read( - lib_plankton.string.coin( - "templates/{{name}}.html.tpl", - { - "name": name, - } - ) + const content : string = await lib_plankton.cache.get( + _zeitbild.cache_templates, + name, + null, + () => ( + lib_plankton.file.read( + lib_plankton.string.coin( + "templates/{{name}}.html.tpl", + { + "name": name, + } ) ) - .toString() - ); - _template_cache[name] = content; - } - else { - content = _template_cache[name]; - } + .then( + x => Promise.resolve(x.toString()) + ) + ) + ); return Promise.resolve( lib_plankton.string.coin( content, diff --git a/source/main.ts b/source/main.ts index 85464ed..0cf97b0 100644 --- a/source/main.ts +++ b/source/main.ts @@ -258,7 +258,10 @@ async function main( "name": "help", }), }); - const args : Record = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" ")); + const args : Record = arg_handler.read( + lib_plankton.args.enum_environment.cli, + args_raw.join(" ") + ); // init2 await _zeitbild.conf.init( @@ -313,17 +316,21 @@ async function main( break; } } - ) - ) - ); - _zeitbild.cache = lib_plankton.cache.chest.implementation( - lib_plankton.cache.chest.make( - { - "chest": lib_plankton.storage.memory.implementation_chest({}), } ) ); - await _zeitbild.cache.init(); + { + _zeitbild.cache_regular = lib_plankton.cache.make(); + await lib_plankton.cache.init(_zeitbild.cache_regular); + } + { + _zeitbild.cache_external_resources = lib_plankton.cache.make(); + await lib_plankton.cache.init(_zeitbild.cache_external_resources); + } + { + _zeitbild.cache_templates = lib_plankton.cache.make(); + await lib_plankton.cache.init(_zeitbild.cache_templates); + } // exec if (args["help"]) { @@ -443,6 +450,7 @@ async function main( "checklevel_restriction": lib_plankton.api.enum_checklevel.hard, // "checklevel_input": lib_plankton.api.enum_checklevel.soft, // "checklevel_output": lib_plankton.api.enum_checklevel.soft, + "set_content_length": false, } ); const output : string = lib_plankton.http.encode_response(http_response); From a08f7f3bf4c1d02000a91b7b35a8cb89d214c390 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 16:44:50 +0200 Subject: [PATCH 4/5] [mod] caching --- source/repositories/calendar.ts | 9 +++++---- source/repositories/resource.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source/repositories/calendar.ts b/source/repositories/calendar.ts index abfea1c..0fc9362 100644 --- a/source/repositories/calendar.ts +++ b/source/repositories/calendar.ts @@ -251,7 +251,7 @@ namespace _zeitbild.repository.calendar {"level": access_attributed_row["level"]} ); } - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); return Promise.resolve<_zeitbild.type_calendar_id>(calendar_id); } @@ -313,7 +313,7 @@ namespace _zeitbild.repository.calendar ); } } - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); return Promise.resolve(undefined); } @@ -325,7 +325,7 @@ namespace _zeitbild.repository.calendar calendar_id : _zeitbild.type_calendar_id ) : Promise { - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); const core_store = get_core_store(); const access_attributed_chest = get_access_attributed_chest(); // attributed access @@ -375,11 +375,12 @@ namespace _zeitbild.repository.calendar > { return lib_plankton.cache.get_complex>( - _zeitbild.cache, + _zeitbild.cache_regular, "calendar_overview", { "user_id": user_id, }, + null, () => ( lib_plankton.file.read("sql/calendar_overview.sql") .then( diff --git a/source/repositories/resource.ts b/source/repositories/resource.ts index 6bae0ca..a191bfd 100644 --- a/source/repositories/resource.ts +++ b/source/repositories/resource.ts @@ -401,7 +401,7 @@ namespace _zeitbild.repository.resource "sub_id": local_resource_id, } ); - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); return Promise.resolve<_zeitbild.type_resource_id>(resource_id); break; } @@ -419,7 +419,7 @@ namespace _zeitbild.repository.resource "sub_id": caldav_resource_id, } ); - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); return Promise.resolve<_zeitbild.type_resource_id>(resource_id); break; } @@ -499,7 +499,7 @@ namespace _zeitbild.repository.resource "read_only": resource_object.data.read_only, } ); - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); break; } default: { @@ -561,7 +561,7 @@ namespace _zeitbild.repository.resource } ) ); - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); return Promise.resolve(local_resource_event_id); } } @@ -589,7 +589,7 @@ namespace _zeitbild.repository.resource } ) ); - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); return Promise.resolve(undefined); } } @@ -602,7 +602,7 @@ namespace _zeitbild.repository.resource local_resource_event_id : _zeitbild.type_local_resource_event_id ) : Promise { - await _zeitbild.cache.clear(); + await lib_plankton.cache.clear(_zeitbild.cache_regular); const dataset_core : Record = await get_resource_core_store().read(resource_id); if (! (dataset_core.kind === "local")) { throw (new Error("not a local resource")); From 3d7ba02b784529c3bde7ef672182a139e655d19b Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 16:48:16 +0200 Subject: [PATCH 5/5] [fix] api actions --- source/api/actions/calendar_add.ts | 5 +++-- source/api/actions/calendar_change.ts | 2 +- source/api/actions/calendar_event_add.ts | 2 +- source/api/actions/calendar_event_change.ts | 2 +- source/api/actions/calendar_event_get.ts | 2 +- source/api/actions/calendar_event_remove.ts | 2 +- source/api/actions/calendar_get.ts | 2 +- source/api/actions/calendar_list.ts | 2 +- source/api/actions/calendar_remove.ts | 2 +- source/api/actions/events.ts | 2 +- source/api/actions/meta_ping.ts | 12 +++++++----- source/api/actions/meta_spec.ts | 12 ++++++------ source/api/actions/session_begin.ts | 10 +++++----- source/api/actions/session_end.ts | 2 +- source/api/actions/session_oidc.ts | 2 +- source/api/actions/session_prepare.ts | 10 +++++----- source/api/actions/users.ts | 2 +- 17 files changed, 38 insertions(+), 35 deletions(-) diff --git a/source/api/actions/calendar_add.ts b/source/api/actions/calendar_add.ts index cee2aa9..f54fc76 100644 --- a/source/api/actions/calendar_add.ts +++ b/source/api/actions/calendar_add.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_add( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< @@ -64,7 +64,8 @@ namespace _zeitbild.api else { // TODO move logic to calendar service let resource_object : _zeitbild.type_resource_object; - switch (stuff.input.resource.kind) { + switch (stuff.input.resource.kind) + { case "local": { resource_object = { "kind": "local", diff --git a/source/api/actions/calendar_change.ts b/source/api/actions/calendar_change.ts index 07a32d8..9ba5733 100644 --- a/source/api/actions/calendar_change.ts +++ b/source/api/actions/calendar_change.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_change( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_add.ts b/source/api/actions/calendar_event_add.ts index df4c00e..0dfd8a1 100644 --- a/source/api/actions/calendar_event_add.ts +++ b/source/api/actions/calendar_event_add.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_add( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_change.ts b/source/api/actions/calendar_event_change.ts index 42ec2d3..9e78895 100644 --- a/source/api/actions/calendar_event_change.ts +++ b/source/api/actions/calendar_event_change.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_change( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_get.ts b/source/api/actions/calendar_event_get.ts index 34427a7..cd6f352 100644 --- a/source/api/actions/calendar_event_get.ts +++ b/source/api/actions/calendar_event_get.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_get( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_event_remove.ts b/source/api/actions/calendar_event_remove.ts index cd83b3a..f5271cc 100644 --- a/source/api/actions/calendar_event_remove.ts +++ b/source/api/actions/calendar_event_remove.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_event_remove( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_get.ts b/source/api/actions/calendar_get.ts index cdb4b0d..f22d098 100644 --- a/source/api/actions/calendar_get.ts +++ b/source/api/actions/calendar_get.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_get( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_list.ts b/source/api/actions/calendar_list.ts index 5c345dd..a00596b 100644 --- a/source/api/actions/calendar_list.ts +++ b/source/api/actions/calendar_list.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_list( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/calendar_remove.ts b/source/api/actions/calendar_remove.ts index 693afc4..10c3066 100644 --- a/source/api/actions/calendar_remove.ts +++ b/source/api/actions/calendar_remove.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_calendar_remove( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/events.ts b/source/api/actions/events.ts index 2032f75..cf59c3e 100644 --- a/source/api/actions/events.ts +++ b/source/api/actions/events.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_events( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/meta_ping.ts b/source/api/actions/meta_ping.ts index bfe01f1..7fee0d3 100644 --- a/source/api/actions/meta_ping.ts +++ b/source/api/actions/meta_ping.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_meta_ping( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_http.register< null, string > @@ -17,7 +17,7 @@ namespace _zeitbild.api lib_plankton.http.enum_method.get, _zeitbild.conf.get().server.path_base + "/meta/ping", { - "description": "sendet ein 'pong' zurück; gedacht um die Erreichbarkeit des Backends zu prüfen", + "description": () => "sendet ein 'pong' zurück; gedacht um die Erreichbarkeit des Backends zu prüfen", "input_schema": () => ({ "nullable": true, }), @@ -25,8 +25,10 @@ namespace _zeitbild.api "nullable": false, "type": "string", }), - "restriction": restriction_none, - "execution": () => { + "response_body_encode": () => (body) => Promise.resolve(body), + "response_body_mimetype": () => "text/plain", + "restriction": () => restriction_none, + "execution": () => () => { return Promise.resolve({ "status_code": 200, "data": "pong", diff --git a/source/api/actions/meta_spec.ts b/source/api/actions/meta_spec.ts index cecb3ad..cf0fd7d 100644 --- a/source/api/actions/meta_spec.ts +++ b/source/api/actions/meta_spec.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_meta_spec( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_http.register< null, any > @@ -17,17 +17,17 @@ namespace _zeitbild.api lib_plankton.http.enum_method.get, _zeitbild.conf.get().server.path_base + "/meta/spec", { - "description": "gibt die API-Spezifikation im OpenAPI-Format aus", + "description": () => "gibt die API-Spezifikation im OpenAPI-Format aus", "input_schema": () => ({ "nullable": true, }), "output_schema": () => ({ }), - "restriction": restriction_none, - "execution": () => { + "restriction": () => restriction_none, + "execution": () => () => { return Promise.resolve({ "status_code": 200, - "data": lib_plankton.rest.to_oas(rest_subject), + "data": lib_plankton.rest_http.to_oas(rest_subject), }); }, } diff --git a/source/api/actions/session_begin.ts b/source/api/actions/session_begin.ts index 8125575..2cc384e 100644 --- a/source/api/actions/session_begin.ts +++ b/source/api/actions/session_begin.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_session_begin( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_http.register< { name : string; password : string; @@ -23,7 +23,7 @@ namespace _zeitbild.api lib_plankton.http.enum_method.post, "/session/begin", { - "description": "führt die Anmeldung am System aus um geschützte Aktionen nutzen zu können", + "description": () => "führt die Anmeldung am System aus um geschützte Aktionen nutzen zu können", "input_schema": () => ({ "type": "object", "properties": { @@ -44,8 +44,8 @@ namespace _zeitbild.api "type": "string", "description": "der Sitzungs-Schlüssel, der als Header 'X-Session-Key' gesetzt werden muss um Erlaubnis zur Ausführung geschützter Aktionen zu erhalten", }), - "restriction": restriction_none, - "execution": async ({"input": input}) => { + "restriction": () => restriction_none, + "execution": () => async ({"input": input}) => { if (input === null) { return Promise.reject(new Error("impossible")); } diff --git a/source/api/actions/session_end.ts b/source/api/actions/session_end.ts index 124bb5e..08c723c 100644 --- a/source/api/actions/session_end.ts +++ b/source/api/actions/session_end.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_session_end( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register( diff --git a/source/api/actions/session_oidc.ts b/source/api/actions/session_oidc.ts index d609537..a80aa72 100644 --- a/source/api/actions/session_oidc.ts +++ b/source/api/actions/session_oidc.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_session_oidc( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register< diff --git a/source/api/actions/session_prepare.ts b/source/api/actions/session_prepare.ts index e76e225..7081000 100644 --- a/source/api/actions/session_prepare.ts +++ b/source/api/actions/session_prepare.ts @@ -5,10 +5,10 @@ namespace _zeitbild.api /** */ export function register_session_prepare( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { - lib_plankton.rest.register< + lib_plankton.rest_http.register< any, { kind : string; @@ -19,15 +19,15 @@ namespace _zeitbild.api lib_plankton.http.enum_method.post, "/session/prepare", { - "description": "gibt die nötigen Werkzeuge für eine Anmeldung aus", + "description": () => "gibt die nötigen Werkzeuge für eine Anmeldung aus", "input_schema": () => ({ "nullable": true, }), "output_schema": () => ({ "nullable": false }), - "restriction": restriction_none, - "execution": async (stuff) => { + "restriction": () => restriction_none, + "execution": () => async (stuff) => { const preparation = await _zeitbild.auth.prepare(stuff.input); return Promise.resolve({ "status_code": 200, diff --git a/source/api/actions/users.ts b/source/api/actions/users.ts index fc4010b..2b190db 100644 --- a/source/api/actions/users.ts +++ b/source/api/actions/users.ts @@ -5,7 +5,7 @@ namespace _zeitbild.api /** */ export function register_users( - rest_subject : lib_plankton.rest.type_rest + rest_subject : lib_plankton.rest_http.type_rest ) : void { register<