@nats-io/nats-core
Advanced tools
Comparing version 3.0.0-31 to 3.0.0-32
@@ -98,3 +98,3 @@ "use strict"; | ||
if (!this.pub && !this.sub && !this.req && !this.rep) { | ||
throw new Error("no bench option selected"); | ||
throw new Error("no options selected"); | ||
} | ||
@@ -106,3 +106,3 @@ } | ||
if (err) { | ||
throw new Error(`bench closed with an error`, { cause: err }); | ||
throw err; | ||
} | ||
@@ -109,0 +109,0 @@ }); |
@@ -87,3 +87,3 @@ "use strict"; | ||
if (typeof prefix !== "string") { | ||
throw (new Error("prefix must be a string")); | ||
throw (new TypeError("prefix must be a string")); | ||
} | ||
@@ -93,3 +93,3 @@ prefix.split(".") | ||
if (v === "*" || v === ">") { | ||
throw errors_1.InvalidOptionError.illegalArgument("prefix", `cannot have wildcards ('${prefix}')`); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.InvalidArgumentError.format("prefix", `cannot have wildcards ('${prefix}')`)); | ||
} | ||
@@ -96,0 +96,0 @@ }); |
@@ -0,16 +1,36 @@ | ||
/** | ||
* Represents an error that is thrown when an invalid subject is encountered. | ||
* This class extends the built-in Error object. | ||
* | ||
* @class | ||
* @extends Error | ||
*/ | ||
export declare class InvalidSubjectError extends Error { | ||
constructor(subject: string, options?: ErrorOptions); | ||
} | ||
export declare class InvalidHeaderError extends Error { | ||
export declare class InvalidArgumentError extends Error { | ||
constructor(message: string, options?: ErrorOptions); | ||
static format(name: string, message: string): string; | ||
static formatMultiple(names: string[], message: string): string; | ||
} | ||
export declare class InvalidOptionError extends Error { | ||
constructor(message: string, options?: ErrorOptions); | ||
static exclusiveOptions(opts: string[]): InvalidOptionError; | ||
static illegalArgument(name: string, message: string): InvalidOptionError; | ||
static illegalOption(prop: string, message: string): InvalidOptionError; | ||
} | ||
/** | ||
* InvalidOperationError is a custom error class that extends the standard Error object. | ||
* It represents an error that occurs when an invalid operation is attempted on one of | ||
* objects returned by the API. For example, trying to iterate on an object that was | ||
* configured with a callback. | ||
* | ||
* @class InvalidOperationError | ||
* @extends {Error} | ||
* | ||
* @param {string} message - The error message that explains the reason for the error. | ||
* @param {ErrorOptions} [options] - Optional parameter to provide additional error options. | ||
*/ | ||
export declare class InvalidOperationError extends Error { | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Represents an error indicating that user authentication has expired. | ||
* This error is typically thrown when a user attempts to access a connection | ||
* but their authentication credentials have expired. | ||
*/ | ||
export declare class UserAuthenticationExpiredError extends Error { | ||
@@ -20,2 +40,8 @@ constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Represents an error related to authorization issues. | ||
* Note that these could represent an authorization violation, | ||
* or that the account authentication configuration has expired, | ||
* or an authentication timeout. | ||
*/ | ||
export declare class AuthorizationError extends Error { | ||
@@ -25,20 +51,78 @@ constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Class representing an error thrown when an operation is attempted on a closed connection. | ||
* | ||
* This error is intended to signal that a connection-related operation could not be completed | ||
* because the connection is no longer open or has been terminated. | ||
* | ||
* @class | ||
* @extends Error | ||
*/ | ||
export declare class ClosedConnectionError extends Error { | ||
constructor(); | ||
} | ||
export declare class ConnectionDrainingError extends Error { | ||
/** | ||
* The `ConnectionDrainingError` class represents a specific type of error | ||
* that occurs when a connection is being drained. | ||
* | ||
* This error is typically used in scenarios where connections need to be | ||
* gracefully closed or when they are transitioning to an inactive state. | ||
* | ||
* The error message is set to "connection draining" and the error name is | ||
* overridden to "DrainingConnectionError". | ||
*/ | ||
export declare class DrainingConnectionError extends Error { | ||
constructor(); | ||
} | ||
/** | ||
* Represents an error that occurs when a network connection fails. | ||
* Extends the built-in Error class to provide additional context for connection-related issues. | ||
* | ||
* @param {string} message - A human-readable description of the error. | ||
* @param {ErrorOptions} [options] - Optional settings for customizing the error behavior. | ||
*/ | ||
export declare class ConnectionError extends Error { | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Represents an error encountered during protocol operations. | ||
* This class extends the built-in `Error` class, providing a specific | ||
* error type called `ProtocolError`. | ||
* | ||
* @param {string} message - A descriptive message describing the error. | ||
* @param {ErrorOptions} [options] - Optional parameters to include additional details. | ||
*/ | ||
export declare class ProtocolError extends Error { | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Class representing an error that occurs during an request operation | ||
* (such as TimeoutError, or NoRespondersError, or some other error). | ||
* | ||
* @extends Error | ||
*/ | ||
export declare class RequestError extends Error { | ||
constructor(message?: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* TimeoutError is a custom error class that extends the built-in Error class. | ||
* It is used to represent an error that occurs when an operation exceeds a | ||
* predefined time limit. | ||
* | ||
* @class | ||
* @extends {Error} | ||
*/ | ||
export declare class TimeoutError extends Error { | ||
constructor(options?: ErrorOptions); | ||
} | ||
/** | ||
* NoRespondersError is an error thrown when no responders (no service is | ||
* subscribing to the subject) are found for a given subject. This error | ||
* is typically found as the cause for a RequestError | ||
* | ||
* @extends Error | ||
* | ||
* @param {string} subject - The subject for which no responders were found. | ||
* @param {ErrorOptions} [options] - Optional error options. | ||
*/ | ||
export declare class NoRespondersError extends Error { | ||
@@ -48,5 +132,9 @@ subject: string; | ||
} | ||
export declare class ServerError extends Error { | ||
constructor(message: string, options?: ErrorOptions); | ||
} | ||
/** | ||
* Class representing a Permission Violation Error. | ||
* It provides information about the operation (either "publish" or "subscription") | ||
* and the subject used for the operation and the optional queue (if a subscription). | ||
* | ||
* This error is terminal for a subscription. | ||
*/ | ||
export declare class PermissionViolationError extends Error { | ||
@@ -59,1 +147,16 @@ operation: "publish" | "subscription"; | ||
} | ||
export declare const errors: { | ||
AuthorizationError: typeof AuthorizationError; | ||
ClosedConnectionError: typeof ClosedConnectionError; | ||
ConnectionError: typeof ConnectionError; | ||
DrainingConnectionError: typeof DrainingConnectionError; | ||
InvalidArgumentError: typeof InvalidArgumentError; | ||
InvalidOperationError: typeof InvalidOperationError; | ||
InvalidSubjectError: typeof InvalidSubjectError; | ||
NoRespondersError: typeof NoRespondersError; | ||
PermissionViolationError: typeof PermissionViolationError; | ||
ProtocolError: typeof ProtocolError; | ||
RequestError: typeof RequestError; | ||
TimeoutError: typeof TimeoutError; | ||
UserAuthenticationExpiredError: typeof UserAuthenticationExpiredError; | ||
}; |
@@ -17,3 +17,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PermissionViolationError = exports.ServerError = exports.NoRespondersError = exports.TimeoutError = exports.RequestError = exports.ProtocolError = exports.ConnectionError = exports.ConnectionDrainingError = exports.ClosedConnectionError = exports.AuthorizationError = exports.UserAuthenticationExpiredError = exports.InvalidOperationError = exports.InvalidOptionError = exports.InvalidHeaderError = exports.InvalidSubjectError = void 0; | ||
exports.errors = exports.PermissionViolationError = exports.NoRespondersError = exports.TimeoutError = exports.RequestError = exports.ProtocolError = exports.ConnectionError = exports.DrainingConnectionError = exports.ClosedConnectionError = exports.AuthorizationError = exports.UserAuthenticationExpiredError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.InvalidSubjectError = void 0; | ||
/** | ||
* Represents an error that is thrown when an invalid subject is encountered. | ||
* This class extends the built-in Error object. | ||
* | ||
* @class | ||
* @extends Error | ||
*/ | ||
class InvalidSubjectError extends Error { | ||
@@ -26,26 +33,28 @@ constructor(subject, options) { | ||
exports.InvalidSubjectError = InvalidSubjectError; | ||
class InvalidHeaderError extends Error { | ||
class InvalidArgumentError extends Error { | ||
constructor(message, options) { | ||
super(`invalid header: ${message}`, options); | ||
this.name = "InvalidHeaderError"; | ||
} | ||
} | ||
exports.InvalidHeaderError = InvalidHeaderError; | ||
class InvalidOptionError extends Error { | ||
constructor(message, options) { | ||
super(message, options); | ||
this.name = "InvalidOptionError"; | ||
this.name = "InvalidArgumentError"; | ||
} | ||
static exclusiveOptions(opts) { | ||
const names = opts.map((o) => `'${o}'`).join(","); | ||
return new InvalidOptionError(`options ${names} are mutually exclusive.`); | ||
static format(name, message) { | ||
return `'${name}' ${message}`; | ||
} | ||
static illegalArgument(name, message) { | ||
return new InvalidOptionError(`argument '${name}' ${message}`); | ||
static formatMultiple(names, message) { | ||
names = names.map((n) => `'${n}'`); | ||
return `${names.join(",")} ${message}`; | ||
} | ||
static illegalOption(prop, message) { | ||
return new InvalidOptionError(`option '${prop}' ${message}`); | ||
} | ||
} | ||
exports.InvalidOptionError = InvalidOptionError; | ||
exports.InvalidArgumentError = InvalidArgumentError; | ||
/** | ||
* InvalidOperationError is a custom error class that extends the standard Error object. | ||
* It represents an error that occurs when an invalid operation is attempted on one of | ||
* objects returned by the API. For example, trying to iterate on an object that was | ||
* configured with a callback. | ||
* | ||
* @class InvalidOperationError | ||
* @extends {Error} | ||
* | ||
* @param {string} message - The error message that explains the reason for the error. | ||
* @param {ErrorOptions} [options] - Optional parameter to provide additional error options. | ||
*/ | ||
class InvalidOperationError extends Error { | ||
@@ -58,2 +67,7 @@ constructor(message, options) { | ||
exports.InvalidOperationError = InvalidOperationError; | ||
/** | ||
* Represents an error indicating that user authentication has expired. | ||
* This error is typically thrown when a user attempts to access a connection | ||
* but their authentication credentials have expired. | ||
*/ | ||
class UserAuthenticationExpiredError extends Error { | ||
@@ -73,2 +87,8 @@ constructor(message, options) { | ||
exports.UserAuthenticationExpiredError = UserAuthenticationExpiredError; | ||
/** | ||
* Represents an error related to authorization issues. | ||
* Note that these could represent an authorization violation, | ||
* or that the account authentication configuration has expired, | ||
* or an authentication timeout. | ||
*/ | ||
class AuthorizationError extends Error { | ||
@@ -95,2 +115,11 @@ constructor(message, options) { | ||
exports.AuthorizationError = AuthorizationError; | ||
/** | ||
* Class representing an error thrown when an operation is attempted on a closed connection. | ||
* | ||
* This error is intended to signal that a connection-related operation could not be completed | ||
* because the connection is no longer open or has been terminated. | ||
* | ||
* @class | ||
* @extends Error | ||
*/ | ||
class ClosedConnectionError extends Error { | ||
@@ -103,3 +132,13 @@ constructor() { | ||
exports.ClosedConnectionError = ClosedConnectionError; | ||
class ConnectionDrainingError extends Error { | ||
/** | ||
* The `ConnectionDrainingError` class represents a specific type of error | ||
* that occurs when a connection is being drained. | ||
* | ||
* This error is typically used in scenarios where connections need to be | ||
* gracefully closed or when they are transitioning to an inactive state. | ||
* | ||
* The error message is set to "connection draining" and the error name is | ||
* overridden to "DrainingConnectionError". | ||
*/ | ||
class DrainingConnectionError extends Error { | ||
constructor() { | ||
@@ -110,3 +149,10 @@ super("connection draining"); | ||
} | ||
exports.ConnectionDrainingError = ConnectionDrainingError; | ||
exports.DrainingConnectionError = DrainingConnectionError; | ||
/** | ||
* Represents an error that occurs when a network connection fails. | ||
* Extends the built-in Error class to provide additional context for connection-related issues. | ||
* | ||
* @param {string} message - A human-readable description of the error. | ||
* @param {ErrorOptions} [options] - Optional settings for customizing the error behavior. | ||
*/ | ||
class ConnectionError extends Error { | ||
@@ -119,2 +165,10 @@ constructor(message, options) { | ||
exports.ConnectionError = ConnectionError; | ||
/** | ||
* Represents an error encountered during protocol operations. | ||
* This class extends the built-in `Error` class, providing a specific | ||
* error type called `ProtocolError`. | ||
* | ||
* @param {string} message - A descriptive message describing the error. | ||
* @param {ErrorOptions} [options] - Optional parameters to include additional details. | ||
*/ | ||
class ProtocolError extends Error { | ||
@@ -127,2 +181,8 @@ constructor(message, options) { | ||
exports.ProtocolError = ProtocolError; | ||
/** | ||
* Class representing an error that occurs during an request operation | ||
* (such as TimeoutError, or NoRespondersError, or some other error). | ||
* | ||
* @extends Error | ||
*/ | ||
class RequestError extends Error { | ||
@@ -135,2 +195,10 @@ constructor(message = "", options) { | ||
exports.RequestError = RequestError; | ||
/** | ||
* TimeoutError is a custom error class that extends the built-in Error class. | ||
* It is used to represent an error that occurs when an operation exceeds a | ||
* predefined time limit. | ||
* | ||
* @class | ||
* @extends {Error} | ||
*/ | ||
class TimeoutError extends Error { | ||
@@ -143,2 +211,12 @@ constructor(options) { | ||
exports.TimeoutError = TimeoutError; | ||
/** | ||
* NoRespondersError is an error thrown when no responders (no service is | ||
* subscribing to the subject) are found for a given subject. This error | ||
* is typically found as the cause for a RequestError | ||
* | ||
* @extends Error | ||
* | ||
* @param {string} subject - The subject for which no responders were found. | ||
* @param {ErrorOptions} [options] - Optional error options. | ||
*/ | ||
class NoRespondersError extends Error { | ||
@@ -153,9 +231,9 @@ subject; | ||
exports.NoRespondersError = NoRespondersError; | ||
class ServerError extends Error { | ||
constructor(message, options) { | ||
super(message, options); | ||
this.name = "ServerError"; | ||
} | ||
} | ||
exports.ServerError = ServerError; | ||
/** | ||
* Class representing a Permission Violation Error. | ||
* It provides information about the operation (either "publish" or "subscription") | ||
* and the subject used for the operation and the optional queue (if a subscription). | ||
* | ||
* This error is terminal for a subscription. | ||
*/ | ||
class PermissionViolationError extends Error { | ||
@@ -195,2 +273,17 @@ operation; | ||
exports.PermissionViolationError = PermissionViolationError; | ||
exports.errors = { | ||
AuthorizationError, | ||
ClosedConnectionError, | ||
ConnectionError, | ||
DrainingConnectionError, | ||
InvalidArgumentError, | ||
InvalidOperationError, | ||
InvalidSubjectError, | ||
NoRespondersError, | ||
PermissionViolationError, | ||
ProtocolError, | ||
RequestError, | ||
TimeoutError, | ||
UserAuthenticationExpiredError, | ||
}; | ||
//# sourceMappingURL=errors.js.map |
@@ -51,3 +51,3 @@ "use strict"; | ||
if (c === colon || c < start || c > end) { | ||
throw new errors_1.InvalidHeaderError(`'${k[i]}' is not a valid character in a header name`); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format("header", `'${k[i]}' is not a valid character in a header name`)); | ||
} | ||
@@ -67,3 +67,3 @@ if (upper && a <= c && c <= z) { | ||
if ((code === 0 && description !== "") || (code > 0 && description === "")) { | ||
throw new Error("setting status requires both code and description"); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format("description", "is required")); | ||
} | ||
@@ -161,3 +161,3 @@ return new MsgHdrsImpl(code, description); | ||
if (inv.test(k)) { | ||
throw new errors_1.InvalidHeaderError("values cannot contain \\r or \\n"); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format("header", "values cannot contain \\r or \\n")); | ||
} | ||
@@ -164,0 +164,0 @@ return k.trim(); |
@@ -40,2 +40,2 @@ export { NatsConnectionImpl } from "./nats"; | ||
export { wsconnect, wsUrlParseFn } from "./ws_transport"; | ||
export { AuthorizationError, ClosedConnectionError, ConnectionDrainingError, ConnectionError, InvalidOptionError, NoRespondersError, PermissionViolationError, ProtocolError, RequestError, ServerError, TimeoutError, UserAuthenticationExpiredError, } from "./errors"; | ||
export { errors } from "./errors"; |
@@ -32,3 +32,3 @@ "use strict"; | ||
exports.TE = exports.TD = exports.Metric = exports.Bench = exports.writeAll = exports.readAll = exports.MAX_SIZE = exports.DenoBuffer = exports.State = exports.Parser = exports.Kind = exports.QueuedIteratorImpl = exports.usernamePasswordAuthenticator = exports.tokenAuthenticator = exports.nkeyAuthenticator = exports.jwtAuthenticator = exports.credsAuthenticator = exports.RequestOne = exports.parseOptions = exports.defaultOptions = exports.DEFAULT_MAX_RECONNECT_ATTEMPTS = exports.checkUnsupportedOption = exports.checkOptions = exports.buildAuthenticator = exports.DataBuffer = exports.MuxSubscription = exports.Heartbeat = exports.MsgHdrsImpl = exports.headers = exports.canonicalMIMEHeaderKey = exports.timeout = exports.SimpleMutex = exports.render = exports.nanos = exports.millis = exports.extend = exports.delay = exports.deferred = exports.deadline = exports.collect = exports.backoff = exports.ProtocolHandler = exports.INFO = exports.Connect = exports.setTransportFactory = exports.getResolveFn = exports.MsgImpl = exports.nuid = exports.Nuid = exports.NatsConnectionImpl = void 0; | ||
exports.UserAuthenticationExpiredError = exports.TimeoutError = exports.ServerError = exports.RequestError = exports.ProtocolError = exports.PermissionViolationError = exports.NoRespondersError = exports.InvalidOptionError = exports.ConnectionError = exports.ConnectionDrainingError = exports.ClosedConnectionError = exports.AuthorizationError = exports.wsUrlParseFn = exports.wsconnect = exports.SHA256 = exports.Base64UrlPaddedCodec = exports.Base64UrlCodec = exports.Base64Codec = exports.Servers = exports.isIPV4OrHostname = exports.IdleHeartbeatMonitor = exports.Subscriptions = exports.SubscriptionImpl = exports.syncIterator = exports.RequestStrategy = exports.Match = exports.Events = exports.DebugEvents = exports.createInbox = exports.protoLen = exports.extractProtocolMessage = exports.Empty = exports.parseSemVer = exports.Features = exports.Feature = exports.compare = exports.parseIP = exports.isIP = exports.ipV4 = void 0; | ||
exports.errors = exports.wsUrlParseFn = exports.wsconnect = exports.SHA256 = exports.Base64UrlPaddedCodec = exports.Base64UrlCodec = exports.Base64Codec = exports.Servers = exports.isIPV4OrHostname = exports.IdleHeartbeatMonitor = exports.Subscriptions = exports.SubscriptionImpl = exports.syncIterator = exports.RequestStrategy = exports.Match = exports.Events = exports.DebugEvents = exports.createInbox = exports.protoLen = exports.extractProtocolMessage = exports.Empty = exports.parseSemVer = exports.Features = exports.Feature = exports.compare = exports.parseIP = exports.isIP = exports.ipV4 = void 0; | ||
var nats_1 = require("./nats"); | ||
@@ -142,14 +142,3 @@ Object.defineProperty(exports, "NatsConnectionImpl", { enumerable: true, get: function () { return nats_1.NatsConnectionImpl; } }); | ||
var errors_1 = require("./errors"); | ||
Object.defineProperty(exports, "AuthorizationError", { enumerable: true, get: function () { return errors_1.AuthorizationError; } }); | ||
Object.defineProperty(exports, "ClosedConnectionError", { enumerable: true, get: function () { return errors_1.ClosedConnectionError; } }); | ||
Object.defineProperty(exports, "ConnectionDrainingError", { enumerable: true, get: function () { return errors_1.ConnectionDrainingError; } }); | ||
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_1.ConnectionError; } }); | ||
Object.defineProperty(exports, "InvalidOptionError", { enumerable: true, get: function () { return errors_1.InvalidOptionError; } }); | ||
Object.defineProperty(exports, "NoRespondersError", { enumerable: true, get: function () { return errors_1.NoRespondersError; } }); | ||
Object.defineProperty(exports, "PermissionViolationError", { enumerable: true, get: function () { return errors_1.PermissionViolationError; } }); | ||
Object.defineProperty(exports, "ProtocolError", { enumerable: true, get: function () { return errors_1.ProtocolError; } }); | ||
Object.defineProperty(exports, "RequestError", { enumerable: true, get: function () { return errors_1.RequestError; } }); | ||
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_1.ServerError; } }); | ||
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } }); | ||
Object.defineProperty(exports, "UserAuthenticationExpiredError", { enumerable: true, get: function () { return errors_1.UserAuthenticationExpiredError; } }); | ||
Object.defineProperty(exports, "errors", { enumerable: true, get: function () { return errors_1.errors; } }); | ||
//# sourceMappingURL=internal_mod.js.map |
@@ -1,2 +0,2 @@ | ||
export { AuthorizationError, backoff, Bench, buildAuthenticator, canonicalMIMEHeaderKey, ClosedConnectionError, ConnectionDrainingError, ConnectionError, createInbox, credsAuthenticator, deadline, DebugEvents, deferred, delay, Empty, Events, headers, InvalidOptionError, jwtAuthenticator, Match, Metric, millis, MsgHdrsImpl, nanos, nkeyAuthenticator, nkeys, NoRespondersError, Nuid, nuid, PermissionViolationError, ProtocolError, RequestError, RequestStrategy, ServerError, syncIterator, TimeoutError, tokenAuthenticator, UserAuthenticationExpiredError, usernamePasswordAuthenticator, wsconnect, } from "./internal_mod"; | ||
export { backoff, Bench, buildAuthenticator, canonicalMIMEHeaderKey, createInbox, credsAuthenticator, deadline, DebugEvents, deferred, delay, Empty, errors, Events, headers, jwtAuthenticator, Match, Metric, millis, MsgHdrsImpl, nanos, nkeyAuthenticator, nkeys, Nuid, nuid, RequestStrategy, syncIterator, tokenAuthenticator, usernamePasswordAuthenticator, wsconnect, } from "./internal_mod"; | ||
export type { Auth, Authenticator, Backoff, BenchOpts, Codec, ConnectionOptions, Deferred, Delay, JwtAuth, Msg, MsgCallback, MsgHdrs, Nanos, NatsConnection, NKeyAuth, NoAuth, Payload, Perf, Publisher, PublishOptions, QueuedIterator, RequestManyOptions, RequestOptions, ReviverFn, ServerInfo, ServersChanged, Stats, Status, SubOpts, Subscription, SubscriptionOptions, SyncIterator, Timeout, TlsOptions, TokenAuth, UserPass, } from "./internal_mod"; |
@@ -17,5 +17,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.wsconnect = exports.usernamePasswordAuthenticator = exports.UserAuthenticationExpiredError = exports.tokenAuthenticator = exports.TimeoutError = exports.syncIterator = exports.ServerError = exports.RequestStrategy = exports.RequestError = exports.ProtocolError = exports.PermissionViolationError = exports.nuid = exports.Nuid = exports.NoRespondersError = exports.nkeys = exports.nkeyAuthenticator = exports.nanos = exports.MsgHdrsImpl = exports.millis = exports.Metric = exports.Match = exports.jwtAuthenticator = exports.InvalidOptionError = exports.headers = exports.Events = exports.Empty = exports.delay = exports.deferred = exports.DebugEvents = exports.deadline = exports.credsAuthenticator = exports.createInbox = exports.ConnectionError = exports.ConnectionDrainingError = exports.ClosedConnectionError = exports.canonicalMIMEHeaderKey = exports.buildAuthenticator = exports.Bench = exports.backoff = exports.AuthorizationError = void 0; | ||
exports.wsconnect = exports.usernamePasswordAuthenticator = exports.tokenAuthenticator = exports.syncIterator = exports.RequestStrategy = exports.nuid = exports.Nuid = exports.nkeys = exports.nkeyAuthenticator = exports.nanos = exports.MsgHdrsImpl = exports.millis = exports.Metric = exports.Match = exports.jwtAuthenticator = exports.headers = exports.Events = exports.errors = exports.Empty = exports.delay = exports.deferred = exports.DebugEvents = exports.deadline = exports.credsAuthenticator = exports.createInbox = exports.canonicalMIMEHeaderKey = exports.buildAuthenticator = exports.Bench = exports.backoff = void 0; | ||
var internal_mod_1 = require("./internal_mod"); | ||
Object.defineProperty(exports, "AuthorizationError", { enumerable: true, get: function () { return internal_mod_1.AuthorizationError; } }); | ||
Object.defineProperty(exports, "backoff", { enumerable: true, get: function () { return internal_mod_1.backoff; } }); | ||
@@ -25,5 +24,2 @@ Object.defineProperty(exports, "Bench", { enumerable: true, get: function () { return internal_mod_1.Bench; } }); | ||
Object.defineProperty(exports, "canonicalMIMEHeaderKey", { enumerable: true, get: function () { return internal_mod_1.canonicalMIMEHeaderKey; } }); | ||
Object.defineProperty(exports, "ClosedConnectionError", { enumerable: true, get: function () { return internal_mod_1.ClosedConnectionError; } }); | ||
Object.defineProperty(exports, "ConnectionDrainingError", { enumerable: true, get: function () { return internal_mod_1.ConnectionDrainingError; } }); | ||
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return internal_mod_1.ConnectionError; } }); | ||
Object.defineProperty(exports, "createInbox", { enumerable: true, get: function () { return internal_mod_1.createInbox; } }); | ||
@@ -36,5 +32,5 @@ Object.defineProperty(exports, "credsAuthenticator", { enumerable: true, get: function () { return internal_mod_1.credsAuthenticator; } }); | ||
Object.defineProperty(exports, "Empty", { enumerable: true, get: function () { return internal_mod_1.Empty; } }); | ||
Object.defineProperty(exports, "errors", { enumerable: true, get: function () { return internal_mod_1.errors; } }); | ||
Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return internal_mod_1.Events; } }); | ||
Object.defineProperty(exports, "headers", { enumerable: true, get: function () { return internal_mod_1.headers; } }); | ||
Object.defineProperty(exports, "InvalidOptionError", { enumerable: true, get: function () { return internal_mod_1.InvalidOptionError; } }); | ||
Object.defineProperty(exports, "jwtAuthenticator", { enumerable: true, get: function () { return internal_mod_1.jwtAuthenticator; } }); | ||
@@ -48,16 +44,9 @@ Object.defineProperty(exports, "Match", { enumerable: true, get: function () { return internal_mod_1.Match; } }); | ||
Object.defineProperty(exports, "nkeys", { enumerable: true, get: function () { return internal_mod_1.nkeys; } }); | ||
Object.defineProperty(exports, "NoRespondersError", { enumerable: true, get: function () { return internal_mod_1.NoRespondersError; } }); | ||
Object.defineProperty(exports, "Nuid", { enumerable: true, get: function () { return internal_mod_1.Nuid; } }); | ||
Object.defineProperty(exports, "nuid", { enumerable: true, get: function () { return internal_mod_1.nuid; } }); | ||
Object.defineProperty(exports, "PermissionViolationError", { enumerable: true, get: function () { return internal_mod_1.PermissionViolationError; } }); | ||
Object.defineProperty(exports, "ProtocolError", { enumerable: true, get: function () { return internal_mod_1.ProtocolError; } }); | ||
Object.defineProperty(exports, "RequestError", { enumerable: true, get: function () { return internal_mod_1.RequestError; } }); | ||
Object.defineProperty(exports, "RequestStrategy", { enumerable: true, get: function () { return internal_mod_1.RequestStrategy; } }); | ||
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return internal_mod_1.ServerError; } }); | ||
Object.defineProperty(exports, "syncIterator", { enumerable: true, get: function () { return internal_mod_1.syncIterator; } }); | ||
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return internal_mod_1.TimeoutError; } }); | ||
Object.defineProperty(exports, "tokenAuthenticator", { enumerable: true, get: function () { return internal_mod_1.tokenAuthenticator; } }); | ||
Object.defineProperty(exports, "UserAuthenticationExpiredError", { enumerable: true, get: function () { return internal_mod_1.UserAuthenticationExpiredError; } }); | ||
Object.defineProperty(exports, "usernamePasswordAuthenticator", { enumerable: true, get: function () { return internal_mod_1.usernamePasswordAuthenticator; } }); | ||
Object.defineProperty(exports, "wsconnect", { enumerable: true, get: function () { return internal_mod_1.wsconnect; } }); | ||
//# sourceMappingURL=mod.js.map |
@@ -65,13 +65,13 @@ "use strict"; | ||
if (this.isClosed()) { | ||
throw new errors_1.ClosedConnectionError(); | ||
throw new errors_1.errors.ClosedConnectionError(); | ||
} | ||
if (sub && this.isDraining()) { | ||
throw new errors_1.ConnectionDrainingError(); | ||
throw new errors_1.errors.DrainingConnectionError(); | ||
} | ||
if (pub && this.protocol.noMorePublishing) { | ||
throw new errors_1.ConnectionDrainingError(); | ||
throw new errors_1.errors.DrainingConnectionError(); | ||
} | ||
subject = subject || ""; | ||
if (subject.length === 0) { | ||
throw new errors_1.InvalidSubjectError(subject); | ||
throw new errors_1.errors.InvalidSubjectError(subject); | ||
} | ||
@@ -142,3 +142,3 @@ } | ||
if (opts.maxWait < 1) { | ||
return Promise.reject(errors_1.InvalidOptionError.illegalOption("timeout", "should be greater than 0")); | ||
return Promise.reject(new errors_1.errors.InvalidArgumentError(errors_1.InvalidArgumentError.format("timeout", "must be greater than 0"))); | ||
} | ||
@@ -173,3 +173,3 @@ // the iterator for user results | ||
msg?.headers?.status === "503") { | ||
err = new errors_1.NoRespondersError(subject); | ||
err = new errors_1.errors.NoRespondersError(subject); | ||
} | ||
@@ -287,6 +287,6 @@ // augment any error with the current stack to provide context | ||
if (opts.timeout < 1) { | ||
return Promise.reject(errors_1.InvalidOptionError.illegalOption("timeout", `must be greater than 0`)); | ||
return Promise.reject(new errors_1.errors.InvalidArgumentError(errors_1.InvalidArgumentError.format("timeout", `must be greater than 0`))); | ||
} | ||
if (!opts.noMux && opts.reply) { | ||
return Promise.reject(errors_1.InvalidOptionError.exclusiveOptions(["reply", "noMux"])); | ||
return Promise.reject(new errors_1.errors.InvalidArgumentError(errors_1.InvalidArgumentError.formatMultiple(["reply", "noMux"], "are mutually exclusive"))); | ||
} | ||
@@ -298,3 +298,3 @@ if (opts.noMux) { | ||
const d = (0, util_1.deferred)(); | ||
const errCtx = asyncTraces ? new errors_1.RequestError("") : null; | ||
const errCtx = asyncTraces ? new errors_1.errors.RequestError("") : null; | ||
const sub = this.subscribe(inbox, { | ||
@@ -306,3 +306,3 @@ max: 1, | ||
if (msg && msg.data?.length === 0 && msg.headers?.code === 503) { | ||
err = new errors_1.NoRespondersError(subject); | ||
err = new errors_1.errors.NoRespondersError(subject); | ||
} | ||
@@ -317,3 +317,3 @@ if (err) { | ||
else { | ||
err = new errors_1.RequestError(err.message, { cause: err }); | ||
err = new errors_1.errors.RequestError(err.message, { cause: err }); | ||
} | ||
@@ -360,3 +360,3 @@ d.reject(err); | ||
if (this.isClosed()) { | ||
return Promise.reject(new errors_1.ClosedConnectionError()); | ||
return Promise.reject(new errors_1.errors.ClosedConnectionError()); | ||
} | ||
@@ -367,6 +367,6 @@ return this.protocol.flush(); | ||
if (this.isClosed()) { | ||
return Promise.reject(new errors_1.ClosedConnectionError()); | ||
return Promise.reject(new errors_1.errors.ClosedConnectionError()); | ||
} | ||
if (this.isDraining()) { | ||
return Promise.reject(new errors_1.ConnectionDrainingError()); | ||
return Promise.reject(new errors_1.errors.DrainingConnectionError()); | ||
} | ||
@@ -421,6 +421,6 @@ this.draining = true; | ||
if (this.isClosed()) { | ||
throw new errors_1.ClosedConnectionError(); | ||
throw new errors_1.errors.ClosedConnectionError(); | ||
} | ||
if (!this.protocol.connected) { | ||
throw new errors_1.RequestError("connection disconnected"); | ||
throw new errors_1.errors.RequestError("connection disconnected"); | ||
} | ||
@@ -436,6 +436,6 @@ const start = Date.now(); | ||
if (this.isClosed()) { | ||
return Promise.reject(new errors_1.ClosedConnectionError()); | ||
return Promise.reject(new errors_1.errors.ClosedConnectionError()); | ||
} | ||
if (this.isDraining()) { | ||
return Promise.reject(new errors_1.ConnectionDrainingError()); | ||
return Promise.reject(new errors_1.errors.DrainingConnectionError()); | ||
} | ||
@@ -442,0 +442,0 @@ return this.protocol.reconnect(); |
@@ -80,3 +80,3 @@ "use strict"; | ||
if (opts.servers.length > 0 && opts.port) { | ||
throw errors_1.InvalidOptionError.exclusiveOptions(["servers", "port"]); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.formatMultiple(["servers", "port"], "are mutually exclusive")); | ||
} | ||
@@ -93,3 +93,3 @@ if (opts.servers.length === 0 && opts.port) { | ||
if (options[n] && typeof options[n] !== "function") { | ||
throw errors_1.InvalidOptionError.illegalOption(n, "must be a function"); | ||
throw TypeError(`'${n}' must be a function`); | ||
} | ||
@@ -119,3 +119,3 @@ }); | ||
if (typeof (0, transport_1.getResolveFn)() !== "function") { | ||
throw errors_1.InvalidOptionError.illegalOption("resolve", "not supported by this client implementation"); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format("resolve", "is not supported in the current runtime")); | ||
} | ||
@@ -128,7 +128,7 @@ } | ||
if ((proto === undefined || proto < 1) && options.noEcho) { | ||
throw new errors_1.ConnectionError(`option 'noEcho' is not available`); | ||
throw new errors_1.errors.ConnectionError(`server does not support 'noEcho'`); | ||
} | ||
const tls = tlsRequired || tlsAvailable || false; | ||
if (options.tls && !tls) { | ||
throw new errors_1.ConnectionError(`option 'tls' is not available`); | ||
throw new errors_1.errors.ConnectionError(`server does not support 'tls'`); | ||
} | ||
@@ -138,5 +138,5 @@ } | ||
if (v) { | ||
throw errors_1.InvalidOptionError.illegalOption(prop, "is not supported"); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format(prop, "is not supported")); | ||
} | ||
} | ||
//# sourceMappingURL=options.js.map |
@@ -13,3 +13,3 @@ import type { Transport } from "./transport"; | ||
import type { ConnectionOptions, Dispatcher, Msg, Payload, Publisher, PublishOptions, Request, Server, ServerInfo, Status, Subscription, SubscriptionOptions } from "./core"; | ||
import { AuthorizationError, PermissionViolationError, UserAuthenticationExpiredError } from "./errors"; | ||
import type { AuthorizationError, PermissionViolationError, UserAuthenticationExpiredError } from "./errors"; | ||
export declare const INFO: RegExp; | ||
@@ -16,0 +16,0 @@ export declare class Connect { |
@@ -153,6 +153,6 @@ "use strict"; | ||
if (this.protocol.isClosed()) { | ||
return Promise.reject(new errors_1.ClosedConnectionError()); | ||
return Promise.reject(new errors_1.errors.ClosedConnectionError()); | ||
} | ||
if (this.isClosed()) { | ||
return Promise.reject(new errors_1.InvalidOperationError("subscription is already closed")); | ||
return Promise.reject(new errors_1.errors.InvalidOperationError("subscription is already closed")); | ||
} | ||
@@ -333,3 +333,3 @@ if (!this.drained) { | ||
// because that confuses API consumers | ||
const err = new errors_1.RequestError("connection disconnected"); | ||
const err = new errors_1.errors.RequestError("connection disconnected"); | ||
err.stack = ""; | ||
@@ -410,3 +410,3 @@ pongs.forEach((p) => { | ||
// authenticator that dynamically updates | ||
if (this.lastError instanceof errors_1.UserAuthenticationExpiredError) { | ||
if (this.lastError instanceof errors_1.errors.UserAuthenticationExpiredError) { | ||
this.lastError = undefined; | ||
@@ -525,3 +525,3 @@ } | ||
else { | ||
throw new errors_1.ConnectionError("connection refused"); | ||
throw new errors_1.errors.ConnectionError("connection refused"); | ||
} | ||
@@ -563,15 +563,15 @@ } | ||
static toError(s) { | ||
let err = errors_1.PermissionViolationError.parse(s); | ||
let err = errors_1.errors.PermissionViolationError.parse(s); | ||
if (err) { | ||
return err; | ||
} | ||
err = errors_1.UserAuthenticationExpiredError.parse(s); | ||
err = errors_1.errors.UserAuthenticationExpiredError.parse(s); | ||
if (err) { | ||
return err; | ||
} | ||
err = errors_1.AuthorizationError.parse(s); | ||
err = errors_1.errors.AuthorizationError.parse(s); | ||
if (err) { | ||
return err; | ||
} | ||
return new errors_1.ProtocolError(s); | ||
return new errors_1.errors.ProtocolError(s); | ||
} | ||
@@ -603,3 +603,3 @@ processMsg(msg, data) { | ||
switch (err.constructor) { | ||
case errors_1.PermissionViolationError: { | ||
case errors_1.errors.PermissionViolationError: { | ||
const pe = err; | ||
@@ -614,3 +614,2 @@ const mux = this.subscriptions.getMux(); | ||
} | ||
break; | ||
} | ||
@@ -622,7 +621,7 @@ } | ||
handleError(err) { | ||
if (err instanceof errors_1.UserAuthenticationExpiredError || | ||
err instanceof errors_1.AuthorizationError) { | ||
if (err instanceof errors_1.errors.UserAuthenticationExpiredError || | ||
err instanceof errors_1.errors.AuthorizationError) { | ||
this.handleAuthError(err); | ||
} | ||
if (!(err instanceof errors_1.PermissionViolationError)) { | ||
if (!(err instanceof errors_1.errors.PermissionViolationError)) { | ||
this.lastError = err; | ||
@@ -632,4 +631,4 @@ } | ||
handleAuthError(err) { | ||
if ((this.lastError instanceof errors_1.UserAuthenticationExpiredError || | ||
this.lastError instanceof errors_1.AuthorizationError) && | ||
if ((this.lastError instanceof errors_1.errors.UserAuthenticationExpiredError || | ||
this.lastError instanceof errors_1.errors.AuthorizationError) && | ||
this.options.ignoreAuthErrorAbort === false) { | ||
@@ -746,3 +745,3 @@ this.abortReconnect = true; | ||
else { | ||
throw errors_1.InvalidOptionError.illegalArgument("payload", "supported payloads types are strings or Uint8Array"); | ||
throw new TypeError("payload types can be strings or Uint8Array"); | ||
} | ||
@@ -756,3 +755,3 @@ let len = data.length; | ||
if (this.info && !this.info.headers) { | ||
throw errors_1.InvalidOptionError.illegalOption("headers", "are not supported by the current server"); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format("headers", "are not available on this server")); | ||
} | ||
@@ -765,3 +764,3 @@ const hdrs = options.headers; | ||
if (this.info && len > this.info.max_payload) { | ||
throw new errors_1.ServerError(`server 'max_payload' exceeded`); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.errors.InvalidArgumentError.format("payload", "max_payload size exceeded")); | ||
} | ||
@@ -768,0 +767,0 @@ this.outBytes += len; |
@@ -41,3 +41,3 @@ "use strict"; | ||
if (typeof this.opts.callback !== "function") { | ||
throw new Error("callback is required"); | ||
throw new TypeError("callback must be a function"); | ||
} | ||
@@ -44,0 +44,0 @@ this.callback = this.opts.callback; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "3.0.0-31"; | ||
export declare const version = "3.0.0-32"; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// This file is generated - do not edit | ||
exports.version = "3.0.0-31"; | ||
exports.version = "3.0.0-32"; | ||
//# sourceMappingURL=version.js.map |
@@ -132,3 +132,3 @@ "use strict"; | ||
const evt = e; | ||
const err = new errors_1.ConnectionError(evt.message); | ||
const err = new errors_1.errors.ConnectionError(evt.message); | ||
if (!connected) { | ||
@@ -300,3 +300,3 @@ ok.reject(err); | ||
if (opts.tls) { | ||
throw errors_1.InvalidOptionError.illegalOption("tls", "is not configurable on w3c websocket connections"); | ||
throw new errors_1.errors.InvalidArgumentError(errors_1.InvalidArgumentError.format("tls", "is not configurable on w3c websocket connections")); | ||
} | ||
@@ -303,0 +303,0 @@ return new WsTransport(); |
{ | ||
"name": "@nats-io/nats-core", | ||
"version": "3.0.0-31", | ||
"version": "3.0.0-32", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib/", |
@@ -110,3 +110,3 @@ # Core | ||
// import the connect function from a transport | ||
import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-4"; | ||
import { connect } from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
@@ -183,3 +183,3 @@ const servers = [ | ||
// import the connect function from a transport | ||
import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-4"; | ||
import { connect } from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
@@ -246,4 +246,4 @@ // to create a connection to a nats-server: | ||
```typescript | ||
import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-4"; | ||
import type { Subscription } from "jsr:@nats-io/nats-transport-deno@3.0.0-4"; | ||
import { connect } from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
import type { Subscription } from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
const nc = await connect({ servers: "demo.nats.io:4222" }); | ||
@@ -424,7 +424,7 @@ | ||
```typescript | ||
import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; | ||
import { connect } from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
import type { | ||
NatsConnection, | ||
Subscription, | ||
} from "jsr:@nats-io/nats-transport-deno@3.0.0-4"; | ||
} from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
@@ -548,10 +548,12 @@ async function createService( | ||
```typescript | ||
import { connect, ErrorCode } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; | ||
import type { NatsError } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; | ||
import { connect } from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
import { | ||
NoRespondersError, | ||
RequestError, | ||
TimeoutError, | ||
} from "jsr:@nats-io/transport-deno@3.0.0-7"; | ||
const nc = await connect( | ||
{ | ||
servers: `demo.nats.io`, | ||
}, | ||
); | ||
const nc = await connect({ | ||
servers: `demo.nats.io`, | ||
}); | ||
@@ -562,12 +564,14 @@ try { | ||
} catch (err) { | ||
const nerr = err as NatsError; | ||
switch (nerr.code) { | ||
case ErrorCode.NoResponders: | ||
if (err instanceof RequestError) { | ||
if (err.cause instanceof TimeoutError) { | ||
console.log("someone is listening but didn't respond"); | ||
} else if (err.cause instanceof NoRespondersError) { | ||
console.log("no one is listening to 'hello.world'"); | ||
break; | ||
case ErrorCode.Timeout: | ||
console.log("someone is listening but didn't respond"); | ||
break; | ||
default: | ||
console.log("request failed", err); | ||
} else { | ||
console.log( | ||
`failed due to unknown error: ${(err.cause as Error)?.message}`, | ||
); | ||
} | ||
} else { | ||
console.log(`request failed: ${(err as Error).message}`); | ||
} | ||
@@ -600,3 +604,3 @@ } | ||
// `token` options in the NatsConnectionOptions | ||
import { connect } from "jsr:@nats-io/nats-transport-deno@3.0.0-5"; | ||
import { connect } from "jsr:@nats-io/transport-deno@3.0.0-5"; | ||
@@ -690,4 +694,4 @@ const nc1 = await connect({ | ||
- `callback`: a function with the signature | ||
`(err: NatsError|null, msg: Msg) => void;` that should be used for handling | ||
the message. Subscriptions with callbacks are NOT iterators. | ||
`(err: Error|null, msg: Msg) => void;` that should be used for handling the | ||
message. Subscriptions with callbacks are NOT iterators. | ||
@@ -694,0 +698,0 @@ #### Auto Unsubscribe |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
534282
8422
916