refactor(schema): extract public event definitions (#33579)

This commit is contained in:
Kit Langton
2026-06-24 16:43:17 -04:00
committed by GitHub
parent 858f35f1b3
commit 24b0132bc5
93 changed files with 2740 additions and 2124 deletions
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, test } from "bun:test"
import { Schema } from "effect"
import { Event } from "../src/event"
describe("public event schemas", () => {
test("definition is pure", () => {
const definitions = Event.inventory()
Event.define({ type: "test.pure", schema: { value: Schema.String } })
expect(definitions).toEqual([])
})
test("latest selection is independent of declaration order", () => {
const historical = Event.define({
type: "test.versioned",
durable: { aggregate: "id", version: 1 },
schema: { id: Schema.String },
})
const current = Event.define({
type: "test.versioned",
durable: { aggregate: "id", version: 2 },
schema: { id: Schema.String, value: Schema.String },
})
expect(Event.latest([historical, current]).get(current.type)).toBe(current)
expect(Event.latest([current, historical]).get(current.type)).toBe(current)
})
test("durable definitions are indexed by type and version", () => {
const definition = Event.define({
type: "test.durable",
durable: { aggregate: "id", version: 1 },
schema: { id: Schema.String },
})
expect(Event.durable([definition]).get("test.durable.1")).toBe(definition)
})
})