@dugongjs/cli
Version:
29 lines (28 loc) • 1.12 kB
JavaScript
import { AggregateQueryClientProxyService } from "@dugongjs/nestjs-microservice-query";
import { ClientProxyFactory, Transport as NestJSTransport } from "@nestjs/microservices";
import { getCurrentContext } from "../config/context.js";
export function getAggregateQueryAdapter() {
const context = getCurrentContext();
if (!context) {
throw new Error("No current context configured. Use 'dugong config use-context <name>' to set a context.");
}
switch (context.adapter) {
case "nestjs-microservices":
const transportMap = {
tcp: NestJSTransport.TCP
};
const adapter = new AggregateQueryClientProxyService(ClientProxyFactory.create({
transport: transportMap[context.transport],
options: {
host: context.host,
port: context.port
}
}));
return {
adapter,
close: () => adapter.close()
};
default:
throw new Error(`Unknown adapter "${context.adapter}".`);
}
}