Tsed: [QUESTION] Changing IFilter to IPipe

Created on 28 Apr 2020  路  3Comments  路  Source: tsedio/tsed

I read docs and codes related. https://tsed.io/docs/filters.html

I couldn't found any alternatives of IFilter(we need to use req/res) you deprecated and ParseService as well.

Is there better way instead of using deprecated classes or anything I'm missing?

question

All 3 comments

The pipe feature exist but isn't documented actually. This is a hidden feature, until, I haven't finished to write official documentation and the official API. I'm sorry about the premature depreciation.

But if you want to use Pipe feature you can find many example, here:
https://github.com/TypedProject/tsed/tree/production/packages/common/src/mvc/pipes
The usePipe decorator to attach class to a param:
https://github.com/TypedProject/tsed/blob/production/packages/common/src/mvc/decorators/params/usePipe.ts
and useParam which use different pipes :
https://github.com/TypedProject/tsed/blob/production/packages/common/src/mvc/decorators/params/useParam.ts

The idea is to combine pipe (like angular with his pipes) and declare your own pipe.

Here an example decorator:

function UseCustomPipe (options: any) {
  return applyDecorators(
    UseParamType(ParamTypes.REQUEST), // we need to start from REQUEST (or RESPONSE)
    UsePipe(MyCustomPipe, options)
  );
}

And his pipe:

@Injectable()
export class MyCustomPipe implements IPipe {
  transform(value: any, param: ParamMetadata) {
    const options = param.store.get(MyCustomPipe)

    return "new value";
  }
}

You can use the pipe feature. The API is mature and stable. You're feedback are welcome :)

Pipe documentation is out :)

Thank you!! everything works well!!

Was this page helpful?
0 / 5 - 0 ratings