From 6da85fd286b9aa06d6ce4ccc716d8b5104dbe0ce Mon Sep 17 00:00:00 2001 From: ankitsridhar16 Date: Fri, 20 Jan 2023 16:12:45 +0530 Subject: [PATCH] chore: updated types to def and changed deleted many as a new indexed type --- .../hoppscotch-backend/src/pubsub/pubsub.service.ts | 7 ++----- .../src/pubsub/subscriptionTopicsDefs.ts | 12 ++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/hoppscotch-backend/src/pubsub/pubsub.service.ts b/packages/hoppscotch-backend/src/pubsub/pubsub.service.ts index 854ef2e92..ba86342e1 100644 --- a/packages/hoppscotch-backend/src/pubsub/pubsub.service.ts +++ b/packages/hoppscotch-backend/src/pubsub/pubsub.service.ts @@ -4,7 +4,7 @@ import { default as Redis, RedisOptions } from 'ioredis'; import { RedisPubSub } from 'graphql-redis-subscriptions'; import { PubSub as LocalPubSub } from 'graphql-subscriptions'; -import { MessageType } from './subscriptionTopicsDefs'; +import { TopicDef } from './subscriptionTopicsDefs'; /** * RedisPubSub uses JSON parsing for back and forth conversion, which loses Date objects, hence this reviver brings them back @@ -71,10 +71,7 @@ export class PubSubService implements OnModuleInit { return this.pubsub.asyncIterator(topic, options); } - async publish( - topic: T, - payload: MessageType[T], - ) { + async publish(topic: T, payload: TopicDef[T]) { await this.pubsub.publish(topic, payload); } } diff --git a/packages/hoppscotch-backend/src/pubsub/subscriptionTopicsDefs.ts b/packages/hoppscotch-backend/src/pubsub/subscriptionTopicsDefs.ts index c860d55a4..4a1fbcb27 100644 --- a/packages/hoppscotch-backend/src/pubsub/subscriptionTopicsDefs.ts +++ b/packages/hoppscotch-backend/src/pubsub/subscriptionTopicsDefs.ts @@ -1,14 +1,10 @@ import { UserEnvironment } from '../user-environment/user-environments.model'; -import { PrimitiveTypes } from '../types/primitiveTypes'; // A custom message type that defines the topic and the corresponding payload. // For every module that publishes a subscription add its type def and the possible subscription type. -export type MessageType = { +export type TopicDef = { [ - topic: `user_environment/${string}/${ - | 'created' - | 'updated' - | 'deleted' - | 'deleted_many'}` - ]: UserEnvironment | PrimitiveTypes; // Returning a number hence having a union with `PrimitiveTypes`. + topic: `user_environment/${string}/${'created' | 'updated' | 'deleted'}` + ]: UserEnvironment; + [topic: `user_environment/${string}/deleted_many`]: number; };