refactor(schema): declare event durability at definition level (#35172)
This commit is contained in:
parent
bd8d858bf7
commit
de476aa51b
53 changed files with 700 additions and 1165 deletions
|
|
@ -92,8 +92,9 @@ export class SubscriberOverflowError extends Schema.TaggedErrorClass<SubscriberO
|
|||
{ capacity: Schema.Int },
|
||||
) {}
|
||||
|
||||
export const define = Event.define
|
||||
export const versionedType = Event.versionedType
|
||||
export const durable = Event.durable
|
||||
export const ephemeral = Event.ephemeral
|
||||
|
||||
export interface PublishOptions {
|
||||
readonly id?: ID
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import type { DeepMutable } from "../schema"
|
|||
import { Slug } from "../util/slug"
|
||||
|
||||
type DatabaseService = Database.Interface["db"]
|
||||
type MessageEvent = Exclude<SessionEvent.Event, typeof SessionEvent.Forked.Type>
|
||||
type MessageEvent = Exclude<SessionEvent.DurableEvent, typeof SessionEvent.Forked.Type>
|
||||
|
||||
const decodeMessage = Schema.decodeUnknownSync(SessionMessage.Message)
|
||||
const encodeMessage = Schema.encodeSync(SessionMessage.Message)
|
||||
|
|
@ -417,7 +417,7 @@ function run(db: DatabaseService, event: MessageEvent) {
|
|||
})
|
||||
}
|
||||
|
||||
function insertMessage(db: DatabaseService, event: SessionEvent.Event, message: SessionMessage.Message) {
|
||||
function insertMessage(db: DatabaseService, event: SessionEvent.DurableEvent, message: SessionMessage.Message) {
|
||||
if (event.durable === undefined) return Effect.die("Durable Session event is missing aggregate sequence")
|
||||
const encoded = encodeMessage(message)
|
||||
const { id, type, ...data } = encoded
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ const locationLayer = Layer.succeed(
|
|||
location({ directory: AbsolutePath.make("project"), workspaceID: WorkspaceV2.ID.make("wrk_test") }),
|
||||
),
|
||||
)
|
||||
const Message = EventV2.define({
|
||||
const Message = EventV2.ephemeral({
|
||||
type: "test.message",
|
||||
schema: {
|
||||
text: Schema.String,
|
||||
},
|
||||
})
|
||||
|
||||
const SyncMessage = EventV2.define({
|
||||
const SyncMessage = EventV2.durable({
|
||||
type: "test.sync",
|
||||
durable: {
|
||||
version: 1,
|
||||
|
|
@ -41,7 +41,7 @@ const SyncMessage = EventV2.define({
|
|||
},
|
||||
})
|
||||
|
||||
const SyncSent = EventV2.define({
|
||||
const SyncSent = EventV2.durable({
|
||||
type: "test.sent",
|
||||
durable: {
|
||||
version: 1,
|
||||
|
|
@ -53,14 +53,14 @@ const SyncSent = EventV2.define({
|
|||
},
|
||||
})
|
||||
|
||||
const GlobalMessage = EventV2.define({
|
||||
const GlobalMessage = EventV2.ephemeral({
|
||||
type: "test.global",
|
||||
schema: {
|
||||
text: Schema.String,
|
||||
},
|
||||
})
|
||||
|
||||
const VersionedMessage = EventV2.define({
|
||||
const VersionedMessage = EventV2.durable({
|
||||
type: "test.versioned",
|
||||
durable: {
|
||||
version: 2,
|
||||
|
|
@ -129,12 +129,12 @@ describe("EventV2", () => {
|
|||
|
||||
it.effect("selects the latest durable definition independent of declaration order", () =>
|
||||
Effect.sync(() => {
|
||||
const latest = EventV2.define({
|
||||
const latest = EventV2.durable({
|
||||
type: "test.out-of-order",
|
||||
durable: { version: 2, aggregate: "id" },
|
||||
schema: { id: Schema.String },
|
||||
})
|
||||
const historical = EventV2.define({
|
||||
const historical = EventV2.durable({
|
||||
type: "test.out-of-order",
|
||||
durable: { version: 1, aggregate: "id" },
|
||||
schema: { id: Schema.String },
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ describe("SessionV2.log", () => {
|
|||
|
||||
it.effect("reads across undecodable gaps in aggregate order and marks the true log position", () =>
|
||||
Effect.gen(function* () {
|
||||
const GapEvent = EventV2.define({
|
||||
const GapEvent = EventV2.durable({
|
||||
type: "test.session.log.gap",
|
||||
durable: { aggregate: "sessionID", version: 1 },
|
||||
schema: { sessionID: SessionV2.ID, value: Schema.String },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue