66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
/**
|
|
* Class model for Provider Interface
|
|
*/
|
|
|
|
import type {
|
|
ProviderInterface,
|
|
ProviderCapabilitiesInterface,
|
|
ProviderModelInterface
|
|
} from "@/types/provider";
|
|
import { clonePlain } from './clone-plain';
|
|
|
|
export class ProviderObject implements ProviderModelInterface {
|
|
|
|
_data!: ProviderInterface;
|
|
|
|
constructor() {
|
|
this._data = {
|
|
'@type': 'mail:provider',
|
|
version: 1,
|
|
identifier: '',
|
|
label: '',
|
|
capabilities: {},
|
|
};
|
|
}
|
|
|
|
fromJson(data: ProviderInterface): ProviderObject {
|
|
this._data = clonePlain(data);
|
|
return this;
|
|
}
|
|
|
|
toJson(): ProviderInterface {
|
|
return clonePlain(this._data);
|
|
}
|
|
|
|
clone(): ProviderObject {
|
|
return new ProviderObject().fromJson(this.toJson());
|
|
}
|
|
|
|
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
|
const value = this._data.capabilities?.[capability];
|
|
return value !== undefined && value !== false;
|
|
}
|
|
|
|
capability(capability: keyof ProviderCapabilitiesInterface): any | null {
|
|
if (this._data.capabilities) {
|
|
return this._data.capabilities[capability];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/** Immutable Properties */
|
|
|
|
get identifier(): string {
|
|
return this._data.identifier;
|
|
}
|
|
|
|
get label(): string {
|
|
return this._data.label;
|
|
}
|
|
|
|
get capabilities(): ProviderCapabilitiesInterface {
|
|
return clonePlain(this._data.capabilities);
|
|
}
|
|
|
|
}
|