swc/bundler/tests/.cache/untrusted/336df93c2a634a9f28c546dccbf769fdf6ffe950.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

216 lines
5.0 KiB
TypeScript

// Loaded from https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-rc4/nats-base-client/types.ts
/*
* Copyright 2020-2021 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.
*/
import { NatsError } from "./error.ts";
import type { MsgHdrs } from "./headers.ts";
import type { Authenticator } from "./authenticator.ts";
export const Empty = new Uint8Array(0);
export enum Events {
DISCONNECT = "disconnect",
RECONNECT = "reconnect",
UPDATE = "update",
LDM = "ldm",
ERROR = "error",
}
export interface Status {
type: Events | DebugEvents;
data: string | ServersChanged;
}
export enum DebugEvents {
RECONNECTING = "reconnecting",
PING_TIMER = "pingTimer",
STALE_CONNECTION = "staleConnection",
}
export const DEFAULT_PORT = 4222;
export const DEFAULT_HOST = "127.0.0.1";
// 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;
maxPingOut?: number;
maxReconnectAttempts?: number;
name?: string;
noEcho?: boolean;
noRandomize?: 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;
inboxPrefix?: string;
}
// these may not be supported on all environments
export interface TlsOptions {
certFile?: string;
cert?: string;
caFile?: string;
ca?: string;
keyFile?: string;
key?: 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;
reply?: string;
}
export interface PublishOptions {
reply?: string;
headers?: MsgHdrs;
}
export interface Stats {
inBytes: number;
outBytes: number;
inMsgs: number;
outMsgs: number;
}
export interface URLParseFn {
(u: string): string;
}