Skip to content

x-utils 1.0.0

Install from the command line:
Learn more about npm packages
$ npm install @polyflix/x-utils@1.0.0
Install via package.json:
"@polyflix/x-utils": "1.0.0"

About this version

X Utils

Install

Install the package with the following command :

npm i @polyflix/x-utils

How to use

This module expose some utilities

Decorators

Get user roles

 get(@IsAdmin(): isAdmin: boolean) {}

 get(@MeRoles(): roles: Role[]) {}

 get(@MeRoles("Admin"): roles: Role[]) {}

Get user id

 get(@MeId(): me: string) {}

Guards

Allow only specific roles on a route

@Roles(Role.Admin, Role.Contributor)

Kafka

Create kafka modules

@Global()
@Module({
    imports: [
        KafkaModule.register({
            useFactory: (configService: ConfigService) => {
                return kafkaConfig(configService.get("kafka"));
            },
            inject: [ConfigService]
        })
    ],
    exports: [KafkaModule]
})

Use kafka client

constructor(
    @InjectKafkaClient() private readonly kafkaClient: ClientKafka,
) {}

Kafka message

export interface PolyflixKafkaMessage {
  key: string;
  value: {
    trigger: TriggerType;
    payload: any;
  };
}

export interface PolyflixKafkaValue {
  trigger: TriggerType;
  payload: any;
}


this.kafkaClient.emit<string, PolyflixKafkaMessage>(topic, {
  key: video.slug,
  value: {
    trigger: TriggerType.PROCESSING,
    payload: video
  },
});


@EventPattern("polyflix.legacy.video")
video(@Payload("value") message: PolyflixKafkaValue) {
  // TODO
}

MinIO

MinIoMessageValue match to the payload of an MinIO event in kafka

@EventPattern("minio.upload")
async process(@Payload("value") message: MinIOMessageValue) { }

Details


Assets

  • x-utils-1.0.0.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all