import { DomainEvent } from "@classytic/primitives/events"; import { OperationContext } from "@classytic/primitives/context"; import { RetryPolicy } from "@classytic/repo-core/repository"; //#region src/domain/ports/common.d.ts /** * MusterContext — operation context threaded through every domain verb. * * Extends `OperationContext` from `@classytic/primitives/context` so muster * is structurally compatible with every other `@classytic/*` package. * * Only `organizationId` is required. The actor fields default to a * `system` identity so scripts and seeds can pass `{ organizationId }` without * constructing a full context: * `await repo.checkIn(data, { organizationId: 'org-123' })` */ interface MusterContext extends Omit { /** Required — muster is strictly multi-tenant by default. */ organizationId: string; /** Actor performing the operation. Defaults to `'system'`. */ actorId?: string | undefined; /** For tracing / event correlation. Auto-generated if omitted. */ correlationId?: string | undefined; /** * Classifier for the actor. Defaults to `'system'` when `actorId` is * absent. Set to `'user'` or `'service'` for authenticated callers. */ actorKind?: 'user' | 'system' | 'service' | undefined; /** * Cooperative cancellation — threaded into every repo call via * `repoOptionsFromCtx`. Mongokit (3.16+) checks the signal at each op * boundary; aborting never rolls back a committed write. */ signal?: AbortSignal | undefined; /** * Driver round-trip retry policy — threaded into every repo call via * `repoOptionsFromCtx`. Mongokit wraps round-trips in `withRetry` * automatically; hooks still run exactly once. */ retryPolicy?: RetryPolicy | undefined; } interface ResolvedMusterContext extends MusterContext { actorId: string; correlationId: string; actorKind: 'user' | 'system' | 'service'; } /** Fill in optional identity fields so internal code can always read them. */ declare function resolveCtx(ctx: MusterContext): ResolvedMusterContext; /** * Internal: key under which the post-commit event-publish queue is threaded * through the context. When set, repository `dispatch` calls APPEND to this * queue instead of publishing immediately — and the outer domain verb * flushes the queue after its transaction commits. This prevents * `eventTransport.publish` from emitting ghost events on transaction * retries / aborts (the body of a `session.withTransaction(...)` callback * may run multiple times). * * Outbox writes (`outbox.save`) stay inside the transaction — that's * correct, the relay reads only committed rows. * * The key is a Symbol so it never collides with host-supplied context * fields and never appears in the public `MusterContext` type. */ declare const PENDING_EVENTS: unique symbol; //#endregion export { MusterContext, PENDING_EVENTS, ResolvedMusterContext, resolveCtx };