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