Comparing version 2.5.0 to 2.6.0
@@ -110,3 +110,3 @@ "use strict"; | ||
// FIXME: specify expires | ||
`${this.prefix}.CONSUMER.MSG.NEXT.${stream}.${durable}`, this.jc.encode({ no_wait: true, batch: 1, expires: (0, jsutil_1.nanos)(this.timeout) }), { noMux: true, timeout: this.timeout }); | ||
`${this.prefix}.CONSUMER.MSG.NEXT.${stream}.${durable}`, this.jc.encode({ no_wait: true, batch: 1, expires: 0 }), { noMux: true, timeout: this.timeout }); | ||
const err = (0, jsutil_1.checkJsError)(msg); | ||
@@ -135,2 +135,5 @@ if (err) { | ||
args.no_wait = opts.no_wait || false; | ||
if (args.no_wait && args.expires) { | ||
args.expires = 0; | ||
} | ||
const expires = opts.expires || 0; | ||
@@ -174,3 +177,5 @@ if (expires) { | ||
} | ||
if ((0, error_1.isNatsError)(err) && err.code === error_1.ErrorCode.JetStream404NoMessages) { | ||
if ((0, error_1.isNatsError)(err) && | ||
(err.code === error_1.ErrorCode.JetStream404NoMessages || | ||
err.code === error_1.ErrorCode.JetStream408RequestTimeout)) { | ||
qi.stop(); | ||
@@ -501,4 +506,5 @@ } | ||
pull(opts = { batch: 1 }) { | ||
const { stream, config } = this.sub.info; | ||
const consumer = config.durable_name; | ||
var _a; | ||
const { stream, config, name } = this.sub.info; | ||
const consumer = (_a = config.durable_name) !== null && _a !== void 0 ? _a : name; | ||
const args = {}; | ||
@@ -505,0 +511,0 @@ args.batch = opts.batch || 1; |
@@ -46,3 +46,6 @@ import { ConsumerConfig, ConsumerOpts, ConsumerOptsBuilder, JsMsgCallback } from "./types"; | ||
bind(stream: string, durable: string): void; | ||
inactiveEphemeralThreshold(millis: number): void; | ||
maxPullBatch(n: number): void; | ||
maxPullRequestExpires(millis: number): void; | ||
} | ||
export declare function isConsumerOptsBuilder(o: ConsumerOptsBuilder | Partial<ConsumerOpts>): o is ConsumerOptsBuilderImpl; |
@@ -160,2 +160,11 @@ "use strict"; | ||
} | ||
inactiveEphemeralThreshold(millis) { | ||
this.config.inactive_threshold = (0, jsutil_1.nanos)(millis); | ||
} | ||
maxPullBatch(n) { | ||
this.config.max_batch = n; | ||
} | ||
maxPullRequestExpires(millis) { | ||
this.config.max_expires = (0, jsutil_1.nanos)(millis); | ||
} | ||
} | ||
@@ -162,0 +171,0 @@ exports.ConsumerOptsBuilderImpl = ConsumerOptsBuilderImpl; |
@@ -23,3 +23,3 @@ import { DeliveryInfo, JsMsg, Msg, NextRequest } from "./types"; | ||
ack(): void; | ||
nak(): void; | ||
nak(millis?: number): void; | ||
working(): void; | ||
@@ -26,0 +26,0 @@ next(subj?: string, ro?: Partial<NextRequest>): void; |
@@ -16,2 +16,3 @@ "use strict"; | ||
const request_1 = require("./request"); | ||
const jsutil_1 = require("./jsutil"); | ||
exports.ACK = Uint8Array.of(43, 65, 67, 75); | ||
@@ -131,4 +132,8 @@ const NAK = Uint8Array.of(45, 78, 65, 75); | ||
} | ||
nak() { | ||
this.doAck(NAK); | ||
nak(millis) { | ||
let payload = NAK; | ||
if (millis) { | ||
payload = (0, codec_1.StringCodec)().encode(`-NAK ${JSON.stringify({ delay: (0, jsutil_1.nanos)(millis) })}`); | ||
} | ||
this.doAck(payload); | ||
} | ||
@@ -135,0 +140,0 @@ working() { |
@@ -85,2 +85,4 @@ "use strict"; | ||
switch (code) { | ||
case 408: | ||
return error_1.NatsError.errorForCode(error_1.ErrorCode.JetStream408RequestTimeout, new Error(description)); | ||
case 503: | ||
@@ -87,0 +89,0 @@ return error_1.NatsError.errorForCode(error_1.ErrorCode.JetStreamNotEnabled, new Error(description)); |
@@ -44,8 +44,12 @@ "use strict"; | ||
opts = opts || { servers: [dhp] }; | ||
if (opts.port) { | ||
opts.servers = [`${types_1.DEFAULT_HOST}:${opts.port}`]; | ||
} | ||
opts.servers = opts.servers || []; | ||
if (typeof opts.servers === "string") { | ||
opts.servers = [opts.servers]; | ||
} | ||
if (opts.servers.length > 0 && opts.port) { | ||
throw new error_1.NatsError("port and servers options are mutually exclusive", error_1.ErrorCode.InvalidOption); | ||
} | ||
if (opts.servers.length === 0 && opts.port) { | ||
opts.servers = [`${types_1.DEFAULT_HOST}:${opts.port}`]; | ||
} | ||
if (opts.servers && opts.servers.length === 0) { | ||
@@ -52,0 +56,0 @@ opts.servers = [dhp]; |
import { DnsResolveFn, Server, ServerInfo, ServersChanged } from "./types"; | ||
export declare function isIPV4OrHostname(hp: string): boolean; | ||
export declare function hostPort(u: string): { | ||
listen: string; | ||
hostname: string; | ||
port: number; | ||
}; | ||
/** | ||
@@ -3,0 +9,0 @@ * @hidden |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Servers = exports.ServerImpl = void 0; | ||
exports.Servers = exports.ServerImpl = exports.hostPort = exports.isIPV4OrHostname = void 0; | ||
/* | ||
@@ -33,3 +33,21 @@ * Copyright 2018-2021 The NATS Authors | ||
const ipparser_1 = require("./ipparser"); | ||
function isIPV4OrHostname(hp) { | ||
if (hp.indexOf(".") !== -1) { | ||
return true; | ||
} | ||
if (hp.indexOf("[") !== -1 || hp.indexOf("::") !== -1) { | ||
return false; | ||
} | ||
// if we have a plain hostname or host:port | ||
if (hp.split(":").length <= 2) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
exports.isIPV4OrHostname = isIPV4OrHostname; | ||
function isIPV6(hp) { | ||
return !isIPV4OrHostname(hp); | ||
} | ||
function hostPort(u) { | ||
u = u.trim(); | ||
// remove any protocol that may have been provided | ||
@@ -42,11 +60,30 @@ if (u.match(/^(.*:\/\/)(.*)/m)) { | ||
// parsable correctly. | ||
const url = new URL(`http://${u}`); | ||
if (!url.port) { | ||
url.port = `${types_1.DEFAULT_PORT}`; | ||
// the third complication is that we may have been given | ||
// an IPv6 | ||
// we only wrap cases where they gave us a plain ipv6 | ||
// and we are not already bracketed | ||
if (isIPV6(u) && u.indexOf("[") === -1) { | ||
u = `[${u}]`; | ||
} | ||
// if we have ipv6, we expect port after ']:' otherwise after ':' | ||
const op = isIPV6(u) ? u.match(/(]:)(\d+)/) : u.match(/(:)(\d+)/); | ||
const port = op && op.length === 3 && op[1] && op[2] | ||
? parseInt(op[2]) | ||
: types_1.DEFAULT_PORT; | ||
// the next complication is that new URL() may | ||
// eat ports which match the protocol - so for example | ||
// port 80 may be eliminated - so we flip the protocol | ||
// so that it always yields a value | ||
const protocol = port === 80 ? "https" : "http"; | ||
const url = new URL(`${protocol}://${u}`); | ||
url.port = `${port}`; | ||
let hostname = url.hostname; | ||
// if we are bracketed, we need to rip it out | ||
if (hostname.charAt(0) === "[") { | ||
hostname = hostname.substring(1, hostname.length - 1); | ||
} | ||
const listen = url.host; | ||
const hostname = url.hostname; | ||
const port = parseInt(url.port, 10); | ||
return { listen, hostname, port }; | ||
} | ||
exports.hostPort = hostPort; | ||
/** | ||
@@ -84,10 +121,12 @@ * @hidden | ||
else { | ||
// resolve the hostname to ips | ||
const ips = yield opts.fn(this.hostname); | ||
for (const ip of ips) { | ||
for (let ip of ips) { | ||
// letting URL handle the details of representing IPV6 ip with a port, etc | ||
const url = new URL(`http://${this.listen}`); | ||
if (!url.port) { | ||
url.port = `${types_1.DEFAULT_PORT}`; | ||
} | ||
url.hostname = ip; | ||
// careful to make sure the protocol doesn't line with standard ports or they | ||
// get swallowed | ||
const proto = this.port === 80 ? "https" : "http"; | ||
// ipv6 won't be bracketed here, because it came from resolve | ||
const url = new URL(`${proto}://${isIPV6(ip) ? "[" + ip + "]" : ip}`); | ||
url.port = `${this.port}`; | ||
const ss = new ServerImpl(url.host, false); | ||
@@ -94,0 +133,0 @@ ss.tlsName = this.hostname; |
@@ -291,2 +291,5 @@ import { NatsError } from "./error"; | ||
bind(stream: string, durable: string): void; | ||
maxPullBatch(n: number): void; | ||
maxPullRequestExpires(millis: number): void; | ||
inactiveEphemeralThreshold(millis: number): void; | ||
} | ||
@@ -326,3 +329,3 @@ export interface Lister<T> { | ||
ack(): void; | ||
nak(): void; | ||
nak(millis?: number): void; | ||
working(): void; | ||
@@ -608,2 +611,5 @@ term(): void; | ||
"deliver_subject"?: string; | ||
"max_batch"?: number; | ||
"max_expires"?: Nanos; | ||
"inactive_threshold"?: Nanos; | ||
} | ||
@@ -610,0 +616,0 @@ export interface Consumer { |
@@ -46,3 +46,3 @@ "use strict"; | ||
const dns = require("dns"); | ||
const VERSION = "2.5.0"; | ||
const VERSION = "2.6.0"; | ||
const LANG = "nats.js"; | ||
@@ -49,0 +49,0 @@ class NodeTransport { |
{ | ||
"name": "nats", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"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.5.0 https://github.com/nats-io/nats.deno.git", | ||
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.6.0 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
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
616437
9850