2020-12-17 11:38:21 +00:00
|
|
|
import type { RenderedGrpcRequest, RenderedGrpcRequestBody } from '../../common/render';
|
|
|
|
import {
|
|
|
|
getRenderedGrpcRequest,
|
|
|
|
getRenderedGrpcRequestMessage,
|
|
|
|
RENDER_PURPOSE_SEND,
|
|
|
|
} from '../../common/render';
|
2021-07-22 23:04:56 +00:00
|
|
|
import * as models from '../../models';
|
|
|
|
import type { GrpcMethodType } from './method';
|
2020-12-17 11:38:21 +00:00
|
|
|
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 request = await getRenderedGrpcRequest(
|
2021-07-26 00:49:34 +00:00
|
|
|
{
|
|
|
|
// @ts-expect-error -- TSCONVERSION req can be null but should not try to render if it is null
|
|
|
|
request: req,
|
|
|
|
environmentId,
|
|
|
|
purpose: RENDER_PURPOSE_SEND,
|
|
|
|
skipBody: canClientStream(methodType),
|
|
|
|
},
|
2020-12-17 11:38:21 +00:00
|
|
|
);
|
2021-07-26 00:49:34 +00:00
|
|
|
|
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);
|
2021-07-26 00:49:34 +00:00
|
|
|
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
|
2021-07-26 00:49:34 +00:00
|
|
|
request: req,
|
|
|
|
environmentId,
|
|
|
|
purpose: RENDER_PURPOSE_SEND,
|
|
|
|
},
|
2020-12-17 11:38:21 +00:00
|
|
|
);
|
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
|
|
|
};
|