From f48ba72899e6585e65afcbadaeb7789a7d9f2e99 Mon Sep 17 00:00:00 2001 From: Alberto Ricart Date: Mon, 21 Oct 2024 11:44:41 -0500 Subject: [PATCH] refactor(core): Consolidate Subscription type and remove Base interface Replaced Sub type alias with Subscription and merged its properties into Subscription interface. Removed the unnecessary Base interface, simplifying the codebase and reducing redundancy. Signed-off-by: Alberto Ricart --- core/src/core.ts | 18 ++---------------- core/src/internal_mod.ts | 1 - core/src/mod.ts | 1 - core/src/protocol.ts | 3 +-- services/src/service.ts | 4 ++-- 5 files changed, 5 insertions(+), 22 deletions(-) diff --git a/core/src/core.ts b/core/src/core.ts index f062e5b9..4878511b 100644 --- a/core/src/core.ts +++ b/core/src/core.ts @@ -359,11 +359,6 @@ export interface ServersChanged { readonly deleted: string[]; } -/** - * Type alias for NATS core subscriptions - */ -export type Subscription = Sub; - export enum Match { // Exact option is case sensitive Exact = 0, @@ -696,7 +691,7 @@ export function syncIterator(src: AsyncIterable): SyncIterator { /** * Basic interface to a Subscription type */ -export interface Sub extends AsyncIterable { +export interface Subscription extends AsyncIterable { /** A promise that resolves when the subscription closes */ closed: Promise; @@ -729,7 +724,7 @@ export interface Sub extends AsyncIterable { /** * @ignore */ - callback(err: NatsError | null, msg: Msg): void; + callback: MsgCallback; /** * Returns the subject that was used to create the subscription. @@ -1088,15 +1083,6 @@ export const DEFAULT_HOST = "127.0.0.1"; export type ConnectFn = (opts: ConnectionOptions) => Promise; -export interface Base { - subject: string; - callback: (error: NatsError | null, msg: Msg) => void; - received: number; - timeout?: number | null; - max?: number | undefined; - draining: boolean; -} - export interface URLParseFn { (u: string, encrypted?: boolean): string; } diff --git a/core/src/internal_mod.ts b/core/src/internal_mod.ts index 8520ac61..8d801642 100644 --- a/core/src/internal_mod.ts +++ b/core/src/internal_mod.ts @@ -108,7 +108,6 @@ export type { ServersChanged, Stats, Status, - Sub, SubOpts, Subscription, SubscriptionOptions, diff --git a/core/src/mod.ts b/core/src/mod.ts index e5a48bdb..70986628 100644 --- a/core/src/mod.ts +++ b/core/src/mod.ts @@ -76,7 +76,6 @@ export type { ServersChanged, Stats, Status, - Sub, SubOpts, Subscription, SubscriptionOptions, diff --git a/core/src/protocol.ts b/core/src/protocol.ts index 9ff71397..8d96ffff 100644 --- a/core/src/protocol.ts +++ b/core/src/protocol.ts @@ -32,7 +32,6 @@ import { Features, parseSemVer } from "./semver.ts"; import { DebugEvents, ErrorCode, Events, NatsError } from "./core.ts"; import type { - Base, ConnectionOptions, Dispatcher, Msg, @@ -101,7 +100,7 @@ export class Connect { } export class SubscriptionImpl extends QueuedIteratorImpl - implements Base, Subscription { + implements Subscription { sid!: number; queue?: string; draining: boolean; diff --git a/services/src/service.ts b/services/src/service.ts index fb6036e3..3ddd1814 100644 --- a/services/src/service.ts +++ b/services/src/service.ts @@ -32,7 +32,7 @@ import type { PublishOptions, QueuedIterator, ReviverFn, - Sub, + Subscription, } from "@nats-io/nats-core/internal"; import { @@ -239,7 +239,7 @@ type ServiceSubscription = & NamedEndpoint & { internal: boolean; - sub: Sub; + sub: Subscription; qi?: QueuedIterator; stats: NamedEndpointStatsImpl; metadata?: Record;