/** * Transport Test Interfaces * * Contract testing interfaces for transport layer implementations. * Tests ONLY message delivery mechanics and connection management. */ import { Effect, Stream, Scope, Schema } from 'effect'; import type { ConnectionState as CoreConnectionState, TransportError, } from '@codeforbreakfast/eventsourcing-transport'; // ============================================================================= // TRANSPORT CONTRACT TEST INTERFACES // ============================================================================= /** * Transport message schema for compile-time and runtime validation */ export const TransportMessageSchema = Schema.Struct({ id: Schema.NonEmptyString, type: Schema.NonEmptyString, payload: Schema.Unknown, metadata: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Unknown })), }); export interface TransportMessage extends Schema.Schema.Type { readonly id: string; } /** * Connection state from transport contracts */ export type ConnectionState = CoreConnectionState; /** * Transport test context for testing the simplified ConnectedTransport interface. * * IMPORTANT: This interface models the Effect.acquireRelease pattern. * The `createConnectedTransport` method should use Scope to manage lifecycle. * When the Scope closes, the transport should automatically disconnect. */ export interface TransportTestContext { // Transport factory using Effect's Scope for lifecycle management readonly makeConnectedTransport: ( url: string ) => Effect.Effect; // Optional test utilities for advanced testing scenarios readonly simulateDisconnect?: () => Effect.Effect; readonly simulateReconnect?: () => Effect.Effect; } /** * Test interface that mirrors the simplified ConnectedTransport interface */ export interface ConnectedTransportTestInterface { // Connection state monitoring readonly connectionState: Stream.Stream; // Message operations with proper error typing readonly publish: (message: TransportMessage) => Effect.Effect; readonly subscribe: ( filter?: (msg: TransportMessage) => boolean ) => Effect.Effect, TransportError, never>; } /** * Test runner type for transport contract tests */ export type TransportTestRunner = ( name: string, setup: () => Effect.Effect ) => void;