Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Consolidate Subscription type and remove Base interface #92

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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