chore: standardize chrono provider

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-17 03:11:18 -05:00
parent 974d3fe11b
commit fccd7b1df6
31 changed files with 3800 additions and 2076 deletions
+168 -89
View File
@@ -1,11 +1,8 @@
/**
* Class model for Collection Interface
*/
import type {
CollectionInterface,
CollectionContentsInterface,
CollectionPermissionsInterface,
} from "@/types/collection";
import type { CollectionContentsInterface, CollectionInterface, CollectionPropertiesInterface } from "@/types/collection";
export class CollectionObject implements CollectionInterface {
@@ -13,81 +10,195 @@ export class CollectionObject implements 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,
provider: '',
service: '',
collection: null,
identifier: '',
signature: null,
permissions: {},
contents: {},
created: null,
modified: null,
properties: {
'@type': 'chrono.collection',
version: 1,
total: 0,
contents: {},
label: '',
description: null,
rank: 0,
visibility: null,
color: null,
},
};
}
fromJson(data: CollectionInterface): CollectionObject {
this._data = data;
if (data.properties) {
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
} else {
this._data.properties = new CollectionPropertiesObject();
}
return this;
}
toJson(): CollectionInterface {
return this._data;
const json = { ...this._data };
if (this._data.properties instanceof CollectionPropertiesObject) {
json.properties = this._data.properties.toJson();
}
return json;
}
clone(): CollectionObject {
const cloned = new CollectionObject();
cloned._data = JSON.parse(JSON.stringify(this._data));
cloned._data = { ...this._data };
cloned._data.properties = this.properties.clone();
return cloned;
}
/** Properties */
/** Immutable Properties */
get provider(): string {
return this._data.provider;
}
get service(): string | number {
return this._data.service;
}
get collection(): string | number | null {
return this._data.collection;
}
get identifier(): string | number {
return this._data.identifier;
}
get signature(): string | null | undefined {
return this._data.signature;
}
get created(): string | null | undefined {
return this._data.created;
}
get modified(): string | null | undefined {
return this._data.modified;
}
get properties(): CollectionPropertiesObject {
if (this._data.properties instanceof CollectionPropertiesObject) {
return this._data.properties;
}
if (this._data.properties) {
const hydrated = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
this._data.properties = hydrated;
return hydrated;
}
return new CollectionPropertiesObject();
}
set properties(value: CollectionPropertiesObject) {
if (value instanceof CollectionPropertiesObject) {
this._data.properties = value as any;
} else {
this._data.properties = value;
}
}
}
export class CollectionPropertiesObject implements CollectionPropertiesInterface {
_data!: CollectionPropertiesInterface;
constructor() {
this._data = {
'@type': 'chrono.collection',
version: 1,
total: 0,
contents: {},
label: '',
description: null,
rank: null,
visibility: null,
color: null,
};
}
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
this._data = data;
const raw = this._data as any;
if ((!raw.contents || Object.keys(raw.contents).length === 0) && raw.content !== undefined && raw.content !== null) {
if (typeof raw.content === 'string') {
raw.contents = {
event: raw.content === 'event',
task: raw.content === 'task',
journal: raw.content === 'journal',
};
} else if (typeof raw.content === 'object') {
raw.contents = raw.content;
}
}
return this;
}
toJson(): CollectionPropertiesInterface {
return this._data;
}
clone(): CollectionPropertiesObject {
const cloned = new CollectionPropertiesObject();
cloned._data = { ...this._data };
return cloned;
}
/** Immutable Properties */
get '@type'(): string {
return this._data['@type'];
}
get provider(): string | null {
return this._data.provider;
get version(): number {
return this._data.version;
}
set provider(value: string | null) {
this._data.provider = value;
get total(): number | undefined {
return this._data.total;
}
get service(): string | null {
return this._data.service;
get contents(): CollectionContentsInterface {
const raw = this._data as any;
if (raw.contents && Object.keys(raw.contents).length > 0) {
return raw.contents;
}
if (typeof raw.content === 'string') {
return {
event: raw.content === 'event',
task: raw.content === 'task',
journal: raw.content === 'journal',
};
}
if (raw.content && typeof raw.content === 'object') {
return raw.content;
}
return {};
}
set service(value: string | null) {
this._data.service = value;
/** Mutable Properties */
get label(): string {
return this._data.label || '';
}
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) {
set label(value: string) {
this._data.label = value;
}
@@ -99,19 +210,19 @@ export class CollectionObject implements CollectionInterface {
this._data.description = value;
}
get priority(): number | null {
return this._data.priority;
get rank(): number | null {
return this._data.rank;
}
set priority(value: number | null) {
this._data.priority = value;
set rank(value: number | null) {
this._data.rank = value;
}
get visibility(): string | null {
get visibility(): boolean | null {
return this._data.visibility;
}
set visibility(value: string | null) {
set visibility(value: boolean | null) {
this._data.visibility = value;
}
@@ -123,36 +234,4 @@ export class CollectionObject implements CollectionInterface {
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;
}
}
}