From 6c548272fe307c9f207580c834ad0fe1bc46b99d Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Fri, 17 Oct 2025 13:16:56 +0200 Subject: [PATCH] [task-388] --- source/repositories/calendar.ts | 118 +++++++++++++++++++++----------- source/repositories/resource.ts | 20 +++++- source/repositories/user.ts | 80 +++++++++++++++------- 3 files changed, 149 insertions(+), 69 deletions(-) diff --git a/source/repositories/calendar.ts b/source/repositories/calendar.ts index 28fa046..9118972 100644 --- a/source/repositories/calendar.ts +++ b/source/repositories/calendar.ts @@ -23,25 +23,37 @@ namespace _zeitbild.repository.calendar /** */ - const hue_scaling : int = 0xFFFF; + type type_core_row = { + name : string; + hue : int; + access_public : boolean; + access_level_default : int; + resource_id : int; + }; + + + /** + */ + type type_access_attributed_row = { + // calendar_id : int; + user_id : int; + level : int; + }; /** */ type type_dispersal = { - core_row : Record< - string, - any - >; - access_attributed_rows : Array< - Record< - string, - any - > - >; + core_row : type_core_row; + access_attributed_rows : Array; }; + /** + */ + const hue_scaling : int = 0xFFFF; + + /** */ var _core_store : ( @@ -195,11 +207,11 @@ namespace _zeitbild.repository.calendar ) : _zeitbild.type_calendar_object { return { - "name": dispersal.core_row["name"], - "hue": (dispersal.core_row["hue"] / hue_scaling), + "name": dispersal.core_row.name, + "hue": (dispersal.core_row.hue / hue_scaling), "access": { - "public": dispersal.core_row["access_public"], - "default_level": decode_access_level(dispersal.core_row["access_level_default"]), + "public": dispersal.core_row.access_public, + "default_level": decode_access_level(dispersal.core_row.access_level_default), "attributed": lib_plankton.map.hashmap.implementation_map( lib_plankton.map.hashmap.make<_zeitbild.type_user_id, _zeitbild.enum_access_level>( x => x.toFixed(0), @@ -209,8 +221,10 @@ namespace _zeitbild.repository.calendar .map( (access_attributed_row) => ({ // "calendar_id": access_attributed_row["calendar_id"], - "key": access_attributed_row["preview"]["user_id"], - "value": decode_access_level(access_attributed_row["preview"]["level"]), + // "key": access_attributed_row["preview"]["user_id"], + "key": access_attributed_row.user_id, + // "value": decode_access_level(access_attributed_row["preview"]["level"]), + "value": decode_access_level(access_attributed_row.level), }) ) ), @@ -218,7 +232,7 @@ namespace _zeitbild.repository.calendar ) ), }, - "resource_id": dispersal.core_row["resource_id"], + "resource_id": dispersal.core_row.resource_id, }; } @@ -233,29 +247,43 @@ namespace _zeitbild.repository.calendar return ( get_core_store().read(id) .then( - (core_row) => ( - get_access_attributed_chest().search( - { - "expression": "(calendar_id = $calendar_id)", - "arguments": { - "calendar_id": id, - } - } - ) - .then( - (access_attributed_rows) => Promise.resolve( + (core_row_raw) => { + const core_row : type_core_row = (core_row_raw as type_core_row); + return ( + get_access_attributed_chest().search( { - "core_row": core_row, - "access_attributed_rows": access_attributed_rows, + "expression": "(calendar_id = $calendar_id)", + "arguments": { + "calendar_id": id, + } } ) - ) - .then( - (dispersal) => Promise.resolve<_zeitbild.type_calendar_object>( - decode(dispersal) + .then( + (hits) => Promise.resolve( + { + "core_row": core_row, + "access_attributed_rows": ( + hits + .map( + hit => ( + { + // "calendar_id": null, + "user_id": hit.preview.user_id, + "level": hit.preview.level, + } + ) + ) + ), + } + ) ) - ) - ) + .then( + (dispersal) => Promise.resolve<_zeitbild.type_calendar_object>( + decode(dispersal) + ) + ) + ); + } ) ); } @@ -347,17 +375,24 @@ namespace _zeitbild.repository.calendar /** * @todo remove events from resource? + * @todo remove resource */ export async function delete_( calendar_id : _zeitbild.type_calendar_id - ) : Promise + ) + : Promise { await lib_plankton.cache.clear(_zeitbild.cache_regular); const core_store = get_core_store(); const access_attributed_chest = get_access_attributed_chest(); // attributed access { - const hits : Array> = await access_attributed_chest.search( + const hits : Array< + { + key : Array; + preview : Record; + } + > = await access_attributed_chest.search( { "expression": "(calendar_id = $calendar_id)", "arguments": { @@ -365,9 +400,10 @@ namespace _zeitbild.repository.calendar } } ); - for await (const hit of hits) { + for (const hit of hits) + { await access_attributed_chest.delete( - [calendar_id, hit["user_id"]] + hit.key ); } } diff --git a/source/repositories/resource.ts b/source/repositories/resource.ts index bd9591a..98500c6 100644 --- a/source/repositories/resource.ts +++ b/source/repositories/resource.ts @@ -21,6 +21,22 @@ along with »zeitbild«. If not, see . namespace _zeitbild.repository.resource { + /** + */ + type type_row = { + kind : string; + sub_id : int; + }; + + + /** + */ + type type_preview = { + kind : string; + sub_id : int; + }; + + /** */ type type_local_resource_event_stuff = { @@ -81,10 +97,10 @@ namespace _zeitbild.repository.resource | lib_plankton.storage.type_store< _zeitbild.type_resource_id, - Record, + /*type_row*/Record, {}, lib_plankton.storage.type_sql_table_autokey_search_term, - Record + /*type_preview*/Record > ) = null; diff --git a/source/repositories/user.ts b/source/repositories/user.ts index a303f98..62b2cbf 100644 --- a/source/repositories/user.ts +++ b/source/repositories/user.ts @@ -21,6 +21,22 @@ along with »zeitbild«. If not, see . namespace _zeitbild.repository.user { + /** + */ + type type_row = { + name : string; + email_address : (null | string); + dav_token : (null | string); + }; + + + /** + */ + type type_preview = { + name : string; + }; + + /** */ var _store : ( @@ -28,10 +44,10 @@ namespace _zeitbild.repository.user | lib_plankton.storage.type_store< _zeitbild.type_user_id, - Record, + /*type_row*/Record, {}, lib_plankton.storage.type_sql_table_autokey_search_term, - Record + /*type_preview*/Record > ) = null; @@ -39,15 +55,17 @@ namespace _zeitbild.repository.user /** */ function get_store( - ) : lib_plankton.storage.type_store< + ) + : lib_plankton.storage.type_store< _zeitbild.type_user_id, - Record, + /*type_row*/Record, {}, lib_plankton.storage.type_sql_table_autokey_search_term, - Record + /*type_preview*/Record > { - if (_store === null) { + if (_store === null) + { _store = lib_plankton.storage.sql_table_autokey_store( { "database_implementation": _zeitbild.database.get_implementation(), @@ -56,7 +74,8 @@ namespace _zeitbild.repository.user } ); } - else { + else + { // do nothing } return _store; @@ -67,7 +86,8 @@ namespace _zeitbild.repository.user */ function encode( user_object : _zeitbild.type_user_object - ) : Record + ) + : type_row { return { "name": user_object.name, @@ -80,13 +100,14 @@ namespace _zeitbild.repository.user /** */ function decode( - row : Record - ) : _zeitbild.type_user_object + row : type_row + ) + : _zeitbild.type_user_object { return { - "name": row["name"], - "email_address": row["email_address"], - "dav_token": row["dav_token"], + "name": row.name, + "email_address": row.email_address, + "dav_token": row.dav_token, }; } @@ -94,7 +115,8 @@ namespace _zeitbild.repository.user /** */ export async function list( - ) : Promise< + ) + : Promise< Array< { id : _zeitbild.type_user_id; @@ -103,7 +125,7 @@ namespace _zeitbild.repository.user > > { - const hits : Array<{key : int; preview : Record;}> = await get_store().search({"expression": "TRUE", "arguments": {}}); + const hits : Array<{key : int; preview : /*type_preview*/Record;}> = await get_store().search({"expression": "TRUE", "arguments": {}}); return Promise.resolve( hits .map( @@ -120,9 +142,10 @@ namespace _zeitbild.repository.user */ export async function read( user_id : _zeitbild.type_user_id - ) : Promise<_zeitbild.type_user_object> + ) + : Promise<_zeitbild.type_user_object> { - const row : Record = await get_store().read(user_id); + const row : type_row = ((await get_store().read(user_id)) as type_row); const user_object : _zeitbild.type_user_object = decode(row); return Promise.resolve<_zeitbild.type_user_object>(user_object); } @@ -132,9 +155,10 @@ namespace _zeitbild.repository.user */ export async function create( user_object : _zeitbild.type_user_object - ) : Promise<_zeitbild.type_user_id> + ) + : Promise<_zeitbild.type_user_id> { - const row : Record = encode(user_object); + const row : type_row = encode(user_object); const user_id : _zeitbild.type_user_id = await get_store().create(row); return Promise.resolve<_zeitbild.type_user_id>(user_id); } @@ -145,10 +169,11 @@ namespace _zeitbild.repository.user export async function update( user_id : _zeitbild.type_user_id, user_object : _zeitbild.type_user_object - ) : Promise + ) + : Promise { - const dispersal : Record = encode(user_object); - await get_store().update(user_id, dispersal); + const row : type_row = encode(user_object); + await get_store().update(user_id, row); return Promise.resolve(undefined); } @@ -157,9 +182,10 @@ namespace _zeitbild.repository.user */ export async function identify( name : string - ) : Promise<_zeitbild.type_user_id> + ) + : Promise<_zeitbild.type_user_id> { - const hits : Array<{key : _zeitbild.type_user_id; preview : any;}> = await get_store().search( + const hits : Array<{key : _zeitbild.type_user_id; preview : /*type_preview*/Record;}> = await get_store().search( { "expression": "(name = $name)", "arguments": { @@ -167,10 +193,12 @@ namespace _zeitbild.repository.user } } ); - if (hits.length <= 0) { + if (hits.length <= 0) + { return Promise.reject<_zeitbild.type_user_id>(new Error("not found")); } - else { + else + { return Promise.resolve<_zeitbild.type_user_id>(hits[0].key); } }