UNPKG

alinea

Version:
80 lines (78 loc) 2 kB
import "../../chunks/chunk-NZLE2WMY.js"; // src/core/db/WriteableGraph.ts import { Entry } from "../Entry.js"; import { Graph } from "../Graph.js"; import { MediaFile } from "../media/MediaTypes.js"; import { ArchiveOperation, CreateOp, DeleteOp, DiscardOp, MoveOperation, PublishOperation, UnpublishOperation, UpdateOperation, UploadOperation } from "./Operation.js"; var WriteableGraph = class extends Graph { async create(create) { const op = new CreateOp(create); await this.commit(op); return this.get({ id: op.id, type: create.type, locale: create.locale, status: create.status === "draft" ? "preferDraft" : create.status === "archived" ? "archived" : "preferPublished" }); } async update(update) { const op = new UpdateOperation(update); await this.commit(op); return this.get({ type: update.type, id: update.id, locale: update.locale ?? null, status: update.status ?? "published" }); } async remove(...entryIds) { await this.commit(new DeleteOp(entryIds)); } async publish(publish) { await this.commit(new PublishOperation(publish)); } async unpublish(unpublish) { await this.commit(new UnpublishOperation(unpublish)); } async archive(archive) { await this.commit(new ArchiveOperation(archive)); } async move(query) { const op = new MoveOperation(query); await this.commit(op); return this.get({ id: query.id, select: { index: Entry.index }, status: "preferDraft" }); } async discard(query) { const op = new DiscardOp(query); await this.commit(op); } async upload(query) { const op = new UploadOperation(query); await this.commit(op); return this.get({ type: MediaFile, id: op.id }); } async commit(...operations) { const mutations = await Promise.all(operations.map((op) => op.task(this))); await this.mutate(mutations.flat()); } }; export { WriteableGraph };