Skip to content

Commit

Permalink
refactor(core): Consolidate Subscription type and remove Base interface
Browse files Browse the repository at this point in the history
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 <alberto@synadia.com>
  • Loading branch information
aricart committed Oct 21, 2024
1 parent a973855 commit f48ba72
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 22 deletions.
18 changes: 2 additions & 16 deletions core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,6 @@ export interface ServersChanged {
readonly deleted: string[];
}

/**
* Type alias for NATS core subscriptions
*/
export type Subscription = Sub<Msg>;

export enum Match {
// Exact option is case sensitive
Exact = 0,
Expand Down Expand Up @@ -696,7 +691,7 @@ export function syncIterator<T>(src: AsyncIterable<T>): SyncIterator<T> {
/**
* Basic interface to a Subscription type
*/
export interface Sub<T> extends AsyncIterable<T> {
export interface Subscription extends AsyncIterable<Msg> {
/** A promise that resolves when the subscription closes */
closed: Promise<void>;

Expand Down Expand Up @@ -729,7 +724,7 @@ export interface Sub<T> extends AsyncIterable<T> {
/**
* @ignore
*/
callback(err: NatsError | null, msg: Msg): void;
callback: MsgCallback<Msg>;

/**
* Returns the subject that was used to create the subscription.
Expand Down Expand Up @@ -1088,15 +1083,6 @@ export const DEFAULT_HOST = "127.0.0.1";

export type ConnectFn = (opts: ConnectionOptions) => Promise<NatsConnection>;

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;
}
Expand Down
1 change: 0 additions & 1 deletion core/src/internal_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export type {
ServersChanged,
Stats,
Status,
Sub,
SubOpts,
Subscription,
SubscriptionOptions,
Expand Down
1 change: 0 additions & 1 deletion core/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export type {
ServersChanged,
Stats,
Status,
Sub,
SubOpts,
Subscription,
SubscriptionOptions,
Expand Down
3 changes: 1 addition & 2 deletions core/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { Features, parseSemVer } from "./semver.ts";
import { DebugEvents, ErrorCode, Events, NatsError } from "./core.ts";

import type {
Base,
ConnectionOptions,
Dispatcher,
Msg,
Expand Down Expand Up @@ -101,7 +100,7 @@ export class Connect {
}

export class SubscriptionImpl extends QueuedIteratorImpl<Msg>
implements Base, Subscription {
implements Subscription {
sid!: number;
queue?: string;
draining: boolean;
Expand Down
4 changes: 2 additions & 2 deletions services/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
PublishOptions,
QueuedIterator,
ReviverFn,
Sub,
Subscription,
} from "@nats-io/nats-core/internal";

import {
Expand Down Expand Up @@ -239,7 +239,7 @@ type ServiceSubscription<T = unknown> =
& NamedEndpoint
& {
internal: boolean;
sub: Sub<T>;
sub: Subscription;
qi?: QueuedIterator<T>;
stats: NamedEndpointStatsImpl;
metadata?: Record<string, string>;
Expand Down

0 comments on commit f48ba72

Please sign in to comment.