// TODO find way to avoid any /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument */ import {isNotOccupiedByTransformableField} from '../../util/is-not-occupied-by-transformable-field.js'; import type {OneOfTransformableField} from '../class/decorator/one-of-transformable-field.js'; import {transformableFieldsMap} from '../class/decorator/transformable-fields-map.js'; import type {ValueTransformer} from './value-transformer.js'; import type {ValueTransformerDecorator} from './value-transformer-decorator.js'; export function createValueTransformerDecorator( transformer: ValueTransformer, ): ValueTransformerDecorator { return (prototype: any, key: any): any => { if (prototype === null && key === null) { return transformer; } console.assert(isNotOccupiedByTransformableField(prototype, key)); let transformers: OneOfTransformableField[] | undefined = transformableFieldsMap.get(prototype); if (transformers === undefined) { transformers = []; transformableFieldsMap.set(prototype, transformers); } transformers.push([key, transformer]); }; }