@nats-io/nats-core
Advanced tools
Comparing version 3.0.0-37 to 3.0.0-38
@@ -14,5 +14,3 @@ /** | ||
/** Client received an async error from the server */ | ||
Error = "error", | ||
/** Slow Consumer - a buffered subscription (iterator) that is accumulating messages beyond a specify threshold */ | ||
SlowConsumer = "slow_consumer" | ||
Error = "error" | ||
} | ||
@@ -59,10 +57,2 @@ /** | ||
callback?: MsgCallback<T>; | ||
/** | ||
* Number of pending messages in a subscription to exceed prior to considering | ||
* a subscription a Slow Consumer. By default, slow consumer is on a subscription | ||
* is not accounted for. | ||
* | ||
* This is an experimental option. | ||
*/ | ||
slow?: number; | ||
} | ||
@@ -69,0 +59,0 @@ export interface DnsResolveFn { |
@@ -37,4 +37,2 @@ "use strict"; | ||
Events["Error"] = "error"; | ||
/** Slow Consumer - a buffered subscription (iterator) that is accumulating messages beyond a specify threshold */ | ||
Events["SlowConsumer"] = "slow_consumer"; | ||
})(Events || (exports.Events = Events = {})); | ||
@@ -41,0 +39,0 @@ /** |
@@ -14,3 +14,3 @@ export { NatsConnectionImpl } from "./nats"; | ||
export { DataBuffer } from "./databuffer"; | ||
export { buildAuthenticator, checkOptions, checkUnsupportedOption, DEFAULT_MAX_RECONNECT_ATTEMPTS, defaultOptions, parseOptions, } from "./options"; | ||
export { buildAuthenticator, checkOptions, checkUnsupportedOption, DEFAULT_MAX_RECONNECT_ATTEMPTS, defaultOptions, hasWsProtocol, parseOptions, } from "./options"; | ||
export { RequestOne } from "./request"; | ||
@@ -17,0 +17,0 @@ export { credsAuthenticator, jwtAuthenticator, nkeyAuthenticator, tokenAuthenticator, usernamePasswordAuthenticator, } from "./authenticator"; |
@@ -31,4 +31,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.RequestError = exports.ProtocolError = exports.PermissionViolationError = exports.NoRespondersError = exports.InvalidSubjectError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.errors = exports.DrainingConnectionError = exports.ConnectionError = 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.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.hasWsProtocol = 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.RequestError = exports.ProtocolError = exports.PermissionViolationError = exports.NoRespondersError = exports.InvalidSubjectError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.errors = exports.DrainingConnectionError = exports.ConnectionError = 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 = exports.TE = void 0; | ||
var nats_1 = require("./nats"); | ||
@@ -76,2 +76,3 @@ Object.defineProperty(exports, "NatsConnectionImpl", { enumerable: true, get: function () { return nats_1.NatsConnectionImpl; } }); | ||
Object.defineProperty(exports, "defaultOptions", { enumerable: true, get: function () { return options_1.defaultOptions; } }); | ||
Object.defineProperty(exports, "hasWsProtocol", { enumerable: true, get: function () { return options_1.hasWsProtocol; } }); | ||
Object.defineProperty(exports, "parseOptions", { enumerable: true, get: function () { return options_1.parseOptions; } }); | ||
@@ -78,0 +79,0 @@ var request_1 = require("./request"); |
@@ -1,2 +0,2 @@ | ||
export { AuthorizationError, backoff, Bench, buildAuthenticator, canonicalMIMEHeaderKey, ClosedConnectionError, ConnectionError, createInbox, credsAuthenticator, deadline, DebugEvents, deferred, delay, DrainingConnectionError, Empty, errors, Events, headers, InvalidArgumentError, InvalidOperationError, InvalidSubjectError, jwtAuthenticator, Match, Metric, millis, MsgHdrsImpl, nanos, nkeyAuthenticator, nkeys, NoRespondersError, Nuid, nuid, PermissionViolationError, ProtocolError, RequestError, RequestStrategy, syncIterator, TimeoutError, tokenAuthenticator, UserAuthenticationExpiredError, usernamePasswordAuthenticator, wsconnect, } from "./internal_mod"; | ||
export { AuthorizationError, backoff, Bench, buildAuthenticator, canonicalMIMEHeaderKey, ClosedConnectionError, ConnectionError, createInbox, credsAuthenticator, deadline, DebugEvents, deferred, delay, DrainingConnectionError, Empty, errors, Events, hasWsProtocol, headers, InvalidArgumentError, InvalidOperationError, InvalidSubjectError, jwtAuthenticator, Match, Metric, millis, MsgHdrsImpl, nanos, nkeyAuthenticator, nkeys, NoRespondersError, Nuid, nuid, PermissionViolationError, ProtocolError, RequestError, RequestStrategy, syncIterator, TimeoutError, tokenAuthenticator, UserAuthenticationExpiredError, 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,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.wsconnect = exports.usernamePasswordAuthenticator = exports.UserAuthenticationExpiredError = exports.tokenAuthenticator = exports.TimeoutError = exports.syncIterator = 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.InvalidSubjectError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.headers = exports.Events = exports.errors = exports.Empty = exports.DrainingConnectionError = exports.delay = exports.deferred = exports.DebugEvents = exports.deadline = exports.credsAuthenticator = exports.createInbox = exports.ConnectionError = exports.ClosedConnectionError = exports.canonicalMIMEHeaderKey = exports.buildAuthenticator = exports.Bench = exports.backoff = exports.AuthorizationError = void 0; | ||
exports.wsconnect = exports.usernamePasswordAuthenticator = exports.UserAuthenticationExpiredError = exports.tokenAuthenticator = exports.TimeoutError = exports.syncIterator = 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.InvalidSubjectError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.headers = exports.hasWsProtocol = exports.Events = exports.errors = exports.Empty = exports.DrainingConnectionError = exports.delay = exports.deferred = exports.DebugEvents = exports.deadline = exports.credsAuthenticator = exports.createInbox = exports.ConnectionError = exports.ClosedConnectionError = exports.canonicalMIMEHeaderKey = exports.buildAuthenticator = exports.Bench = exports.backoff = exports.AuthorizationError = void 0; | ||
var internal_mod_1 = require("./internal_mod"); | ||
@@ -37,2 +37,3 @@ Object.defineProperty(exports, "AuthorizationError", { enumerable: true, get: function () { return internal_mod_1.AuthorizationError; } }); | ||
Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return internal_mod_1.Events; } }); | ||
Object.defineProperty(exports, "hasWsProtocol", { enumerable: true, get: function () { return internal_mod_1.hasWsProtocol; } }); | ||
Object.defineProperty(exports, "headers", { enumerable: true, get: function () { return internal_mod_1.headers; } }); | ||
@@ -39,0 +40,0 @@ Object.defineProperty(exports, "InvalidArgumentError", { enumerable: true, get: function () { return internal_mod_1.InvalidArgumentError; } }); |
@@ -104,11 +104,2 @@ "use strict"; | ||
const sub = new protocol_1.SubscriptionImpl(this.protocol, subject, opts); | ||
if (typeof opts.callback !== "function" && typeof opts.slow === "number") { | ||
const subj = sub.getSubject(); | ||
sub.setSlowNotificationFn(opts.slow, (pending) => { | ||
this.protocol.dispatchStatus({ | ||
type: core_1.Events.SlowConsumer, | ||
data: `subscription (${sub.sid}) ${subj} is slow: msgs ${pending}`, | ||
}); | ||
}); | ||
} | ||
this.protocol.subscribe(sub); | ||
@@ -115,0 +106,0 @@ return sub; |
@@ -9,2 +9,3 @@ import type { Authenticator, ConnectionOptions, ServerInfo } from "./core"; | ||
export declare function defaultOptions(): ConnectionOptions; | ||
export declare function hasWsProtocol(opts?: ConnectionOptions): boolean; | ||
export declare function buildAuthenticator(opts: ConnectionOptions): Authenticator; | ||
@@ -11,0 +12,0 @@ export declare function parseOptions(opts?: ConnectionOptions): ConnectionOptions; |
@@ -19,2 +19,3 @@ "use strict"; | ||
exports.defaultOptions = defaultOptions; | ||
exports.hasWsProtocol = hasWsProtocol; | ||
exports.buildAuthenticator = buildAuthenticator; | ||
@@ -54,2 +55,19 @@ exports.parseOptions = parseOptions; | ||
} | ||
function hasWsProtocol(opts) { | ||
if (opts) { | ||
let { servers } = opts; | ||
if (typeof servers === "string") { | ||
servers = [servers]; | ||
} | ||
if (servers) { | ||
for (let i = 0; i < servers.length; i++) { | ||
const s = servers[i].toLowerCase(); | ||
if (s.startsWith("ws://") || s.startsWith("wss://")) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
function buildAuthenticator(opts) { | ||
@@ -56,0 +74,0 @@ const buf = []; |
@@ -37,9 +37,2 @@ import type { Transport } from "./transport"; | ||
} | ||
declare class SlowNotifier { | ||
slow: number; | ||
cb: (pending: number) => void; | ||
notified: boolean; | ||
constructor(slow: number, cb: (pending: number) => void); | ||
maybeNotify(pending: number): void; | ||
} | ||
export declare class SubscriptionImpl extends QueuedIteratorImpl<Msg> implements Subscription { | ||
@@ -58,5 +51,3 @@ sid: number; | ||
requestSubject?: string; | ||
slow?: SlowNotifier; | ||
constructor(protocol: ProtocolHandler, subject: string, opts?: SubscriptionOptions); | ||
setSlowNotificationFn(slow: number, fn?: (pending: number) => void): void; | ||
callback(err: Error | null, msg: Msg): void; | ||
@@ -163,2 +154,1 @@ close(): void; | ||
} | ||
export {}; |
@@ -69,25 +69,2 @@ "use strict"; | ||
exports.Connect = Connect; | ||
class SlowNotifier { | ||
slow; | ||
cb; | ||
notified; | ||
constructor(slow, cb) { | ||
this.slow = slow; | ||
this.cb = cb; | ||
this.notified = false; | ||
} | ||
maybeNotify(pending) { | ||
// if we are below the threshold reset the ability to notify | ||
if (pending <= this.slow) { | ||
this.notified = false; | ||
} | ||
else { | ||
if (!this.notified) { | ||
// crossed the threshold, notify and silence. | ||
this.cb(pending); | ||
this.notified = true; | ||
} | ||
} | ||
} | ||
} | ||
class SubscriptionImpl extends queued_iterator_1.QueuedIteratorImpl { | ||
@@ -106,3 +83,2 @@ sid; | ||
requestSubject; | ||
slow; | ||
constructor(protocol, subject, opts = {}) { | ||
@@ -141,17 +117,5 @@ super(); | ||
} | ||
setSlowNotificationFn(slow, fn) { | ||
this.slow = undefined; | ||
if (fn) { | ||
if (this.noIterator) { | ||
throw new Error("callbacks don't support slow notifications"); | ||
} | ||
this.slow = new SlowNotifier(slow, fn); | ||
} | ||
} | ||
callback(err, msg) { | ||
this.cancelTimeout(); | ||
err ? this.stop(err) : this.push(msg); | ||
if (!err && this.slow) { | ||
this.slow.maybeNotify(this.getPending()); | ||
} | ||
} | ||
@@ -158,0 +122,0 @@ close() { |
@@ -1,1 +0,1 @@ | ||
export declare const version = "3.0.0-37"; | ||
export declare const version = "3.0.0-38"; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// This file is generated - do not edit | ||
exports.version = "3.0.0-37"; | ||
exports.version = "3.0.0-38"; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@nats-io/nats-core", | ||
"version": "3.0.0-37", | ||
"version": "3.0.0-38", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib/", |
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
541740
8496