Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 00:00
    github-actions[bot] locked #733
  • 00:00
    github-actions[bot] commented #733
  • Jun 11 08:05

    dependabot[bot] on npm_and_yarn

    (compare)

  • Jun 11 08:05

    dependabot[bot] on develop

    build(deps-dev): bump rollup fr… (compare)

  • Jun 11 08:05
    dependabot[bot] closed #776
  • Jun 11 08:04
    dependabot[bot] edited #776
  • Jun 11 08:04
    typestack-ci commented #776
  • Jun 11 08:04
    dependabot[bot] labeled #776
  • Jun 11 08:04
    dependabot[bot] opened #776
  • Jun 11 08:04

    dependabot[bot] on npm_and_yarn

    build(deps-dev): bump rollup fr… (compare)

  • Jun 11 00:00
    github-actions[bot] locked #730
  • Jun 11 00:00
    github-actions[bot] commented #730
  • Jun 11 00:00
    github-actions[bot] locked #731
  • Jun 11 00:00
    github-actions[bot] commented #731
  • Jun 10 00:00
    github-actions[bot] locked #725
  • Jun 10 00:00
    github-actions[bot] commented #725
  • Jun 10 00:00
    github-actions[bot] locked #726
  • Jun 10 00:00
    github-actions[bot] commented #726
  • Jun 10 00:00
    github-actions[bot] locked #727
  • Jun 10 00:00
    github-actions[bot] commented #727
David Rojas Camaggi
@drojas
Hi,
Attila Oláh
@NoNameProvided
Hey
Jürgen Brandstetter
@BrandiATMuhkuh
I'm trying deserialize a Class I import from a package I have made. Sadly the decorators or so seem to be lost. Any inner objects are not deserialize correctly. But when I copy the Class into the project where I want to use it, the deserialization works fine. I'm guessing my tsconfig is incorrect. But I can't find the issue.
Peter Schrott
@peterschrott

Hi folks,
I am trying to use the @Transfrom()decoder from class-transformers in combination with routing-controllers to have automatic deserialization of JSON payload to TS class instances.
The thing is the 'transform-logic' in @Transform is not picked up. The function I am passing is not called at all. When I am testing it with plainToClass(Class, json) its working just fine.
Is this supposed to actually work and I just got my setup wrong?

Thanks for helping! Cheers

Peter Schrott
@peterschrott
@NoNameProvided , could you maybe give me some thoughts about that, or is it better to ask in the #routing-controllers group?
Brandon Faulkner
@bfaulk96
Hey all, I was looking at using this library and was curious if there is any significant performance cost associated with it?
Alex Plescan
@alexpls

Hello :wave:, are there any active maintainers of this package? We currently have our own fork of class-transformer, but would love to move back to mainline. All fixes which we needed have been merged into the develop branch, however a release which includes them hasn't been published to NPM yet (see typestack/class-transformer#236).

If there's anything I can do to help expedite a release, please let me know.

Alex Plescan
@alexpls
Howdy, any update on the above :point_up:?
Genhain
@Genhain

hi there i'm trying to serialise my class to post to our backend but its not using the specified name property of the @Expose decorator e.g

@Expose({ name: "start_at" })
startAt!: string

when i serialise it it remains as "startAt"

Genhain
@Genhain
I have been reading through the documentation and a few issues, i'm getting the inclination that this is expected behaviour?
Genhain
@Genhain
nevermind, i was using Realm to store the objects and in typescript those get returned as RealmObjects, once i turned it into the correct object it seriealised it correctly
Christoph Kuper
@ChristophKuper
hey, just wanna know if the projects class-transformer, class-validator are still alive ? seems like a lot of issues and PR are ignored.
Thiago Rodrigues
@xthiago
Hello @ChristophKuper, I have the same doubt.
@peterschrott what are the future perspectives of the project?
Jürgen Brandstetter
@BrandiATMuhkuh
Does anyone know of an alternative projects? We are using classTransformer all over the place in our codebase.
Thiago Rodrigues
@xthiago

@peterschrott what are the future perspectives of the project?

Ops. I mentioned the wrong person. Sorry for that.

Jonathas Morais
@jotamorais

Hello /all,

I can help with the project maintenance and move it forward, but I have limited daily/weekly availability.
I'd like your suggestions and inputs on how to approach the issues and PRs and what should be prioritized.

Also, I would like you to help with the roadmap so we can bring a stable and steady release cycle to the project.
I will not have much time to work on code itself, but I will make myself available for PR reviews, merges, release preparation and NPM publish, following whatever the community judge as a priority.

