Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nats

Package Overview
Dependencies
Maintainers
3
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nats - npm Package Compare versions

Comparing version 2.8.1-1 to 2.8.1-2

1

lib/nats-base-client/jsclient.d.ts

@@ -13,2 +13,3 @@ import type { ConsumerOptsBuilder, Views } from "./types";

constructor(nc: NatsConnection, opts?: JetStreamOptions);
get apiPrefix(): string;
get views(): Views;

@@ -15,0 +16,0 @@ publish(subj: string, data?: Uint8Array, opts?: Partial<JetStreamPublishOptions>): Promise<PubAck>;

@@ -71,2 +71,5 @@ "use strict";

}
get apiPrefix() {
return this.prefix;
}
get views() {

@@ -73,0 +76,0 @@ return new ViewsImpl(this);

@@ -46,2 +46,3 @@ import { ConsumerConfig, ConsumerOpts, ConsumerOptsBuilder, JsMsgCallback } from "./types";

bind(stream: string, durable: string): this;
bindStream(stream: string): this;
inactiveEphemeralThreshold(millis: number): this;

@@ -48,0 +49,0 @@ maxPullBatch(n: number): this;

@@ -192,2 +192,6 @@ "use strict";

}
bindStream(stream) {
this.stream = stream;
return this;
}
inactiveEphemeralThreshold(millis) {

@@ -194,0 +198,0 @@ this.config.inactive_threshold = (0, jsutil_1.nanos)(millis);

5

lib/nats-base-client/jsmdirect_api.js

@@ -45,5 +45,6 @@ "use strict";

const payload = qq ? this.jc.encode(qq) : types_1.Empty;
const pre = this.opts.apiPrefix || "$JS.API";
const subj = last_by_subj
? `$JS.API.DIRECT.GET.${stream}.${last_by_subj}`
: `$JS.API.DIRECT.GET.${stream}`;
? `${pre}.DIRECT.GET.${stream}.${last_by_subj}`
: `${pre}.DIRECT.GET.${stream}`;
const r = yield this.nc.request(subj, payload);

@@ -50,0 +51,0 @@ // response is not a JS.API response

@@ -1,4 +0,5 @@

import { JetStreamOptions, KvStatus, Lister, MsgRequest, NatsConnection, ObjectStoreStatus, PurgeOpts, PurgeResponse, StoredMsg, StreamAPI, StreamConfig, StreamInfo, StreamInfoRequestOptions, StreamMsgResponse, StreamUpdateConfig } from "./types";
import { JetStreamOptions, KvStatus, Lister, MsgRequest, NatsConnection, ObjectStoreStatus, PurgeOpts, PurgeResponse, StoredMsg, StreamAPI, StreamConfig, StreamInfo, StreamInfoRequestOptions, StreamMsgResponse, StreamSource, StreamUpdateConfig } from "./types";
import { BaseApiClient } from "./jsbaseclient_api";
import { MsgHdrs } from "./headers";
export declare function convertStreamSourceDomain(s?: StreamSource): StreamSource;
export declare class StreamAPIImpl extends BaseApiClient implements StreamAPI {

@@ -5,0 +6,0 @@ constructor(nc: NatsConnection, opts?: JetStreamOptions);

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.StoredMsgImpl = exports.StreamAPIImpl = void 0;
exports.StoredMsgImpl = exports.StreamAPIImpl = exports.convertStreamSourceDomain = void 0;
const types_1 = require("./types");

@@ -35,2 +35,22 @@ const jsbaseclient_api_1 = require("./jsbaseclient_api");

const objectstore_1 = require("./objectstore");
function convertStreamSourceDomain(s) {
if (s === undefined) {
return undefined;
}
const { domain } = s;
if (domain === undefined) {
return s;
}
const copy = Object.assign({}, s);
delete copy.domain;
if (domain === "") {
return copy;
}
if (copy.external) {
throw new Error("domain and external are both set");
}
copy.external = { api: `$JS.${domain}.API` };
return copy;
}
exports.convertStreamSourceDomain = convertStreamSourceDomain;
class StreamAPIImpl extends jsbaseclient_api_1.BaseApiClient {

@@ -41,4 +61,8 @@ constructor(nc, opts) {

add(cfg = {}) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
(0, jsutil_1.validateStreamName)(cfg.name);
cfg.mirror = convertStreamSourceDomain(cfg.mirror);
//@ts-ignore: the sources are either set or not - so no item should be undefined in the list
cfg.sources = (_a = cfg.sources) === null || _a === void 0 ? void 0 : _a.map(convertStreamSourceDomain);
const r = yield this._request(`${this.prefix}.STREAM.CREATE.${cfg.name}`, cfg);

@@ -59,2 +83,3 @@ const si = r;

update(name, cfg = {}) {
var _a;
return __awaiter(this, void 0, void 0, function* () {

@@ -70,2 +95,5 @@ if (typeof name === "object") {

const update = Object.assign(old.config, cfg);
update.mirror = convertStreamSourceDomain(update.mirror);
//@ts-ignore: the sources are either set or not - so no item should be undefined in the list
update.sources = (_a = update.sources) === null || _a === void 0 ? void 0 : _a.map(convertStreamSourceDomain);
const r = yield this._request(`${this.prefix}.STREAM.UPDATE.${name}`, update);

@@ -72,0 +100,0 @@ const si = r;

@@ -20,4 +20,6 @@ import { callbackFn, ConsumerConfig, JetStreamClient, JetStreamManager, JsMsg, KV, KvCodec, KvCodecs, KvEntry, KvOptions, KvPutOptions, KvRemove, KvStatus, Placement, PurgeOpts, PurgeResponse, Republish, StorageType, StoredMsg, StreamInfo } from "./types";

codec: KvCodecs;
prefix: string;
editPrefix: string;
useJsPrefix: boolean;
_prefixLen: number;
subjPrefix: string;
constructor(bucket: string, jsm: JetStreamManager, js: JetStreamClient);

@@ -29,5 +31,6 @@ static create(js: JetStreamClient, name: string, opts?: Partial<KvOptions>): Promise<KV>;

init(opts?: Partial<KvOptions>): Promise<void>;
initializePrefixes(info: StreamInfo): void;
bucketName(): string;
subjectForBucket(): string;
subjectForKey(k: string): string;
subjectForKey(k: string, edit?: boolean): string;
fullKeyName(k: string): string;

@@ -34,0 +37,0 @@ get prefixLen(): number;

@@ -143,9 +143,6 @@ "use strict";

this.bucket = bucket;
this.prefix = kvSubjectPrefix;
this.editPrefix = "";
this.useJsPrefix = false;
this._prefixLen = 0;
this.subjPrefix = kvSubjectPrefix;
const jsi = js;
const prefix = jsi.prefix || "$JS.API";
if (prefix !== "$JS.API") {
this.subjPrefix = `${prefix}.${kvSubjectPrefix}`;
}
}

@@ -180,2 +177,3 @@ static create(js, name, opts = {}) {

bucket.direct = (_a = info.config.allow_direct) !== null && _a !== void 0 ? _a : false;
bucket.initializePrefixes(info);
return bucket;

@@ -191,3 +189,2 @@ });

this.stream = sc.name = (_a = opts.streamName) !== null && _a !== void 0 ? _a : this.bucketName();
sc.subjects = [this.subjectForBucket()];
sc.retention = types_1.RetentionPolicy.Limits;

@@ -218,2 +215,22 @@ sc.max_msgs_per_subject = bo.history;

}
if (opts.mirror) {
const mirror = Object.assign({}, opts.mirror);
if (!mirror.name.startsWith(exports.kvPrefix)) {
mirror.name = `${exports.kvPrefix}${mirror.name}`;
}
sc.mirror = mirror;
sc.mirror_direct = true;
}
else if (opts.sources) {
const sources = opts.sources.map((s) => {
const c = Object.assign({}, s);
if (!c.name.startsWith(exports.kvPrefix)) {
c.name = `${exports.kvPrefix}${c.name}`;
}
});
sc.sources = sources;
}
else {
sc.subjects = [this.subjectForBucket()];
}
const nci = this.js.nc;

@@ -244,4 +261,5 @@ const have = nci.getServerVersion();

sc.allow_rollup_hdrs = true;
let info;
try {
const info = yield this.jsm.streams.info(sc.name);
info = yield this.jsm.streams.info(sc.name);
if (!info.config.allow_direct && this.direct === true) {

@@ -253,7 +271,33 @@ this.direct = false;

if (err.message === "stream not found") {
yield this.jsm.streams.add(sc);
info = yield this.jsm.streams.add(sc);
}
else {
throw err;
}
}
this.initializePrefixes(info);
});
}
initializePrefixes(info) {
this._prefixLen = 0;
this.prefix = `$KV.${this.bucket}`;
this.useJsPrefix =
this.js.opts.apiPrefix !== "$JS.API";
const { mirror } = info.config;
if (mirror) {
let n = mirror.name;
if (n.startsWith(exports.kvPrefix)) {
n = n.substring(exports.kvPrefix.length);
}
if (mirror.external && mirror.external.api !== "") {
const mb = mirror.name.substring(exports.kvPrefix.length);
this.useJsPrefix = false;
this.prefix = `$KV.${mb}`;
this.editPrefix = `${mirror.external.api}.$KV.${n}`;
}
else {
this.editPrefix = this.prefix;
}
}
}
bucketName() {

@@ -264,8 +308,29 @@ var _a;

subjectForBucket() {
return `${this.subjPrefix}.${this.bucket}.>`;
return `${this.prefix}.${this.bucket}.>`;
}
subjectForKey(k) {
return `${this.subjPrefix}.${this.bucket}.${k}`;
subjectForKey(k, edit = false) {
const builder = [];
if (edit) {
if (this.useJsPrefix) {
builder.push(this.js.apiPrefix);
}
if (this.editPrefix !== "") {
builder.push(this.editPrefix);
}
else {
builder.push(this.prefix);
}
}
else {
if (this.prefix) {
builder.push(this.prefix);
}
}
builder.push(k);
return builder.join(".");
}
fullKeyName(k) {
if (this.prefix !== "") {
return `${this.prefix}.${k}`;
}
return `${kvSubjectPrefix}.${this.bucket}.${k}`;

@@ -275,3 +340,3 @@ }

if (this._prefixLen === 0) {
this._prefixLen = `${kvSubjectPrefix}.${this.bucket}.`.length;
this._prefixLen = this.prefix.length + 1;
}

@@ -367,3 +432,3 @@ return this._prefixLen;

try {
const pa = yield this.js.publish(this.subjectForKey(ek), data, o);
const pa = yield this.js.publish(this.subjectForKey(ek, true), data, o);
return pa.seq;

@@ -386,3 +451,3 @@ }

this.validateKey(ek);
let arg = { last_by_subj: this.fullKeyName(ek) };
let arg = { last_by_subj: this.subjectForKey(ek) };
if (opts && opts.revision > 0) {

@@ -507,3 +572,3 @@ arg = { seq: opts.revision };

}
yield this.js.publish(this.subjectForKey(ek), types_1.Empty, { headers: h });
yield this.js.publish(this.subjectForKey(ek, true), types_1.Empty, { headers: h });
});

@@ -542,2 +607,3 @@ }

const copts = (0, mod_1.consumerOpts)(cc);
copts.bindStream(this.stream);
copts.orderedConsumer();

@@ -613,2 +679,3 @@ copts.callback((err, jm) => {

const copts = (0, mod_1.consumerOpts)(cc);
copts.bindStream(this.stream);
copts.orderedConsumer();

@@ -678,2 +745,3 @@ copts.callback((err, jm) => {

const copts = (0, mod_1.consumerOpts)(cc);
copts.bindStream(this.stream);
copts.orderedConsumer();

@@ -680,0 +748,0 @@ const sub = yield this.js.subscribe(subj, copts);

@@ -81,3 +81,3 @@ import { ConnectionOptions, PublishOptions, Server, ServerInfo, Status, Subscription } from "./types";

disconnect(): void;
disconnected(_err?: Error): Promise<void>;
disconnected(err?: Error): Promise<void>;
dial(srv: Server): Promise<void>;

@@ -84,0 +84,0 @@ _doDial(srv: Server): Promise<void>;

@@ -114,5 +114,8 @@ "use strict";

this.pongs = [];
// reject the pongs
// reject the pongs - the disconnect from here shouldn't have a trace
// because that confuses API consumers
const err = error_1.NatsError.errorForCode(error_1.ErrorCode.Disconnect);
err.stack = "";
pongs.forEach((p) => {
p.reject(error_1.NatsError.errorForCode(error_1.ErrorCode.Disconnect));
p.reject(err);
});

@@ -158,3 +161,3 @@ this.parser = new parser_1.Parser(this);

}
disconnected(_err) {
disconnected(err) {
return __awaiter(this, void 0, void 0, function* () {

@@ -178,3 +181,3 @@ this.dispatchStatus({

else {
yield this._close();
yield this._close(err);
}

@@ -181,0 +184,0 @@ });

@@ -19,3 +19,3 @@ /// <reference types="node" />

done: boolean;
closedError?: Error;
closeError?: Error;
constructor();

@@ -22,0 +22,0 @@ connect(hp: {

@@ -46,3 +46,3 @@ "use strict";

const dns = require("dns");
const VERSION = "2.8.1-1";
const VERSION = "2.8.1-2";
const LANG = "nats.js";

@@ -280,3 +280,2 @@ class NodeTransport {

this._closed(connError, false);
this.socket = undefined;
});

@@ -364,8 +363,12 @@ }

return;
this.closedError = err;
if (!err && this.socket) {
this.closeError = err;
if (err) {
console.log(`transport closed with error: ${err.message}`);
console.log(`${err.stack}`);
}
// only try to flush the outbound buffer if we got no error and
// the close is internal, if the transport closed, we are done.
if (!err && this.socket && internal) {
try {
// this is a noop for the server, but gives us a place to hang
// 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(""));
}

@@ -382,2 +385,3 @@ catch (err) {

this.socket.destroy();
this.socket = undefined;
}

@@ -389,3 +393,3 @@ }

this.done = true;
this.closedNotification.resolve(err);
this.closedNotification.resolve(this.closeError);
});

@@ -392,0 +396,0 @@ }

{
"name": "nats",
"version": "2.8.1-1",
"version": "2.8.1-2",
"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 handle-initial-pong-rejection https://github.com/nats-io/nats.deno.git",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch main 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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc