From 85faaa374741e7cb5099d3be2016a80b1d00a8c5 Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Sun, 28 Jun 2026 12:22:15 -0400 Subject: [PATCH] refactor: minor code cleanup Signed-off-by: Sebastian Krupinski --- src/models/collection.ts | 12 +++++------- src/models/entity.ts | 27 ++++++++++----------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/models/collection.ts b/src/models/collection.ts index f8195ab..c5bdedc 100644 --- a/src/models/collection.ts +++ b/src/models/collection.ts @@ -9,11 +9,11 @@ import type { CollectionPropertiesInterface, CollectionPropertiesModelInterface } from "@/types/collection"; -import { clonePlain } from './clone-plain'; import type { CollectionIdentifier, ServiceIdentifier } from "@/types/common"; +import { clonePlain } from './clone-plain'; export class CollectionObject implements CollectionModelInterface { @@ -28,7 +28,7 @@ export class CollectionObject implements CollectionModelInterface { service: '' as ServiceIdentifier, collection: null as CollectionIdentifier | null, identifier: '' as CollectionIdentifier, - properties: { '@type': 'people:addressbook', content: [], label: '', description: null, rank: null, visibility: null, color: null }, + properties: new CollectionPropertiesObject().toJson(), }; } @@ -40,12 +40,8 @@ export class CollectionObject implements CollectionModelInterface { toJson(): CollectionInterface { const json = this._properties - ? { - ...this._data, - properties: this._properties.toJson(), - } + ? { ...this._data, properties: this._properties.toJson() } : this._data; - return clonePlain(json); } @@ -83,6 +79,8 @@ export class CollectionObject implements CollectionModelInterface { return this._data.modified; } + /** Mutable Properties */ + get properties(): CollectionPropertiesObject { if (this._properties) { return this._properties; diff --git a/src/models/entity.ts b/src/models/entity.ts index c1a4727..9f171d6 100644 --- a/src/models/entity.ts +++ b/src/models/entity.ts @@ -12,10 +12,12 @@ import { OrganizationObject } from "./organization"; import { GroupObject } from "./group"; import { clonePlain } from './clone-plain'; +export type EntityPropertiesObject = IndividualObject | OrganizationObject | GroupObject; + export class EntityObject implements EntityModelInterface { private _data!: EntityInterface; - private _properties: IndividualObject | OrganizationObject | GroupObject | undefined = undefined; + private _properties: EntityPropertiesObject | undefined = undefined; constructor() { this._data = { @@ -40,12 +42,8 @@ export class EntityObject implements EntityModelInterface { toJson(): EntityInterface { const json = this._properties - ? { - ...this._data, - properties: this._properties.toJson(), - } + ? { ...this._data, properties: this._properties.toJson() } : this._data; - return clonePlain(json); } @@ -85,17 +83,13 @@ export class EntityObject implements EntityModelInterface { /** Entity Properties (individual | organization | group) */ - get properties(): IndividualObject | OrganizationObject | GroupObject { - if (this._properties) { - return this._properties; - } + get properties(): EntityPropertiesObject { + if (this._properties) return this._properties; - const raw = this._data.properties as EntityPropertiesInterface; - const type = (raw as { type?: string })?.type; - - if (type === 'organization') { + const raw = this._data.properties; + if (raw.type === 'organization') { this._properties = new OrganizationObject().fromJson(raw as OrganizationInterface); - } else if (type === 'group') { + } else if (raw.type === 'group') { this._properties = new GroupObject().fromJson(raw as GroupInterface); } else { this._properties = new IndividualObject().fromJson(raw as IndividualInterface); @@ -104,8 +98,7 @@ export class EntityObject implements EntityModelInterface { return this._properties; } - set properties(value: IndividualObject | OrganizationObject | GroupObject) { + set properties(value: EntityPropertiesObject) { this._properties = value; } - }