- Split OperationRegistry into separate specs and handlers maps
- Add registerSpec(), registerHandler(), getHandler() methods
- register() still accepts IOperationDefinition (backward compatible)
- execute() now requires both spec and handler, throws if missing
- Update @alkdev/pubsub integration for v0.1.0 API:
- subscribe(type, id) now requires id parameter (use for all events)
- publish(type, id, payload) now requires 3 args
- Events unwrapped from EventEnvelope via .payload
- Update buildCallHandler to use getSpec() + getHandler() separately
- Update subscribe.ts to use getHandler()
- Update buildEnv to use getAllSpecs() instead of list()
- Update scanner to validate against OperationSpecSchema
- Update from_mcp and from_openapi to use OperationSpec & { handler } types
- Remove OperationDefinitionSchema from public exports
- Add 7 new registry tests for handler separation
33 lines
820 B
TypeScript
33 lines
820 B
TypeScript
import type { OperationContext } from "./types.js";
|
|
import { OperationRegistry } from "./registry.js";
|
|
|
|
export async function* subscribe(
|
|
registry: OperationRegistry,
|
|
operationId: string,
|
|
input: unknown,
|
|
context: OperationContext,
|
|
): AsyncGenerator<unknown, void, unknown> {
|
|
const spec = registry.getSpec(operationId);
|
|
|
|
if (!spec) {
|
|
throw new Error(`Operation not found: ${operationId}`);
|
|
}
|
|
|
|
const handler = registry.getHandler(operationId);
|
|
|
|
if (!handler) {
|
|
throw new Error(`No handler registered for operation: ${operationId}`);
|
|
}
|
|
|
|
const generator = handler(input, context) as AsyncGenerator<unknown, void, unknown>;
|
|
|
|
try {
|
|
for await (const value of generator) {
|
|
yield value;
|
|
}
|
|
} finally {
|
|
if (generator.return) {
|
|
await generator.return(undefined);
|
|
}
|
|
}
|
|
} |