chore: bunch of improvements
All checks were successful
JS Unit Tests / test (pull_request) Successful in 33s
Build Test / test (pull_request) Successful in 36s
PHP Unit Tests / test (pull_request) Successful in 1m12s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-04-23 22:00:50 -04:00
parent b617234b40
commit 3362afb7ec
28 changed files with 1717 additions and 1297 deletions

View File

@@ -2,45 +2,48 @@
* Class model for Collection Interface
*/
import type { CollectionInterface, CollectionPropertiesInterface } from "@/types/collection";
import type { CollectionInterface, CollectionModelInterface, CollectionPropertiesInterface, CollectionPropertiesModelInterface } from "@/types/collection";
export class CollectionObject implements CollectionInterface {
export class CollectionObject implements CollectionModelInterface {
_data!: CollectionInterface;
_data!: CollectionInterface<CollectionPropertiesInterface>;
_properties!: CollectionPropertiesObject;
constructor() {
this._data = {
'@type': 'mail:collection',
version: 1,
provider: '',
service: '',
collection: null,
identifier: '',
signature: null,
created: null,
modified: null,
properties: new CollectionPropertiesObject(),
properties: {'@type': 'mail:folder', label: ''},
};
}
fromJson(data: CollectionInterface): CollectionObject {
this._data = data;
if (data.properties) {
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
}
return this;
}
toJson(): CollectionInterface {
const json = { ...this._data };
if (this._data.properties instanceof CollectionPropertiesObject) {
json.properties = this._data.properties.toJson();
const json = {
...this._data
};
if (this._properties) {
json.properties = this._properties.toJson();
}
return json;
}
clone(): CollectionObject {
const cloned = new CollectionObject();
cloned._data = { ...this._data };
cloned._data.properties = this.properties.clone();
cloned._data = {
...this._data,
};
if (this._properties) {
cloned._properties = this._properties.clone();
}
return cloned;
}
@@ -75,36 +78,30 @@ export class CollectionObject implements CollectionInterface {
}
get properties(): CollectionPropertiesObject {
if (this._data.properties instanceof CollectionPropertiesObject) {
return this._data.properties;
if (this._properties) {
return this._properties;
}
if (this._data.properties) {
const hydrated = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
this._data.properties = hydrated;
return hydrated;
else if (this._data.properties) {
const properties = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
this._properties = properties;
return properties;
}
return new CollectionPropertiesObject();
}
set properties(value: CollectionPropertiesObject) {
if (value instanceof CollectionPropertiesObject) {
this._data.properties = value as any;
} else {
this._data.properties = value;
}
this._properties = value;
}
}
export class CollectionPropertiesObject implements CollectionPropertiesInterface {
export class CollectionPropertiesObject implements CollectionPropertiesModelInterface {
_data!: CollectionPropertiesInterface;
private _data!: CollectionPropertiesInterface;
constructor() {
this._data = {
'@type': 'mail:collection',
version: 1,
'@type': 'mail:folder',
total: 0,
unread: 0,
role: null,
@@ -131,14 +128,6 @@ export class CollectionPropertiesObject implements CollectionPropertiesInterface
/** Immutable Properties */
get '@type'(): string {
return this._data['@type'];
}
get version(): number {
return this._data.version;
}
get role(): string | null | undefined {
return this._data.role;
}