frontend-dali/source/types.ts
fenris 44c70a10bb [task-419]
Co-authored-by: Fenris Wolf <fenris@folksprak.org>
Co-committed-by: Fenris Wolf <fenris@folksprak.org>
2025-10-28 11:41:17 +01:00

335 lines
5.5 KiB
TypeScript

/*
This file is part of »dali«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»dali« 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.
»dali« 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 »dali«. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*/
namespace _dali
{
/**
*/
export enum enum_access_level
{
none,
view,
edit,
admin
}
/**
*/
export type type_group_id = int;
/**
*/
export type type_group_object = {
name : string;
label : string;
};
/**
*/
export type type_user_id = int;
/**
*/
export type type_user_object = {
name : string;
label : string;
email_address : (
null
|
string
);
};
/**
* @todo deprecate?
*/
export type type_local_resource_event_id = int;
/**
* info: das ist nicht deckungsgleich mit der Event-ID aus dem Backend; hiermit werden sowohl lokale als auch
* extern eingebundene Events kodiert
*
* @example "local:1234"
* @example "ics~2345"
*/
export type type_event_key = string;
/**
*/
export type type_event_object = {
name : string;
begin : lib_plankton.pit.type_datetime;
end : (
null
|
lib_plankton.pit.type_datetime
);
location : (
null
|
string
);
link : (
null
|
string
);
description : (
null
|
string
);
};
/**
*/
export type type_event_entry = {
id : (null | type_local_resource_event_id);
key : type_event_key;
object : type_event_object;
};
/**
*/
export type type_event_object_extended = {
key : type_event_key;
calendar_id : type_calendar_id;
calendar_name : string;
hue : float;
access_level : enum_access_level;
event_id : (null | type_local_resource_event_id);
event_object : type_event_object;
};
/**
*/
export type type_resource_id = int;
/**
*/
export type type_resource_object = (
{
kind : "local";
data : {
events : Array<
type_event_object
>;
};
}
|
{
kind : "caldav";
data : {
read_only : boolean;
url : string;
};
}
);
/**
*/
export type type_calendar_id = int;
/**
*/
export type type_calendar_object = {
name : string;
hue : float;
access : {
public : boolean;
default_level : enum_access_level;
attributed_group : lib_plankton.map.type_map<
type_group_id,
enum_access_level
>;
attributed_user : lib_plankton.map.type_map<
type_user_id,
enum_access_level
>;
};
resource_id : type_resource_id;
};
/**
*/
export type type_calendar_object_reduced = {
name : string;
hue : float;
access_level : enum_access_level;
};
/**
*/
export type type_calendar_object_reduced_with_id = {
id : type_calendar_id;
name : string;
hue : float;
access_level : enum_access_level;
};
/**
*/
export function access_level_encode(
access_level : _dali.enum_access_level
)
: ("none" | "view" | "edit" | "admin")
{
switch (access_level)
{
case _dali.enum_access_level.none: return "none";
case _dali.enum_access_level.view: return "view";
case _dali.enum_access_level.edit: return "edit";
case _dali.enum_access_level.admin: return "admin";
}
}
/**
*/
export function access_level_decode(
representation : /*("none" | "view" | "edit" | "admin")*/string
)
: _dali.enum_access_level
{
switch (representation)
{
case "none": return _dali.enum_access_level.none;
case "view": return _dali.enum_access_level.view;
case "edit": return _dali.enum_access_level.edit;
case "admin": return _dali.enum_access_level.admin;
default: throw (new Error("invalid access level representation: " + representation));
}
}
/**
*/
export enum enum_view_mode
{
week,
list,
}
/**
*/
export function view_mode_encode(
mode : _dali.enum_view_mode
)
: string
{
switch (mode)
{
case _dali.enum_view_mode.week: {return "week"; break;}
case _dali.enum_view_mode.list: {return "list"; break;}
default: {throw (new Error("invalid mode"));}
}
}
/**
*/
export function view_mode_decode(
view_mode_encoded : string
)
: _dali.enum_view_mode
{
const map : Record<string, _dali.enum_view_mode> = {
"week": _dali.enum_view_mode.week,
"list": _dali.enum_view_mode.list,
};
if (! (view_mode_encoded in map))
{
throw (new Error("invalid mode: " + view_mode_encoded));
}
else
{
return map[view_mode_encoded];
}
}
/**
*/
export enum enum_view_kind
{
regular,
touch,
}
/**
*/
export function view_kind_encode(
kind : _dali.enum_view_kind
)
: string
{
switch (kind)
{
case _dali.enum_view_kind.regular: {return "regular"; break;}
case _dali.enum_view_kind.touch: {return "touch"; break;}
default: {throw (new Error("invalid kind"));}
}
}
/**
*/
export function view_kind_decode(
view_kind_encoded : string
)
: _dali.enum_view_kind
{
const map : Record<string, _dali.enum_view_kind> = {
"regular": _dali.enum_view_kind.regular,
"touch": _dali.enum_view_kind.touch,
};
if (! (view_kind_encoded in map))
{
throw (new Error("invalid kind: " + view_kind_encoded));
}
else
{
return map[view_kind_encoded];
}
}
}