import { Result } from "@webiny/feature/api"; import { UpdateEntryRepository as RepositoryAbstraction } from "./abstractions.js"; import { EntryPersistenceError } from "~/domain/contentEntry/errors.js"; import type { CmsEntry, CmsEntryValues, CmsModel } from "~/types/index.js"; import { UpdateEntryStorageOperation } from "~/features/shared/storageOperations/entry/UpdateEntryStorageOperation.js"; import { EntryToStorageTransform } from "~/legacy/abstractions.js"; import { RuntimeTenant } from "~/features/runtimeTenant/abstractions.js"; /** * UpdateEntryRepository - Handles persistence of entry updates. * Transforms domain entry to storage format and persists changes. */ class UpdateEntryRepositoryImpl implements RepositoryAbstraction.Interface { public constructor( private entryToStorageTransform: EntryToStorageTransform.Interface, private updateEntryStorage: UpdateEntryStorageOperation.Interface, private runtimeTenant: RuntimeTenant.Interface ) {} async execute( initialModel: CmsModel, initialEntry: CmsEntry ): Promise> { const model = this.runtimeTenant.assign(initialModel); const entry = this.runtimeTenant.assign(initialEntry); try { // Transform domain entry to storage format const storageEntry = await this.entryToStorageTransform(model, entry); // Persist to storage await this.updateEntryStorage.execute(model, { entry, storageEntry }); return Result.ok(); } catch (error) { return Result.fail(new EntryPersistenceError(error as Error)); } } } export const UpdateEntryRepository = RepositoryAbstraction.createImplementation({ implementation: UpdateEntryRepositoryImpl, dependencies: [EntryToStorageTransform, UpdateEntryStorageOperation, RuntimeTenant] });