Type Alias: ScopedBus<Namespace, Subjects, FilterPayload>
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.
Type Declaration
Section titled “Type Declaration”getContext()
Section titled “getContext()”getContext():
MakaioBusContext
Get the bus context for advanced use cases.
Returns
Section titled “Returns”withFilter()
Section titled “withFilter()”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.
Parameters
Section titled “Parameters”filter
Section titled “filter”TypedPayloadFilter<FilterPayload>
Base filter to apply to all subscriptions
Returns
Section titled “Returns”IFilteredBus<Namespace, Subjects, FilterPayload>
FilteredBus with the specified filter
Example
Section titled “Example”// Type-safe filtering - keys auto-inferred from pre-computed FilterPayloadconst scopedBus = await CodexMcpNamespace.scopedBus();scopedBus.withFilter({ agentId: this.agentId }); // ✅ agentId validatedscopedBus.withFilter({ unknownKey: 'x' }); // ❌ Error - unknown key
// Explicit type override still worksinterface CustomPayload { agentId: string; sessionId: string }scopedBus.withFilter<CustomPayload>({ agentId: 'x' });Type Parameters
Section titled “Type Parameters”Namespace
Section titled “Namespace”Namespace extends string
The namespace domain string (e.g., ‘adapter:codex-mcp’)
Subjects
Section titled “Subjects”Subjects = SubjectRecord
SubjectRecord for payload types (used by on/once/emit)
FilterPayload
Section titled “FilterPayload”FilterPayload = unknown
Pre-computed intersection of all filterable payloads. When provided, withFilter constrains filter keys to this type.
Type Composition
Section titled “Type Composition”-
- `IScopedBusBase
& { /**
- Create a filtered bus with a base payload filter.
- The filter is automatically applied to all
on()andonce()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()andonce()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
Resolved Shape
Section titled “Resolved Shape”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;};