79 lines
1.7 KiB
TypeScript
79 lines
1.7 KiB
TypeScript
import type { DocumentInterface, DocumentModelInterface } from "@/types/document";
|
|
|
|
export class DocumentObject implements DocumentModelInterface {
|
|
|
|
_data!: DocumentInterface;
|
|
|
|
constructor() {
|
|
this._data = {
|
|
'@type': 'documents:document',
|
|
urid: null,
|
|
size: 0,
|
|
label: '',
|
|
mime: null,
|
|
format: null,
|
|
encoding: null,
|
|
};
|
|
}
|
|
|
|
fromJson(data: DocumentInterface): DocumentObject {
|
|
this._data = data;
|
|
return this;
|
|
}
|
|
|
|
toJson(): DocumentInterface {
|
|
return this._data;
|
|
}
|
|
|
|
clone(): DocumentObject {
|
|
const cloned = new DocumentObject();
|
|
cloned._data = { ...this._data };
|
|
return cloned;
|
|
}
|
|
|
|
/** Immutable Properties */
|
|
|
|
get urid(): string | null {
|
|
return this._data.urid;
|
|
}
|
|
|
|
get size(): number {
|
|
const parsed = typeof this._data.size === 'number' ? this._data.size : Number(this._data.size);
|
|
return Number.isFinite(parsed) && parsed >= 0 ? parsed : 0;
|
|
}
|
|
|
|
/** Mutable Properties */
|
|
|
|
get label(): string | null {
|
|
return this._data.label || null;
|
|
}
|
|
|
|
set label(value: string) {
|
|
this._data.label = value;
|
|
}
|
|
|
|
get mime(): string | null {
|
|
return this._data.mime;
|
|
}
|
|
|
|
set mime(value: string) {
|
|
this._data.mime = value;
|
|
}
|
|
|
|
get format(): string | null {
|
|
return this._data.format;
|
|
}
|
|
|
|
set format(value: string) {
|
|
this._data.format = value;
|
|
}
|
|
|
|
get encoding(): string | null {
|
|
return this._data.encoding;
|
|
}
|
|
|
|
set encoding(value: string) {
|
|
this._data.encoding = value;
|
|
}
|
|
|
|
} |