feat(unified-callhandler): simplify CallHandler to delegate to registry.execute()
- Remove separate spec lookup, handler lookup, access control, and input validation from buildCallHandler - Call registry.execute() directly; access control enforced via execute() (trusted not set) - On error, look up spec for errorSchemas and pass to mapError() - Make callMap required in CallHandlerConfig (no longer optional) - Update tests: remove no-callMap tests, use callMap for all handler tests - Add test for mapError with spec errorSchemas - All 226 tests passing
This commit is contained in:
16
src/call.ts
16
src/call.ts
@@ -58,7 +58,7 @@ interface PendingRequest {
|
||||
|
||||
export interface CallHandlerConfig {
|
||||
registry: OperationRegistry;
|
||||
callMap?: PendingRequestMap;
|
||||
callMap: PendingRequestMap;
|
||||
}
|
||||
|
||||
export type CallHandler = (event: CallRequestedEvent) => Promise<void>;
|
||||
@@ -194,17 +194,11 @@ export function buildCallHandler(config: CallHandlerConfig): CallHandler {
|
||||
|
||||
try {
|
||||
const envelope = await registry.execute(operationId, input, context);
|
||||
|
||||
if (callMap) {
|
||||
callMap.respond(requestId, envelope);
|
||||
}
|
||||
callMap.respond(requestId, envelope);
|
||||
} catch (error) {
|
||||
const callError = mapError(error);
|
||||
if (callMap) {
|
||||
callMap.emitError(requestId, callError.code, callError.message, callError.details);
|
||||
} else {
|
||||
throw callError;
|
||||
}
|
||||
const spec = registry.getSpec(operationId);
|
||||
const callError = mapError(error, spec?.errorSchemas);
|
||||
callMap.emitError(requestId, callError.code, callError.message, callError.details);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user