2020-12-17 11:38:21 +00:00
|
|
|
import type { RenderedGrpcRequest, RenderedGrpcRequestBody } from '../../common/render';
|
|
|
|
import type { GrpcMethodType } from './method';
|
|
|
|
import * as models from '../../models';
|
|
|
|
import {
|
|
|
|
getRenderedGrpcRequest,
|
|
|
|
getRenderedGrpcRequestMessage,
|
|
|
|
RENDER_PURPOSE_SEND,
|
|
|
|
} from '../../common/render';
|
|
|
|
import { canClientStream } from './method';
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export interface GrpcIpcRequestParams {
|
|
|
|
request: RenderedGrpcRequest;
|
|
|
|
}
|
2020-12-17 11:38:21 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export interface GrpcIpcMessageParams {
|
|
|
|
requestId: string;
|
|
|
|
body: RenderedGrpcRequestBody;
|
|
|
|
}
|
2020-12-17 11:38:21 +00:00
|
|
|
|
|
|
|
export const prepareGrpcRequest = async (
|
|
|
|
requestId: string,
|
|
|
|
environmentId: string,
|
|
|
|
methodType: GrpcMethodType,
|
|
|
|
): Promise<GrpcIpcRequestParams> => {
|
|
|
|
const req = await models.grpcRequest.getById(requestId);
|
|
|
|
const environment = await models.environment.getById(environmentId || 'n/a');
|
|
|
|
const request = await getRenderedGrpcRequest(
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION req can be null but should not try to render if it is null
|
2020-12-17 11:38:21 +00:00
|
|
|
req,
|
|
|
|
environment,
|
|
|
|
RENDER_PURPOSE_SEND,
|
|
|
|
{},
|
|
|
|
canClientStream(methodType),
|
|
|
|
);
|
2021-05-12 06:35:00 +00:00
|
|
|
return {
|
|
|
|
request,
|
|
|
|
};
|
2020-12-17 11:38:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const prepareGrpcMessage = async (
|
|
|
|
requestId: string,
|
|
|
|
environmentId: string,
|
|
|
|
): Promise<GrpcIpcMessageParams> => {
|
|
|
|
const req = await models.grpcRequest.getById(requestId);
|
|
|
|
const environment = await models.environment.getById(environmentId || 'n/a');
|
|
|
|
const requestBody = await getRenderedGrpcRequestMessage(
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION req can be null but should not try to render if it is null
|
2020-12-17 11:38:21 +00:00
|
|
|
req,
|
|
|
|
environment,
|
|
|
|
RENDER_PURPOSE_SEND,
|
|
|
|
{},
|
|
|
|
);
|
2021-05-12 06:35:00 +00:00
|
|
|
return {
|
|
|
|
body: requestBody,
|
|
|
|
// @ts-expect-error -- TSCONVERSION req can be null
|
|
|
|
requestId: req._id,
|
|
|
|
};
|
2020-12-17 11:38:21 +00:00
|
|
|
};
|