2024-09-12 16:35:57 +02:00
|
|
|
|
|
|
|
namespace _zeitbild.repository.resource
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2024-09-26 10:33:33 +02:00
|
|
|
type type_local_resource_event_stuff = {
|
|
|
|
event : _zeitbild.type_event_object;
|
|
|
|
local_resource_id : int;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
var _local_resource_event_store : (
|
2024-09-12 16:35:57 +02:00
|
|
|
null
|
|
|
|
|
|
2024-09-26 10:33:33 +02:00
|
|
|
lib_plankton.storage.type_store<
|
|
|
|
int,
|
2024-09-12 16:35:57 +02:00
|
|
|
Record<string, any>,
|
2024-09-26 10:33:33 +02:00
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
2024-09-12 16:35:57 +02:00
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
) = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2024-09-25 14:50:32 +02:00
|
|
|
var _local_resource_core_store : (
|
2024-09-12 16:35:57 +02:00
|
|
|
null
|
|
|
|
|
|
|
|
|
lib_plankton.storage.type_store<
|
|
|
|
int,
|
|
|
|
Record<string, any>,
|
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
) = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
var _caldav_resource_store : (
|
|
|
|
null
|
|
|
|
|
|
|
|
|
lib_plankton.storage.type_store<
|
|
|
|
int,
|
|
|
|
Record<string, any>,
|
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
) = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
var _resource_core_store : (
|
|
|
|
null
|
|
|
|
|
|
|
|
|
lib_plankton.storage.type_store<
|
2024-09-21 11:05:24 +02:00
|
|
|
_zeitbild.type_resource_id,
|
2024-09-12 16:35:57 +02:00
|
|
|
Record<string, any>,
|
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
) = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2024-09-26 10:33:33 +02:00
|
|
|
function get_local_resource_event_store(
|
|
|
|
) : lib_plankton.storage.type_store<
|
|
|
|
int,
|
2024-09-12 16:35:57 +02:00
|
|
|
Record<string, any>,
|
2024-09-26 10:33:33 +02:00
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
2024-09-12 16:35:57 +02:00
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
{
|
2024-09-26 10:33:33 +02:00
|
|
|
if (_local_resource_event_store === null) {
|
|
|
|
_local_resource_event_store = lib_plankton.storage.sql_table_autokey_store(
|
2024-09-12 16:35:57 +02:00
|
|
|
{
|
|
|
|
"database_implementation": _zeitbild.database.get_implementation(),
|
2024-09-25 14:50:32 +02:00
|
|
|
"table_name": "local_resource_events",
|
2024-09-26 10:33:33 +02:00
|
|
|
"key_name": "id",
|
2024-09-12 16:35:57 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// do nothing
|
|
|
|
}
|
2024-09-26 10:33:33 +02:00
|
|
|
return _local_resource_event_store;
|
2024-09-12 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2024-09-25 14:50:32 +02:00
|
|
|
function get_local_resource_core_store(
|
2024-09-12 16:35:57 +02:00
|
|
|
) : lib_plankton.storage.type_store<
|
|
|
|
int,
|
|
|
|
Record<string, any>,
|
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
{
|
2024-09-25 14:50:32 +02:00
|
|
|
if (_local_resource_core_store === null) {
|
|
|
|
_local_resource_core_store = lib_plankton.storage.sql_table_autokey_store(
|
2024-09-12 16:35:57 +02:00
|
|
|
{
|
|
|
|
"database_implementation": _zeitbild.database.get_implementation(),
|
2024-09-25 14:50:32 +02:00
|
|
|
"table_name": "local_resources",
|
2024-09-12 16:35:57 +02:00
|
|
|
"key_name": "id",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// do nothing
|
|
|
|
}
|
2024-09-25 14:50:32 +02:00
|
|
|
return _local_resource_core_store;
|
2024-09-12 16:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
function get_caldav_resource_store(
|
|
|
|
) : lib_plankton.storage.type_store<
|
|
|
|
int,
|
|
|
|
Record<string, any>,
|
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
{
|
|
|
|
if (_caldav_resource_store === null) {
|
|
|
|
_caldav_resource_store = lib_plankton.storage.sql_table_autokey_store(
|
|
|
|
{
|
|
|
|
"database_implementation": _zeitbild.database.get_implementation(),
|
|
|
|
"table_name": "caldav_resources",
|
|
|
|
"key_name": "id",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
return _caldav_resource_store;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
function get_resource_core_store(
|
|
|
|
) : lib_plankton.storage.type_store<
|
2024-09-21 11:05:24 +02:00
|
|
|
_zeitbild.type_resource_id,
|
2024-09-12 16:35:57 +02:00
|
|
|
Record<string, any>,
|
|
|
|
{},
|
|
|
|
lib_plankton.storage.type_sql_table_autokey_search_term,
|
|
|
|
Record<string, any>
|
|
|
|
>
|
|
|
|
{
|
|
|
|
if (_resource_core_store === null) {
|
|
|
|
_resource_core_store = lib_plankton.storage.sql_table_autokey_store(
|
|
|
|
{
|
|
|
|
"database_implementation": _zeitbild.database.get_implementation(),
|
|
|
|
"table_name": "resources",
|
|
|
|
"key_name": "id",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
return _resource_core_store;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-26 10:33:33 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
function encode_local_resource_event(
|
|
|
|
stuff : type_local_resource_event_stuff
|
|
|
|
) : Record<string, any>
|
|
|
|
{
|
2024-09-26 16:47:38 +02:00
|
|
|
const encode_datetime : ((datetime : lib_plankton.pit.type_datetime) => string) = ((datetime) => {
|
2024-09-26 10:33:33 +02:00
|
|
|
return lib_plankton.string.coin(
|
|
|
|
"{{timezone_shift}}|{{date}}{{macro_time}}",
|
|
|
|
{
|
|
|
|
"timezone_shift": datetime.timezone_shift.toFixed(0).padStart(2, "0"),
|
|
|
|
"date": lib_plankton.string.coin(
|
|
|
|
"{{year}}-{{month}}-{{day}}",
|
|
|
|
{
|
|
|
|
"year": datetime.date.year.toFixed(0).padStart(4, "0"),
|
|
|
|
"month": datetime.date.month.toFixed(0).padStart(2, "0"),
|
|
|
|
"day": datetime.date.day.toFixed(0).padStart(2, "0"),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"macro_time": (
|
|
|
|
(datetime.time === null)
|
|
|
|
?
|
|
|
|
""
|
|
|
|
:
|
|
|
|
lib_plankton.string.coin(
|
|
|
|
"T{{hour}}:{{minute}}:{{second}}",
|
|
|
|
{
|
|
|
|
"hour": datetime.time.hour.toFixed(0).padStart(2, "0"),
|
|
|
|
"minute": datetime.time.minute.toFixed(0).padStart(2, "0"),
|
|
|
|
"second": datetime.time.second.toFixed(0).padStart(2, "0"),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
"local_resource_id": stuff.local_resource_id,
|
|
|
|
"name": stuff.event.name,
|
|
|
|
"begin": encode_datetime(stuff.event.begin),
|
|
|
|
"end": (
|
|
|
|
(stuff.event.end === null)
|
|
|
|
?
|
|
|
|
null
|
|
|
|
:
|
|
|
|
encode_datetime(stuff.event.end)
|
|
|
|
),
|
|
|
|
"location": stuff.event.location,
|
|
|
|
"description": stuff.event.description,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
function decode_local_resource_event(
|
|
|
|
row : Record<string, any>
|
|
|
|
) : type_local_resource_event_stuff
|
|
|
|
{
|
2024-09-26 16:47:38 +02:00
|
|
|
const decode_datetime : ((datetime_raw : string) => lib_plankton.pit.type_datetime) = ((datetime_raw) => {
|
2024-09-26 10:33:33 +02:00
|
|
|
const parts : Array<string> = datetime_raw.split("|");
|
|
|
|
const timezone_shift : int = parseInt(parts[0]);
|
|
|
|
if (parts[1].length <= 10) {
|
|
|
|
return {
|
|
|
|
"timezone_shift": timezone_shift,
|
|
|
|
"date": {
|
|
|
|
"year": parseInt(parts[1].slice(0, 4)),
|
|
|
|
"month": parseInt(parts[1].slice(5, 7)),
|
|
|
|
"day": parseInt(parts[1].slice(8, 10)),
|
|
|
|
},
|
|
|
|
"time": null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {
|
|
|
|
"timezone_shift": timezone_shift,
|
|
|
|
"date": {
|
|
|
|
"year": parseInt(parts[1].slice(0, 4)),
|
|
|
|
"month": parseInt(parts[1].slice(5, 7)),
|
|
|
|
"day": parseInt(parts[1].slice(8, 10)),
|
|
|
|
},
|
|
|
|
"time": {
|
|
|
|
"hour": parseInt(parts[1].slice(11, 13)),
|
|
|
|
"minute": parseInt(parts[1].slice(14, 16)),
|
|
|
|
"second": parseInt(parts[1].slice(17, 19)),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
"local_resource_id": row["local_resource_id"],
|
|
|
|
"event": {
|
|
|
|
"name": row["name"],
|
|
|
|
"begin": decode_datetime(row["begin"]),
|
|
|
|
"end": (
|
|
|
|
(row["end"] === null)
|
|
|
|
?
|
|
|
|
null
|
|
|
|
:
|
|
|
|
decode_datetime(row["end"])
|
|
|
|
),
|
|
|
|
"location": row["location"],
|
|
|
|
"description": row["description"],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-12 16:35:57 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function encode_resource_core(
|
|
|
|
stuff : {
|
2024-09-21 11:05:24 +02:00
|
|
|
object : _zeitbild.type_resource_object;
|
2024-09-12 16:35:57 +02:00
|
|
|
sub_id : int;
|
|
|
|
}
|
|
|
|
) : Record<string, any>
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
"kind": stuff.object.kind,
|
|
|
|
"sub_id": stuff.sub_id
|
|
|
|
};
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo data
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function decode_resource_core(
|
|
|
|
row : Record<string, any>
|
|
|
|
) : {
|
2024-09-21 11:05:24 +02:00
|
|
|
object : _zeitbild.type_resource_object;
|
2024-09-12 16:35:57 +02:00
|
|
|
sub_id : int;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
"object": {
|
|
|
|
"kind": row["kind"],
|
|
|
|
"data": null,
|
|
|
|
},
|
|
|
|
"sub_id": row["sub_id"],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function read(
|
2024-09-21 11:05:24 +02:00
|
|
|
resource_id : _zeitbild.type_resource_id
|
|
|
|
) : Promise<_zeitbild.type_resource_object>
|
2024-09-12 16:35:57 +02:00
|
|
|
{
|
|
|
|
const dataset_core : Record<string, any> = await get_resource_core_store().read(resource_id);
|
|
|
|
switch (dataset_core.kind) {
|
|
|
|
case "local": {
|
|
|
|
const dataset_extra_local_core : Record<string, any> = await get_local_resource_core_store().read(dataset_core.sub_id);
|
2024-09-26 10:33:33 +02:00
|
|
|
const datasets_extra_local_event_ids : Array<Record<string, any>> = await get_local_resource_event_store().search(
|
2024-09-12 16:35:57 +02:00
|
|
|
{
|
|
|
|
"expression": "(local_resource_id = $local_resource_id)",
|
|
|
|
"arguments": {
|
|
|
|
"local_resource_id": dataset_core.sub_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2024-09-21 11:05:24 +02:00
|
|
|
return Promise.resolve<_zeitbild.type_resource_object>(
|
2024-09-12 16:35:57 +02:00
|
|
|
{
|
|
|
|
"kind": "local",
|
|
|
|
"data": {
|
2024-09-25 14:50:32 +02:00
|
|
|
"event_ids": (
|
|
|
|
datasets_extra_local_event_ids
|
2024-09-26 10:33:33 +02:00
|
|
|
.map((hit) => hit.preview["id"])
|
2024-09-25 14:50:32 +02:00
|
|
|
)
|
2024-09-12 16:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
const dataset_extra_caldav : Record<string, any> = await get_caldav_resource_store().read(dataset_core.sub_id);
|
2024-09-21 11:05:24 +02:00
|
|
|
return Promise.resolve<_zeitbild.type_resource_object>(
|
2024-09-12 16:35:57 +02:00
|
|
|
{
|
|
|
|
"kind": "caldav",
|
|
|
|
"data": {
|
|
|
|
"url": dataset_extra_caldav["url"],
|
|
|
|
"read_only": dataset_extra_caldav["read_only"],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2024-09-21 11:05:24 +02:00
|
|
|
return Promise.reject<_zeitbild.type_resource_object>(
|
2024-09-12 16:35:57 +02:00
|
|
|
new Error("invalid resource kind: " + dataset_core.kind)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-18 18:17:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function create(
|
2024-09-21 11:05:24 +02:00
|
|
|
resource_object : _zeitbild.type_resource_object
|
|
|
|
) : Promise<_zeitbild.type_resource_id>
|
2024-09-18 18:17:25 +02:00
|
|
|
{
|
|
|
|
switch (resource_object.kind) {
|
|
|
|
case "local": {
|
|
|
|
const local_resource_id : int = await get_local_resource_core_store().create(
|
|
|
|
{
|
|
|
|
"_dummy": null,
|
|
|
|
}
|
|
|
|
);
|
2024-09-21 11:05:24 +02:00
|
|
|
const resource_id : _zeitbild.type_resource_id = await get_resource_core_store().create(
|
2024-09-18 18:17:25 +02:00
|
|
|
{
|
|
|
|
"kind": "local",
|
|
|
|
"sub_id": local_resource_id,
|
|
|
|
}
|
|
|
|
);
|
2024-09-21 11:05:24 +02:00
|
|
|
return Promise.resolve<_zeitbild.type_resource_id>(resource_id);
|
2024-09-18 18:17:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
const caldav_resource_id : int = await get_caldav_resource_store().create(
|
|
|
|
{
|
|
|
|
"url": resource_object.data.url,
|
|
|
|
"read_only": resource_object.data.read_only,
|
|
|
|
}
|
|
|
|
);
|
2024-09-21 11:05:24 +02:00
|
|
|
const resource_id : _zeitbild.type_resource_id = await get_resource_core_store().create(
|
2024-09-18 18:17:25 +02:00
|
|
|
{
|
|
|
|
"kind": "caldav",
|
|
|
|
"sub_id": caldav_resource_id,
|
|
|
|
}
|
|
|
|
);
|
2024-09-21 11:05:24 +02:00
|
|
|
return Promise.resolve<_zeitbild.type_resource_id>(resource_id);
|
2024-09-18 18:17:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2024-09-25 15:28:25 +02:00
|
|
|
// @ts-ignore
|
2024-09-25 14:50:32 +02:00
|
|
|
throw (new Error("invalid resource kind: " + resource_object.kind));
|
2024-09-18 18:17:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:50:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo allow kind change?
|
|
|
|
*/
|
|
|
|
export async function update(
|
|
|
|
resource_id : _zeitbild.type_resource_id,
|
|
|
|
resource_object : _zeitbild.type_resource_object
|
|
|
|
) : Promise<void>
|
|
|
|
{
|
|
|
|
const dataset_core : Record<string, any> = await get_resource_core_store().read(resource_id);
|
|
|
|
if (dataset_core["kind"] !== resource_object.kind) {
|
|
|
|
return Promise.reject(new Error("resource kind may not be altered"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (resource_object.kind) {
|
|
|
|
case "local": {
|
|
|
|
// event_id list may not be altered directly
|
|
|
|
/*
|
|
|
|
const current_event_id_rows : {key : int; preview : Array<Record<string, any>>;} = await get_local_resource_event_chest().search(
|
|
|
|
{
|
|
|
|
"expression": "(local_resource_id = $local_resource_id)",
|
|
|
|
"arguments": {
|
|
|
|
"local_resource_id": dataset_core["sub_id"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const contrast : {
|
|
|
|
only_left : Array<{key : int; left : any;}>;
|
|
|
|
both : Array<{key : int; left : any; right : any;}>;
|
|
|
|
only_right : Array<{key : int; right : any;}>;
|
|
|
|
} = lib_plankton.list.contrast<
|
|
|
|
{key : Array<any>; preview : Record<string, any>;},
|
|
|
|
_zeitbild.type_local_resource_event_id
|
|
|
|
>(
|
|
|
|
event_rows,
|
|
|
|
(hit => hit.key),
|
|
|
|
resource_object.data.event_ids,
|
|
|
|
(x => x)
|
|
|
|
);
|
|
|
|
// TODO: single delete?
|
|
|
|
for await (const entry of constrast.only_left) {
|
|
|
|
await get_local_resource_event_store().delete(
|
|
|
|
entry.key
|
|
|
|
);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
for await (const entry of contrast.both) {
|
|
|
|
await get_local_resource_event_store().update(
|
|
|
|
entry.left.key,
|
2024-09-26 10:33:33 +02:00
|
|
|
encode_local_resource_event(entry.right.object)
|
2024-09-25 14:50:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
for await (const entry of contrast.only_right) {
|
|
|
|
const event_id : type_local_resource_event_id = await get_local_resource_event_store().create(
|
2024-09-26 10:33:33 +02:00
|
|
|
encode_local_resource_event(entry.right.object)
|
2024-09-25 14:50:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "caldav": {
|
|
|
|
await get_caldav_resource_store().update(
|
|
|
|
dataset_core["sub_id"],
|
|
|
|
{
|
|
|
|
"url": resource_object.data.url,
|
|
|
|
"read_only": resource_object.data.read_only,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2024-09-25 15:28:25 +02:00
|
|
|
// @ts-ignore
|
2024-09-25 14:50:32 +02:00
|
|
|
throw (new Error("invalid resource kind: " + resource_object.kind));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2024-09-26 10:33:33 +02:00
|
|
|
export async function local_resource_event_read(
|
2024-09-25 14:50:32 +02:00
|
|
|
resource_id : _zeitbild.type_resource_id,
|
2024-09-26 10:33:33 +02:00
|
|
|
local_resource_event_id : _zeitbild.type_local_resource_event_id
|
|
|
|
) : Promise<_zeitbild.type_event_object>
|
2024-09-25 14:50:32 +02:00
|
|
|
{
|
|
|
|
const dataset_core : Record<string, any> = await get_resource_core_store().read(resource_id);
|
|
|
|
if (! (dataset_core.kind === "local")) {
|
|
|
|
throw (new Error("not a local resource"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (
|
2024-09-26 10:33:33 +02:00
|
|
|
get_local_resource_event_store().read(
|
|
|
|
local_resource_event_id
|
2024-09-25 14:50:32 +02:00
|
|
|
)
|
|
|
|
.then(
|
2024-09-26 10:33:33 +02:00
|
|
|
(row) => Promise.resolve(decode_local_resource_event(row))
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
(local_resource_event_stuff : type_local_resource_event_stuff) => Promise.resolve(
|
|
|
|
local_resource_event_stuff.event
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function local_resource_event_create(
|
|
|
|
resource_id : _zeitbild.type_resource_id,
|
|
|
|
event_object : _zeitbild.type_event_object
|
|
|
|
) : Promise<_zeitbild.type_local_resource_event_id>
|
|
|
|
{
|
|
|
|
const dataset_core : Record<string, any> = await get_resource_core_store().read(resource_id);
|
|
|
|
if (! (dataset_core.kind === "local")) {
|
|
|
|
throw (new Error("not a local resource"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return get_local_resource_event_store().create(
|
|
|
|
encode_local_resource_event(
|
|
|
|
{
|
|
|
|
"local_resource_id": dataset_core["sub_id"],
|
|
|
|
"event": event_object,
|
|
|
|
}
|
2024-09-25 14:50:32 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2024-09-25 15:28:25 +02:00
|
|
|
export async function local_resource_event_delete(
|
2024-09-25 14:50:32 +02:00
|
|
|
resource_id : _zeitbild.type_resource_id,
|
2024-09-26 10:33:33 +02:00
|
|
|
local_resource_event_id : _zeitbild.type_local_resource_event_id
|
2024-09-25 14:50:32 +02:00
|
|
|
) : Promise<void>
|
|
|
|
{
|
|
|
|
const dataset_core : Record<string, any> = await get_resource_core_store().read(resource_id);
|
|
|
|
if (! (dataset_core.kind === "local")) {
|
|
|
|
throw (new Error("not a local resource"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (
|
2024-09-26 10:33:33 +02:00
|
|
|
get_local_resource_event_store().delete(
|
|
|
|
local_resource_event_id
|
2024-09-25 14:50:32 +02:00
|
|
|
)
|
|
|
|
.then(
|
|
|
|
() => Promise.resolve(undefined)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-12 16:35:57 +02:00
|
|
|
}
|