Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/adapter/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export class AdapterEndpoint<T extends EndpointGenerics> implements AdapterEndpo
this.customInputValidation = params.customInputValidation
this.customOutputValidation = params.customOutputValidation
this.overrides = params.overrides
this.requestTransforms = [this.symbolOverrider.bind(this), ...(params.requestTransforms || [])]
this.requestTransforms = [
this.symbolOverrider.bind(this),
this.normalizeInputCase.bind(this),
...(params.requestTransforms || []),
]
}

/**
Expand Down Expand Up @@ -147,6 +151,27 @@ export class AdapterEndpoint<T extends EndpointGenerics> implements AdapterEndpo
return req
}

/**
* Default request transform that normalizes base and quote input parameters to uppercase.
* Controlled by the NORMALIZE_CASE_INPUTS setting (default: true).
* This prevents subscription churn when the same asset is requested with different casings.
*/
normalizeInputCase(
req: AdapterRequest<TypeFromDefinition<T['Parameters']>>,
settings: T['Settings'],
): void {
if (!(settings as Record<string, unknown>)['NORMALIZE_CASE_INPUTS']) {
return
}
const data = req.requestContext.data as Record<string, unknown>
if (typeof data['base'] === 'string') {
data['base'] = data['base'].toUpperCase()
}
if (typeof data['quote'] === 'string') {
data['quote'] = data['quote'].toUpperCase()
}
}

getTransportNameForRequest(
req: AdapterRequest<TypeFromDefinition<T['Parameters']>>,
settings: T['Settings'],
Expand Down
6 changes: 6 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ export const BaseSettingsDefinition = {
'Whether to enable debug enpoints (/debug/*) for this adapter. Enabling them might consume more resources.',
default: false,
},
NORMALIZE_CASE_INPUTS: {
type: 'boolean',
description:
'When true, normalizes base and quote input parameters to uppercase before cache key computation and subscription registration. Set to false for adapters that require case-sensitive asset identifiers.',
default: true,
},
} as const satisfies SettingsDefinitionMap

export const buildAdapterSettings = <
Expand Down
Loading
Loading