Initial commit
This commit is contained in:
18
src/main.ts
Normal file
18
src/main.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useCollectionsStore } from '@/stores/collectionsStore'
|
||||
import { useEntitiesStore } from '@/stores/entitiesStore'
|
||||
import { useProvidersStore } from '@/stores/providersStore'
|
||||
import { useServicesStore } from '@/stores/servicesStore'
|
||||
|
||||
/**
|
||||
* Chrono Manager Module Boot Script
|
||||
*
|
||||
* This script is executed when the chrono_manager module is loaded.
|
||||
* It initializes the chronoStore which manages calendars, events, tasks, and journals state.
|
||||
*/
|
||||
|
||||
console.log('[ChronoManager] Booting Chrono Manager module...')
|
||||
|
||||
console.log('[ChronoManager] Chrono Manager module booted successfully')
|
||||
|
||||
// Export store for external use if needed
|
||||
export { useCollectionsStore, useEntitiesStore, useProvidersStore, useServicesStore }
|
||||
158
src/models/collection.ts
Normal file
158
src/models/collection.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* Class model for Collection Interface
|
||||
*/
|
||||
import type {
|
||||
CollectionInterface,
|
||||
CollectionContentsInterface,
|
||||
CollectionPermissionsInterface,
|
||||
} from "@/types/collection";
|
||||
|
||||
export class CollectionObject implements CollectionInterface {
|
||||
|
||||
_data!: CollectionInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'chrono:collection',
|
||||
provider: null,
|
||||
service: null,
|
||||
in: null,
|
||||
id: null,
|
||||
label: null,
|
||||
description: null,
|
||||
priority: null,
|
||||
visibility: null,
|
||||
color: null,
|
||||
enabled: true,
|
||||
signature: null,
|
||||
permissions: {},
|
||||
contents: {},
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: CollectionInterface): CollectionObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): CollectionInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): CollectionObject {
|
||||
const cloned = new CollectionObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get provider(): string | null {
|
||||
return this._data.provider;
|
||||
}
|
||||
|
||||
set provider(value: string | null) {
|
||||
this._data.provider = value;
|
||||
}
|
||||
|
||||
get service(): string | null {
|
||||
return this._data.service;
|
||||
}
|
||||
|
||||
set service(value: string | null) {
|
||||
this._data.service = value;
|
||||
}
|
||||
|
||||
get in(): number | string | null {
|
||||
return this._data.in;
|
||||
}
|
||||
|
||||
set in(value: number | string | null) {
|
||||
this._data.in = value;
|
||||
}
|
||||
|
||||
get id(): number | string | null {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
set id(value: number | string | null) {
|
||||
this._data.id = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get priority(): number | null {
|
||||
return this._data.priority;
|
||||
}
|
||||
|
||||
set priority(value: number | null) {
|
||||
this._data.priority = value;
|
||||
}
|
||||
|
||||
get visibility(): string | null {
|
||||
return this._data.visibility;
|
||||
}
|
||||
|
||||
set visibility(value: string | null) {
|
||||
this._data.visibility = value;
|
||||
}
|
||||
|
||||
get color(): string | null {
|
||||
return this._data.color;
|
||||
}
|
||||
|
||||
set color(value: string | null) {
|
||||
this._data.color = value;
|
||||
}
|
||||
|
||||
get enabled(): boolean {
|
||||
return this._data.enabled;
|
||||
}
|
||||
|
||||
set enabled(value: boolean) {
|
||||
this._data.enabled = value;
|
||||
}
|
||||
|
||||
get signature(): string | null {
|
||||
return this._data.signature;
|
||||
}
|
||||
|
||||
set signature(value: string | null) {
|
||||
this._data.signature = value;
|
||||
}
|
||||
|
||||
get permissions(): CollectionPermissionsInterface {
|
||||
return this._data.permissions;
|
||||
}
|
||||
|
||||
set permissions(value: CollectionPermissionsInterface) {
|
||||
this._data.permissions = value;
|
||||
}
|
||||
|
||||
get contents(): CollectionContentsInterface {
|
||||
return this._data.contents;
|
||||
}
|
||||
|
||||
set contents(value: CollectionContentsInterface) {
|
||||
this._data.contents = value;
|
||||
}
|
||||
|
||||
}
|
||||
162
src/models/entity.ts
Normal file
162
src/models/entity.ts
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Class model for Entity Interface
|
||||
*/
|
||||
import type { EntityInterface } from "@/types/entity";
|
||||
import type { EventInterface } from "@/types/event";
|
||||
import type { TaskInterface } from "@/types/task";
|
||||
import type { JournalInterface } from "@/types/journal";
|
||||
import { EventObject } from "./event";
|
||||
import { TaskObject } from "./task";
|
||||
import { JournalObject } from "./journal";
|
||||
|
||||
export class EntityObject implements EntityInterface {
|
||||
|
||||
_data!: EntityInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'chrono:entity',
|
||||
version: 1,
|
||||
in: null,
|
||||
id: null,
|
||||
createdOn: null,
|
||||
createdBy: null,
|
||||
modifiedOn: null,
|
||||
modifiedBy: null,
|
||||
signature: null,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EntityInterface): EntityObject {
|
||||
this._data = data;
|
||||
if (data.data) {
|
||||
const type = data.data.type;
|
||||
if (type === 'task') {
|
||||
this._data.data = new TaskObject().fromJson(data.data as TaskInterface);
|
||||
} else if (type === 'journal') {
|
||||
this._data.data = new JournalObject().fromJson(data.data as JournalInterface);
|
||||
} else {
|
||||
this._data.data = new EventObject().fromJson(data.data as EventInterface);
|
||||
}
|
||||
} else {
|
||||
this._data.data = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EntityInterface {
|
||||
const json = { ...this._data };
|
||||
if (this._data.data instanceof EventObject ||
|
||||
this._data.data instanceof TaskObject ||
|
||||
this._data.data instanceof JournalObject) {
|
||||
json.data = this._data.data.toJson();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
clone(): EntityObject {
|
||||
const cloned = new EntityObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get version(): number {
|
||||
return this._data.version;
|
||||
}
|
||||
|
||||
set version(value: number) {
|
||||
this._data.version = value;
|
||||
}
|
||||
|
||||
get in(): string | number | null {
|
||||
return this._data.in;
|
||||
}
|
||||
|
||||
set in(value: string | number | null) {
|
||||
this._data.in = value;
|
||||
}
|
||||
|
||||
get id(): string | number | null {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
set id(value: string | number | null) {
|
||||
this._data.id = value;
|
||||
}
|
||||
|
||||
get createdOn(): Date | null {
|
||||
return this._data.createdOn;
|
||||
}
|
||||
|
||||
set createdOn(value: Date | null) {
|
||||
this._data.createdOn = value;
|
||||
}
|
||||
|
||||
get createdBy(): string | null {
|
||||
return this._data.createdBy;
|
||||
}
|
||||
|
||||
set createdBy(value: string | null) {
|
||||
this._data.createdBy = value;
|
||||
}
|
||||
|
||||
get modifiedOn(): Date | null {
|
||||
return this._data.modifiedOn;
|
||||
}
|
||||
|
||||
set modifiedOn(value: Date | null) {
|
||||
this._data.modifiedOn = value;
|
||||
}
|
||||
|
||||
get modifiedBy(): string | null {
|
||||
return this._data.modifiedBy;
|
||||
}
|
||||
|
||||
set modifiedBy(value: string | null) {
|
||||
this._data.modifiedBy = value;
|
||||
}
|
||||
|
||||
get signature(): string | null {
|
||||
return this._data.signature;
|
||||
}
|
||||
|
||||
set signature(value: string | null) {
|
||||
this._data.signature = value;
|
||||
}
|
||||
|
||||
get data(): EventObject | TaskObject | JournalObject | null {
|
||||
if (this._data.data instanceof EventObject ||
|
||||
this._data.data instanceof TaskObject ||
|
||||
this._data.data instanceof JournalObject) {
|
||||
return this._data.data;
|
||||
}
|
||||
|
||||
if (this._data.data) {
|
||||
const type = this._data.data.type;
|
||||
let hydrated;
|
||||
if (type === 'task') {
|
||||
hydrated = new TaskObject().fromJson(this._data.data as TaskInterface);
|
||||
} else if (type === 'journal') {
|
||||
hydrated = new JournalObject().fromJson(this._data.data as JournalInterface);
|
||||
} else {
|
||||
hydrated = new EventObject().fromJson(this._data.data as EventInterface);
|
||||
}
|
||||
this._data.data = hydrated;
|
||||
return hydrated;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
set data(value: EventObject | TaskObject | JournalObject | null) {
|
||||
this._data.data = value;
|
||||
}
|
||||
|
||||
}
|
||||
82
src/models/event-location-physical.ts
Normal file
82
src/models/event-location-physical.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Class model for Event Physical Location Interface
|
||||
*/
|
||||
import type { EventLocationPhysicalInterface } from "@/types/event";
|
||||
|
||||
export class EventLocationPhysicalObject implements EventLocationPhysicalInterface {
|
||||
|
||||
_data!: EventLocationPhysicalInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
identifier: null
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventLocationPhysicalInterface): EventLocationPhysicalObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventLocationPhysicalInterface {
|
||||
const result: Partial<EventLocationPhysicalInterface> = {};
|
||||
|
||||
for (const key in this._data) {
|
||||
const value = this._data[key as keyof EventLocationPhysicalInterface];
|
||||
if (value !== null && value !== undefined) {
|
||||
(result as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result as EventLocationPhysicalInterface;
|
||||
}
|
||||
|
||||
clone(): EventLocationPhysicalObject {
|
||||
const cloned = new EventLocationPhysicalObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get identifier(): string | null {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
set identifier(value: string | null) {
|
||||
this._data.identifier = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label ?? null;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description ?? null;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get relation(): 'start' | 'end' | null {
|
||||
return this._data.relation ?? null;
|
||||
}
|
||||
|
||||
set relation(value: 'start' | 'end' | null) {
|
||||
this._data.relation = value;
|
||||
}
|
||||
|
||||
get timeZone(): string | null {
|
||||
return this._data.timeZone ?? null;
|
||||
}
|
||||
|
||||
set timeZone(value: string | null) {
|
||||
this._data.timeZone = value;
|
||||
}
|
||||
|
||||
}
|
||||
83
src/models/event-location-virtual.ts
Normal file
83
src/models/event-location-virtual.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Class model for Event Virtual Location Interface
|
||||
*/
|
||||
import type { EventLocationVirtualInterface } from "@/types/event";
|
||||
|
||||
export class EventLocationVirtualObject implements EventLocationVirtualInterface {
|
||||
|
||||
_data!: EventLocationVirtualInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
identifier: null,
|
||||
location: ''
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventLocationVirtualInterface): EventLocationVirtualObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventLocationVirtualInterface {
|
||||
const result: Partial<EventLocationVirtualInterface> = {};
|
||||
|
||||
for (const key in this._data) {
|
||||
const value = this._data[key as keyof EventLocationVirtualInterface];
|
||||
if (value !== null && value !== undefined) {
|
||||
(result as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result as EventLocationVirtualInterface;
|
||||
}
|
||||
|
||||
clone(): EventLocationVirtualObject {
|
||||
const cloned = new EventLocationVirtualObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get identifier(): string | null {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
set identifier(value: string | null) {
|
||||
this._data.identifier = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label ?? null;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description ?? null;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get relation(): string | null {
|
||||
return this._data.relation ?? null;
|
||||
}
|
||||
|
||||
set relation(value: string | null) {
|
||||
this._data.relation = value;
|
||||
}
|
||||
|
||||
get location(): string {
|
||||
return this._data.location;
|
||||
}
|
||||
|
||||
set location(value: string) {
|
||||
this._data.location = value;
|
||||
}
|
||||
|
||||
}
|
||||
481
src/models/event-mutation.ts
Normal file
481
src/models/event-mutation.ts
Normal file
@@ -0,0 +1,481 @@
|
||||
/**
|
||||
* Class model for Event Mutation Interface
|
||||
*/
|
||||
import type {
|
||||
EventMutation,
|
||||
EventLocationPhysicalInterface,
|
||||
EventLocationVirtualInterface,
|
||||
EventOrganizerInterface,
|
||||
EventParticipantInterface,
|
||||
EventNotificationInterface
|
||||
} from "@/types/event";
|
||||
import { EventLocationPhysicalObject } from "./event-location-physical";
|
||||
import { EventLocationVirtualObject } from "./event-location-virtual";
|
||||
import { EventOrganizerObject } from "./event-organizer";
|
||||
import { EventParticipantObject } from "./event-participant";
|
||||
import { EventNotificationObject } from "./event-notification";
|
||||
import { generateKey } from "../utils/key-generator";
|
||||
|
||||
export class EventMutationObject implements EventMutation {
|
||||
|
||||
_data!: EventMutation;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
mutationId: null,
|
||||
mutationTz: null,
|
||||
mutationExclusion: null,
|
||||
sequence: null,
|
||||
timeZone: null,
|
||||
startsOn: null,
|
||||
startsTZ: null,
|
||||
endsOn: null,
|
||||
endsTZ: null,
|
||||
duration: null,
|
||||
timeless: null,
|
||||
label: null,
|
||||
description: null,
|
||||
locationsPhysical: {},
|
||||
locationsVirtual: {},
|
||||
availability: null,
|
||||
priority: null,
|
||||
sensitivity: null,
|
||||
color: null,
|
||||
tags: [],
|
||||
organizer: {
|
||||
realm: 'E',
|
||||
address: ''
|
||||
},
|
||||
participants: {},
|
||||
notifications: {}
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventMutation): EventMutationObject {
|
||||
this._data = JSON.parse(JSON.stringify(data));
|
||||
|
||||
// Convert organizer to object instance
|
||||
if (this._data.organizer) {
|
||||
this._data.organizer = new EventOrganizerObject().fromJson(this._data.organizer) as any;
|
||||
}
|
||||
|
||||
// Convert locations physical to object instances
|
||||
for (const key in this._data.locationsPhysical) {
|
||||
const loc = this._data.locationsPhysical[key];
|
||||
if (loc) {
|
||||
this._data.locationsPhysical[key] = new EventLocationPhysicalObject().fromJson(loc) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert locations virtual to object instances
|
||||
for (const key in this._data.locationsVirtual) {
|
||||
const loc = this._data.locationsVirtual[key];
|
||||
if (loc) {
|
||||
this._data.locationsVirtual[key] = new EventLocationVirtualObject().fromJson(loc) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert participants to object instances
|
||||
for (const key in this._data.participants) {
|
||||
const participant = this._data.participants[key];
|
||||
if (participant) {
|
||||
this._data.participants[key] = new EventParticipantObject().fromJson(participant) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert notifications to object instances
|
||||
for (const key in this._data.notifications) {
|
||||
const notification = this._data.notifications[key];
|
||||
if (notification) {
|
||||
this._data.notifications[key] = new EventNotificationObject().fromJson(notification) as any;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventMutation {
|
||||
return JSON.parse(JSON.stringify(this._data));
|
||||
}
|
||||
|
||||
clone(): EventMutationObject {
|
||||
const cloned = new EventMutationObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get mutationId(): string | null {
|
||||
return this._data.mutationId;
|
||||
}
|
||||
|
||||
set mutationId(value: string | null) {
|
||||
this._data.mutationId = value;
|
||||
}
|
||||
|
||||
get mutationTz(): string | null {
|
||||
return this._data.mutationTz;
|
||||
}
|
||||
|
||||
set mutationTz(value: string | null) {
|
||||
this._data.mutationTz = value;
|
||||
}
|
||||
|
||||
get mutationExclusion(): boolean | null {
|
||||
return this._data.mutationExclusion;
|
||||
}
|
||||
|
||||
set mutationExclusion(value: boolean | null) {
|
||||
this._data.mutationExclusion = value;
|
||||
}
|
||||
|
||||
get sequence(): number | null {
|
||||
return this._data.sequence;
|
||||
}
|
||||
|
||||
set sequence(value: number | null) {
|
||||
this._data.sequence = value;
|
||||
}
|
||||
|
||||
get timeZone(): string | null {
|
||||
return this._data.timeZone;
|
||||
}
|
||||
|
||||
set timeZone(value: string | null) {
|
||||
this._data.timeZone = value;
|
||||
}
|
||||
|
||||
get startsOn(): string | null {
|
||||
return this._data.startsOn;
|
||||
}
|
||||
|
||||
set startsOn(value: string | null) {
|
||||
this._data.startsOn = value;
|
||||
}
|
||||
|
||||
get startsTZ(): string | null {
|
||||
return this._data.startsTZ;
|
||||
}
|
||||
|
||||
set startsTZ(value: string | null) {
|
||||
this._data.startsTZ = value;
|
||||
}
|
||||
|
||||
get endsOn(): string | null {
|
||||
return this._data.endsOn;
|
||||
}
|
||||
|
||||
set endsOn(value: string | null) {
|
||||
this._data.endsOn = value;
|
||||
}
|
||||
|
||||
get endsTZ(): string | null {
|
||||
return this._data.endsTZ;
|
||||
}
|
||||
|
||||
set endsTZ(value: string | null) {
|
||||
this._data.endsTZ = value;
|
||||
}
|
||||
|
||||
get duration(): string | null {
|
||||
return this._data.duration;
|
||||
}
|
||||
|
||||
set duration(value: string | null) {
|
||||
this._data.duration = value;
|
||||
}
|
||||
|
||||
get timeless(): boolean | null {
|
||||
return this._data.timeless;
|
||||
}
|
||||
|
||||
set timeless(value: boolean | null) {
|
||||
this._data.timeless = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get locationsPhysical(): Record<string, EventLocationPhysicalObject> {
|
||||
return this._data.locationsPhysical as any;
|
||||
}
|
||||
|
||||
set locationsPhysical(value: Record<string, EventLocationPhysicalInterface|EventLocationPhysicalObject>) {
|
||||
this._data.locationsPhysical = {} as any;
|
||||
for (const key in value) {
|
||||
const loc = value[key];
|
||||
if (loc) {
|
||||
if (loc instanceof EventLocationPhysicalObject) {
|
||||
(this._data.locationsPhysical as any)[key] = loc;
|
||||
} else {
|
||||
(this._data.locationsPhysical as any)[key] = new EventLocationPhysicalObject().fromJson(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addLocationPhysical(value?: EventLocationPhysicalInterface|EventLocationPhysicalObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let location: EventLocationPhysicalObject;
|
||||
|
||||
if (!value) {
|
||||
location = new EventLocationPhysicalObject();
|
||||
location.identifier = key;
|
||||
}
|
||||
else if (value instanceof EventLocationPhysicalObject) {
|
||||
location = value;
|
||||
location.identifier = key;
|
||||
}
|
||||
else {
|
||||
location = new EventLocationPhysicalObject().fromJson(value);
|
||||
location.identifier = key;
|
||||
}
|
||||
|
||||
(this._data.locationsPhysical as any)[key] = location;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeLocationPhysical(key: string): void {
|
||||
delete this._data.locationsPhysical[key];
|
||||
}
|
||||
|
||||
getLocationPhysical(key: string): EventLocationPhysicalObject | undefined {
|
||||
return this._data.locationsPhysical[key] as any;
|
||||
}
|
||||
|
||||
get locationsVirtual(): Record<string, EventLocationVirtualObject> {
|
||||
return this._data.locationsVirtual as any;
|
||||
}
|
||||
|
||||
set locationsVirtual(value: Record<string, EventLocationVirtualInterface|EventLocationVirtualObject>) {
|
||||
this._data.locationsVirtual = {} as any;
|
||||
for (const key in value) {
|
||||
const loc = value[key];
|
||||
if (loc) {
|
||||
if (loc instanceof EventLocationVirtualObject) {
|
||||
(this._data.locationsVirtual as any)[key] = loc;
|
||||
} else {
|
||||
(this._data.locationsVirtual as any)[key] = new EventLocationVirtualObject().fromJson(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addLocationVirtual(value?: EventLocationVirtualInterface|EventLocationVirtualObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let location: EventLocationVirtualObject;
|
||||
|
||||
if (!value) {
|
||||
location = new EventLocationVirtualObject();
|
||||
location.identifier = key;
|
||||
}
|
||||
else if (value instanceof EventLocationVirtualObject) {
|
||||
location = value;
|
||||
location.identifier = key;
|
||||
}
|
||||
else {
|
||||
location = new EventLocationVirtualObject().fromJson(value);
|
||||
location.identifier = key;
|
||||
}
|
||||
|
||||
(this._data.locationsVirtual as any)[key] = location;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeLocationVirtual(key: string): void {
|
||||
delete this._data.locationsVirtual[key];
|
||||
}
|
||||
|
||||
getLocationVirtual(key: string): EventLocationVirtualObject | undefined {
|
||||
return this._data.locationsVirtual[key] as any;
|
||||
}
|
||||
|
||||
get availability(): 'free' | 'busy' | null {
|
||||
return this._data.availability;
|
||||
}
|
||||
|
||||
set availability(value: 'free' | 'busy' | null) {
|
||||
this._data.availability = value;
|
||||
}
|
||||
|
||||
get priority(): number | null {
|
||||
return this._data.priority;
|
||||
}
|
||||
|
||||
set priority(value: number | null) {
|
||||
this._data.priority = value;
|
||||
}
|
||||
|
||||
get sensitivity(): 'public' | 'private' | 'secret' | null {
|
||||
return this._data.sensitivity;
|
||||
}
|
||||
|
||||
set sensitivity(value: 'public' | 'private' | 'secret' | null) {
|
||||
this._data.sensitivity = value;
|
||||
}
|
||||
|
||||
get color(): string | null {
|
||||
return this._data.color;
|
||||
}
|
||||
|
||||
set color(value: string | null) {
|
||||
this._data.color = value;
|
||||
}
|
||||
|
||||
get tags(): string[] {
|
||||
return this._data.tags;
|
||||
}
|
||||
|
||||
set tags(value: string[]) {
|
||||
this._data.tags = value;
|
||||
}
|
||||
|
||||
addTag(tag: string): void {
|
||||
if (!this._data.tags.includes(tag)) {
|
||||
this._data.tags.push(tag);
|
||||
}
|
||||
}
|
||||
|
||||
removeTag(tag: string): void {
|
||||
const index = this._data.tags.indexOf(tag);
|
||||
if (index > -1) {
|
||||
this._data.tags.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get organizer(): EventOrganizerObject | null {
|
||||
return this._data.organizer as any;
|
||||
}
|
||||
|
||||
set organizer(value: EventOrganizerInterface|EventOrganizerObject|null) {
|
||||
if (!value) {
|
||||
this._data.organizer = null;
|
||||
} else if (value instanceof EventOrganizerObject) {
|
||||
this._data.organizer = value as any;
|
||||
} else {
|
||||
this._data.organizer = new EventOrganizerObject().fromJson(value) as any;
|
||||
}
|
||||
}
|
||||
|
||||
get participants(): Record<string, EventParticipantObject> {
|
||||
return this._data.participants as any;
|
||||
}
|
||||
|
||||
set participants(value: Record<string, EventParticipantInterface|EventParticipantObject>) {
|
||||
this._data.participants = {} as any;
|
||||
for (const key in value) {
|
||||
const participant = value[key];
|
||||
if (participant) {
|
||||
if (participant instanceof EventParticipantObject) {
|
||||
(this._data.participants as any)[key] = participant;
|
||||
} else {
|
||||
(this._data.participants as any)[key] = new EventParticipantObject().fromJson(participant);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addParticipant(value?: EventParticipantInterface|EventParticipantObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let participant: EventParticipantObject;
|
||||
|
||||
if (!value) {
|
||||
participant = new EventParticipantObject();
|
||||
participant.identifier = key;
|
||||
}
|
||||
else if (value instanceof EventParticipantObject) {
|
||||
participant = value;
|
||||
participant.identifier = key;
|
||||
}
|
||||
else {
|
||||
participant = new EventParticipantObject().fromJson(value);
|
||||
participant.identifier = key;
|
||||
}
|
||||
|
||||
(this._data.participants as any)[key] = participant;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeParticipant(key: string): void {
|
||||
delete this._data.participants[key];
|
||||
}
|
||||
|
||||
getParticipant(key: string): EventParticipantObject | undefined {
|
||||
return this._data.participants[key] as any;
|
||||
}
|
||||
|
||||
get notifications(): Record<string, EventNotificationObject> {
|
||||
return this._data.notifications as any;
|
||||
}
|
||||
|
||||
set notifications(value: Record<string, EventNotificationInterface|EventNotificationObject>) {
|
||||
this._data.notifications = {} as any;
|
||||
for (const key in value) {
|
||||
const notification = value[key];
|
||||
if (notification) {
|
||||
if (notification instanceof EventNotificationObject) {
|
||||
(this._data.notifications as any)[key] = notification;
|
||||
} else {
|
||||
(this._data.notifications as any)[key] = new EventNotificationObject().fromJson(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addNotification(value?: EventNotificationInterface|EventNotificationObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let notification: EventNotificationObject;
|
||||
|
||||
if (!value) {
|
||||
notification = new EventNotificationObject();
|
||||
}
|
||||
else if (value instanceof EventNotificationObject) {
|
||||
notification = value;
|
||||
}
|
||||
else {
|
||||
notification = new EventNotificationObject().fromJson(value);
|
||||
}
|
||||
|
||||
(this._data.notifications as any)[key] = notification;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeNotification(key: string): void {
|
||||
delete this._data.notifications[key];
|
||||
}
|
||||
|
||||
getNotification(key: string): EventNotificationObject | undefined {
|
||||
return this._data.notifications[key] as any;
|
||||
}
|
||||
|
||||
}
|
||||
110
src/models/event-notification.ts
Normal file
110
src/models/event-notification.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Class model for Event Notification Interface
|
||||
*/
|
||||
import type { EventNotificationInterface } from "@/types/event";
|
||||
|
||||
export class EventNotificationObject implements EventNotificationInterface {
|
||||
|
||||
_data!: EventNotificationInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
identifier: null,
|
||||
type: 'email',
|
||||
pattern: 'unknown'
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventNotificationInterface): EventNotificationObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventNotificationInterface {
|
||||
const result: Partial<EventNotificationInterface> = {};
|
||||
|
||||
for (const key in this._data) {
|
||||
const value = this._data[key as keyof EventNotificationInterface];
|
||||
if (value !== null && value !== undefined) {
|
||||
(result as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result as EventNotificationInterface;
|
||||
}
|
||||
|
||||
clone(): EventNotificationObject {
|
||||
const cloned = new EventNotificationObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get identifier(): string | null {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
set identifier(value: string | null) {
|
||||
this._data.identifier = value;
|
||||
}
|
||||
|
||||
get type(): 'visual' | 'audible' | 'email' {
|
||||
return this._data.type;
|
||||
}
|
||||
|
||||
set type(value: 'visual' | 'audible' | 'email') {
|
||||
this._data.type = value;
|
||||
}
|
||||
|
||||
get pattern(): 'absolute' | 'relative' | 'unknown' {
|
||||
return this._data.pattern;
|
||||
}
|
||||
|
||||
set pattern(value: 'absolute' | 'relative' | 'unknown') {
|
||||
this._data.pattern = value;
|
||||
if (value === 'absolute') {
|
||||
this._data.anchor = null;
|
||||
this._data.offset = null;
|
||||
} else if (value === 'relative') {
|
||||
this._data.when = null;
|
||||
} else {
|
||||
this._data.when = null;
|
||||
this._data.anchor = null;
|
||||
this._data.offset = null;
|
||||
}
|
||||
}
|
||||
|
||||
get when(): string | null {
|
||||
return this._data.when ?? null;
|
||||
}
|
||||
|
||||
set when(value: string | null) {
|
||||
this._data.pattern = 'absolute';
|
||||
this._data.anchor = null;
|
||||
this._data.offset = null;
|
||||
this._data.when = value;
|
||||
}
|
||||
|
||||
get anchor(): 'start' | 'end' | null {
|
||||
return this._data.anchor ?? null;
|
||||
}
|
||||
|
||||
set anchor(value: 'start' | 'end' | null) {
|
||||
this._data.pattern = 'relative';
|
||||
this._data.when = null;
|
||||
this._data.anchor = value;
|
||||
}
|
||||
|
||||
get offset(): string | null {
|
||||
return this._data.offset ?? null;
|
||||
}
|
||||
|
||||
set offset(value: string | null) {
|
||||
this._data.pattern = 'relative';
|
||||
this._data.anchor = 'start';
|
||||
this._data.when = null;
|
||||
this._data.offset = value;
|
||||
}
|
||||
|
||||
}
|
||||
362
src/models/event-occurrence.ts
Normal file
362
src/models/event-occurrence.ts
Normal file
@@ -0,0 +1,362 @@
|
||||
/**
|
||||
* Class model for Event Occurrence Interface
|
||||
*/
|
||||
import type { EventOccurrence } from "@/types/event";
|
||||
|
||||
export class EventOccurrenceObject implements EventOccurrence {
|
||||
|
||||
_data!: EventOccurrence;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
pattern: 'absolute',
|
||||
precision: 'daily',
|
||||
interval: 1,
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventOccurrence): EventOccurrenceObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventOccurrence {
|
||||
const result: Partial<EventOccurrence> = {};
|
||||
|
||||
for (const key in this._data) {
|
||||
const value = this._data[key as keyof EventOccurrence];
|
||||
if (value !== null && value !== undefined) {
|
||||
(result as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result as EventOccurrence;
|
||||
}
|
||||
|
||||
clone(): EventOccurrenceObject {
|
||||
const cloned = new EventOccurrenceObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get pattern(): 'absolute' | 'relative' {
|
||||
return this._data.pattern;
|
||||
}
|
||||
|
||||
set pattern(value: 'absolute' | 'relative') {
|
||||
this._data.pattern = value;
|
||||
}
|
||||
|
||||
get precision(): 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely' | 'secondly' {
|
||||
return this._data.precision;
|
||||
}
|
||||
|
||||
set precision(value: 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely' | 'secondly') {
|
||||
this._data.precision = value;
|
||||
}
|
||||
|
||||
get interval(): number {
|
||||
return this._data.interval;
|
||||
}
|
||||
|
||||
set interval(value: number) {
|
||||
this._data.interval = value;
|
||||
}
|
||||
|
||||
get iterations(): number | null {
|
||||
return this._data.iterations ?? null;
|
||||
}
|
||||
|
||||
set iterations(value: number | null) {
|
||||
this._data.iterations = value;
|
||||
}
|
||||
|
||||
get concludes(): string | null {
|
||||
return this._data.concludes ?? null;
|
||||
}
|
||||
|
||||
set concludes(value: string | null) {
|
||||
this._data.concludes = value;
|
||||
}
|
||||
|
||||
get scale(): string | null {
|
||||
return this._data.scale ?? null;
|
||||
}
|
||||
|
||||
set scale(value: string | null) {
|
||||
this._data.scale = value;
|
||||
}
|
||||
|
||||
get onDayOfWeek(): number[] | null {
|
||||
return this._data.onDayOfWeek ?? null;
|
||||
}
|
||||
|
||||
set onDayOfWeek(value: number[] | null) {
|
||||
this._data.onDayOfWeek = value;
|
||||
}
|
||||
|
||||
addOnDayOfWeek(value: number): void {
|
||||
if (!this._data.onDayOfWeek) {
|
||||
this._data.onDayOfWeek = [];
|
||||
}
|
||||
if (!this._data.onDayOfWeek.includes(value)) {
|
||||
this._data.onDayOfWeek.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnDayOfWeek(value: number): void {
|
||||
if (!this._data.onDayOfWeek) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onDayOfWeek.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onDayOfWeek.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onDayOfMonth(): number[] | null {
|
||||
return this._data.onDayOfMonth ?? null;
|
||||
}
|
||||
|
||||
set onDayOfMonth(value: number[] | null) {
|
||||
this._data.onDayOfMonth = value;
|
||||
}
|
||||
|
||||
addOnDayOfMonth(value: number): void {
|
||||
if (!this._data.onDayOfMonth) {
|
||||
this._data.onDayOfMonth = [];
|
||||
}
|
||||
if (!this._data.onDayOfMonth.includes(value)) {
|
||||
this._data.onDayOfMonth.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnDayOfMonth(value: number): void {
|
||||
if (!this._data.onDayOfMonth) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onDayOfMonth.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onDayOfMonth.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onDayOfYear(): number[] | null {
|
||||
return this._data.onDayOfYear ?? null;
|
||||
}
|
||||
|
||||
set onDayOfYear(value: number[] | null) {
|
||||
this._data.onDayOfYear = value;
|
||||
}
|
||||
|
||||
addOnDayOfYear(value: number): void {
|
||||
if (!this._data.onDayOfYear) {
|
||||
this._data.onDayOfYear = [];
|
||||
}
|
||||
if (!this._data.onDayOfYear.includes(value)) {
|
||||
this._data.onDayOfYear.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnDayOfYear(value: number): void {
|
||||
if (!this._data.onDayOfYear) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onDayOfYear.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onDayOfYear.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onWeekOfMonth(): number[] | null {
|
||||
return this._data.onWeekOfMonth ?? null;
|
||||
}
|
||||
|
||||
set onWeekOfMonth(value: number[] | null) {
|
||||
this._data.onWeekOfMonth = value;
|
||||
}
|
||||
|
||||
addOnWeekOfMonth(value: number): void {
|
||||
if (!this._data.onWeekOfMonth) {
|
||||
this._data.onWeekOfMonth = [];
|
||||
}
|
||||
if (!this._data.onWeekOfMonth.includes(value)) {
|
||||
this._data.onWeekOfMonth.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnWeekOfMonth(value: number): void {
|
||||
if (!this._data.onWeekOfMonth) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onWeekOfMonth.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onWeekOfMonth.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onWeekOfYear(): number[] | null {
|
||||
return this._data.onWeekOfYear ?? null;
|
||||
}
|
||||
|
||||
set onWeekOfYear(value: number[] | null) {
|
||||
this._data.onWeekOfYear = value;
|
||||
}
|
||||
|
||||
addOnWeekOfYear(value: number): void {
|
||||
if (!this._data.onWeekOfYear) {
|
||||
this._data.onWeekOfYear = [];
|
||||
}
|
||||
if (!this._data.onWeekOfYear.includes(value)) {
|
||||
this._data.onWeekOfYear.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnWeekOfYear(value: number): void {
|
||||
if (!this._data.onWeekOfYear) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onWeekOfYear.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onWeekOfYear.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onMonthOfYear(): number[] | null {
|
||||
return this._data.onMonthOfYear ?? null;
|
||||
}
|
||||
|
||||
set onMonthOfYear(value: number[] | null) {
|
||||
this._data.onMonthOfYear = value;
|
||||
}
|
||||
|
||||
addOnMonthOfYear(value: number): void {
|
||||
if (!this._data.onMonthOfYear) {
|
||||
this._data.onMonthOfYear = [];
|
||||
}
|
||||
if (!this._data.onMonthOfYear.includes(value)) {
|
||||
this._data.onMonthOfYear.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnMonthOfYear(value: number): void {
|
||||
if (!this._data.onMonthOfYear) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onMonthOfYear.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onMonthOfYear.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onHour(): number[] | null {
|
||||
return this._data.onHour ?? null;
|
||||
}
|
||||
|
||||
set onHour(value: number[] | null) {
|
||||
this._data.onHour = value;
|
||||
}
|
||||
|
||||
addOnHour(value: number): void {
|
||||
if (!this._data.onHour) {
|
||||
this._data.onHour = [];
|
||||
}
|
||||
if (!this._data.onHour.includes(value)) {
|
||||
this._data.onHour.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnHour(value: number): void {
|
||||
if (!this._data.onHour) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onHour.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onHour.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onMinute(): number[] | null {
|
||||
return this._data.onMinute ?? null;
|
||||
}
|
||||
|
||||
set onMinute(value: number[] | null) {
|
||||
this._data.onMinute = value;
|
||||
}
|
||||
|
||||
addOnMinute(value: number): void {
|
||||
if (!this._data.onMinute) {
|
||||
this._data.onMinute = [];
|
||||
}
|
||||
if (!this._data.onMinute.includes(value)) {
|
||||
this._data.onMinute.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnMinute(value: number): void {
|
||||
if (!this._data.onMinute) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onMinute.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onMinute.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onSecond(): number[] | null {
|
||||
return this._data.onSecond ?? null;
|
||||
}
|
||||
|
||||
set onSecond(value: number[] | null) {
|
||||
this._data.onSecond = value;
|
||||
}
|
||||
|
||||
addOnSecond(value: number): void {
|
||||
if (!this._data.onSecond) {
|
||||
this._data.onSecond = [];
|
||||
}
|
||||
if (!this._data.onSecond.includes(value)) {
|
||||
this._data.onSecond.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnSecond(value: number): void {
|
||||
if (!this._data.onSecond) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onSecond.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onSecond.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get onPosition(): number[] | null {
|
||||
return this._data.onPosition ?? null;
|
||||
}
|
||||
|
||||
set onPosition(value: number[] | null) {
|
||||
this._data.onPosition = value;
|
||||
}
|
||||
|
||||
addOnPosition(value: number): void {
|
||||
if (!this._data.onPosition) {
|
||||
this._data.onPosition = [];
|
||||
}
|
||||
if (!this._data.onPosition.includes(value)) {
|
||||
this._data.onPosition.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
removeOnPosition(value: number): void {
|
||||
if (!this._data.onPosition) {
|
||||
return;
|
||||
}
|
||||
const index = this._data.onPosition.indexOf(value);
|
||||
if (index > -1) {
|
||||
this._data.onPosition.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
67
src/models/event-organizer.ts
Normal file
67
src/models/event-organizer.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Class model for Event Organizer Interface
|
||||
*/
|
||||
import type { EventOrganizerInterface } from "@/types/event";
|
||||
|
||||
export class EventOrganizerObject implements EventOrganizerInterface {
|
||||
|
||||
_data!: EventOrganizerInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
realm: 'E',
|
||||
address: ''
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventOrganizerInterface): EventOrganizerObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventOrganizerInterface {
|
||||
const result: Partial<EventOrganizerInterface> = {};
|
||||
|
||||
for (const key in this._data) {
|
||||
const value = this._data[key as keyof EventOrganizerInterface];
|
||||
if (value !== null && value !== undefined) {
|
||||
(result as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result as EventOrganizerInterface;
|
||||
}
|
||||
|
||||
clone(): EventOrganizerObject {
|
||||
const cloned = new EventOrganizerObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get realm(): 'I' | 'E' {
|
||||
return this._data.realm;
|
||||
}
|
||||
|
||||
set realm(value: 'I' | 'E') {
|
||||
this._data.realm = value;
|
||||
}
|
||||
|
||||
get address(): string {
|
||||
return this._data.address;
|
||||
}
|
||||
|
||||
set address(value: string) {
|
||||
this._data.address = value;
|
||||
}
|
||||
|
||||
get name(): string | null {
|
||||
return this._data.name ?? null;
|
||||
}
|
||||
|
||||
set name(value: string | null) {
|
||||
this._data.name = value;
|
||||
}
|
||||
|
||||
}
|
||||
144
src/models/event-participant.ts
Normal file
144
src/models/event-participant.ts
Normal file
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Class model for Event Participant Interface
|
||||
*/
|
||||
import type { EventParticipantInterface } from "@/types/event";
|
||||
|
||||
export class EventParticipantObject implements EventParticipantInterface {
|
||||
|
||||
_data!: EventParticipantInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
identifier: null,
|
||||
realm: 'E',
|
||||
address: '',
|
||||
type: 'individual',
|
||||
status: 'none',
|
||||
roles: []
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventParticipantInterface): EventParticipantObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventParticipantInterface {
|
||||
const result: Partial<EventParticipantInterface> = {};
|
||||
|
||||
for (const key in this._data) {
|
||||
const value = this._data[key as keyof EventParticipantInterface];
|
||||
if (value !== null && value !== undefined) {
|
||||
(result as any)[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return result as EventParticipantInterface;
|
||||
}
|
||||
|
||||
clone(): EventParticipantObject {
|
||||
const cloned = new EventParticipantObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get identifier(): string | null {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
set identifier(value: string | null) {
|
||||
this._data.identifier = value;
|
||||
}
|
||||
|
||||
get realm(): 'I' | 'E' {
|
||||
return this._data.realm;
|
||||
}
|
||||
|
||||
set realm(value: 'I' | 'E') {
|
||||
this._data.realm = value;
|
||||
}
|
||||
|
||||
get name(): string | null {
|
||||
return this._data.name ?? null;
|
||||
}
|
||||
|
||||
set name(value: string | null) {
|
||||
this._data.name = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description ?? null;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get language(): string | null {
|
||||
return this._data.language ?? null;
|
||||
}
|
||||
|
||||
set language(value: string | null) {
|
||||
this._data.language = value;
|
||||
}
|
||||
|
||||
get address(): string {
|
||||
return this._data.address;
|
||||
}
|
||||
|
||||
set address(value: string) {
|
||||
this._data.address = value;
|
||||
}
|
||||
|
||||
get type(): 'unknown' | 'individual' | 'group' | 'resource' | 'location' {
|
||||
return this._data.type;
|
||||
}
|
||||
|
||||
set type(value: 'unknown' | 'individual' | 'group' | 'resource' | 'location') {
|
||||
this._data.type = value;
|
||||
}
|
||||
|
||||
get status(): 'none' | 'accepted' | 'declined' | 'tentative' | 'delegated' {
|
||||
return this._data.status;
|
||||
}
|
||||
|
||||
set status(value: 'none' | 'accepted' | 'declined' | 'tentative' | 'delegated') {
|
||||
this._data.status = value;
|
||||
}
|
||||
|
||||
get comment(): string | null {
|
||||
return this._data.comment ?? null;
|
||||
}
|
||||
|
||||
set comment(value: string | null) {
|
||||
this._data.comment = value;
|
||||
}
|
||||
|
||||
get roles(): ('owner' | 'chair' | 'attendee' | 'optional' | 'informational' | 'contact')[] {
|
||||
return this._data.roles;
|
||||
}
|
||||
|
||||
set roles(value: ('owner' | 'chair' | 'attendee' | 'optional' | 'informational' | 'contact')[]) {
|
||||
this._data.roles = value;
|
||||
}
|
||||
|
||||
addRole(role: 'owner' | 'chair' | 'attendee' | 'optional' | 'informational' | 'contact'): void {
|
||||
if (!this._data.roles.includes(role)) {
|
||||
this._data.roles.push(role);
|
||||
}
|
||||
}
|
||||
|
||||
removeRole(role: 'owner' | 'chair' | 'attendee' | 'optional' | 'informational' | 'contact'): void {
|
||||
const index = this._data.roles.indexOf(role);
|
||||
if (index > -1) {
|
||||
this._data.roles.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
hasRole(role: 'owner' | 'chair' | 'attendee' | 'optional' | 'informational' | 'contact'): boolean {
|
||||
return this._data.roles.includes(role);
|
||||
}
|
||||
|
||||
}
|
||||
574
src/models/event.ts
Normal file
574
src/models/event.ts
Normal file
@@ -0,0 +1,574 @@
|
||||
/**
|
||||
* Class model for Event Interface
|
||||
*/
|
||||
import type {
|
||||
EventInterface,
|
||||
EventLocationPhysicalInterface,
|
||||
EventLocationVirtualInterface,
|
||||
EventOrganizerInterface,
|
||||
EventParticipantInterface,
|
||||
EventNotificationInterface,
|
||||
EventOccurrence,
|
||||
EventMutation
|
||||
} from "@/types/event";
|
||||
import { EventLocationPhysicalObject } from "./event-location-physical";
|
||||
import { EventLocationVirtualObject } from "./event-location-virtual";
|
||||
import { EventOrganizerObject } from "./event-organizer";
|
||||
import { EventParticipantObject } from "./event-participant";
|
||||
import { EventNotificationObject } from "./event-notification";
|
||||
import { EventOccurrenceObject } from "./event-occurrence";
|
||||
import { EventMutationObject } from "./event-mutation";
|
||||
import { generateKey } from "../utils/key-generator";
|
||||
|
||||
export class EventObject implements EventInterface {
|
||||
|
||||
_data!: EventInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
type: 'event',
|
||||
version: 1,
|
||||
urid: null,
|
||||
created: null,
|
||||
modified: null,
|
||||
sequence: null,
|
||||
timeZone: null,
|
||||
startsOn: null,
|
||||
startsTZ: null,
|
||||
endsOn: null,
|
||||
endsTZ: null,
|
||||
duration: null,
|
||||
timeless: null,
|
||||
label: null,
|
||||
description: null,
|
||||
locationsPhysical: {},
|
||||
locationsVirtual: {},
|
||||
availability: null,
|
||||
sensitivity: null,
|
||||
priority: null,
|
||||
color: null,
|
||||
tags: [],
|
||||
organizer: null,
|
||||
participants: {},
|
||||
notifications: {},
|
||||
pattern: null,
|
||||
mutations: {}
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EventInterface): EventObject {
|
||||
// Deep copy the data to avoid reference issues
|
||||
this._data = JSON.parse(JSON.stringify(data));
|
||||
|
||||
// Convert organizer to object instance
|
||||
if (this._data.organizer) {
|
||||
this._data.organizer = new EventOrganizerObject().fromJson(this._data.organizer) as any;
|
||||
}
|
||||
|
||||
// Convert locations physical to object instances
|
||||
for (const key in this._data.locationsPhysical) {
|
||||
const loc = this._data.locationsPhysical[key];
|
||||
if (loc) {
|
||||
this._data.locationsPhysical[key] = new EventLocationPhysicalObject().fromJson(loc) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert locations virtual to object instances
|
||||
for (const key in this._data.locationsVirtual) {
|
||||
const loc = this._data.locationsVirtual[key];
|
||||
if (loc) {
|
||||
this._data.locationsVirtual[key] = new EventLocationVirtualObject().fromJson(loc) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert participants to object instances
|
||||
for (const key in this._data.participants) {
|
||||
const participant = this._data.participants[key];
|
||||
if (participant) {
|
||||
this._data.participants[key] = new EventParticipantObject().fromJson(participant) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert notifications to object instances
|
||||
for (const key in this._data.notifications) {
|
||||
const notification = this._data.notifications[key];
|
||||
if (notification) {
|
||||
this._data.notifications[key] = new EventNotificationObject().fromJson(notification) as any;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert pattern to object instance
|
||||
if (this._data.pattern) {
|
||||
this._data.pattern = new EventOccurrenceObject().fromJson(this._data.pattern) as any;
|
||||
}
|
||||
|
||||
// Convert mutations to object instances
|
||||
for (const key in this._data.mutations) {
|
||||
const mutation = this._data.mutations[key];
|
||||
if (mutation) {
|
||||
this._data.mutations[key] = new EventMutationObject().fromJson(mutation) as any;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EventInterface {
|
||||
// Return a deep copy to avoid external modifications
|
||||
return JSON.parse(JSON.stringify(this._data));
|
||||
}
|
||||
|
||||
clone(): EventObject {
|
||||
const cloned = new EventObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get type(): string {
|
||||
return this._data.type;
|
||||
}
|
||||
|
||||
get version(): number {
|
||||
return this._data.version;
|
||||
}
|
||||
|
||||
set version(value: number) {
|
||||
this._data.version = value;
|
||||
}
|
||||
|
||||
get urid(): string | null {
|
||||
return this._data.urid;
|
||||
}
|
||||
|
||||
set urid(value: string | null) {
|
||||
this._data.urid = value;
|
||||
}
|
||||
|
||||
get created(): string | null {
|
||||
return this._data.created;
|
||||
}
|
||||
|
||||
set created(value: string | null) {
|
||||
this._data.created = value;
|
||||
}
|
||||
|
||||
get modified(): string | null {
|
||||
return this._data.modified;
|
||||
}
|
||||
|
||||
set modified(value: string | null) {
|
||||
this._data.modified = value;
|
||||
}
|
||||
|
||||
get sequence(): number | null {
|
||||
return this._data.sequence;
|
||||
}
|
||||
|
||||
set sequence(value: number | null) {
|
||||
this._data.sequence = value;
|
||||
}
|
||||
|
||||
get timeZone(): string | null {
|
||||
return this._data.timeZone;
|
||||
}
|
||||
|
||||
set timeZone(value: string | null) {
|
||||
this._data.timeZone = value;
|
||||
}
|
||||
|
||||
get startsOn(): string | null {
|
||||
return this._data.startsOn;
|
||||
}
|
||||
|
||||
set startsOn(value: string | null) {
|
||||
this._data.startsOn = value;
|
||||
}
|
||||
|
||||
get startsTZ(): string | null {
|
||||
return this._data.startsTZ;
|
||||
}
|
||||
|
||||
set startsTZ(value: string | null) {
|
||||
this._data.startsTZ = value;
|
||||
}
|
||||
|
||||
get endsOn(): string | null {
|
||||
return this._data.endsOn;
|
||||
}
|
||||
|
||||
set endsOn(value: string | null) {
|
||||
this._data.endsOn = value;
|
||||
}
|
||||
|
||||
get endsTZ(): string | null {
|
||||
return this._data.endsTZ;
|
||||
}
|
||||
|
||||
set endsTZ(value: string | null) {
|
||||
this._data.endsTZ = value;
|
||||
}
|
||||
|
||||
get duration(): string | null {
|
||||
return this._data.duration;
|
||||
}
|
||||
|
||||
set duration(value: string | null) {
|
||||
this._data.duration = value;
|
||||
}
|
||||
|
||||
get timeless(): boolean | null {
|
||||
return this._data.timeless;
|
||||
}
|
||||
|
||||
set timeless(value: boolean | null) {
|
||||
this._data.timeless = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get availability(): 'free' | 'busy' | null {
|
||||
return this._data.availability;
|
||||
}
|
||||
|
||||
set availability(value: 'free' | 'busy' | null) {
|
||||
this._data.availability = value;
|
||||
}
|
||||
|
||||
get sensitivity(): 'public' | 'private' | 'secret' | null {
|
||||
return this._data.sensitivity;
|
||||
}
|
||||
|
||||
set sensitivity(value: 'public' | 'private' | 'secret' | null) {
|
||||
this._data.sensitivity = value;
|
||||
}
|
||||
|
||||
get priority(): number | null {
|
||||
return this._data.priority;
|
||||
}
|
||||
|
||||
set priority(value: number | null) {
|
||||
this._data.priority = value;
|
||||
}
|
||||
|
||||
get color(): string | null {
|
||||
return this._data.color;
|
||||
}
|
||||
|
||||
set color(value: string | null) {
|
||||
this._data.color = value;
|
||||
}
|
||||
|
||||
get locationsPhysical(): Record<string, EventLocationPhysicalObject> {
|
||||
return this._data.locationsPhysical as any;
|
||||
}
|
||||
|
||||
set locationsPhysical(value: Record<string, EventLocationPhysicalInterface|EventLocationPhysicalObject>) {
|
||||
this._data.locationsPhysical = {} as any;
|
||||
for (const key in value) {
|
||||
const loc = value[key];
|
||||
if (loc) {
|
||||
if (loc instanceof EventLocationPhysicalObject) {
|
||||
(this._data.locationsPhysical as any)[key] = loc;
|
||||
} else {
|
||||
(this._data.locationsPhysical as any)[key] = new EventLocationPhysicalObject().fromJson(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addLocationPhysical(value?: EventLocationPhysicalInterface|EventLocationPhysicalObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let location: EventLocationPhysicalObject;
|
||||
|
||||
if (!value) {
|
||||
location = new EventLocationPhysicalObject();
|
||||
location.identifier = key;
|
||||
}
|
||||
else if (value instanceof EventLocationPhysicalObject) {
|
||||
location = value;
|
||||
location.identifier = key;
|
||||
}
|
||||
else {
|
||||
location = new EventLocationPhysicalObject().fromJson(value);
|
||||
location.identifier = key;
|
||||
}
|
||||
|
||||
(this._data.locationsPhysical as any)[key] = location;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeLocationPhysical(key: string): void {
|
||||
delete this._data.locationsPhysical[key];
|
||||
}
|
||||
|
||||
getLocationPhysical(key: string): EventLocationPhysicalObject | undefined {
|
||||
return this._data.locationsPhysical[key] as any;
|
||||
}
|
||||
|
||||
get locationsVirtual(): Record<string, EventLocationVirtualObject> {
|
||||
return this._data.locationsVirtual as any;
|
||||
}
|
||||
|
||||
set locationsVirtual(value: Record<string, EventLocationVirtualInterface|EventLocationVirtualObject>) {
|
||||
this._data.locationsVirtual = {} as any;
|
||||
for (const key in value) {
|
||||
const loc = value[key];
|
||||
if (loc) {
|
||||
if (loc instanceof EventLocationVirtualObject) {
|
||||
(this._data.locationsVirtual as any)[key] = loc;
|
||||
} else {
|
||||
(this._data.locationsVirtual as any)[key] = new EventLocationVirtualObject().fromJson(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addLocationVirtual(value?: EventLocationVirtualInterface|EventLocationVirtualObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let location: EventLocationVirtualObject;
|
||||
|
||||
if (!value) {
|
||||
location = new EventLocationVirtualObject();
|
||||
location.identifier = key;
|
||||
}
|
||||
else if (value instanceof EventLocationVirtualObject) {
|
||||
location = value;
|
||||
location.identifier = key;
|
||||
}
|
||||
else {
|
||||
location = new EventLocationVirtualObject().fromJson(value);
|
||||
location.identifier = key;
|
||||
}
|
||||
|
||||
(this._data.locationsVirtual as any)[key] = location;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeLocationVirtual(key: string): void {
|
||||
delete this._data.locationsVirtual[key];
|
||||
}
|
||||
|
||||
getLocationVirtual(key: string): EventLocationVirtualObject | undefined {
|
||||
return this._data.locationsVirtual[key] as any;
|
||||
}
|
||||
|
||||
get tags(): string[] {
|
||||
return this._data.tags;
|
||||
}
|
||||
|
||||
set tags(value: string[]) {
|
||||
this._data.tags = value;
|
||||
}
|
||||
|
||||
addTag(tag: string): void {
|
||||
if (!this._data.tags.includes(tag)) {
|
||||
this._data.tags.push(tag);
|
||||
}
|
||||
}
|
||||
|
||||
removeTag(tag: string): void {
|
||||
const index = this._data.tags.indexOf(tag);
|
||||
if (index > -1) {
|
||||
this._data.tags.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
get organizer(): EventOrganizerObject {
|
||||
return this._data.organizer as any;
|
||||
}
|
||||
|
||||
set organizer(value: EventOrganizerInterface|EventOrganizerObject) {
|
||||
if (value instanceof EventOrganizerObject) {
|
||||
(this._data.organizer as any) = value;
|
||||
} else {
|
||||
(this._data.organizer as any) = new EventOrganizerObject().fromJson(value);
|
||||
}
|
||||
}
|
||||
|
||||
get participants(): Record<string, EventParticipantObject> {
|
||||
return this._data.participants as any;
|
||||
}
|
||||
|
||||
set participants(value: Record<string, EventParticipantInterface|EventParticipantObject>) {
|
||||
this._data.participants = {} as any;
|
||||
for (const key in value) {
|
||||
const participant = value[key];
|
||||
if (participant) {
|
||||
if (participant instanceof EventParticipantObject) {
|
||||
(this._data.participants as any)[key] = participant;
|
||||
} else {
|
||||
(this._data.participants as any)[key] = new EventParticipantObject().fromJson(participant);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getParticipant(key: string): EventParticipantObject | undefined {
|
||||
return this._data.participants[key] as any;
|
||||
}
|
||||
|
||||
addParticipant(value?: EventParticipantInterface|EventParticipantObject|null, key?: string): string {
|
||||
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let participant: EventParticipantObject;
|
||||
|
||||
if (!value) {
|
||||
participant = new EventParticipantObject();
|
||||
participant.identifier = key;
|
||||
}
|
||||
else if (value instanceof EventParticipantObject) {
|
||||
participant = value;
|
||||
participant.identifier = key;
|
||||
}
|
||||
else {
|
||||
participant = new EventParticipantObject().fromJson(value);
|
||||
participant.identifier = key;
|
||||
}
|
||||
|
||||
(this._data.participants as any)[key] = participant;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeParticipant(key: string): void {
|
||||
delete this._data.participants[key];
|
||||
}
|
||||
|
||||
get notifications(): Record<string, EventNotificationObject> {
|
||||
return this._data.notifications as any;
|
||||
}
|
||||
|
||||
set notifications(value: Record<string, EventNotificationInterface|EventNotificationObject>) {
|
||||
this._data.notifications = {} as any;
|
||||
for (const key in value) {
|
||||
const notification = value[key];
|
||||
if (notification) {
|
||||
if (notification instanceof EventNotificationObject) {
|
||||
(this._data.notifications as any)[key] = notification;
|
||||
} else {
|
||||
(this._data.notifications as any)[key] = new EventNotificationObject().fromJson(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addNotification(value?: EventNotificationInterface|EventNotificationObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let notification: EventNotificationObject;
|
||||
|
||||
if (!value) {
|
||||
notification = new EventNotificationObject();
|
||||
}
|
||||
else if (value instanceof EventNotificationObject) {
|
||||
notification = value;
|
||||
}
|
||||
else {
|
||||
notification = new EventNotificationObject().fromJson(value);
|
||||
}
|
||||
|
||||
(this._data.notifications as any)[key] = notification;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeNotification(key: string): void {
|
||||
delete this._data.notifications[key];
|
||||
}
|
||||
|
||||
getNotification(key: string): EventNotificationObject | undefined {
|
||||
return this._data.notifications[key] as any;
|
||||
}
|
||||
|
||||
get pattern(): EventOccurrenceObject | null {
|
||||
return this._data.pattern as any;
|
||||
}
|
||||
|
||||
set pattern(value: EventOccurrence|EventOccurrenceObject|null) {
|
||||
if (!value) {
|
||||
this._data.pattern = null;
|
||||
} else if (value instanceof EventOccurrenceObject) {
|
||||
this._data.pattern = value as any;
|
||||
} else {
|
||||
this._data.pattern = new EventOccurrenceObject().fromJson(value) as any;
|
||||
}
|
||||
}
|
||||
|
||||
get mutations(): Record<string, EventMutationObject> {
|
||||
return this._data.mutations as any;
|
||||
}
|
||||
|
||||
set mutations(value: Record<string, EventMutation|EventMutationObject>) {
|
||||
this._data.mutations = {} as any;
|
||||
for (const key in value) {
|
||||
const mutation = value[key];
|
||||
if (mutation) {
|
||||
if (mutation instanceof EventMutationObject) {
|
||||
(this._data.mutations as any)[key] = mutation;
|
||||
} else {
|
||||
(this._data.mutations as any)[key] = new EventMutationObject().fromJson(mutation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addMutation(value?: EventMutation|EventMutationObject|null, key?: string): string {
|
||||
if (!key) {
|
||||
key = generateKey();
|
||||
}
|
||||
|
||||
let mutation: EventMutationObject;
|
||||
|
||||
if (!value) {
|
||||
mutation = new EventMutationObject();
|
||||
}
|
||||
else if (value instanceof EventMutationObject) {
|
||||
mutation = value;
|
||||
}
|
||||
else {
|
||||
mutation = new EventMutationObject().fromJson(value);
|
||||
}
|
||||
|
||||
(this._data.mutations as any)[key] = mutation;
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
removeMutation(key: string): void {
|
||||
delete this._data.mutations[key];
|
||||
}
|
||||
|
||||
getMutation(key: string): EventMutationObject | undefined {
|
||||
return this._data.mutations[key] as any;
|
||||
}
|
||||
|
||||
}
|
||||
11
src/models/index.ts
Normal file
11
src/models/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Central export point for all Chrono Manager models
|
||||
*/
|
||||
|
||||
export { Collection } from './collection';
|
||||
export { Entity } from './entity';
|
||||
export { Event } from './event';
|
||||
export { Task } from './task';
|
||||
export { Journal } from './journal';
|
||||
export { Provider } from './provider';
|
||||
export { Service } from './service';
|
||||
157
src/models/journal.ts
Normal file
157
src/models/journal.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Class model for Journal Interface
|
||||
*/
|
||||
import type {
|
||||
JournalInterface,
|
||||
JournalAttachment
|
||||
} from "@/types/journal";
|
||||
|
||||
export class JournalObject implements JournalInterface {
|
||||
|
||||
_data!: JournalInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
type: 'journal',
|
||||
version: 0,
|
||||
urid: null,
|
||||
created: null,
|
||||
modified: null,
|
||||
label: null,
|
||||
description: null,
|
||||
content: null,
|
||||
startsOn: null,
|
||||
endsOn: null,
|
||||
status: null,
|
||||
visibility: null,
|
||||
attachments: {},
|
||||
tags: [],
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: JournalInterface): JournalObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): JournalInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): JournalObject {
|
||||
const cloned = new JournalObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get type(): string {
|
||||
return this._data.type;
|
||||
}
|
||||
|
||||
get version(): number {
|
||||
return this._data.version;
|
||||
}
|
||||
|
||||
set version(value: number) {
|
||||
this._data.version = value;
|
||||
}
|
||||
|
||||
get urid(): string | null {
|
||||
return this._data.urid;
|
||||
}
|
||||
|
||||
set urid(value: string | null) {
|
||||
this._data.urid = value;
|
||||
}
|
||||
|
||||
get created(): Date | null {
|
||||
return this._data.created;
|
||||
}
|
||||
|
||||
set created(value: Date | null) {
|
||||
this._data.created = value;
|
||||
}
|
||||
|
||||
get modified(): Date | null {
|
||||
return this._data.modified;
|
||||
}
|
||||
|
||||
set modified(value: Date | null) {
|
||||
this._data.modified = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get content(): string | null {
|
||||
return this._data.content;
|
||||
}
|
||||
|
||||
set content(value: string | null) {
|
||||
this._data.content = value;
|
||||
}
|
||||
|
||||
get startsOn(): Date | null {
|
||||
return this._data.startsOn;
|
||||
}
|
||||
|
||||
set startsOn(value: Date | null) {
|
||||
this._data.startsOn = value;
|
||||
}
|
||||
|
||||
get endsOn(): Date | null {
|
||||
return this._data.endsOn;
|
||||
}
|
||||
|
||||
set endsOn(value: Date | null) {
|
||||
this._data.endsOn = value;
|
||||
}
|
||||
|
||||
get status(): string | null {
|
||||
return this._data.status;
|
||||
}
|
||||
|
||||
set status(value: string | null) {
|
||||
this._data.status = value;
|
||||
}
|
||||
|
||||
get visibility(): string | null {
|
||||
return this._data.visibility;
|
||||
}
|
||||
|
||||
set visibility(value: string | null) {
|
||||
this._data.visibility = value;
|
||||
}
|
||||
|
||||
get attachments(): Record<string, JournalAttachment> {
|
||||
return this._data.attachments;
|
||||
}
|
||||
|
||||
set attachments(value: Record<string, JournalAttachment>) {
|
||||
this._data.attachments = value;
|
||||
}
|
||||
|
||||
get tags(): string[] {
|
||||
return this._data.tags;
|
||||
}
|
||||
|
||||
set tags(value: string[]) {
|
||||
this._data.tags = value;
|
||||
}
|
||||
|
||||
}
|
||||
63
src/models/provider.ts
Normal file
63
src/models/provider.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Class model for Provider Interface
|
||||
*/
|
||||
import type { ProviderCapabilitiesInterface, ProviderInterface } from "@/types/provider";
|
||||
|
||||
export class ProviderObject implements ProviderInterface {
|
||||
|
||||
_data!: ProviderInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'chrono:provider',
|
||||
id: '',
|
||||
label: '',
|
||||
capabilities: {},
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: ProviderInterface): ProviderObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): ProviderInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): ProviderObject {
|
||||
const cloned = new ProviderObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
||||
return !!(this._data.capabilities && this._data.capabilities[capability]);
|
||||
}
|
||||
|
||||
capability(capability: keyof ProviderCapabilitiesInterface): any | null {
|
||||
if (this._data.capabilities) {
|
||||
return this._data.capabilities[capability];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
get capabilities(): ProviderCapabilitiesInterface {
|
||||
return this._data.capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
77
src/models/service.ts
Normal file
77
src/models/service.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Class model for Service Interface
|
||||
*/
|
||||
import type { ServiceCapabilitiesInterface, ServiceInterface } from "@/types/service";
|
||||
|
||||
export class ServiceObject implements ServiceInterface {
|
||||
|
||||
_data!: ServiceInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'chrono:service',
|
||||
provider: '',
|
||||
id: '',
|
||||
label: '',
|
||||
capabilities: {},
|
||||
enabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: ServiceInterface): ServiceObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): ServiceInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): ServiceObject {
|
||||
const cloned = new ServiceObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
capable(capability: keyof ServiceCapabilitiesInterface): boolean {
|
||||
return !!(this._data.capabilities && this._data.capabilities[capability]);
|
||||
}
|
||||
|
||||
capability(capability: keyof ServiceCapabilitiesInterface): any | null {
|
||||
if (this._data.capabilities) {
|
||||
return this._data.capabilities[capability];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get provider(): string {
|
||||
return this._data.provider;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
get capabilities(): ServiceCapabilitiesInterface | undefined {
|
||||
return this._data.capabilities;
|
||||
}
|
||||
|
||||
get enabled(): boolean {
|
||||
return this._data.enabled;
|
||||
}
|
||||
|
||||
set enabled(value: boolean) {
|
||||
this._data.enabled = value;
|
||||
}
|
||||
|
||||
}
|
||||
204
src/models/task.ts
Normal file
204
src/models/task.ts
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* Class model for Task Interface
|
||||
*/
|
||||
import type {
|
||||
TaskInterface,
|
||||
TaskSubtask,
|
||||
TaskAttachment,
|
||||
TaskRecurrence
|
||||
} from "@/types/task";
|
||||
|
||||
export class TaskObject implements TaskInterface {
|
||||
|
||||
_data!: TaskInterface;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
type: 'task',
|
||||
version: 0,
|
||||
urid: null,
|
||||
created: null,
|
||||
modified: null,
|
||||
label: null,
|
||||
description: null,
|
||||
startsOn: null,
|
||||
dueOn: null,
|
||||
completedOn: null,
|
||||
status: null,
|
||||
priority: null,
|
||||
progress: null,
|
||||
color: null,
|
||||
recurrence: null,
|
||||
subtasks: {},
|
||||
attachments: {},
|
||||
tags: [],
|
||||
notes: null,
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: TaskInterface): TaskObject {
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): TaskInterface {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
clone(): TaskObject {
|
||||
const cloned = new TaskObject();
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Properties */
|
||||
|
||||
get type(): string {
|
||||
return this._data.type;
|
||||
}
|
||||
|
||||
get version(): number {
|
||||
return this._data.version;
|
||||
}
|
||||
|
||||
set version(value: number) {
|
||||
this._data.version = value;
|
||||
}
|
||||
|
||||
get urid(): string | null {
|
||||
return this._data.urid;
|
||||
}
|
||||
|
||||
set urid(value: string | null) {
|
||||
this._data.urid = value;
|
||||
}
|
||||
|
||||
get created(): Date | null {
|
||||
return this._data.created;
|
||||
}
|
||||
|
||||
set created(value: Date | null) {
|
||||
this._data.created = value;
|
||||
}
|
||||
|
||||
get modified(): Date | null {
|
||||
return this._data.modified;
|
||||
}
|
||||
|
||||
set modified(value: Date | null) {
|
||||
this._data.modified = value;
|
||||
}
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description;
|
||||
}
|
||||
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get startsOn(): Date | null {
|
||||
return this._data.startsOn;
|
||||
}
|
||||
|
||||
set startsOn(value: Date | null) {
|
||||
this._data.startsOn = value;
|
||||
}
|
||||
|
||||
get dueOn(): Date | null {
|
||||
return this._data.dueOn;
|
||||
}
|
||||
|
||||
set dueOn(value: Date | null) {
|
||||
this._data.dueOn = value;
|
||||
}
|
||||
|
||||
get completedOn(): Date | null {
|
||||
return this._data.completedOn;
|
||||
}
|
||||
|
||||
set completedOn(value: Date | null) {
|
||||
this._data.completedOn = value;
|
||||
}
|
||||
|
||||
get status(): string | null {
|
||||
return this._data.status;
|
||||
}
|
||||
|
||||
set status(value: string | null) {
|
||||
this._data.status = value;
|
||||
}
|
||||
|
||||
get priority(): number | null {
|
||||
return this._data.priority;
|
||||
}
|
||||
|
||||
set priority(value: number | null) {
|
||||
this._data.priority = value;
|
||||
}
|
||||
|
||||
get progress(): number | null {
|
||||
return this._data.progress;
|
||||
}
|
||||
|
||||
set progress(value: number | null) {
|
||||
this._data.progress = value;
|
||||
}
|
||||
|
||||
get color(): string | null {
|
||||
return this._data.color;
|
||||
}
|
||||
|
||||
set color(value: string | null) {
|
||||
this._data.color = value;
|
||||
}
|
||||
|
||||
get recurrence(): TaskRecurrence | null {
|
||||
return this._data.recurrence;
|
||||
}
|
||||
|
||||
set recurrence(value: TaskRecurrence | null) {
|
||||
this._data.recurrence = value;
|
||||
}
|
||||
|
||||
get subtasks(): Record<string, TaskSubtask> {
|
||||
return this._data.subtasks;
|
||||
}
|
||||
|
||||
set subtasks(value: Record<string, TaskSubtask>) {
|
||||
this._data.subtasks = value;
|
||||
}
|
||||
|
||||
get attachments(): Record<string, TaskAttachment> {
|
||||
return this._data.attachments;
|
||||
}
|
||||
|
||||
set attachments(value: Record<string, TaskAttachment>) {
|
||||
this._data.attachments = value;
|
||||
}
|
||||
|
||||
get tags(): string[] {
|
||||
return this._data.tags;
|
||||
}
|
||||
|
||||
set tags(value: string[]) {
|
||||
this._data.tags = value;
|
||||
}
|
||||
|
||||
get notes(): string | null {
|
||||
return this._data.notes;
|
||||
}
|
||||
|
||||
set notes(value: string | null) {
|
||||
this._data.notes = value;
|
||||
}
|
||||
|
||||
}
|
||||
88
src/services/collectionService.ts
Normal file
88
src/services/collectionService.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Collection management service
|
||||
*/
|
||||
|
||||
import { createFetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper-core';
|
||||
|
||||
const fetchWrapper = createFetchWrapper();
|
||||
import type {
|
||||
CollectionListRequest,
|
||||
CollectionListResponse,
|
||||
CollectionExtantRequest,
|
||||
CollectionExtantResponse,
|
||||
CollectionFetchRequest,
|
||||
CollectionFetchResponse,
|
||||
CollectionCreateRequest,
|
||||
CollectionCreateResponse,
|
||||
CollectionModifyRequest,
|
||||
CollectionModifyResponse,
|
||||
CollectionDestroyRequest,
|
||||
CollectionDestroyResponse,
|
||||
} from '../types/collection';
|
||||
|
||||
const BASE_URL = '/m/chrono_manager/collection';
|
||||
|
||||
export const collectionService = {
|
||||
|
||||
/**
|
||||
* List all available collections
|
||||
*
|
||||
* @param request - Collection list request parameters
|
||||
* @returns Promise with collection list grouped by provider and service
|
||||
*/
|
||||
async list(request: CollectionListRequest = {}): Promise<CollectionListResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/list`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which collections exist/are available
|
||||
*
|
||||
* @param request - Collection extant request with source selector
|
||||
* @returns Promise with collection availability status
|
||||
*/
|
||||
async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/extant`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch a specific collection
|
||||
*
|
||||
* @param request - Collection fetch request
|
||||
* @returns Promise with collection details
|
||||
*/
|
||||
async fetch(request: CollectionFetchRequest): Promise<CollectionFetchResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/fetch`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new collection
|
||||
*
|
||||
* @param request - Collection create request
|
||||
* @returns Promise with created collection
|
||||
*/
|
||||
async create(request: CollectionCreateRequest): Promise<CollectionCreateResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/create`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify an existing collection
|
||||
*
|
||||
* @param request - Collection modify request
|
||||
* @returns Promise with modified collection
|
||||
*/
|
||||
async modify(request: CollectionModifyRequest): Promise<CollectionModifyResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/modify`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a collection
|
||||
*
|
||||
* @param request - Collection destroy request
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async destroy(request: CollectionDestroyRequest): Promise<CollectionDestroyResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/destroy`, request);
|
||||
},
|
||||
};
|
||||
|
||||
export default collectionService;
|
||||
100
src/services/entityService.ts
Normal file
100
src/services/entityService.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Entity management service
|
||||
*/
|
||||
|
||||
import { createFetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper-core';
|
||||
|
||||
const fetchWrapper = createFetchWrapper();
|
||||
import type {
|
||||
EntityListRequest,
|
||||
EntityListResponse,
|
||||
EntityDeltaRequest,
|
||||
EntityDeltaResponse,
|
||||
EntityExtantRequest,
|
||||
EntityExtantResponse,
|
||||
EntityFetchRequest,
|
||||
EntityFetchResponse,
|
||||
EntityCreateRequest,
|
||||
EntityCreateResponse,
|
||||
EntityModifyRequest,
|
||||
EntityModifyResponse,
|
||||
EntityDestroyRequest,
|
||||
EntityDestroyResponse,
|
||||
} from '../types/entity';
|
||||
|
||||
const BASE_URL = '/m/chrono_manager/entity';
|
||||
|
||||
export const entityService = {
|
||||
|
||||
/**
|
||||
* List all available entities (events, tasks, journals)
|
||||
*
|
||||
* @param request - Entity list request parameters
|
||||
* @returns Promise with entity list grouped by provider, service, and collection
|
||||
*/
|
||||
async list(request: EntityListRequest = {}): Promise<EntityListResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/list`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get delta changes for entities
|
||||
*
|
||||
* @param request - Entity delta request with source selector
|
||||
* @returns Promise with delta changes (created, modified, deleted)
|
||||
*/
|
||||
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/delta`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which entities exist/are available
|
||||
*
|
||||
* @param request - Entity extant request with source selector
|
||||
* @returns Promise with entity availability status
|
||||
*/
|
||||
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/extant`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch specific entities
|
||||
*
|
||||
* @param request - Entity fetch request
|
||||
* @returns Promise with entity details
|
||||
*/
|
||||
async fetch(request: EntityFetchRequest): Promise<EntityFetchResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/fetch`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new entity
|
||||
*
|
||||
* @param request - Entity create request
|
||||
* @returns Promise with created entity
|
||||
*/
|
||||
async create(request: EntityCreateRequest): Promise<EntityCreateResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/create`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify an existing entity
|
||||
*
|
||||
* @param request - Entity modify request
|
||||
* @returns Promise with modified entity
|
||||
*/
|
||||
async modify(request: EntityModifyRequest): Promise<EntityModifyResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/modify`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete an entity
|
||||
*
|
||||
* @param request - Entity destroy request
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async destroy(request: EntityDestroyRequest): Promise<EntityDestroyResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/destroy`, request);
|
||||
},
|
||||
};
|
||||
|
||||
export default entityService;
|
||||
16
src/services/index.ts
Normal file
16
src/services/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Central export point for all Chrono Manager services
|
||||
*/
|
||||
|
||||
// Services
|
||||
export { providerService } from './providerService';
|
||||
export { serviceService } from './serviceService';
|
||||
export { collectionService } from './collectionService';
|
||||
export { entityService } from './entityService';
|
||||
|
||||
// Type exports
|
||||
export type * from '../types/common';
|
||||
export type * from '../types/provider';
|
||||
export type * from '../types/service';
|
||||
export type * from '../types/collection';
|
||||
export type * from '../types/entity';
|
||||
36
src/services/providerService.ts
Normal file
36
src/services/providerService.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Provider management service
|
||||
*/
|
||||
|
||||
import { createFetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper-core';
|
||||
|
||||
const fetchWrapper = createFetchWrapper();
|
||||
import type { ProviderListResponse, ProviderExtantResponse } from '../types/provider';
|
||||
import type { SourceSelector } from '../types/common';
|
||||
|
||||
const BASE_URL = '/m/chrono_manager/provider';
|
||||
|
||||
export const providerService = {
|
||||
|
||||
/**
|
||||
* List all available providers
|
||||
*
|
||||
* @returns Promise with provider list keyed by provider ID
|
||||
*/
|
||||
async list(): Promise<ProviderListResponse> {
|
||||
return await fetchWrapper.get(`${BASE_URL}/list`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which providers exist/are available
|
||||
*
|
||||
* @param sources - Source selector with provider IDs to check
|
||||
*
|
||||
* @returns Promise with provider availability status
|
||||
*/
|
||||
async extant(sources: SourceSelector): Promise<ProviderExtantResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/extant`, { sources });
|
||||
},
|
||||
};
|
||||
|
||||
export default providerService;
|
||||
52
src/services/serviceService.ts
Normal file
52
src/services/serviceService.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Service management service
|
||||
*/
|
||||
|
||||
import { createFetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper-core';
|
||||
|
||||
const fetchWrapper = createFetchWrapper();
|
||||
import type {
|
||||
ServiceListRequest,
|
||||
ServiceListResponse,
|
||||
ServiceExtantRequest,
|
||||
ServiceExtantResponse,
|
||||
ServiceFetchRequest,
|
||||
ServiceFetchResponse,
|
||||
} from '../types/service';
|
||||
|
||||
const BASE_URL = '/m/chrono_manager/service';
|
||||
|
||||
export const serviceService = {
|
||||
|
||||
/**
|
||||
* List all available services
|
||||
*
|
||||
* @param request - Service list request parameters
|
||||
* @returns Promise with service list grouped by provider
|
||||
*/
|
||||
async list(request: ServiceListRequest = {}): Promise<ServiceListResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/list`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which services exist/are available
|
||||
*
|
||||
* @param request - Service extant request with source selector
|
||||
* @returns Promise with service availability status
|
||||
*/
|
||||
async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/extant`, request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch a specific service
|
||||
*
|
||||
* @param request - Service fetch request with provider and service IDs
|
||||
* @returns Promise with service details
|
||||
*/
|
||||
async fetch(request: ServiceFetchRequest): Promise<ServiceFetchResponse> {
|
||||
return await fetchWrapper.post(`${BASE_URL}/fetch`, request);
|
||||
},
|
||||
};
|
||||
|
||||
export default serviceService;
|
||||
202
src/stores/collectionsStore.ts
Normal file
202
src/stores/collectionsStore.ts
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* Chrono Manager - Collections Store
|
||||
*/
|
||||
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { collectionService } from '../services/collectionService';
|
||||
import type {
|
||||
SourceSelector,
|
||||
ListFilter,
|
||||
ListSort,
|
||||
} from '../types/common';
|
||||
import { CollectionObject } from '../models/collection';
|
||||
import type { ServiceObject } from '../models/service';
|
||||
import type { CollectionInterface } from '../types/collection';
|
||||
|
||||
export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
||||
// State
|
||||
const collections = ref<CollectionObject[]>([]);
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Retrieve collections from the server
|
||||
*/
|
||||
async function list(
|
||||
sources?: SourceSelector,
|
||||
filter?: ListFilter,
|
||||
sort?: ListSort,
|
||||
uid?: string
|
||||
): Promise<CollectionObject[]> {
|
||||
try {
|
||||
const response = await collectionService.list({ sources, filter, sort, uid });
|
||||
|
||||
// Flatten the nested response into a flat array
|
||||
const flatCollections: CollectionObject[] = [];
|
||||
Object.entries(response).forEach(([_providerId, providerCollections]) => {
|
||||
Object.entries(providerCollections).forEach(([_serviceId, serviceCollections]) => {
|
||||
Object.values(serviceCollections).forEach((collection: CollectionInterface) => {
|
||||
flatCollections.push(new CollectionObject().fromJson(collection));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully retrieved', flatCollections.length, 'collections:', flatCollections.map(c => ({
|
||||
id: c.id,
|
||||
label: c.label,
|
||||
service: c.service,
|
||||
provider: c.provider
|
||||
})));
|
||||
|
||||
collections.value = flatCollections;
|
||||
return flatCollections;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to retrieve collections:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a specific collection
|
||||
*/
|
||||
async function fetch(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string | number,
|
||||
uid?: string
|
||||
): Promise<CollectionObject | null> {
|
||||
try {
|
||||
const response = await collectionService.fetch({ provider, service, identifier, uid });
|
||||
|
||||
return new CollectionObject().fromJson(response);
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to fetch collection:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh collection object with default values
|
||||
*/
|
||||
function fresh(): CollectionObject {
|
||||
return new CollectionObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection
|
||||
*/
|
||||
async function create(
|
||||
service: ServiceObject,
|
||||
collection: CollectionObject,
|
||||
options?: string[],
|
||||
uid?: string
|
||||
): Promise<CollectionObject | null> {
|
||||
try {
|
||||
if (service.provider === null || service.id === null) {
|
||||
throw new Error('Invalid service object, must have a provider and identifier');
|
||||
}
|
||||
|
||||
const response = await collectionService.create({
|
||||
provider: service.provider,
|
||||
service: service.id,
|
||||
data: collection.toJson(),
|
||||
options,
|
||||
uid
|
||||
});
|
||||
|
||||
const createdCollection = new CollectionObject().fromJson(response);
|
||||
collections.value.push(createdCollection);
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully created collection');
|
||||
|
||||
return createdCollection;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to create collection:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify an existing collection
|
||||
*/
|
||||
async function modify(
|
||||
collection: CollectionObject,
|
||||
uid?: string
|
||||
): Promise<CollectionObject | null> {
|
||||
try {
|
||||
if (!collection.provider || !collection.service || !collection.id) {
|
||||
throw new Error('Collection must have provider, service, and id');
|
||||
}
|
||||
|
||||
const response = await collectionService.modify({
|
||||
provider: collection.provider,
|
||||
service: collection.service,
|
||||
identifier: collection.id,
|
||||
data: collection.toJson(),
|
||||
uid
|
||||
});
|
||||
|
||||
const modifiedCollection = new CollectionObject().fromJson(response);
|
||||
const index = collections.value.findIndex(c => c.id === collection.id);
|
||||
if (index !== -1) {
|
||||
collections.value[index] = modifiedCollection;
|
||||
}
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully modified collection');
|
||||
|
||||
return modifiedCollection;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to modify collection:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a collection
|
||||
*/
|
||||
async function destroy(
|
||||
collection: CollectionObject,
|
||||
uid?: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
if (!collection.provider || !collection.service || !collection.id) {
|
||||
throw new Error('Collection must have provider, service, and id');
|
||||
}
|
||||
|
||||
const response = await collectionService.destroy({
|
||||
provider: collection.provider,
|
||||
service: collection.service,
|
||||
identifier: collection.id,
|
||||
uid
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
const index = collections.value.findIndex(c => c.id === collection.id);
|
||||
if (index !== -1) {
|
||||
collections.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully destroyed collection');
|
||||
|
||||
return response.success;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to destroy collection:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
collections,
|
||||
|
||||
// Actions
|
||||
list,
|
||||
fetch,
|
||||
fresh,
|
||||
create,
|
||||
modify,
|
||||
destroy,
|
||||
};
|
||||
});
|
||||
281
src/stores/entitiesStore.ts
Normal file
281
src/stores/entitiesStore.ts
Normal file
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* Chrono Manager - Entities Store
|
||||
*/
|
||||
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { entityService } from '../services/entityService';
|
||||
import { EntityObject } from '../models/entity';
|
||||
import { EventObject } from '../models/event';
|
||||
import { TaskObject } from '../models/task';
|
||||
import { JournalObject } from '../models/journal';
|
||||
import { CollectionObject } from '../models/collection';
|
||||
import type {
|
||||
SourceSelector,
|
||||
ListFilter,
|
||||
ListSort,
|
||||
ListRange,
|
||||
} from '../types/common';
|
||||
import type {
|
||||
EntityInterface,
|
||||
} from '../types/entity';
|
||||
|
||||
export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
||||
// State
|
||||
const entities = ref<EntityObject[]>([]);
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Reset the store to initial state
|
||||
*/
|
||||
function reset(): void {
|
||||
entities.value = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* List entities for all or specific collection
|
||||
*/
|
||||
async function list(
|
||||
provider: string | null,
|
||||
service: string | null,
|
||||
collection: string | number | null,
|
||||
filter?: ListFilter,
|
||||
sort?: ListSort,
|
||||
range?: ListRange,
|
||||
uid?: string
|
||||
): Promise<EntityObject[]> {
|
||||
try {
|
||||
// Validate hierarchical requirements
|
||||
if (collection !== null && (service === null || provider === null)) {
|
||||
throw new Error('Collection requires both service and provider');
|
||||
}
|
||||
if (service !== null && provider === null) {
|
||||
throw new Error('Service requires provider');
|
||||
}
|
||||
|
||||
// Build sources object level by level
|
||||
const sources: SourceSelector = {};
|
||||
if (provider !== null) {
|
||||
if (service !== null) {
|
||||
if (collection !== null) {
|
||||
sources[provider] = { [service]: { [collection]: true } };
|
||||
} else {
|
||||
sources[provider] = { [service]: true };
|
||||
}
|
||||
} else {
|
||||
sources[provider] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Transmit
|
||||
const response = await entityService.list({ sources, filter, sort, range, uid });
|
||||
|
||||
// Flatten the nested response into a flat array
|
||||
const flatEntities: EntityObject[] = [];
|
||||
Object.entries(response).forEach(([, providerEntities]) => {
|
||||
Object.entries(providerEntities).forEach(([, serviceEntities]) => {
|
||||
Object.entries(serviceEntities).forEach(([, collectionEntities]) => {
|
||||
Object.values(collectionEntities).forEach((entity: EntityInterface) => {
|
||||
flatEntities.push(new EntityObject().fromJson(entity));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully retrieved', flatEntities.length, 'entities');
|
||||
|
||||
entities.value = flatEntities;
|
||||
return flatEntities;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to retrieve entities:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch entities for a specific collection
|
||||
*/
|
||||
async function fetch(
|
||||
collection: CollectionObject,
|
||||
identifiers: (string | number)[],
|
||||
uid?: string
|
||||
): Promise<EntityObject[]> {
|
||||
try {
|
||||
if (!collection.provider || !collection.service || !collection.id) {
|
||||
throw new Error('Collection must have provider, service, and id');
|
||||
}
|
||||
|
||||
const response = await entityService.fetch({
|
||||
provider: collection.provider,
|
||||
service: collection.service,
|
||||
collection: collection.id,
|
||||
identifiers,
|
||||
uid
|
||||
});
|
||||
|
||||
return Object.values(response).map(entity => new EntityObject().fromJson(entity));
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to fetch entities:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh entity object
|
||||
*/
|
||||
function fresh(type: string): EntityObject {
|
||||
const entity = new EntityObject();
|
||||
|
||||
if (type === 'event') {
|
||||
entity.data = new EventObject();
|
||||
} else if (type === 'task') {
|
||||
entity.data = new TaskObject();
|
||||
} else if (type === 'journal') {
|
||||
entity.data = new JournalObject();
|
||||
} else {
|
||||
entity.data = new EventObject();
|
||||
}
|
||||
|
||||
if (entity.data) {
|
||||
entity.data.created = new Date();
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new entity
|
||||
*/
|
||||
async function create(
|
||||
collection: CollectionObject,
|
||||
entity: EntityObject,
|
||||
options?: string[],
|
||||
uid?: string
|
||||
): Promise<EntityObject | null> {
|
||||
try {
|
||||
if (!collection.provider || !collection.service || !collection.id) {
|
||||
throw new Error('Collection must have provider, service, and id');
|
||||
}
|
||||
|
||||
const response = await entityService.create({
|
||||
provider: collection.provider,
|
||||
service: collection.service,
|
||||
collection: collection.id,
|
||||
data: entity.toJson(),
|
||||
options,
|
||||
uid
|
||||
});
|
||||
|
||||
const createdEntity = new EntityObject().fromJson(response);
|
||||
entities.value.push(createdEntity);
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully created entity');
|
||||
|
||||
return createdEntity;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to create entity:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify an existing entity
|
||||
*/
|
||||
async function modify(
|
||||
collection: CollectionObject,
|
||||
entity: EntityObject,
|
||||
uid?: string
|
||||
): Promise<EntityObject | null> {
|
||||
try {
|
||||
if (!collection.provider || !collection.service || !collection.id) {
|
||||
throw new Error('Collection must have provider, service, and id');
|
||||
}
|
||||
if (!entity.in || !entity.id) {
|
||||
throw new Error('Invalid entity object, must have an collection and entity identifier');
|
||||
}
|
||||
if (collection.id !== entity.in) {
|
||||
throw new Error('Invalid entity object, does not belong to the specified collection');
|
||||
}
|
||||
|
||||
const response = await entityService.modify({
|
||||
provider: collection.provider,
|
||||
service: collection.service,
|
||||
collection: collection.id,
|
||||
identifier: entity.id,
|
||||
data: entity.toJson(),
|
||||
uid
|
||||
});
|
||||
|
||||
const modifiedEntity = new EntityObject().fromJson(response);
|
||||
const index = entities.value.findIndex(e => e.id === entity.id);
|
||||
if (index !== -1) {
|
||||
entities.value[index] = modifiedEntity;
|
||||
}
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully modified entity');
|
||||
|
||||
return modifiedEntity;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to modify entity:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an entity
|
||||
*/
|
||||
async function destroy(
|
||||
collection: CollectionObject,
|
||||
entity: EntityObject,
|
||||
uid?: string
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
if (!collection.provider || !collection.service || !collection.id) {
|
||||
throw new Error('Collection must have provider, service, and id');
|
||||
}
|
||||
if (!entity.in || !entity.id) {
|
||||
throw new Error('Invalid entity object, must have an collection and entity identifier');
|
||||
}
|
||||
if (collection.id !== entity.in) {
|
||||
throw new Error('Invalid entity object, does not belong to the specified collection');
|
||||
}
|
||||
|
||||
const response = await entityService.destroy({
|
||||
provider: collection.provider,
|
||||
service: collection.service,
|
||||
collection: collection.id,
|
||||
identifier: entity.id,
|
||||
uid
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
const index = entities.value.findIndex(e => e.id === entity.id);
|
||||
if (index !== -1) {
|
||||
entities.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully destroyed entity');
|
||||
|
||||
return response.success;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to destroy entity:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
entities,
|
||||
|
||||
// Actions
|
||||
reset,
|
||||
list,
|
||||
fetch,
|
||||
fresh,
|
||||
create,
|
||||
modify,
|
||||
destroy,
|
||||
};
|
||||
});
|
||||
8
src/stores/index.ts
Normal file
8
src/stores/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Central export point for all Chrono Manager stores
|
||||
*/
|
||||
|
||||
export { useCollectionsStore } from './collectionsStore';
|
||||
export { useEntitiesStore } from './entitiesStore';
|
||||
export { useProvidersStore } from './providersStore';
|
||||
export { useServicesStore } from './servicesStore';
|
||||
62
src/stores/providersStore.ts
Normal file
62
src/stores/providersStore.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Chrono Manager - Providers Store
|
||||
*/
|
||||
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { providerService } from '../services/providerService';
|
||||
import type {
|
||||
SourceSelector,
|
||||
ProviderInterface,
|
||||
} from '../types';
|
||||
|
||||
export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
||||
// State
|
||||
const providers = ref<Record<string, ProviderInterface>>({});
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* List all available providers
|
||||
*
|
||||
* @returns Promise with provider list keyed by provider ID
|
||||
*/
|
||||
async function list(): Promise<Record<string, ProviderInterface>> {
|
||||
try {
|
||||
const response = await providerService.list();
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully retrieved', Object.keys(response).length, 'providers:', Object.keys(response));
|
||||
|
||||
providers.value = response;
|
||||
return response;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to retrieve providers:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check which providers exist/are available
|
||||
*
|
||||
* @param sources - Source selector with provider IDs to check
|
||||
* @returns Promise with provider availability status
|
||||
*/
|
||||
async function extant(sources: SourceSelector): Promise<Record<string, boolean>> {
|
||||
try {
|
||||
const response = await providerService.extant(sources);
|
||||
return response;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to check provider existence:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
providers,
|
||||
|
||||
// Actions
|
||||
list,
|
||||
extant,
|
||||
};
|
||||
});
|
||||
95
src/stores/servicesStore.ts
Normal file
95
src/stores/servicesStore.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Chrono Manager - Services Store
|
||||
*/
|
||||
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { serviceService } from '../services/serviceService';
|
||||
import { ServiceObject } from '../models/service';
|
||||
import type { ServiceInterface } from '../types/service';
|
||||
import type {
|
||||
SourceSelector,
|
||||
ListFilter,
|
||||
ListSort,
|
||||
} from '../types/common';
|
||||
|
||||
export const useServicesStore = defineStore('chronoServicesStore', () => {
|
||||
// State
|
||||
const services = ref<ServiceObject[]>([]);
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Retrieve services from the server
|
||||
*/
|
||||
async function list(
|
||||
sources?: SourceSelector,
|
||||
filter?: ListFilter,
|
||||
sort?: ListSort,
|
||||
uid?: string
|
||||
): Promise<ServiceObject[]> {
|
||||
try {
|
||||
const response = await serviceService.list({ sources, filter, sort, uid });
|
||||
|
||||
// Flatten the nested response into a flat array
|
||||
const flatServices: ServiceObject[] = [];
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
Object.values(providerServices).forEach((service: ServiceInterface) => {
|
||||
// Ensure provider is set on the service object
|
||||
service.provider = service.provider || providerId;
|
||||
flatServices.push(new ServiceObject().fromJson(service));
|
||||
});
|
||||
});
|
||||
|
||||
console.debug('[Chrono Manager](Store) - Successfully retrieved', flatServices.length, 'services:', flatServices.map(s => ({
|
||||
id: s.id,
|
||||
label: s.label,
|
||||
provider: s.provider
|
||||
})));
|
||||
|
||||
services.value = flatServices;
|
||||
return flatServices;
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to retrieve services:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a specific service
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param identifier - Service identifier
|
||||
* @param uid - Optional user identifier
|
||||
* @returns Promise with service object
|
||||
*/
|
||||
async function fetch(
|
||||
provider: string,
|
||||
identifier: string,
|
||||
uid?: string
|
||||
): Promise<ServiceObject | null> {
|
||||
try {
|
||||
const response = await serviceService.fetch({ provider, service: identifier, uid });
|
||||
return new ServiceObject().fromJson(response);
|
||||
} catch (error: any) {
|
||||
console.error('[Chrono Manager](Store) - Failed to fetch service:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh service object with default values
|
||||
*/
|
||||
function fresh(): ServiceObject {
|
||||
return new ServiceObject();
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
services,
|
||||
|
||||
// Actions
|
||||
list,
|
||||
fetch,
|
||||
fresh,
|
||||
};
|
||||
});
|
||||
158
src/types/collection.ts
Normal file
158
src/types/collection.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* Collection-related type definitions for Chrono Manager
|
||||
*/
|
||||
|
||||
import type { ListFilter, ListSort, SourceSelector } from "./common";
|
||||
|
||||
/**
|
||||
* Permission settings for a collection
|
||||
*/
|
||||
export interface CollectionPermissionInterface {
|
||||
view: boolean;
|
||||
create: boolean;
|
||||
modify: boolean;
|
||||
destroy: boolean;
|
||||
share: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permissions settings for multiple users in a collection
|
||||
*/
|
||||
export interface CollectionPermissionsInterface {
|
||||
[userId: string]: CollectionPermissionInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content type settings for a collection
|
||||
*/
|
||||
export interface CollectionContentsInterface {
|
||||
event?: boolean;
|
||||
task?: boolean;
|
||||
journal?: boolean;
|
||||
[contentType: string]: boolean | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a collection (calendar) within a service
|
||||
*/
|
||||
export interface CollectionInterface {
|
||||
'@type': string;
|
||||
provider: string | null;
|
||||
service: string | null;
|
||||
in: number | string | null;
|
||||
id: number | string | null;
|
||||
label: string | null;
|
||||
description: string | null;
|
||||
priority: number | null;
|
||||
visibility: string | null;
|
||||
color: string | null;
|
||||
enabled: boolean;
|
||||
signature: string | null;
|
||||
permissions: CollectionPermissionsInterface;
|
||||
contents: CollectionContentsInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to collection list endpoint
|
||||
*/
|
||||
export interface CollectionListRequest {
|
||||
sources?: SourceSelector;
|
||||
filter?: ListFilter;
|
||||
sort?: ListSort;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from collection list endpoint
|
||||
*/
|
||||
export interface CollectionListResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
[collectionId: string]: CollectionInterface;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to collection extant endpoint
|
||||
*/
|
||||
export interface CollectionExtantRequest {
|
||||
sources: SourceSelector;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from collection extant endpoint
|
||||
*/
|
||||
export interface CollectionExtantResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
[collectionId: string]: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to collection fetch endpoint
|
||||
*/
|
||||
export interface CollectionFetchRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
identifier: string | number;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from collection fetch endpoint
|
||||
*/
|
||||
export interface CollectionFetchResponse extends CollectionInterface {}
|
||||
|
||||
/**
|
||||
* Request to collection create endpoint
|
||||
*/
|
||||
export interface CollectionCreateRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
data: CollectionInterface;
|
||||
options?: (string)[]
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from collection create endpoint
|
||||
*/
|
||||
export interface CollectionCreateResponse extends CollectionInterface {}
|
||||
|
||||
/**
|
||||
* Request to collection modify endpoint
|
||||
*/
|
||||
export interface CollectionModifyRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
identifier: string | number;
|
||||
data: CollectionInterface;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from collection modify endpoint
|
||||
*/
|
||||
export interface CollectionModifyResponse extends CollectionInterface {}
|
||||
|
||||
/**
|
||||
* Request to collection destroy endpoint
|
||||
*/
|
||||
export interface CollectionDestroyRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
identifier: string | number;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Response from collection destroy endpoint
|
||||
*/
|
||||
export interface CollectionDestroyResponse {
|
||||
success: boolean;
|
||||
}
|
||||
65
src/types/common.ts
Normal file
65
src/types/common.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Common types shared across Chrono Manager services
|
||||
*/
|
||||
|
||||
import type { FilterComparisonOperator, FilterConjunctionOperator } from './service';
|
||||
|
||||
/**
|
||||
* Source selector structure for hierarchical resource selection
|
||||
* Structure: Provider -> Service -> Collection -> Entity
|
||||
*
|
||||
* Examples:
|
||||
* - Simple boolean: { "local": true }
|
||||
* - Nested services: { "system": { "personal": true, "recents": true } }
|
||||
* - Collection IDs: { "system": { "personal": { "299": true, "176": true } } }
|
||||
* - Entity IDs: { "system": { "personal": { "299": [1350, 1353, 5000] } } }
|
||||
*/
|
||||
export type SourceSelector = {
|
||||
[provider: string]: boolean | ServiceSelector;
|
||||
};
|
||||
|
||||
export type ServiceSelector = {
|
||||
[service: string]: boolean | CollectionSelector;
|
||||
};
|
||||
|
||||
export type CollectionSelector = {
|
||||
[collection: string | number]: boolean | EntitySelector;
|
||||
};
|
||||
|
||||
export type EntitySelector = (string | number)[];
|
||||
|
||||
/**
|
||||
* Filter condition for building complex queries
|
||||
*/
|
||||
export interface FilterCondition {
|
||||
attribute: string;
|
||||
value: string | number | boolean | any[];
|
||||
comparator?: FilterComparisonOperator;
|
||||
conjunction?: FilterConjunctionOperator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter criteria for list operations
|
||||
* Can be simple key-value pairs or complex filter conditions
|
||||
*/
|
||||
export interface ListFilter {
|
||||
label?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort options for list operations
|
||||
*/
|
||||
export interface ListSort {
|
||||
[key: string]: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Range specification for pagination/limiting results
|
||||
*/
|
||||
export interface ListRange {
|
||||
type: 'tally';
|
||||
anchor: 'absolute' | 'relative';
|
||||
position: number;
|
||||
tally: number;
|
||||
}
|
||||
166
src/types/entity.ts
Normal file
166
src/types/entity.ts
Normal file
@@ -0,0 +1,166 @@
|
||||
import type { ListFilter, ListRange, ListSort, SourceSelector } from './common';
|
||||
import type { EventInterface } from './event';
|
||||
import type { TaskInterface } from './task';
|
||||
import type { JournalInterface } from './journal';
|
||||
|
||||
/**
|
||||
* Entity-related type definitions for Chrono Manager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a chrono entity (event, task, or journal)
|
||||
*/
|
||||
export interface EntityInterface {
|
||||
'@type': string;
|
||||
version: number;
|
||||
in: string | number | null;
|
||||
id: string | number | null;
|
||||
createdOn: Date | null;
|
||||
createdBy: string | null;
|
||||
modifiedOn: Date | null;
|
||||
modifiedBy: string | null;
|
||||
signature: string | null;
|
||||
data: EventInterface | TaskInterface | JournalInterface | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to entity list endpoint
|
||||
*/
|
||||
export interface EntityListRequest {
|
||||
sources?: SourceSelector;
|
||||
filter?: ListFilter;
|
||||
sort?: ListSort;
|
||||
range?: ListRange;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity list endpoint
|
||||
*/
|
||||
export interface EntityListResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
[collectionId: string]: {
|
||||
[entityId: string]: EntityInterface;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to entity delta endpoint
|
||||
*/
|
||||
export interface EntityDeltaRequest {
|
||||
sources: SourceSelector;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity delta endpoint
|
||||
*/
|
||||
export interface EntityDeltaResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
[collectionId: string]: {
|
||||
signature: string;
|
||||
created?: {
|
||||
[entityId: string]: EntityInterface;
|
||||
};
|
||||
modified?: {
|
||||
[entityId: string]: EntityInterface;
|
||||
};
|
||||
deleted?: string[]; // Array of deleted entity IDs
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to entity extant endpoint
|
||||
*/
|
||||
export interface EntityExtantRequest {
|
||||
sources: SourceSelector;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity extant endpoint
|
||||
*/
|
||||
export interface EntityExtantResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
[collectionId: string]: {
|
||||
[entityId: string]: boolean;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to entity fetch endpoint
|
||||
*/
|
||||
export interface EntityFetchRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
collection: string | number;
|
||||
identifiers: (string | number)[];
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity fetch endpoint
|
||||
*/
|
||||
export interface EntityFetchResponse extends Record<string, EntityInterface> {}
|
||||
|
||||
/**
|
||||
* Request to entity create endpoint
|
||||
*/
|
||||
export interface EntityCreateRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
collection: string | number;
|
||||
data: EntityInterface;
|
||||
options?: (string)[]
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity create endpoint
|
||||
*/
|
||||
export interface EntityCreateResponse extends EntityInterface {}
|
||||
|
||||
/**
|
||||
* Request to entity modify endpoint
|
||||
*/
|
||||
export interface EntityModifyRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
collection: string | number;
|
||||
identifier: string | number;
|
||||
data: EntityInterface;
|
||||
options?: (string)[]
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity modify endpoint
|
||||
*/
|
||||
export interface EntityModifyResponse extends EntityInterface {}
|
||||
|
||||
/**
|
||||
* Request to entity destroy endpoint
|
||||
*/
|
||||
export interface EntityDestroyRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
collection: string | number;
|
||||
identifier: string | number;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from entity destroy endpoint
|
||||
*/
|
||||
export interface EntityDestroyResponse {
|
||||
success: boolean;
|
||||
}
|
||||
146
src/types/event.ts
Normal file
146
src/types/event.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Event-related type definitions for Chrono Manager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Physical location information
|
||||
*/
|
||||
export interface EventLocationPhysicalInterface {
|
||||
identifier: string | null;
|
||||
label?: string | null;
|
||||
description?: string | null;
|
||||
relation?: 'start' | 'end' | null;
|
||||
timeZone?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual location information
|
||||
*/
|
||||
export interface EventLocationVirtualInterface {
|
||||
identifier: string | null;
|
||||
location: string;
|
||||
label?: string | null;
|
||||
description?: string | null;
|
||||
relation?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event organizer information
|
||||
*/
|
||||
export interface EventOrganizerInterface {
|
||||
realm: 'I' | 'E'; // I = Internal, E = External
|
||||
address: string;
|
||||
name?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event participant/attendee information
|
||||
*/
|
||||
export interface EventParticipantInterface {
|
||||
identifier: string | null;
|
||||
realm: 'I' | 'E'; // I = Internal, E = External
|
||||
address: string;
|
||||
type: 'unknown' | 'individual' | 'group' | 'resource' | 'location';
|
||||
status: 'none' | 'accepted' | 'declined' | 'tentative' | 'delegated';
|
||||
roles: ('owner' | 'chair' | 'attendee' | 'optional' | 'informational' | 'contact')[];
|
||||
name?: string | null;
|
||||
description?: string | null;
|
||||
comment?: string | null;
|
||||
language?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event notification/alarm
|
||||
*/
|
||||
export interface EventNotificationInterface {
|
||||
identifier: string | null;
|
||||
type: 'visual' | 'audible' | 'email';
|
||||
pattern: 'absolute' | 'relative' | 'unknown';
|
||||
when?: string | null; // ISO 8601 date-time string
|
||||
anchor?: 'start' | 'end' | null;
|
||||
offset?: string | null; // ISO 8601 duration string
|
||||
}
|
||||
|
||||
/**
|
||||
* Event occurrence/recurrence pattern
|
||||
*/
|
||||
export interface EventOccurrence {
|
||||
pattern: 'absolute' | 'relative';
|
||||
precision: 'yearly' | 'monthly' | 'weekly' | 'daily' | 'hourly' | 'minutely' | 'secondly' ;
|
||||
interval: number;
|
||||
iterations?: number | null;
|
||||
concludes?: string | null; // ISO 8601 date-time string
|
||||
scale?: string | null;
|
||||
onDayOfWeek?: number[] | null;
|
||||
onDayOfMonth?: number[] | null;
|
||||
onDayOfYear?: number[] | null;
|
||||
onWeekOfMonth?: number[] | null;
|
||||
onWeekOfYear?: number[] | null;
|
||||
onMonthOfYear?: number[] | null;
|
||||
onHour?: number[] | null;
|
||||
onMinute?: number[] | null;
|
||||
onSecond?: number[] | null;
|
||||
onPosition?: number[] | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event mutation (exception/modification to recurring event)
|
||||
*/
|
||||
export interface EventMutation {
|
||||
mutationId: string | null; // ISO 8601 date-time string
|
||||
mutationTz: string | null;
|
||||
mutationExclusion: boolean | null;
|
||||
sequence: number | null;
|
||||
timeZone: string | null;
|
||||
startsOn: string | null; // ISO 8601 date-time string
|
||||
startsTZ: string | null;
|
||||
endsOn: string | null; // ISO 8601 date-time string
|
||||
endsTZ: string | null;
|
||||
duration: string | null; // ISO 8601 duration string
|
||||
timeless: boolean | null;
|
||||
label: string | null;
|
||||
description: string | null;
|
||||
locationsPhysical: Record<string, EventLocationPhysicalInterface>;
|
||||
locationsVirtual: Record<string, EventLocationVirtualInterface>;
|
||||
availability: 'free' | 'busy' | null;
|
||||
priority: number | null;
|
||||
sensitivity: 'public' | 'private' | 'secret' | null;
|
||||
color: string | null;
|
||||
tags: string[];
|
||||
organizer: EventOrganizerInterface | null;
|
||||
participants: Record<string, EventParticipantInterface>;
|
||||
notifications: Record<string, EventNotificationInterface>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main event interface
|
||||
*/
|
||||
export interface EventInterface {
|
||||
type: string;
|
||||
version: number;
|
||||
urid: string | null;
|
||||
created: string | null; // ISO 8601 date-time string
|
||||
modified: string | null; // ISO 8601 date-time string
|
||||
sequence: number | null;
|
||||
timeZone: string | null;
|
||||
startsOn: string | null; // ISO 8601 date-time string
|
||||
startsTZ: string | null;
|
||||
endsOn: string | null; // ISO 8601 date-time string
|
||||
endsTZ: string | null;
|
||||
duration: string | null; // ISO 8601 duration string
|
||||
timeless: boolean | null;
|
||||
label: string | null;
|
||||
description: string | null;
|
||||
locationsPhysical: Record<string, EventLocationPhysicalInterface>;
|
||||
locationsVirtual: Record<string, EventLocationVirtualInterface>;
|
||||
availability: 'free' | 'busy' | null;
|
||||
sensitivity: 'public' | 'private' | 'secret' | null;
|
||||
priority: number | null;
|
||||
color: string | null;
|
||||
tags: string[];
|
||||
organizer: EventOrganizerInterface | null;
|
||||
participants: Record<string, EventParticipantInterface>;
|
||||
notifications: Record<string, EventNotificationInterface>;
|
||||
pattern: EventOccurrence | null;
|
||||
mutations: Record<string, EventMutation>;
|
||||
}
|
||||
12
src/types/index.ts
Normal file
12
src/types/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Central export point for all Chrono Manager types
|
||||
*/
|
||||
|
||||
export type * from './collection';
|
||||
export type * from './common';
|
||||
export type * from './entity';
|
||||
export type * from './event';
|
||||
export type * from './task';
|
||||
export type * from './journal';
|
||||
export type * from './provider';
|
||||
export type * from './service';
|
||||
33
src/types/journal.ts
Normal file
33
src/types/journal.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Journal-related type definitions for Chrono Manager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Journal attachment
|
||||
*/
|
||||
export interface JournalAttachment {
|
||||
uri: string | null;
|
||||
type: string | null;
|
||||
label: string | null;
|
||||
priority: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data for a journal entity
|
||||
*/
|
||||
export interface JournalInterface {
|
||||
type: string;
|
||||
version: number;
|
||||
urid: string | null;
|
||||
created: Date | null;
|
||||
modified: Date | null;
|
||||
label: string | null;
|
||||
description: string | null;
|
||||
content: string | null;
|
||||
startsOn: Date | null;
|
||||
endsOn: Date | null;
|
||||
status: string | null; // 'draft', 'final', 'cancelled'
|
||||
visibility: string | null; // 'public', 'private', 'confidential'
|
||||
attachments: Record<string, JournalAttachment>;
|
||||
tags: string[];
|
||||
}
|
||||
53
src/types/provider.ts
Normal file
53
src/types/provider.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Provider-specific types
|
||||
*/
|
||||
import type { SourceSelector } from "./common";
|
||||
|
||||
/**
|
||||
* Provider capabilities
|
||||
*/
|
||||
export interface ProviderCapabilitiesInterface {
|
||||
ServiceList?: boolean;
|
||||
ServiceFetch?: boolean;
|
||||
ServiceExtant?: boolean;
|
||||
ServiceCreate?: boolean;
|
||||
ServiceModify?: boolean;
|
||||
ServiceDelete?: boolean;
|
||||
[key: string]: boolean | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider information
|
||||
*/
|
||||
export interface ProviderInterface {
|
||||
'@type': string;
|
||||
id: string;
|
||||
label: string;
|
||||
capabilities: ProviderCapabilitiesInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to provider list endpoint
|
||||
*/
|
||||
export interface ProviderListRequest {}
|
||||
|
||||
/**
|
||||
* Response from provider list endpoint
|
||||
*/
|
||||
export interface ProviderListResponse {
|
||||
[providerId: string]: ProviderInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to provider extant endpoint
|
||||
*/
|
||||
export interface ProviderExtantRequest {
|
||||
sources: SourceSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from provider extant endpoint
|
||||
*/
|
||||
export interface ProviderExtantResponse {
|
||||
[providerId: string]: boolean;
|
||||
}
|
||||
214
src/types/service.ts
Normal file
214
src/types/service.ts
Normal file
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* Service-related type definitions for Chrono Manager
|
||||
*/
|
||||
|
||||
import type { ListFilter, ListSort, SourceSelector } from "./common";
|
||||
|
||||
/**
|
||||
* Filter comparison operators (bitmask values)
|
||||
*/
|
||||
export const FilterComparisonOperator = {
|
||||
EQ: 1, // Equal
|
||||
NEQ: 2, // Not Equal
|
||||
GT: 4, // Greater Than
|
||||
LT: 8, // Less Than
|
||||
GTE: 16, // Greater Than or Equal
|
||||
LTE: 32, // Less Than or Equal
|
||||
IN: 64, // In Array
|
||||
NIN: 128, // Not In Array
|
||||
LIKE: 256, // Like (pattern matching)
|
||||
NLIKE: 512, // Not Like
|
||||
} as const;
|
||||
|
||||
export type FilterComparisonOperator = typeof FilterComparisonOperator[keyof typeof FilterComparisonOperator];
|
||||
|
||||
/**
|
||||
* Filter conjunction operators
|
||||
*/
|
||||
export const FilterConjunctionOperator = {
|
||||
NONE: '',
|
||||
AND: 'AND',
|
||||
OR: 'OR',
|
||||
} as const;
|
||||
|
||||
export type FilterConjunctionOperator = typeof FilterConjunctionOperator[keyof typeof FilterConjunctionOperator];
|
||||
|
||||
/**
|
||||
* Filter specification format
|
||||
* Format: "type:length:defaultComparator:supportedComparators"
|
||||
*
|
||||
* Examples:
|
||||
* - "s:200:256:771" = String field, max 200 chars, default LIKE, supports EQ|NEQ|LIKE|NLIKE
|
||||
* - "a:10:64:192" = Array field, max 10 items, default IN, supports IN|NIN
|
||||
* - "i:0:1:31" = Integer field, default EQ, supports EQ|NEQ|GT|LT|GTE|LTE
|
||||
*
|
||||
* Type codes:
|
||||
* - s = string
|
||||
* - i = integer
|
||||
* - b = boolean
|
||||
* - a = array
|
||||
*
|
||||
* Comparator values are bitmasks that can be combined
|
||||
*/
|
||||
export type FilterSpec = string;
|
||||
|
||||
/**
|
||||
* Parsed filter specification
|
||||
*/
|
||||
export interface ParsedFilterSpec {
|
||||
type: 'string' | 'integer' | 'boolean' | 'array';
|
||||
length: number;
|
||||
defaultComparator: FilterComparisonOperator;
|
||||
supportedComparators: FilterComparisonOperator[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a filter specification string into its components
|
||||
*
|
||||
* @param spec - Filter specification string (e.g., "s:200:256:771")
|
||||
* @returns Parsed filter specification object
|
||||
*
|
||||
* @example
|
||||
* parseFilterSpec("s:200:256:771")
|
||||
* // Returns: {
|
||||
* // type: 'string',
|
||||
* // length: 200,
|
||||
* // defaultComparator: 256 (LIKE),
|
||||
* // supportedComparators: [1, 2, 256, 512] (EQ, NEQ, LIKE, NLIKE)
|
||||
* // }
|
||||
*/
|
||||
export function parseFilterSpec(spec: FilterSpec): ParsedFilterSpec {
|
||||
const [typeCode, lengthStr, defaultComparatorStr, supportedComparatorsStr] = spec.split(':');
|
||||
|
||||
const typeMap: Record<string, ParsedFilterSpec['type']> = {
|
||||
's': 'string',
|
||||
'i': 'integer',
|
||||
'b': 'boolean',
|
||||
'a': 'array',
|
||||
};
|
||||
|
||||
const type = typeMap[typeCode];
|
||||
if (!type) {
|
||||
throw new Error(`Invalid filter type code: ${typeCode}`);
|
||||
}
|
||||
|
||||
const length = parseInt(lengthStr, 10);
|
||||
const defaultComparator = parseInt(defaultComparatorStr, 10) as FilterComparisonOperator;
|
||||
|
||||
// Parse supported comparators from bitmask
|
||||
const supportedComparators: FilterComparisonOperator[] = [];
|
||||
const supportedBitmask = parseInt(supportedComparatorsStr, 10);
|
||||
|
||||
if (supportedBitmask !== 0) {
|
||||
const allComparators = Object.values(FilterComparisonOperator).filter(v => typeof v === 'number') as number[];
|
||||
for (const comparator of allComparators) {
|
||||
if ((supportedBitmask & comparator) === comparator) {
|
||||
supportedComparators.push(comparator as FilterComparisonOperator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type,
|
||||
length,
|
||||
defaultComparator,
|
||||
supportedComparators,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Capabilities available for a service
|
||||
*/
|
||||
export interface ServiceCapabilitiesInterface {
|
||||
// Collection capabilities
|
||||
CollectionList?: boolean;
|
||||
CollectionListFilter?: {
|
||||
[key: string]: FilterSpec;
|
||||
};
|
||||
CollectionListSort?: string[];
|
||||
CollectionExtant?: boolean;
|
||||
CollectionFetch?: boolean;
|
||||
CollectionCreate?: boolean;
|
||||
CollectionModify?: boolean;
|
||||
CollectionDestroy?: boolean;
|
||||
|
||||
// Entity capabilities
|
||||
EntityList?: boolean;
|
||||
EntityListFilter?: {
|
||||
[key: string]: FilterSpec;
|
||||
};
|
||||
EntityListSort?: string[];
|
||||
EntityListRange?: {
|
||||
[rangeType: string]: string[]; // e.g., { "tally": ["absolute", "relative"] }
|
||||
};
|
||||
EntityDelta?: boolean;
|
||||
EntityExtant?: boolean;
|
||||
EntityFetch?: boolean;
|
||||
EntityCreate?: boolean;
|
||||
EntityModify?: boolean;
|
||||
EntityDestroy?: boolean;
|
||||
EntityCopy?: boolean;
|
||||
EntityMove?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a service within a provider
|
||||
*/
|
||||
export interface ServiceInterface {
|
||||
'@type': string;
|
||||
provider: string;
|
||||
id: string;
|
||||
label: string;
|
||||
capabilities?: ServiceCapabilitiesInterface;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to service list endpoint
|
||||
*/
|
||||
export interface ServiceListRequest {
|
||||
sources?: SourceSelector;
|
||||
filter?: ListFilter;
|
||||
sort?: ListSort;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from service list endpoint
|
||||
*/
|
||||
export interface ServiceListResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: ServiceInterface;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to service extant endpoint
|
||||
*/
|
||||
export interface ServiceExtantRequest {
|
||||
sources: SourceSelector;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from service extant endpoint
|
||||
*/
|
||||
export interface ServiceExtantResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to service fetch endpoint
|
||||
*/
|
||||
export interface ServiceFetchRequest {
|
||||
provider: string;
|
||||
service: string;
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response from service fetch endpoint
|
||||
*/
|
||||
export interface ServiceFetchResponse extends ServiceInterface {}
|
||||
60
src/types/task.ts
Normal file
60
src/types/task.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Task-related type definitions for Chrono Manager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Task subtask information
|
||||
*/
|
||||
export interface TaskSubtask {
|
||||
label: string | null;
|
||||
completed: boolean;
|
||||
priority: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task attachment
|
||||
*/
|
||||
export interface TaskAttachment {
|
||||
uri: string | null;
|
||||
type: string | null;
|
||||
label: string | null;
|
||||
priority: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task recurrence rule
|
||||
*/
|
||||
export interface TaskRecurrence {
|
||||
frequency: string | null; // 'daily', 'weekly', 'monthly', 'yearly'
|
||||
interval: number | null;
|
||||
count: number | null;
|
||||
until: Date | null;
|
||||
byDay: string[] | null;
|
||||
byMonthDay: number[] | null;
|
||||
byMonth: number[] | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data for a task entity
|
||||
*/
|
||||
export interface TaskInterface {
|
||||
type: string;
|
||||
version: number;
|
||||
urid: string | null;
|
||||
created: Date | null;
|
||||
modified: Date | null;
|
||||
label: string | null;
|
||||
description: string | null;
|
||||
startsOn: Date | null;
|
||||
dueOn: Date | null;
|
||||
completedOn: Date | null;
|
||||
status: string | null; // 'needs-action', 'in-process', 'completed', 'cancelled'
|
||||
priority: number | null;
|
||||
progress: number | null; // 0-100 percentage
|
||||
color: string | null;
|
||||
recurrence: TaskRecurrence | null;
|
||||
subtasks: Record<string, TaskSubtask>;
|
||||
attachments: Record<string, TaskAttachment>;
|
||||
tags: string[];
|
||||
notes: string | null;
|
||||
}
|
||||
31
src/utils/key-generator.ts
Normal file
31
src/utils/key-generator.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Utility functions for generating unique identifiers
|
||||
*/
|
||||
|
||||
const globalCrypto = typeof globalThis !== "undefined" ? globalThis.crypto : undefined;
|
||||
|
||||
export const generateUrid = (): string => {
|
||||
if (globalCrypto?.randomUUID) {
|
||||
return globalCrypto.randomUUID();
|
||||
}
|
||||
|
||||
const template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
||||
return template.replace(/[xy]/g, char => {
|
||||
const randomNibble = Math.floor(Math.random() * 16);
|
||||
const value = char === "x" ? randomNibble : (randomNibble & 0x3) | 0x8;
|
||||
return value.toString(16);
|
||||
});
|
||||
};
|
||||
|
||||
export const generateKey = (): string => {
|
||||
if (globalCrypto?.randomUUID) {
|
||||
return globalCrypto.randomUUID().replace(/-/g, "");
|
||||
}
|
||||
|
||||
if (globalCrypto?.getRandomValues) {
|
||||
const [value] = globalCrypto.getRandomValues(new Uint32Array(1));
|
||||
return value.toString(16);
|
||||
}
|
||||
|
||||
return Math.random().toString(16).slice(2);
|
||||
};
|
||||
1
src/vite-env.d.ts
vendored
Normal file
1
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
Reference in New Issue
Block a user