refactor: service address
Build Test / test (pull_request) Successful in 37s
JS Unit Tests / test (pull_request) Failing after 37s
PHP Unit Tests / test (pull_request) Successful in 59s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-16 13:31:23 -04:00
parent 0e4bd905a2
commit bea7c1d0fb
10 changed files with 168 additions and 44 deletions
+83
View File
@@ -0,0 +1,83 @@
/**
* Address implementation class for Mail Manager services
*
* Plain value object (no mutation tracking). ServiceObject getters return
* fresh instances built from raw data; mutating a getter result does not
* write back — assign through the setter to persist changes.
*/
import type { ServiceAddressInterface } from '@/types/service';
export class ServiceAddressObject implements ServiceAddressInterface {
_address: string;
_label: string | null;
constructor(address: string = '', label: string | null = null) {
this._address = address;
this._label = label;
}
static fromJson(data: ServiceAddressInterface): ServiceAddressObject {
return new ServiceAddressObject(data.address, data.label ?? null);
}
toJson(): ServiceAddressInterface {
const label = this._label?.trim() ?? '';
return {
address: this._address.trim(),
label: label.length > 0 ? label : null,
};
}
toJSON(): ServiceAddressInterface {
return this.toJson();
}
clone(): ServiceAddressObject {
return new ServiceAddressObject(this._address, this._label);
}
/** Case-insensitive address comparison, ignoring labels */
matches(address: string): boolean {
return this._address.trim().toLowerCase() === address.trim().toLowerCase();
}
equals(other: ServiceAddressObject | null | undefined): boolean {
if (!other) {
return false;
}
const current = this.toJson();
const next = other.toJson();
return current.address === next.address && (current.label ?? null) === (next.label ?? null);
}
/** Display form: "Label <address>" or bare address */
format(): string {
const { address, label } = this.toJson();
return label ? `${label} <${address}>` : address;
}
get empty(): boolean {
return this._address.trim().length === 0;
}
/** Properties (raw values for editing; normalization happens in toJson) */
get address(): string {
return this._address;
}
set address(value: string) {
this._address = value;
}
get label(): string | null {
return this._label;
}
set label(value: string | null) {
this._label = value;
}
}
+2
View File
@@ -1,5 +1,6 @@
export { ProviderObject } from './provider';
export { ServiceObject } from './service';
export { ServiceAddressObject } from './address';
export {
CollectionObject,
CollectionPropertiesObject
@@ -7,6 +8,7 @@ export {
export { EntityObject } from './entity';
export {
MessageObject,
MessageAddressObject,
MessagePartObject
} from './message';
export {
+9 -8
View File
@@ -8,6 +8,7 @@ import type {
ServiceLocation,
ServiceModelInterface
} from "@/types/service";
import { ServiceAddressObject } from './address';
import { Identity } from './identity';
import { Location } from './location';
import { MutationProxy } from './mutation-proxy';
@@ -118,20 +119,20 @@ export class ServiceObject implements ServiceModelInterface {
return this._data.capabilities ?? {};
}
get primaryAddress(): string | null {
return this._data.primaryAddress ?? null;
get primaryAddress(): ServiceAddressObject | null {
return this._data.primaryAddress ? ServiceAddressObject.fromJson(this._data.primaryAddress) : null;
}
set primaryAddress(value: string | null) {
this._data.primaryAddress = value;
set primaryAddress(value: ServiceAddressObject | null) {
this._data.primaryAddress = value ? value.toJson() : null;
}
get secondaryAddresses(): string[] {
return this._data.secondaryAddresses ?? [];
get secondaryAddresses(): ServiceAddressObject[] {
return (this._data.secondaryAddresses ?? []).map(entry => ServiceAddressObject.fromJson(entry));
}
set secondaryAddresses(value: string[] | null) {
this._data.secondaryAddresses = value;
set secondaryAddresses(value: ServiceAddressObject[] | null) {
this._data.secondaryAddresses = value ? value.map(entry => entry.toJson()) : null;
}
/** Mutable Properties */