Comparing version 2.7.0 to 2.7.1-1
@@ -25,3 +25,4 @@ export { NatsConnectionImpl } from "./nats"; | ||
export { checkOptions, checkUnsupportedOption } from "./options"; | ||
export { Request } from "./request"; | ||
export type { Request } from "./request"; | ||
export { RequestOne } from "./request"; | ||
export type { Auth, Authenticator, JwtAuth, NKeyAuth, NoAuth, TokenAuth, UserPass, } from "./authenticator"; | ||
@@ -28,0 +29,0 @@ export { credsAuthenticator, jwtAuthenticator, nkeyAuthenticator, tokenAuthenticator, usernamePasswordAuthenticator, } from "./authenticator"; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JSONCodec = exports.usernamePasswordAuthenticator = exports.tokenAuthenticator = exports.nkeyAuthenticator = exports.jwtAuthenticator = exports.credsAuthenticator = exports.Request = exports.checkUnsupportedOption = exports.checkOptions = exports.DataBuffer = exports.MuxSubscription = exports.Heartbeat = exports.MsgHdrsImpl = exports.Match = exports.headers = exports.canonicalMIMEHeaderKey = exports.timeout = exports.render = exports.extractProtocolMessage = exports.extend = exports.delay = exports.deferred = exports.collect = exports.ProtocolHandler = exports.INFO = exports.createInbox = exports.Connect = exports.setTransportFactory = exports.Subscriptions = exports.SubscriptionImpl = exports.MsgImpl = exports.JsHeaders = exports.Events = exports.Empty = exports.DebugEvents = exports.toJsMsg = exports.consumerOpts = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.DiscardPolicy = exports.DeliverPolicy = exports.AdvisoryKind = exports.AckPolicy = exports.NatsError = exports.isNatsError = exports.ErrorCode = exports.nuid = exports.Nuid = exports.NatsConnectionImpl = void 0; | ||
exports.JSONCodec = exports.usernamePasswordAuthenticator = exports.tokenAuthenticator = exports.nkeyAuthenticator = exports.jwtAuthenticator = exports.credsAuthenticator = exports.RequestOne = exports.checkUnsupportedOption = exports.checkOptions = exports.DataBuffer = exports.MuxSubscription = exports.Heartbeat = exports.MsgHdrsImpl = exports.Match = exports.headers = exports.canonicalMIMEHeaderKey = exports.timeout = exports.render = exports.extractProtocolMessage = exports.extend = exports.delay = exports.deferred = exports.collect = exports.ProtocolHandler = exports.INFO = exports.createInbox = exports.Connect = exports.setTransportFactory = exports.Subscriptions = exports.SubscriptionImpl = exports.MsgImpl = exports.JsHeaders = exports.Events = exports.Empty = exports.DebugEvents = exports.toJsMsg = exports.consumerOpts = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.DiscardPolicy = exports.DeliverPolicy = exports.AdvisoryKind = exports.AckPolicy = exports.NatsError = exports.isNatsError = exports.ErrorCode = exports.nuid = exports.Nuid = exports.NatsConnectionImpl = void 0; | ||
exports.parseSemVer = exports.compare = exports.NoopKvCodecs = exports.defaultBucketOpts = exports.Bucket = exports.Base64KeyCodec = exports.nanos = exports.millis = exports.isHeartbeatMsg = exports.isFlowControlMsg = exports.checkJsError = exports.TypedSubscription = exports.parseIP = exports.isIP = 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.StringCodec = void 0; | ||
@@ -82,3 +82,3 @@ var nats_1 = require("./nats"); | ||
var request_1 = require("./request"); | ||
Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_1.Request; } }); | ||
Object.defineProperty(exports, "RequestOne", { enumerable: true, get: function () { return request_1.RequestOne; } }); | ||
var authenticator_1 = require("./authenticator"); | ||
@@ -85,0 +85,0 @@ Object.defineProperty(exports, "credsAuthenticator", { enumerable: true, get: function () { return authenticator_1.credsAuthenticator; } }); |
@@ -106,3 +106,3 @@ "use strict"; | ||
const proto = mi.publisher; | ||
const r = new request_1.Request(proto.muxSubscriptions, this.msg.reply); | ||
const r = new request_1.RequestOne(proto.muxSubscriptions, this.msg.reply); | ||
proto.request(r); | ||
@@ -109,0 +109,0 @@ try { |
import { ProtocolHandler } from "./protocol"; | ||
import { ConnectionOptions, JetStreamClient, JetStreamManager, JetStreamOptions, Msg, NatsConnection, PublishOptions, RequestOptions, ServerInfo, Stats, Status, Subscription, SubscriptionOptions } from "./types"; | ||
import { ConnectionOptions, JetStreamClient, JetStreamManager, JetStreamOptions, Msg, NatsConnection, PublishOptions, RequestManyOptions, RequestOptions, ServerInfo, Stats, Status, Subscription, SubscriptionOptions } from "./types"; | ||
import type { SemVer } from "./semver"; | ||
@@ -18,2 +18,3 @@ import { QueuedIterator } from "./queued_iterator"; | ||
_resub(s: Subscription, subject: string, max?: number): void; | ||
requestMany(subject: string, data?: Uint8Array, opts?: Partial<RequestManyOptions>): Promise<QueuedIterator<Msg | Error>>; | ||
request(subject: string, data?: Uint8Array, opts?: RequestOptions): Promise<Msg>; | ||
@@ -20,0 +21,0 @@ /** * |
@@ -141,2 +141,58 @@ "use strict"; | ||
} | ||
// possibilities are: | ||
// stop on error or any non-100 status | ||
// AND: | ||
// - wait for timer | ||
// - wait for n messages or timer | ||
// - wait for unknown messages, done when empty or reset timer expires (with possible alt wait) | ||
// - wait for unknown messages, done when an empty payload is received or timer expires (with possible alt wait) | ||
requestMany(subject, data = types_1.Empty, opts = { maxWait: 1000, maxMessages: -1 }) { | ||
try { | ||
this._check(subject, true, true); | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
opts.strategy = opts.strategy || types_1.RequestStrategy.Timer; | ||
opts.maxWait = opts.maxWait || 1000; | ||
if (opts.maxWait < 1) { | ||
return Promise.reject(new error_1.NatsError("timeout", error_1.ErrorCode.InvalidOption)); | ||
} | ||
const qi = new queued_iterator_1.QueuedIteratorImpl(); | ||
const stop = () => { | ||
qi.stop(); | ||
}; | ||
const callback = (err, msg) => { | ||
if (err || msg === null) { | ||
// FIXME: the stop function should not require commenting | ||
if (err !== null) { | ||
qi.push(err); | ||
} | ||
//@ts-ignore: stop function after consuming | ||
qi.push(stop); | ||
} | ||
else { | ||
qi.push(msg); | ||
} | ||
}; | ||
const rmo = opts; | ||
rmo.callback = callback; | ||
qi.iterClosed.then(() => { | ||
r.cancel(); | ||
}).catch((err) => { | ||
r.cancel(err); | ||
}); | ||
const r = new request_1.RequestMany(this.protocol.muxSubscriptions, subject, rmo); | ||
this.protocol.request(r); | ||
try { | ||
this.publish(subject, data, { | ||
reply: `${this.protocol.muxSubscriptions.baseInbox}${r.token}`, | ||
headers: opts.headers, | ||
}); | ||
} | ||
catch (err) { | ||
r.cancel(err); | ||
} | ||
return Promise.resolve(qi); | ||
} | ||
request(subject, data = types_1.Empty, opts = { timeout: 1000, noMux: false }) { | ||
@@ -194,3 +250,3 @@ try { | ||
else { | ||
const r = new request_1.Request(this.protocol.muxSubscriptions, subject, opts); | ||
const r = new request_1.RequestOne(this.protocol.muxSubscriptions, subject, opts); | ||
this.protocol.request(r); | ||
@@ -197,0 +253,0 @@ try { |
@@ -396,3 +396,3 @@ "use strict"; | ||
processPing() { | ||
this.transport.send(PONG_CMD).catch(() => { }); | ||
this.transport.send(PONG_CMD); | ||
} | ||
@@ -598,3 +598,3 @@ processPong() { | ||
if (cmds.length) { | ||
this.transport.send((0, encoders_1.encode)(cmds.join(""))).catch(() => { }); | ||
this.transport.send((0, encoders_1.encode)(cmds.join(""))); | ||
} | ||
@@ -650,3 +650,3 @@ } | ||
const d = this.outbound.drain(); | ||
this.transport.send(d).catch(() => { }); | ||
this.transport.send(d); | ||
} | ||
@@ -653,0 +653,0 @@ } |
import { Deferred, Timeout } from "./util"; | ||
import type { Msg, RequestOptions } from "./types"; | ||
import type { Msg, RequestManyOptions, RequestOptions } from "./types"; | ||
import { NatsError } from "./error"; | ||
import { MuxSubscription } from "./muxsubscription"; | ||
export declare class Request { | ||
export interface Request { | ||
token: string; | ||
requestSubject: string; | ||
received: number; | ||
resolver(err: Error | null, msg: Msg): void; | ||
cancel(err?: NatsError): void; | ||
} | ||
export declare class BaseRequest { | ||
token: string; | ||
received: number; | ||
ctx: Error; | ||
requestSubject: string; | ||
mux: MuxSubscription; | ||
constructor(mux: MuxSubscription, requestSubject: string); | ||
} | ||
export interface RequestManyOptionsInternal extends RequestManyOptions { | ||
callback: (err: Error | null, msg: Msg | null) => void; | ||
} | ||
/** | ||
* Request expects multiple message response | ||
* the request ends when the timer expires, | ||
* an error arrives or an expected count of messages | ||
* arrives, end is signaled by a null message | ||
*/ | ||
export declare class RequestMany extends BaseRequest implements Request { | ||
callback: (err: Error | null, msg: Msg | null) => void; | ||
done: Deferred<void>; | ||
timer: number; | ||
max: number; | ||
opts: Partial<RequestManyOptionsInternal>; | ||
constructor(mux: MuxSubscription, requestSubject: string, opts?: Partial<RequestManyOptions>); | ||
cancel(err?: NatsError): void; | ||
resolver(err: Error | null, msg: Msg): void; | ||
} | ||
export declare class RequestOne extends BaseRequest implements Request { | ||
deferred: Deferred<Msg>; | ||
timer: Timeout<Msg>; | ||
ctx: Error; | ||
requestSubject: string; | ||
private mux; | ||
constructor(mux: MuxSubscription, requestSubject: string, opts?: RequestOptions); | ||
@@ -14,0 +43,0 @@ resolver(err: Error | null, msg: Msg): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Request = void 0; | ||
exports.RequestOne = exports.RequestMany = exports.BaseRequest = void 0; | ||
/* | ||
@@ -19,16 +19,86 @@ * Copyright 2020-2021 The NATS Authors | ||
const util_1 = require("./util"); | ||
const types_1 = require("./types"); | ||
const error_1 = require("./error"); | ||
const nuid_1 = require("./nuid"); | ||
class Request { | ||
constructor(mux, requestSubject, opts = { timeout: 1000 }) { | ||
class BaseRequest { | ||
constructor(mux, requestSubject) { | ||
this.mux = mux; | ||
this.requestSubject = requestSubject; | ||
this.received = 0; | ||
this.deferred = (0, util_1.deferred)(); | ||
this.token = nuid_1.nuid.next(); | ||
(0, util_1.extend)(this, opts); | ||
this.timer = (0, util_1.timeout)(opts.timeout); | ||
this.ctx = new Error(); | ||
} | ||
} | ||
exports.BaseRequest = BaseRequest; | ||
/** | ||
* Request expects multiple message response | ||
* the request ends when the timer expires, | ||
* an error arrives or an expected count of messages | ||
* arrives, end is signaled by a null message | ||
*/ | ||
class RequestMany extends BaseRequest { | ||
constructor(mux, requestSubject, opts = { maxWait: 1000 }) { | ||
super(mux, requestSubject); | ||
this.opts = opts; | ||
if (typeof this.opts.callback !== "function") { | ||
throw new Error("callback is required"); | ||
} | ||
this.callback = this.opts.callback; | ||
this.max = typeof opts.maxMessages === "number" && opts.maxMessages > 0 | ||
? opts.maxMessages | ||
: -1; | ||
this.done = (0, util_1.deferred)(); | ||
this.done.then(() => { | ||
this.callback(null, null); | ||
}); | ||
// @ts-ignore: node is not a number | ||
this.timer = setTimeout(() => { | ||
this.cancel(); | ||
}, opts.maxWait); | ||
} | ||
cancel(err) { | ||
if (err) { | ||
this.callback(err, null); | ||
} | ||
clearTimeout(this.timer); | ||
this.mux.cancel(this); | ||
this.done.resolve(); | ||
} | ||
resolver(err, msg) { | ||
if (err) { | ||
err.stack += `\n\n${this.ctx.stack}`; | ||
this.cancel(err); | ||
} | ||
else { | ||
this.callback(null, msg); | ||
if (this.opts.strategy === types_1.RequestStrategy.Count) { | ||
this.max--; | ||
if (this.max === 0) { | ||
this.cancel(); | ||
} | ||
} | ||
if (this.opts.strategy === types_1.RequestStrategy.JitterTimer) { | ||
clearTimeout(this.timer); | ||
// @ts-ignore: node is not a number | ||
this.timer = setTimeout(() => { | ||
this.cancel(); | ||
}, 300); | ||
} | ||
if (this.opts.strategy === types_1.RequestStrategy.SentinelMsg) { | ||
if (msg && msg.data.length === 0) { | ||
this.cancel(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
exports.RequestMany = RequestMany; | ||
class RequestOne extends BaseRequest { | ||
constructor(mux, requestSubject, opts = { timeout: 1000 }) { | ||
super(mux, requestSubject); | ||
// extend(this, opts); | ||
this.deferred = (0, util_1.deferred)(); | ||
this.timer = (0, util_1.timeout)(opts.timeout); | ||
} | ||
resolver(err, msg) { | ||
if (this.timer) { | ||
@@ -54,3 +124,3 @@ this.timer.cancel(); | ||
} | ||
exports.Request = Request; | ||
exports.RequestOne = RequestOne; | ||
//# sourceMappingURL=request.js.map |
@@ -21,3 +21,3 @@ import { ConnectionOptions, DnsResolveFn, Server, URLParseFn } from "./types"; | ||
isEncrypted(): boolean; | ||
send(frame: Uint8Array): Promise<void>; | ||
send(frame: Uint8Array): void; | ||
close(err?: Error): Promise<void>; | ||
@@ -24,0 +24,0 @@ disconnect(): void; |
@@ -173,2 +173,14 @@ import { NatsError } from "./error"; | ||
} | ||
export declare enum RequestStrategy { | ||
Timer = "timer", | ||
Count = "count", | ||
JitterTimer = "jitterTimer", | ||
SentinelMsg = "sentinelMsg" | ||
} | ||
export interface RequestManyOptions { | ||
strategy: RequestStrategy; | ||
maxWait: number; | ||
headers?: MsgHdrs; | ||
maxMessages?: number; | ||
} | ||
export interface PublishOptions { | ||
@@ -175,0 +187,0 @@ reply?: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JsHeaders = exports.ReplayPolicy = exports.AckPolicy = exports.DeliverPolicy = exports.StorageType = exports.DiscardPolicy = exports.RetentionPolicy = exports.AdvisoryKind = exports.DEFAULT_MAX_PING_OUT = exports.DEFAULT_PING_INTERVAL = exports.DEFAULT_JITTER_TLS = exports.DEFAULT_JITTER = exports.DEFAULT_MAX_RECONNECT_ATTEMPTS = exports.DEFAULT_RECONNECT_TIME_WAIT = exports.DEFAULT_HOST = exports.DEFAULT_PORT = exports.DebugEvents = exports.Events = exports.Empty = void 0; | ||
exports.JsHeaders = exports.ReplayPolicy = exports.AckPolicy = exports.DeliverPolicy = exports.StorageType = exports.DiscardPolicy = exports.RetentionPolicy = exports.AdvisoryKind = exports.RequestStrategy = exports.DEFAULT_MAX_PING_OUT = exports.DEFAULT_PING_INTERVAL = exports.DEFAULT_JITTER_TLS = exports.DEFAULT_JITTER = exports.DEFAULT_MAX_RECONNECT_ATTEMPTS = exports.DEFAULT_RECONNECT_TIME_WAIT = exports.DEFAULT_HOST = exports.DEFAULT_PORT = exports.DebugEvents = exports.Events = exports.Empty = void 0; | ||
exports.Empty = new Uint8Array(0); | ||
@@ -29,2 +29,9 @@ var Events; | ||
exports.DEFAULT_MAX_PING_OUT = 2; | ||
var RequestStrategy; | ||
(function (RequestStrategy) { | ||
RequestStrategy["Timer"] = "timer"; | ||
RequestStrategy["Count"] = "count"; | ||
RequestStrategy["JitterTimer"] = "jitterTimer"; | ||
RequestStrategy["SentinelMsg"] = "sentinelMsg"; | ||
})(RequestStrategy = exports.RequestStrategy || (exports.RequestStrategy = {})); | ||
var AdvisoryKind; | ||
@@ -31,0 +38,0 @@ (function (AdvisoryKind) { |
@@ -38,3 +38,4 @@ /// <reference types="node" /> | ||
isEncrypted(): boolean; | ||
send(frame: Uint8Array): Promise<void>; | ||
_send(frame: Uint8Array): Promise<void>; | ||
send(frame: Uint8Array): void; | ||
private _closed; | ||
@@ -41,0 +42,0 @@ closed(): Promise<void | Error>; |
@@ -46,3 +46,3 @@ "use strict"; | ||
const dns = require("dns"); | ||
const VERSION = "2.7.0"; | ||
const VERSION = "2.7.1-1"; | ||
const LANG = "nats.js"; | ||
@@ -320,3 +320,3 @@ class NodeTransport { | ||
} | ||
send(frame) { | ||
_send(frame) { | ||
if (this.isClosed) { | ||
@@ -337,2 +337,10 @@ return Promise.resolve(); | ||
} | ||
send(frame) { | ||
const p = this._send(frame); | ||
p.catch((err) => { | ||
// we ignore write errors because client will | ||
// fail on a read or when the heartbeat timer | ||
// detects a stale connection | ||
}); | ||
} | ||
_closed(err, internal = true) { | ||
@@ -349,3 +357,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
// a close and ensure that we sent all before closing | ||
yield this.send(new TextEncoder().encode("+OK\r\n")); | ||
yield this._send(new TextEncoder().encode("+OK\r\n")); | ||
} | ||
@@ -352,0 +360,0 @@ catch (err) { |
{ | ||
"name": "nats", | ||
"version": "2.7.0", | ||
"version": "2.7.1-1", | ||
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
"clean": "shx rm -Rf ./lib/* ./nats-base-client ./.deps", | ||
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.7.0 https://github.com/nats-io/nats.deno.git", | ||
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch send-change https://github.com/nats-io/nats.deno.git", | ||
"fmt": "deno fmt ./src/ ./examples/ ./test/", | ||
@@ -46,0 +46,0 @@ "prepack": "npm run clone-nbc && npm run cjs && npm run check-package && npm run build", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
654337
10481
1