import { getStringNoLocale, getUrl, getDatetime, type Thing, createThing, } from "@inrupt/solid-client"; import { RDF, SCHEMA_INRUPT } from "@inrupt/vocab-common-rdf"; import { buildThing } from "@inrupt/solid-client"; const SCHEMA_CUSTOM = { // Types ScheduleAction: "http://schema.org/ScheduleAction", // Properties scheduledTime: "http://schema.org/scheduledTime", actionStatus: "http://schema.org/actionStatus", // Enumeration types ActionStatusType: { active: "http://schema.org/ActiveActionStatus", done: "http://schema.org/CompletedActionStatus", }, }; export const thingToTask = (taskThing: Thing) => ({ type: SCHEMA_CUSTOM.ScheduleAction, id: taskThing.url, name: getStringNoLocale(taskThing, SCHEMA_INRUPT.name) || "", done: getUrl(taskThing, SCHEMA_CUSTOM.actionStatus) === SCHEMA_CUSTOM.ActionStatusType.done, dueDate: getDatetime(taskThing, SCHEMA_CUSTOM.scheduledTime), }); export const taskToThing = (task: Task) => { const taskThing = buildThing(createThing({ url: task.id })) .addStringNoLocale(SCHEMA_INRUPT.name, task.name) .addUrl(RDF.type, SCHEMA_CUSTOM.ScheduleAction) .addUrl( SCHEMA_CUSTOM.actionStatus, task.done ? SCHEMA_CUSTOM.ActionStatusType.done : SCHEMA_CUSTOM.ActionStatusType.active ); if (task.dueDate) taskThing.addDatetime(SCHEMA_CUSTOM.scheduledTime, task.dueDate); return taskThing.build(); };