Skip to content

Commit

Permalink
jsr nbc
Browse files Browse the repository at this point in the history
import type fixes
  • Loading branch information
aricart committed May 9, 2024
1 parent d375627 commit 9346c77
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 100 deletions.
5 changes: 2 additions & 3 deletions nats-base-client/authenticator.ts
Expand Up @@ -14,17 +14,16 @@
*/
import { nkeys } from "./nkeys.ts";
import { TD, TE } from "./encoders.ts";
import {
import type {
Auth,
Authenticator,
ErrorCode,
JwtAuth,
NatsError,
NKeyAuth,
NoAuth,
TokenAuth,
UserPass,
} from "./core.ts";
import { ErrorCode, NatsError } from "./core.ts";

export function multiAuthenticator(authenticators: Authenticator[]) {
return (nonce?: string): Auth => {
Expand Down
3 changes: 2 additions & 1 deletion nats-base-client/bench.ts
Expand Up @@ -17,7 +17,8 @@ import { Empty } from "./types.ts";
import { nuid } from "./nuid.ts";
import { deferred, Perf } from "./util.ts";
import type { NatsConnectionImpl } from "./nats.ts";
import { ErrorCode, NatsConnection, NatsError } from "./core.ts";
import { ErrorCode, NatsError } from "./core.ts";
import type { NatsConnection } from "./core.ts";

export class Metric {
name: string;
Expand Down
4 changes: 3 additions & 1 deletion nats-base-client/core.ts
Expand Up @@ -194,6 +194,8 @@ export class NatsError extends Error {
}
}

export type MsgCallback<T> = (err: NatsError | null, msg: T) => void;

/**
* Subscription Options
*/
Expand Down Expand Up @@ -221,7 +223,7 @@ export interface SubOpts<T> {
* @param err
* @param msg
*/
callback?: (err: NatsError | null, msg: T) => void;
callback?: MsgCallback<T>;
}

export interface DnsResolveFn {
Expand Down
9 changes: 6 additions & 3 deletions nats-base-client/deno.json
Expand Up @@ -2,12 +2,15 @@
"name": "@nats-io/nats-core",
"version": "3.0.0-1",
"exports": {
".": "./src/mod.ts"
".": "./mod.ts",
"./internal": "./internal_mod.ts"
},
"publish": {
"include": [
"./src/**/*",
"jsr.json"
"./**/*"
]
},
"imports": {
"jsr:@nats-io/nkeys": "jsr:@nats-io/nkeys@1.1.1-1"
}
}
6 changes: 3 additions & 3 deletions nats-base-client/encoders.ts
Expand Up @@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const Empty = new Uint8Array(0);
export const Empty: Uint8Array = new Uint8Array(0);

export const TE = new TextEncoder();
export const TD = new TextDecoder();
export const TE: TextEncoder = new TextEncoder();
export const TD: TextDecoder = new TextDecoder();

function concat(...bufs: Uint8Array[]): Uint8Array {
let max = 0;
Expand Down
7 changes: 4 additions & 3 deletions nats-base-client/headers.ts
Expand Up @@ -16,7 +16,8 @@
// Heavily inspired by Golang's https://golang.org/src/net/http/header.go

import { TD, TE } from "./encoders.ts";
import { ErrorCode, Match, MsgHdrs, NatsError } from "./core.ts";
import type { MsgHdrs } from "./core.ts";
import { ErrorCode, Match, NatsError } from "./core.ts";

// https://www.ietf.org/rfc/rfc822.txt
// 3.1.2. STRUCTURE OF HEADER FIELDS
Expand Down Expand Up @@ -82,7 +83,7 @@ export class MsgHdrsImpl implements MsgHdrs {
this.headers = new Map();
}

[Symbol.iterator]() {
[Symbol.iterator](): IterableIterator<[string, string[]]> {
return this.headers.entries();
}

Expand Down Expand Up @@ -276,7 +277,7 @@ export class MsgHdrsImpl implements MsgHdrs {
});
}

get hasError() {
get hasError(): boolean {
return this._code >= 300;
}

Expand Down
8 changes: 5 additions & 3 deletions nats-base-client/heartbeats.ts
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2024 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
Expand All @@ -12,9 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Deferred, deferred } from "./util.ts";

import { DebugEvents, Status } from "./core.ts";
import type { Deferred } from "./util.ts";
import { deferred } from "./util.ts";
import type { Status } from "./core.ts";
import { DebugEvents } from "./core.ts";

export interface PH {
flush(p?: Deferred<void>): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/ipparser.ts
Expand Up @@ -43,7 +43,7 @@ export function ipV4(a: number, b: number, c: number, d: number): Uint8Array {
return ip;
}

export function isIP(h: string) {
export function isIP(h: string): boolean {
return parseIP(h) !== undefined;
}

Expand Down
10 changes: 5 additions & 5 deletions nats-base-client/msg.ts
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 The NATS Authors
* Copyright 2020-2024 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
Expand All @@ -15,16 +15,16 @@
import { MsgHdrsImpl } from "./headers.ts";
import type { MsgArg } from "./parser.ts";
import { Empty, TD } from "./encoders.ts";
import { Codec, JSONCodec } from "./codec.ts";
import {
ErrorCode,
import type { Codec } from "./codec.ts";
import { JSONCodec } from "./codec.ts";
import type {
Msg,
MsgHdrs,
NatsError,
Publisher,
RequestInfo,
ReviverFn,
} from "./core.ts";
import { ErrorCode, NatsError } from "./core.ts";

export function isRequestError(msg: Msg): NatsError | null {
// NATS core only considers errors 503s on messages that have no payload
Expand Down
5 changes: 3 additions & 2 deletions nats-base-client/muxsubscription.ts
Expand Up @@ -13,7 +13,8 @@
* limitations under the License.
*/
import { isRequestError } from "./msg.ts";
import { createInbox, ErrorCode, Msg, NatsError, Request } from "./core.ts";
import type { Msg, MsgCallback, Request } from "./core.ts";
import { createInbox, ErrorCode, NatsError } from "./core.ts";

export class MuxSubscription {
baseInbox!: string;
Expand Down Expand Up @@ -82,7 +83,7 @@ export class MuxSubscription {
return false;
}

dispatcher() {
dispatcher(): MsgCallback<Msg> {
return (err: NatsError | null, m: Msg) => {
const token = this.getToken(m);
if (token) {
Expand Down
24 changes: 11 additions & 13 deletions nats-base-client/nats.ts
Expand Up @@ -18,30 +18,28 @@ import { ProtocolHandler, SubscriptionImpl } from "./protocol.ts";
import { Empty } from "./encoders.ts";
import { NatsError } from "./types.ts";

import type { SemVer } from "./semver.ts";
import { Features, parseSemVer } from "./semver.ts";
import type { Features, SemVer } from "./semver.ts";
import { parseSemVer } from "./semver.ts";

import { parseOptions } from "./options.ts";
import { QueuedIteratorImpl } from "./queued_iterator.ts";
import {
RequestMany,
RequestManyOptionsInternal,
RequestOne,
} from "./request.ts";
import { RequestMany, RequestOne } from "./request.ts";

import type { RequestManyOptionsInternal } from "./request.ts";

import { isRequestError } from "./msg.ts";
import {
import { createInbox, ErrorCode, RequestStrategy } from "./core.ts";

import type {
ConnectionOptions,
Context,
createInbox,
ErrorCode,
Msg,
NatsConnection,
Payload,
PublishOptions,
QueuedIterator,
RequestManyOptions,
RequestOptions,
RequestStrategy,
ServerInfo,
Stats,
Status,
Expand Down Expand Up @@ -115,14 +113,14 @@ export class NatsConnectionImpl implements NatsConnection {
this.protocol.publish(subject, data, options);
}

publishMessage(msg: Msg) {
publishMessage(msg: Msg): void {
return this.publish(msg.subject, msg.data, {
reply: msg.reply,
headers: msg.headers,
});
}

respondMessage(msg: Msg) {
respondMessage(msg: Msg): boolean {
if (msg.reply) {
this.publish(msg.reply, msg.data, {
reply: msg.reply,
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/nkeys.ts
@@ -1 +1 @@
export * as nkeys from "https://raw.githubusercontent.com/nats-io/nkeys.js/v1.0.4/modules/esm/mod.ts";
export * as nkeys from "jsr:@nats-io/nkeys";
10 changes: 2 additions & 8 deletions nats-base-client/options.ts
Expand Up @@ -15,20 +15,14 @@

import { extend } from "./util.ts";
import { defaultPort, getResolveFn } from "./transport.ts";
import { createInbox, ServerInfo } from "./core.ts";
import type { Authenticator, ConnectionOptions, ServerInfo } from "./core.ts";
import { createInbox, DEFAULT_HOST, ErrorCode, NatsError } from "./core.ts";
import {
multiAuthenticator,
noAuthFn,
tokenAuthenticator,
usernamePasswordAuthenticator,
} from "./authenticator.ts";
import {
Authenticator,
ConnectionOptions,
DEFAULT_HOST,
ErrorCode,
NatsError,
} from "./core.ts";

export const DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
export const DEFAULT_JITTER = 100;
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/parser.ts
Expand Up @@ -15,7 +15,7 @@
*/
import { DenoBuffer } from "./denobuffer.ts";
import { TD } from "./encoders.ts";
import { Dispatcher } from "./core.ts";
import type { Dispatcher } from "./core.ts";

export enum Kind {
OK,
Expand Down
40 changes: 19 additions & 21 deletions nats-base-client/protocol.ts
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 The NATS Authors
* Copyright 2018-2024 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
Expand All @@ -13,38 +13,35 @@
* limitations under the License.
*/
import { decode, Empty, encode, TE } from "./encoders.ts";
import {
CR_LF,
CRLF,
getResolveFn,
newTransport,
Transport,
} from "./transport.ts";
import { Deferred, deferred, delay, extend, Timeout, timeout } from "./util.ts";
import { CR_LF, CRLF, getResolveFn, newTransport } from "./transport.ts";
import type { Transport } from "./transport.ts";
import { deferred, delay, extend, timeout } from "./util.ts";
import type { Deferred, Timeout } from "./util.ts";
import { DataBuffer } from "./databuffer.ts";
import { ServerImpl, Servers } from "./servers.ts";
import {
import { Servers } from "./servers.ts";
import type { ServerImpl } from "./servers.ts";
import type {
DispatchedFn,
IngestionFilterFn,
IngestionFilterFnResult,
ProtocolFilterFn,
QueuedIteratorImpl,
} from "./queued_iterator.ts";
import { QueuedIteratorImpl } from "./queued_iterator.ts";
import type { MsgHdrsImpl } from "./headers.ts";
import { MuxSubscription } from "./muxsubscription.ts";
import { Heartbeat, PH } from "./heartbeats.ts";
import { Kind, MsgArg, Parser, ParserEvent } from "./parser.ts";
import { Heartbeat } from "./heartbeats.ts";
import type { PH } from "./heartbeats.ts";
import type { MsgArg, ParserEvent } from "./parser.ts";
import { Kind, Parser } from "./parser.ts";
import { MsgImpl } from "./msg.ts";
import { Features, parseSemVer } from "./semver.ts";
import {
import { DebugEvents, ErrorCode, Events, NatsError } from "./core.ts";

import type {
Base,
ConnectionOptions,
DebugEvents,
Dispatcher,
ErrorCode,
Events,
Msg,
NatsError,
Payload,
Publisher,
PublishOptions,
Expand All @@ -56,6 +53,7 @@ import {
Subscription,
SubscriptionOptions,
} from "./core.ts";

import {
DEFAULT_MAX_PING_OUT,
DEFAULT_PING_INTERVAL,
Expand Down Expand Up @@ -691,7 +689,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
return h;
}

static toError(s: string) {
static toError(s: string): NatsError {
const t = s ? s.toLowerCase() : "";
if (t.indexOf("permissions violation") !== -1) {
const err = new NatsError(s, ErrorCode.PermissionsViolation);
Expand Down Expand Up @@ -964,7 +962,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
}
}

_subunsub(s: SubscriptionImpl) {
_subunsub(s: SubscriptionImpl): SubscriptionImpl {
this._sub(s);
if (s.max) {
this.unsubscribe(s, s.max);
Expand Down
8 changes: 5 additions & 3 deletions nats-base-client/queued_iterator.ts
Expand Up @@ -12,8 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Deferred, deferred } from "./util.ts";
import { ErrorCode, NatsError, QueuedIterator } from "./core.ts";
import type { Deferred } from "./util.ts";
import { deferred } from "./util.ts";
import type { QueuedIterator } from "./core.ts";
import { ErrorCode, NatsError } from "./core.ts";

export type IngestionFilterFnResult = { ingest: boolean; protocol: boolean };

Expand Down Expand Up @@ -83,7 +85,7 @@ export class QueuedIteratorImpl<T> implements QueuedIterator<T> {
this.yielding = false;
}

[Symbol.asyncIterator]() {
[Symbol.asyncIterator](): AsyncIterator<T> {
return this.iterate();
}

Expand Down

0 comments on commit 9346c77

Please sign in to comment.