Separate handler from spec in OperationRegistry, update pubsub API
- 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
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { IOperationDefinition, OperationContext } from "./types.js";
|
||||
import type { OperationContext } from "./types.js";
|
||||
import { OperationRegistry } from "./registry.js";
|
||||
|
||||
export async function* subscribe(
|
||||
@@ -7,13 +7,18 @@ export async function* subscribe(
|
||||
input: unknown,
|
||||
context: OperationContext,
|
||||
): AsyncGenerator<unknown, void, unknown> {
|
||||
const operation = registry.get(operationId);
|
||||
const spec = registry.getSpec(operationId);
|
||||
|
||||
if (!operation) {
|
||||
if (!spec) {
|
||||
throw new Error(`Operation not found: ${operationId}`);
|
||||
}
|
||||
|
||||
const handler = operation.handler;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user