feat(editor) : notify peers of draft overwrite
CI / Verify (push) Successful in 1m20s
CI / Build immutable images and deploy (push) Successful in 1m51s

This commit is contained in:
2026-09-15 19:46:40 +07:00 Unverified
parent fb152c12fe
commit c3a2aa88d6
7 changed files with 121 additions and 50 deletions
+23
View File
@@ -61,4 +61,27 @@ describe("invalidation event envelopes", () => {
payload: { id, version: 6, scope: "unknown" },
})).toBeNull();
});
it("publishes validated overwrite details only on admin events", () => {
const id = "4afeea7b-6f24-43f3-b747-2db98335e01e";
const overwrite = { operation: "overwrite", actorName: "Editor One" };
expect(toInvalidationEvent({
topic: "admin",
aggregateId: id,
eventType: "admin.updated",
payload: { id, version: 7, scope: "weapon", ...overwrite },
})).toEqual({ type: "admin.updated", id, version: 7, scope: "weapon", ...overwrite });
expect(parseInvalidationEvent(JSON.stringify({
type: "admin.updated",
id,
version: 8,
operation: "overwrite",
}))).toBeNull();
expect(toInvalidationEvent({
topic: `page:${id}`,
aggregateId: id,
eventType: "page.updated",
payload: { id, version: 7, ...overwrite },
})).toEqual({ type: "page.updated", id, version: 7 });
});
});
+19 -1
View File
@@ -20,6 +20,8 @@ export interface InvalidationEvent {
id: string;
version: number;
scope?: AdminEditorScope;
operation?: "overwrite";
actorName?: string;
}
export interface OutboxEventLike {
@@ -40,6 +42,17 @@ function isAdminEditorScope(value: unknown): value is AdminEditorScope {
);
}
function overwriteDetails(payload: Record<string, unknown>) {
if (payload.operation === undefined && payload.actorName === undefined) return {};
if (
payload.operation !== "overwrite"
|| typeof payload.actorName !== "string"
|| !payload.actorName.trim()
|| payload.actorName.length > 100
) return null;
return { operation: "overwrite" as const, actorName: payload.actorName };
}
export function expectedTopic(event: InvalidationEvent): string {
switch (event.type) {
case "directory.updated":
@@ -60,6 +73,8 @@ export function toInvalidationEvent(
&& record.payload.scope !== undefined
&& !isAdminEditorScope(record.payload.scope)
) return null;
const details = record.eventType === "admin.updated" ? overwriteDetails(record.payload) : {};
if (details === null) return null;
const id = record.payload.id;
const version = record.payload.version;
if (
@@ -78,6 +93,7 @@ export function toInvalidationEvent(
...(record.eventType === "admin.updated" && isAdminEditorScope(record.payload.scope)
? { scope: record.payload.scope }
: {}),
...details,
};
return expectedTopic(event) === record.topic ? event : null;
}
@@ -89,6 +105,7 @@ export function parseInvalidationEvent(value: string): InvalidationEvent | null
const id = parsed.id;
const version = parsed.version;
const scope = parsed.scope;
const details = type === "admin.updated" ? overwriteDetails(parsed) : {};
if (
typeof type !== "string" ||
!isInvalidationType(type) ||
@@ -102,7 +119,8 @@ export function parseInvalidationEvent(value: string): InvalidationEvent | null
if (scope !== undefined && (type !== "admin.updated" || !isAdminEditorScope(scope))) {
return null;
}
return { type, id, version, ...(scope === undefined ? {} : { scope }) };
if (details === null) return null;
return { type, id, version, ...(scope === undefined ? {} : { scope }), ...details };
} catch {
return null;
}