From 698faf1f02fe0337959f8992b7106f5fbbfabcd6 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Tue, 3 Dec 2024 10:37:59 +0000 Subject: [PATCH] feat: make the conditional order factory case insensitive (#225) --- src/composable/ConditionalOrderFactory.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/composable/ConditionalOrderFactory.ts b/src/composable/ConditionalOrderFactory.ts index 64c825d0..f03c22b6 100644 --- a/src/composable/ConditionalOrderFactory.ts +++ b/src/composable/ConditionalOrderFactory.ts @@ -4,17 +4,31 @@ import { ConditionalOrderParams } from './types' export type FromParams = (params: ConditionalOrderParams) => ConditionalOrder export type ConditionalOrderRegistry = Record> +/** + * Factory for conditional orders. + * + * It uses a registry to instantiate the correct conditional order based on the handler. + * + * Knowing the handler, the factory will instantiate the correct conditional order using the staticInput data. + */ export class ConditionalOrderFactory { public knownOrderTypes constructor(registry: ConditionalOrderRegistry) { - this.knownOrderTypes = registry + // Normalize the keys to lowercase + this.knownOrderTypes = Object.entries(registry).reduce((acc, [key, value]) => { + acc[key.toLowerCase()] = value + return acc + }, {}) } + /** + * Get the conditional order factory from the conditional order parameters + */ public fromParams(params: ConditionalOrderParams): ConditionalOrder | undefined { const { handler } = params - const factory = this.knownOrderTypes[handler] + const factory = this.knownOrderTypes[handler.toLocaleLowerCase()] if (!factory) { return undefined }