* Runs the middlewares over params before executing a request * @param internalParams * @returns
(internalParams: InternalRequestParams)
| 915 | * @returns |
| 916 | */ |
| 917 | _request(internalParams: InternalRequestParams): Promise<any> { |
| 918 | // this is the otel context that is active at the callsite |
| 919 | internalParams.otelParentCtx = this._tracingHelper.getActiveContext() |
| 920 | const middlewareArgsMapper = internalParams.middlewareArgsMapper ?? noopMiddlewareArgsMapper |
| 921 | |
| 922 | // make sure that we don't leak extra properties to users |
| 923 | const params: QueryMiddlewareParams = { |
| 924 | args: middlewareArgsMapper.requestArgsToMiddlewareArgs(internalParams.args), |
| 925 | dataPath: internalParams.dataPath, |
| 926 | runInTransaction: Boolean(internalParams.transaction), |
| 927 | action: internalParams.action, |
| 928 | model: internalParams.model, |
| 929 | } |
| 930 | |
| 931 | // span options for opentelemetry instrumentation |
| 932 | const spanOptions = { |
| 933 | operation: { |
| 934 | name: 'operation', |
| 935 | attributes: { |
| 936 | method: params.action, |
| 937 | model: params.model, |
| 938 | name: params.model ? `${params.model}.${params.action}` : params.action, |
| 939 | }, |
| 940 | } as ExtendedSpanOptions, |
| 941 | } |
| 942 | |
| 943 | // prepare recursive fn that will pipe params through middlewares |
| 944 | const consumer = async (changedMiddlewareParams: QueryMiddlewareParams) => { |
| 945 | // we proceed with request execution |
| 946 | // before we send the execution request, we use the changed params |
| 947 | const { runInTransaction, args, ...changedRequestParams } = changedMiddlewareParams |
| 948 | const requestParams = { |
| 949 | ...internalParams, |
| 950 | ...changedRequestParams, |
| 951 | } |
| 952 | |
| 953 | if (args) { |
| 954 | requestParams.args = middlewareArgsMapper.middlewareArgsToRequestArgs(args) |
| 955 | } |
| 956 | |
| 957 | // if middleware switched off `runInTransaction`, unset `transaction` |
| 958 | // property on request as well so it will be executed outside of the tx |
| 959 | if (internalParams.transaction !== undefined && runInTransaction === false) { |
| 960 | delete requestParams.transaction // client extensions check for this |
| 961 | } |
| 962 | |
| 963 | const result = await applyQueryExtensions(this, requestParams) // also executes the query |
| 964 | if (!requestParams.model) { |
| 965 | return result |
| 966 | } |
| 967 | |
| 968 | const extensionContext = resolveResultExtensionContext({ |
| 969 | dataPath: requestParams.dataPath, |
| 970 | modelName: requestParams.model, |
| 971 | args: requestParams.args, |
| 972 | runtimeDataModel: this._runtimeDataModel, |
| 973 | }) |
| 974 |
no test coverage detected