refactor: documents interfaces

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-09 19:32:27 -04:00
parent ac393843f1
commit 050467919b
23 changed files with 1731 additions and 1581 deletions
+21 -1
View File
@@ -5,6 +5,19 @@ import type { EntityInterface, EntityModelInterface } from "@/types/entity";
import type { DocumentInterface, DocumentModelInterface } from "@/types/document";
import { DocumentObject } from "./document";
/**
* Reduce a serialized resource identifier ("provider:service:collection:entity")
* to its own (last) segment; plain values pass through unchanged
*/
function plainIdentifier(value: string | number | null | undefined): string | number | null {
if (value === null || value === undefined || value === '') {
return value ?? null;
}
const text = String(value);
const index = text.lastIndexOf(':');
return index >= 0 ? text.slice(index + 1) : value;
}
export class EntityObject implements EntityModelInterface {
_data!: EntityInterface<DocumentInterface|DocumentModelInterface>;
@@ -25,7 +38,14 @@ export class EntityObject implements EntityModelInterface {
}
fromJson(data: EntityInterface): EntityObject {
this._data = data
// the wire format carries full resource identifiers (provider:service:collection:entity);
// reduce them to plain ids, which is what the stores and UI operate on
this._data = {
...data,
service: String(plainIdentifier(data.service) ?? ''),
collection: plainIdentifier(data.collection) ?? '',
identifier: plainIdentifier(data.identifier) ?? '',
}
if (data.properties) {
this._data.properties = new DocumentObject().fromJson(data.properties as DocumentInterface);
}