fix(core): better global sync event structure (#22858)
This commit is contained in:
@@ -460,8 +460,7 @@ export namespace Workspace {
|
|||||||
if (!("payload" in evt)) return
|
if (!("payload" in evt)) return
|
||||||
|
|
||||||
if (evt.payload.type === "sync") {
|
if (evt.payload.type === "sync") {
|
||||||
// This name -> type is temporary
|
SyncEvent.replay(evt.payload.syncEvent as SyncEvent.SerializedEvent)
|
||||||
SyncEvent.replay({ ...evt.payload, type: evt.payload.name } as SyncEvent.SerializedEvent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalBus.emit("event", {
|
GlobalBus.emit("event", {
|
||||||
|
|||||||
@@ -155,8 +155,10 @@ function process<Def extends Definition>(def: Def, event: Event<Def>, options: {
|
|||||||
workspace: WorkspaceContext.workspaceID,
|
workspace: WorkspaceContext.workspaceID,
|
||||||
payload: {
|
payload: {
|
||||||
type: "sync",
|
type: "sync",
|
||||||
name: versionedType(def.type, def.version),
|
syncEvent: {
|
||||||
...event,
|
type: versionedType(def.type, def.version),
|
||||||
|
...event,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -164,12 +166,6 @@ function process<Def extends Definition>(def: Def, event: Event<Def>, options: {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
//
|
|
||||||
// * Support applying multiple events at one time. One transaction,
|
|
||||||
// and it validets all the sequence ids
|
|
||||||
// * when loading events from db, apply zod validation to ensure shape
|
|
||||||
|
|
||||||
export function replay(event: SerializedEvent, options?: { publish: boolean }) {
|
export function replay(event: SerializedEvent, options?: { publish: boolean }) {
|
||||||
const def = registry.get(event.type)
|
const def = registry.get(event.type)
|
||||||
if (!def) {
|
if (!def) {
|
||||||
|
|||||||
Reference in New Issue
Block a user