Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify internal/external separation #135

Merged
merged 7 commits into from
May 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/core/lib/messages/baseMessageSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import z from 'zod'

// Core fields that describe event
// Core fields that describe either internal event or external message
export const BASE_MESSAGE_SCHEMA = z.object({
id: z.string().describe('event unique identifier'),
timestamp: z.string().datetime().describe('iso 8601 datetime'),
Expand All @@ -9,20 +9,25 @@ export const BASE_MESSAGE_SCHEMA = z.object({
})

// Extra fields that are optional for the event processing
// For internal domain events that did not originate within a message chain these fields can be omitted, producer should assume it is initiating a new chain then
export const EXTENDED_MESSAGE_SCHEMA = BASE_MESSAGE_SCHEMA.extend({
metadata: z
.object({
schemaVersion: z.string().min(1).describe('message schema version'),
// this is always set to a service that created the message
producedBy: z.string().min(1).describe('app/service that produced the message'),
// this is always propagated within the message chain. For the first message in the chain it is equal to "producedBy"
originatedFrom: z
.string()
.min(1)
.describe('app/service that initiated entire workflow that led to creating this message'),
// this is always propagated within the message chain.
correlationId: z
.string()
.describe('unique identifier passed to all events in workflow chain'),
})
.describe('event metadata'),
.optional()
.describe('external message metadata'),
})

export type BaseMessageType = z.infer<typeof BASE_MESSAGE_SCHEMA>
Loading