Skip to content

Type Alias: ScopedBus<Namespace, Subjects, FilterPayload>

Makaio Framework


Makaio Framework / bus-core / ScopedBus

Type Alias: ScopedBus<Namespace, Subjects, FilterPayload>

Section titled “Type Alias: ScopedBus<Namespace, Subjects, FilterPayload>”

ScopedBus<Namespace, Subjects, FilterPayload> = IScopedBusBase<Namespace> & object

Defined in: ../../../packages/bus-core/src/scoped-bus.ts:14

Scoped bus with namespace isolation and type-safe filtering.

getContext(): MakaioBusContext

Get the bus context for advanced use cases.

MakaioBusContext

withFilter(filter): IFilteredBus<Namespace, Subjects, FilterPayload>

Create a filtered bus with a base payload filter.

The filter is automatically applied to all on() and once() calls.

When FilterPayload is known (via BusNamespace.scopedBus()), filter keys are automatically constrained to the intersection of all subject payloads.

TypedPayloadFilter<FilterPayload>

Base filter to apply to all subscriptions

IFilteredBus<Namespace, Subjects, FilterPayload>

FilteredBus with the specified filter

// Type-safe filtering - keys auto-inferred from pre-computed FilterPayload
const scopedBus = await CodexMcpNamespace.scopedBus();
scopedBus.withFilter({ agentId: this.agentId }); // ✅ agentId validated
scopedBus.withFilter({ unknownKey: 'x' }); // ❌ Error - unknown key
// Explicit type override still works
interface CustomPayload { agentId: string; sessionId: string }
scopedBus.withFilter<CustomPayload>({ agentId: 'x' });

Namespace extends string

The namespace domain string (e.g., ‘adapter:codex-mcp’)

Subjects = SubjectRecord

SubjectRecord for payload types (used by on/once/emit)

FilterPayload = unknown

Pre-computed intersection of all filterable payloads. When provided, withFilter constrains filter keys to this type.

  • ScopedBus

    • `IScopedBusBase & { /**
    • Create a filtered bus with a base payload filter.
    • The filter is automatically applied to all on() and once() calls.
    • When FilterPayload is known (via BusNamespace.scopedBus()), filter keys are
    • automatically constrained to the intersection of all subject payloads.
    • @param filter - Base filter to apply to all subscriptions
    • @returns FilteredBus with the specified filter
    • @example
    • // Type-safe filtering - keys auto-inferred from pre-computed FilterPayload
    • const scopedBus = await CodexMcpNamespace.scopedBus();
    • scopedBus.withFilter({ agentId: this.agentId }); // ✅ agentId validated
    • scopedBus.withFilter({ unknownKey: ‘x’ }); // ❌ Error - unknown key
    • // Explicit type override still works
    • interface CustomPayload { agentId: string; sessionId: string }
    • scopedBus.withFilter({ agentId: ‘x’ });

    */ withFilter(filter: TypedPayloadFilter): IFilteredBus<Namespace, Subjects, FilterPayload>;

    /**

    • Get the bus context for advanced use cases. */ getContext(): MakaioBusContext; }`
    • IScopedBusBase<Namespace>
      • Namespace
    • `{ /**
    • Create a filtered bus with a base payload filter.
    • The filter is automatically applied to all on() and once() calls.
    • When FilterPayload is known (via BusNamespace.scopedBus()), filter keys are
    • automatically constrained to the intersection of all subject payloads.
    • @param filter - Base filter to apply to all subscriptions
    • @returns FilteredBus with the specified filter
    • @example
    • // Type-safe filtering - keys auto-inferred from pre-computed FilterPayload
    • const scopedBus = await CodexMcpNamespace.scopedBus();
    • scopedBus.withFilter({ agentId: this.agentId }); // ✅ agentId validated
    • scopedBus.withFilter({ unknownKey: ‘x’ }); // ❌ Error - unknown key
    • // Explicit type override still works
    • interface CustomPayload { agentId: string; sessionId: string }
    • scopedBus.withFilter({ agentId: ‘x’ });

    */ withFilter(filter: TypedPayloadFilter): IFilteredBus<Namespace, Subjects, FilterPayload>;

    /**

    • Get the bus context for advanced use cases. */ getContext(): MakaioBusContext; }`
type ScopedBus = {
namespace: Namespace;
on: <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, handler: HandlerForSubjectDefinition<Subject>, options?: OnOptions) => () => void;
intercept: <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, handler: InterceptorHandler<Subject['$meta']['payload']>, options?: InterceptOptions) => () => void;
once: { <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, handler: HandlerForSubjectDefinition<Subject>): () => void; <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, options?: OnceOptions<Subject> | undefined): Promise<ContextForSubjectDefinition<Subject>>; };
emit: <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, payload: Subject['$meta']['payload']) => Promise<void>;
request: <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, payload: Subject['$meta']['payload']['request']) => Promise<Subject['$meta']['payload']['response']>;
requestOptional: <Subject extends ScopedSubjectDefinition<Namespace>>(subject: Subject, payload: Subject['$meta']['payload']['request']) => Promise<OptionalResult<Subject['$meta']['payload']['response']>>;
withFilter: (filter: TypedPayloadFilter<FilterPayload>) => IFilteredBus<Namespace, Subjects, FilterPayload>;
getContext: () => MakaioBusContext;
};