William Comartin
@wcomartin
Is this library still in development or at least supported? or is there an alternative I should be looking at?
Jonathas Morais
@jotamorais
Hi @wcomartin yes, it is still in development and we're catching up on support requests
William Comartin
@wcomartin
@jotamorais thank you, I do have a question about how this works, does it run the constructor of the class? can I set extra properties using the constructor? or is getter methods the convention to use?
also is there a way I can use Expose, Type, and Transform at the same time? I have a property I want to change the name and transform to momentjs
8 replies
RW-DiefBell
@RW-DiefBell
Does anyone know any obvious reasons why plainToClass would have suddenly just stopped working?
It was working fine up until the weekend and now it's acting like the decorators on my class properties don't even exist
The class:
export class TestPayrollReportMonthlyQuery extends QueryData
{
    /** Query Data **/
    @Expose({ name: "Employee Id" })
    "Employee ID" : string;

    "First Name" : string;

    @Type(() => Date)
    "Assignment Date" : Date; // string when I first get it, then can convert it to a Date object

    @Transform((projName, obj) => {
        obj["Project Code"] = projName.slice(0, 6);
        return projName;
    })
    "Project" : string;

    @Type(() => Date)
    "Assignment End Date" : Date;

    @Transform((startTime) => plainToClass(Time, startTime).toString())
    "Assignment Start Time" : string;

    /** Derived Data */
    "Project Code" : string;
}
Oof that a big code block, sorry
RW-DiefBell
@RW-DiefBell
And this is where it's instantiated:
public static async GetByName<T extends QueryData>(name: string, classType: new(args : any[]) => T): Promise<Query<T>>
{
    const resQuery = await Axios.post("https://api.peoplehr.net/Query", {
        APIKey: process.env.API_KEY,
        Action: "GetQueryResultByQueryName",
        QueryName: name
    });

    const queryData: any[] = resQuery.data["Result"];

    const queryDataInstances = plainToClass<T, any[]>(classType, queryData);
    debug(queryDataInstances[0]);
    return new Query(queryDataInstances);
}
RW-DiefBell
@RW-DiefBell
I've discovered that it's due to my class and the function that uses it being in separate libraries
So I'll try the workaround detailed here at some point: typestack/class-transformer#337
afdolriski
@afdolriski
Hi, i have question,
im trying to transform a nested object like this:
export class CustomerResponse {
  email: string;

  @Type(() => BookingResponse)
  public bookings: Booking[];

  constructor(partial: Partial<CustomerResponse>) {
    Object.assign(this, partial);
  }
}

export class BookingResponse {
  id: number;

  constructor(partial: Partial<BookingResponse>) {
    Object.assign(this, partial);
  }

  @Expose()
  get name() {
    return 'test';
  }
}
but the output didn't include the name property on BookingResponse
what am i doing wrong ? thanks in advance!!
Saulo S. Toledo
@saulotoledo
@afdolriski Is this what you are looking for? https://repl.it/@saulotoledo/SampleWithClassTransformer
If not, could you replicate your issue somewhere? You can use the link above as an example.
Nikhil
@m-nikhil

Hey all,

Doing planToClass conversation, I want to expose all fields ( don't want to explicitly mark for each field ) and also excludes the values which are not part of the class.

Tried the following -

  1. strategy: 'exposeAll' and excludeExtraneousValues: true but its results in {} empty.
  2. ExposeAll class decorator with excludeExtraneousValues: true. But again results in {} empty.

what's the way to achieve the behavior I need? Thanks

Nikhil
@m-nikhil

typestack/class-transformer#149

I find there is an issue to track. If there is no way to make it work yet, am willing to work on it :)

Charul Bari
@Charul090
Transform decorator doesn't work in the extended class. Any solution/suggestion for making transform work in extended class?
RW-DiefBell
@RW-DiefBell
@m-nikhil Have you put @Expose() for the whole class? That plus excludeExtraneousValues might work.
@Charul090 Is your base class in another library?
zak sesti
@greenreign
I have an object from an external API which uses snake_case as it's naming convention. I would like to map this object into my exposed API object which uses camelCase. Is there a way to map something like 'line_item' to 'lineItem'. It seems like @Expose does the opposite.
zak sesti
@greenreign
Or better yet is there a way to implement a generic Transform for the entire object to map from snake_case to camelCase?
iampervaze
@iampervaze
@afdolriski you Object.assign(this) statement within the constructor is I believe messing with the transformation when "class tranformer" tries to create an instance of your class. Try it by commenting out he object.assign statement.