feat : dont conflit with other editor
This commit is contained in:
@@ -6,10 +6,20 @@ export const INVALIDATION_TYPES = [
|
||||
|
||||
export type InvalidationType = (typeof INVALIDATION_TYPES)[number];
|
||||
|
||||
export type AdminEditorScope =
|
||||
| "overview"
|
||||
| "weapon"
|
||||
| "artifact"
|
||||
| "constellations"
|
||||
| "team"
|
||||
| "extras:list"
|
||||
| `extra:${string}`;
|
||||
|
||||
export interface InvalidationEvent {
|
||||
type: InvalidationType;
|
||||
id: string;
|
||||
version: number;
|
||||
scope?: AdminEditorScope;
|
||||
}
|
||||
|
||||
export interface OutboxEventLike {
|
||||
@@ -23,6 +33,13 @@ function isInvalidationType(value: string): value is InvalidationType {
|
||||
return INVALIDATION_TYPES.some((type) => type === value);
|
||||
}
|
||||
|
||||
function isAdminEditorScope(value: unknown): value is AdminEditorScope {
|
||||
return typeof value === "string" && (
|
||||
["overview", "weapon", "artifact", "constellations", "team", "extras:list"].includes(value)
|
||||
|| /^extra:[0-9a-f-]{36}$/iu.test(value)
|
||||
);
|
||||
}
|
||||
|
||||
export function expectedTopic(event: InvalidationEvent): string {
|
||||
switch (event.type) {
|
||||
case "directory.updated":
|
||||
@@ -38,6 +55,11 @@ export function toInvalidationEvent(
|
||||
record: OutboxEventLike,
|
||||
): InvalidationEvent | null {
|
||||
if (!isInvalidationType(record.eventType)) return null;
|
||||
if (
|
||||
record.eventType === "admin.updated"
|
||||
&& record.payload.scope !== undefined
|
||||
&& !isAdminEditorScope(record.payload.scope)
|
||||
) return null;
|
||||
const id = record.payload.id;
|
||||
const version = record.payload.version;
|
||||
if (
|
||||
@@ -53,6 +75,9 @@ export function toInvalidationEvent(
|
||||
type: record.eventType,
|
||||
id,
|
||||
version,
|
||||
...(record.eventType === "admin.updated" && isAdminEditorScope(record.payload.scope)
|
||||
? { scope: record.payload.scope }
|
||||
: {}),
|
||||
};
|
||||
return expectedTopic(event) === record.topic ? event : null;
|
||||
}
|
||||
@@ -63,6 +88,7 @@ export function parseInvalidationEvent(value: string): InvalidationEvent | null
|
||||
const type = parsed.type;
|
||||
const id = parsed.id;
|
||||
const version = parsed.version;
|
||||
const scope = parsed.scope;
|
||||
if (
|
||||
typeof type !== "string" ||
|
||||
!isInvalidationType(type) ||
|
||||
@@ -73,7 +99,10 @@ export function parseInvalidationEvent(value: string): InvalidationEvent | null
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return { type, id, version };
|
||||
if (scope !== undefined && (type !== "admin.updated" || !isAdminEditorScope(scope))) {
|
||||
return null;
|
||||
}
|
||||
return { type, id, version, ...(scope === undefined ? {} : { scope }) };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user