refactor(core): simplify event model (#33238)

This commit is contained in:
Dax 2026-06-21 16:34:57 +02:00 committed by GitHub
commit fb43c15f88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 231 additions and 569 deletions

View file

@ -45,9 +45,9 @@ export const layer = Layer.effect(
workspace: workspaceID,
payload: { id: event.id, type: event.type, properties: event.data },
})
const sync = EventV2.registry.get(event.type)?.sync
if (sync === undefined || event.seq === undefined || event.version === undefined) return
const aggregateID = (event.data as Record<string, unknown>)[sync.aggregate]
const durable = EventV2.registry.get(event.type)?.durable
if (durable === undefined || event.durable === undefined) return
const aggregateID = (event.data as Record<string, unknown>)[durable.aggregate]
if (typeof aggregateID !== "string") return
GlobalBus.emit("event", {
directory: event.location?.directory ?? ctx?.directory,
@ -57,8 +57,8 @@ export const layer = Layer.effect(
type: "sync",
syncEvent: {
id: event.id,
type: EventV2.versionedType(event.type, event.version),
seq: event.seq,
type: EventV2.versionedType(event.type, event.durable.version),
seq: event.durable.seq,
aggregateID,
data: event.data,
},

View file

@ -16,13 +16,13 @@ const GlobalHealth = Schema.Struct({
const SyncEventSchemas = EventV2.registry
.values()
.flatMap((definition) => {
if (!definition.sync) return []
if (!definition.durable) return []
return [
Schema.Struct({
type: Schema.Literal("sync"),
id: EventV2.ID,
syncEvent: Schema.Struct({
type: Schema.Literal(EventV2.versionedType(definition.type, definition.sync.version)),
type: Schema.Literal(EventV2.versionedType(definition.type, definition.durable.version)),
id: EventV2.ID,
seq: Schema.Finite,
aggregateID: Schema.String,