Skip to content

Commit

Permalink
Override meta.adapterName (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxiao-cll authored Oct 7, 2024
1 parent d3d41a2 commit fd8edd0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ const calculateKey = <T extends EndpointGenerics>({
return `${endpointName}-${transportName}-${paramsKey}`
}

export const calculateAdapterName = (
adapterName: string,
data: Record<string, unknown>,
): string => {
if (Object.keys(data).length === 0) {
logger.trace('Cannot generate Adapter Name without data, using default')
return adapterName
}

if (data && typeof data !== 'object') {
logger.trace('Cannot generate Adapter Name without valid data, using default')
return adapterName
}

if (data['adapterNameOverride'] && typeof data['adapterNameOverride'] === 'string') {
return data['adapterNameOverride'].toUpperCase()
} else {
return adapterName
}
}

export const calculateFeedId = <T extends EndpointGenerics>(
{
adapterSettings,
Expand Down
4 changes: 2 additions & 2 deletions src/cache/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TypeFromDefinition,
} from '../validation/input-params'
import { validator } from '../validation/utils'
import { Cache, calculateCacheKey, calculateFeedId } from './'
import { Cache, calculateCacheKey, calculateFeedId, calculateAdapterName } from './'
import * as cacheMetrics from './metrics'

const logger = makeLogger('ResponseCache')
Expand Down Expand Up @@ -99,7 +99,7 @@ export class ResponseCache<
this.adapterSettings.EXPERIMENTAL_METRICS_ENABLED
) {
response.meta = {
adapterName: this.adapterName,
adapterName: calculateAdapterName(this.adapterName, r.params),
metrics: {
feedId: calculateFeedId(
{
Expand Down

0 comments on commit fd8edd0

Please sign in to comment.