Skip to content

feature: Provide "alias" decorator #677

Closed
@aaleksandrov

Description

@aaleksandrov

Description

I'd like to propose adding a new field decorator @Alias
In nutshell it's similar to Mongoose alias : while running instanceToPlain properties which have @Alias({name: "abc"}) decorator are exposed with an alternative property name.
Reverse logic should be applied when running plainToInstance

example:

        class User {
            @Alias({ name: 'fn'})
            firstName: string;
        }

        const instance = new User();
        instance.firstName = 'Alex';

        const plain = instanceToPlain(instance, {
            useAliases: true,
        });

        expect(plain.firstName).toEqual(undefined);
        expect(plain.fn).toEqual('Alex');

A use case I have in my company: we store JSON objects in DynamoDB, these JSON objects are usually 3-5 KB and have pretty long property names. Amazon charges for each 1 KB written so would be amazing if we could shorten property names in a centralized way and save some cost.

Proposed solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions