mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
214 lines
5.0 KiB
TypeScript
214 lines
5.0 KiB
TypeScript
// Loaded from https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-11/nats-base-client/types.ts
|
|
|
|
|
|
/*
|
|
* Copyright 2020 The NATS Authors
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
//@ts-ignore
|
|
import { NatsError } from "./error.ts";
|
|
import type { MsgHdrs } from "./headers.ts";
|
|
import type { Authenticator } from "./authenticator.ts";
|
|
|
|
export const Empty = new Uint8Array(0);
|
|
|
|
export const Events = Object.freeze({
|
|
DISCONNECT: "disconnect",
|
|
RECONNECT: "reconnect",
|
|
UPDATE: "update",
|
|
LDM: "ldm",
|
|
});
|
|
|
|
export interface Status {
|
|
type: string;
|
|
data: string | ServersChanged;
|
|
}
|
|
|
|
export const DebugEvents = Object.freeze({
|
|
RECONNECTING: "reconnecting",
|
|
PING_TIMER: "pingTimer",
|
|
STALE_CONNECTION: "staleConnection",
|
|
});
|
|
|
|
export const DEFAULT_PORT = 4222;
|
|
export const DEFAULT_HOST = "127.0.0.1";
|
|
export const DEFAULT_HOSTPORT = `${DEFAULT_HOST}:${DEFAULT_PORT}`;
|
|
|
|
// DISCONNECT Parameters, 2 sec wait, 10 tries
|
|
export const DEFAULT_RECONNECT_TIME_WAIT = 2 * 1000;
|
|
export const DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
|
|
export const DEFAULT_JITTER = 100;
|
|
export const DEFAULT_JITTER_TLS = 1000;
|
|
|
|
// Ping interval
|
|
export const DEFAULT_PING_INTERVAL = 2 * 60 * 1000; // 2 minutes
|
|
export const DEFAULT_MAX_PING_OUT = 2;
|
|
|
|
export interface ConnectFn {
|
|
(opts: ConnectionOptions): Promise<NatsConnection>;
|
|
}
|
|
|
|
export interface NatsConnection {
|
|
info?: ServerInfo;
|
|
closed(): Promise<void | Error>;
|
|
close(): Promise<void>;
|
|
publish(subject: string, data?: Uint8Array, options?: PublishOptions): void;
|
|
subscribe(subject: string, opts?: SubscriptionOptions): Subscription;
|
|
request(
|
|
subject: string,
|
|
data?: Uint8Array,
|
|
opts?: RequestOptions,
|
|
): Promise<Msg>;
|
|
flush(): Promise<void>;
|
|
drain(): Promise<void>;
|
|
isClosed(): boolean;
|
|
isDraining(): boolean;
|
|
getServer(): string;
|
|
status(): AsyncIterable<Status>;
|
|
stats(): Stats;
|
|
}
|
|
|
|
export interface ConnectionOptions {
|
|
authenticator?: Authenticator;
|
|
debug?: boolean;
|
|
headers?: boolean;
|
|
maxPingOut?: number;
|
|
maxReconnectAttempts?: number;
|
|
name?: string;
|
|
noEcho?: boolean;
|
|
noRandomize?: boolean;
|
|
noResponders?: boolean;
|
|
pass?: string;
|
|
pedantic?: boolean;
|
|
pingInterval?: number;
|
|
port?: number;
|
|
reconnect?: boolean;
|
|
reconnectDelayHandler?: () => number;
|
|
reconnectJitter?: number;
|
|
reconnectJitterTLS?: number;
|
|
reconnectTimeWait?: number;
|
|
servers?: Array<string> | string;
|
|
timeout?: number;
|
|
tls?: TlsOptions;
|
|
token?: string;
|
|
user?: string;
|
|
verbose?: boolean;
|
|
waitOnFirstConnect?: boolean;
|
|
ignoreClusterUpdates?: boolean;
|
|
}
|
|
|
|
// these may not be supported on all environments
|
|
export interface TlsOptions {
|
|
certFile?: string;
|
|
caFile?: string;
|
|
keyFile?: string;
|
|
}
|
|
|
|
export interface Msg {
|
|
subject: string;
|
|
sid: number;
|
|
reply?: string;
|
|
data: Uint8Array;
|
|
headers?: MsgHdrs;
|
|
|
|
respond(data?: Uint8Array, opts?: PublishOptions): boolean;
|
|
}
|
|
|
|
export interface SubscriptionOptions {
|
|
queue?: string;
|
|
max?: number;
|
|
timeout?: number;
|
|
callback?: (err: NatsError | null, msg: Msg) => void;
|
|
}
|
|
|
|
export interface Base {
|
|
subject: string;
|
|
callback: (error: NatsError | null, msg: Msg) => void;
|
|
received: number;
|
|
timeout?: number | null;
|
|
max?: number | undefined;
|
|
draining: boolean;
|
|
}
|
|
|
|
export interface ServerInfo {
|
|
auth_required?: boolean;
|
|
client_id: number;
|
|
client_ip?: string;
|
|
connect_urls?: string[];
|
|
git_commit?: string;
|
|
go: string;
|
|
headers?: boolean;
|
|
host: string;
|
|
jetstream?: boolean;
|
|
ldm?: boolean;
|
|
max_payload: number;
|
|
nonce?: string;
|
|
port: number;
|
|
proto: number;
|
|
server_id: string;
|
|
server_name: string;
|
|
tls_available?: boolean;
|
|
tls_required?: boolean;
|
|
tls_verify?: boolean;
|
|
version: string;
|
|
}
|
|
|
|
export interface Server {
|
|
hostname: string;
|
|
port: number;
|
|
listen: string;
|
|
src: string;
|
|
tlsName: string;
|
|
}
|
|
|
|
export interface ServersChanged {
|
|
readonly added: string[];
|
|
readonly deleted: string[];
|
|
}
|
|
|
|
export interface Subscription extends AsyncIterable<Msg> {
|
|
unsubscribe(max?: number): void;
|
|
drain(): Promise<void>;
|
|
isDraining(): boolean;
|
|
isClosed(): boolean;
|
|
callback(err: NatsError | null, msg: Msg): void;
|
|
getSubject(): string;
|
|
getReceived(): number;
|
|
getProcessed(): number;
|
|
getPending(): number;
|
|
getID(): number;
|
|
getMax(): number | undefined;
|
|
}
|
|
|
|
export interface RequestOptions {
|
|
timeout: number;
|
|
headers?: MsgHdrs;
|
|
noMux?: boolean;
|
|
}
|
|
|
|
export interface PublishOptions {
|
|
reply?: string;
|
|
headers?: MsgHdrs;
|
|
}
|
|
|
|
export interface Stats {
|
|
inBytes: number;
|
|
outBytes: number;
|
|
inMsgs: number;
|
|
outMsgs: number;
|
|
}
|
|
|
|
export interface URLParseFn {
|
|
(u: string): string;
|
|
}
|