UNPKG

2.19 kBTypeScriptView Raw
1/**
2 * @see https://github.com/nats-io/nats.js
3 */
4export interface NatsCodec<T> {
5 encode(d: T): Uint8Array;
6 decode(a: Uint8Array): T;
7}
8interface RequestOptions {
9 timeout: number;
10 headers?: any;
11 noMux?: boolean;
12 reply?: string;
13}
14interface PublishOptions {
15 reply?: string;
16 headers?: any;
17}
18interface SubOpts<T> {
19 queue?: string;
20 max?: number;
21 timeout?: number;
22 callback?: (err: object | null, msg: T) => void;
23}
24declare type SubscriptionOptions = SubOpts<NatsMsg>;
25export interface NatsMsg {
26 subject: string;
27 sid: number;
28 reply?: string;
29 data: Uint8Array;
30 headers?: any;
31 respond(data?: Uint8Array, opts?: PublishOptions): boolean;
32}
33interface Sub<T> extends AsyncIterable<T> {
34 unsubscribe(max?: number): void;
35 drain(): Promise<void>;
36 isDraining(): boolean;
37 isClosed(): boolean;
38 callback(err: object | null, msg: NatsMsg): void;
39 getSubject(): string;
40 getReceived(): number;
41 getProcessed(): number;
42 getPending(): number;
43 getID(): number;
44 getMax(): number | undefined;
45}
46declare type Subscription = Sub<NatsMsg>;
47declare enum Events {
48 Disconnect = "disconnect",
49 Reconnect = "reconnect",
50 Update = "update",
51 LDM = "ldm",
52 Error = "error"
53}
54interface Status {
55 type: Events | DebugEvents;
56 data: string | number;
57}
58declare enum DebugEvents {
59 Reconnecting = "reconnecting",
60 PingTimer = "pingTimer",
61 StaleConnection = "staleConnection"
62}
63export declare class Client {
64 info?: Record<string, any>;
65 closed(): Promise<void | Error>;
66 close(): Promise<void>;
67 publish(subject: string, data?: Uint8Array, options?: PublishOptions): void;
68 subscribe(subject: string, opts?: SubscriptionOptions): Subscription;
69 request(subject: string, data?: Uint8Array, opts?: RequestOptions): Promise<NatsMsg>;
70 flush(): Promise<void>;
71 drain(): Promise<void>;
72 isClosed(): boolean;
73 isDraining(): boolean;
74 getServer(): string;
75 status(): AsyncIterable<Status>;
76 stats(): Record<string, any>;
77 jetstreamManager(opts?: Record<string, any>): Promise<any>;
78 jetstream(opts?: Record<string, any>): any;
79}
80export {};