@nats-io/jetstream
Advanced tools
Comparing version 3.0.0-19 to 3.0.0-20
@@ -95,3 +95,2 @@ "use strict"; | ||
const status = new jserrors_1.JetStreamStatus(msg); | ||
status.debug(); | ||
if (status.isIdleHeartbeat()) { | ||
@@ -505,3 +504,3 @@ this.notify(types_1.ConsumerDebugEvents.Heartbeat, status.parseHeartbeat()); | ||
if (args.expires < 1000) { | ||
throw new internal_1.errors.InvalidArgumentError(internal_1.errors.InvalidArgumentError.format("expires", "must be at least 1000ms")); | ||
throw internal_1.errors.InvalidArgumentError.format("expires", "must be at least 1000ms"); | ||
} | ||
@@ -567,3 +566,3 @@ // require idle_heartbeat | ||
if (opts.bind) { | ||
return Promise.reject(new internal_1.errors.InvalidArgumentError(internal_1.errors.InvalidArgumentError.format("bind", "is not supported"))); | ||
return Promise.reject(internal_1.errors.InvalidArgumentError.format("bind", "is not supported")); | ||
} | ||
@@ -586,3 +585,3 @@ if (this.type === PullConsumerType.Fetch) { | ||
if (opts.bind) { | ||
return Promise.reject(new internal_1.errors.InvalidArgumentError(internal_1.errors.InvalidArgumentError.format("bind", "is not supported"))); | ||
return Promise.reject(internal_1.errors.InvalidArgumentError.format("bind", "is not supported")); | ||
} | ||
@@ -589,0 +588,0 @@ if (this.type === PullConsumerType.Consume) { |
@@ -10,2 +10,2 @@ export { AdvisoryKind, ConsumerDebugEvents, ConsumerEvents, DirectMsgHeaders, isBoundPushConsumerOptions, isOrderedPushConsumerOptions, isPullConsumer, isPushConsumer, JsHeaders, RepublishHeaders, } from "./types"; | ||
export { ListerImpl } from "./jslister"; | ||
export { isMessageNotFound, JetStreamApiCodes, JetStreamApiError, JetStreamError, } from "./jserrors"; | ||
export { isMessageNotFound, JetStreamApiCodes, JetStreamApiError, JetStreamError, jserrors, } from "./jserrors"; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JetStreamError = exports.JetStreamApiError = exports.JetStreamApiCodes = exports.isMessageNotFound = exports.ListerImpl = exports.StoreCompression = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.PubHeaders = exports.DiscardPolicy = exports.DeliverPolicy = exports.AckPolicy = exports.toJetStreamClient = exports.jetstreamManager = exports.JetStreamClientImpl = exports.jetstream = exports.RepublishHeaders = exports.JsHeaders = exports.isPushConsumer = exports.isPullConsumer = exports.isOrderedPushConsumerOptions = exports.isBoundPushConsumerOptions = exports.DirectMsgHeaders = exports.ConsumerEvents = exports.ConsumerDebugEvents = exports.AdvisoryKind = void 0; | ||
exports.jserrors = exports.JetStreamError = exports.JetStreamApiError = exports.JetStreamApiCodes = exports.isMessageNotFound = exports.ListerImpl = exports.StoreCompression = exports.StorageType = exports.RetentionPolicy = exports.ReplayPolicy = exports.PubHeaders = exports.DiscardPolicy = exports.DeliverPolicy = exports.AckPolicy = exports.toJetStreamClient = exports.jetstreamManager = exports.JetStreamClientImpl = exports.jetstream = exports.RepublishHeaders = exports.JsHeaders = exports.isPushConsumer = exports.isPullConsumer = exports.isOrderedPushConsumerOptions = exports.isBoundPushConsumerOptions = exports.DirectMsgHeaders = exports.ConsumerEvents = exports.ConsumerDebugEvents = exports.AdvisoryKind = void 0; | ||
var types_1 = require("./types"); | ||
@@ -51,2 +51,3 @@ Object.defineProperty(exports, "AdvisoryKind", { enumerable: true, get: function () { return types_1.AdvisoryKind; } }); | ||
Object.defineProperty(exports, "JetStreamError", { enumerable: true, get: function () { return jserrors_1.JetStreamError; } }); | ||
Object.defineProperty(exports, "jserrors", { enumerable: true, get: function () { return jserrors_1.jserrors; } }); | ||
//# sourceMappingURL=internal_mod.js.map |
@@ -49,3 +49,3 @@ "use strict"; | ||
if (!prefix || prefix.length === 0) { | ||
throw new internal_1.errors.InvalidArgumentError(internal_1.errors.InvalidArgumentError.format("prefix", "cannot be empty")); | ||
throw internal_1.errors.InvalidArgumentError.format("prefix", "cannot be empty"); | ||
} | ||
@@ -75,10 +75,13 @@ const c = prefix[prefix.length - 1]; | ||
catch (err) { | ||
const { cause } = err; | ||
if ((cause instanceof internal_1.errors.TimeoutError || | ||
cause instanceof internal_1.errors.NoRespondersError) && | ||
i + 1 < retries) { | ||
const re = err instanceof internal_1.RequestError ? err : null; | ||
if (err instanceof internal_1.errors.TimeoutError || | ||
re?.isNoResponders() && i + 1 < retries) { | ||
await (0, internal_1.delay)(bo.backoff(i)); | ||
} | ||
else { | ||
throw err; | ||
throw re?.isNoResponders() | ||
? new jserrors_1.JetStreamNotEnabled("jetstream is not enabled", { | ||
cause: err, | ||
}) | ||
: err; | ||
} | ||
@@ -93,3 +96,3 @@ } | ||
if (!names.streams || names.streams.length !== 1) { | ||
throw new Error("no stream matches subject"); | ||
throw jserrors_1.StreamNotFoundError.fromMessage("no stream matches subject"); | ||
} | ||
@@ -105,3 +108,14 @@ return names.streams[0]; | ||
if (r.error) { | ||
throw new jserrors_1.JetStreamApiError(r.error); | ||
switch (r.error.err_code) { | ||
case jserrors_1.JetStreamApiCodes.ConsumerNotFound: | ||
throw new jserrors_1.ConsumerNotFoundError(r.error); | ||
case jserrors_1.JetStreamApiCodes.StreamNotFound: | ||
throw new jserrors_1.StreamNotFoundError(r.error); | ||
case jserrors_1.JetStreamApiCodes.JetStreamNotEnabledForAccount: { | ||
const jserr = new jserrors_1.JetStreamApiError(r.error); | ||
throw new jserrors_1.JetStreamNotEnabled(jserr.message, { cause: jserr }); | ||
} | ||
default: | ||
throw new jserrors_1.JetStreamApiError(r.error); | ||
} | ||
} | ||
@@ -108,0 +122,0 @@ return v; |
@@ -56,7 +56,3 @@ "use strict"; | ||
catch (err) { | ||
if (err instanceof internal_2.errors.RequestError && | ||
err.message.includes("no responders")) { | ||
throw new jserrors_1.JetStreamError("jetstream is not enabled", err); | ||
} | ||
throw new jserrors_1.JetStreamError(err.message, err); | ||
throw err; | ||
} | ||
@@ -167,4 +163,3 @@ } | ||
catch (err) { | ||
if (err instanceof internal_2.errors.RequestError && | ||
err.message.includes("no responders")) { | ||
if (err instanceof internal_2.errors.RequestError && err.isNoResponders()) { | ||
await (0, internal_1.delay)(retry_delay); | ||
@@ -171,0 +166,0 @@ } |
import type { Msg } from "@nats-io/nats-core"; | ||
import type { ApiError } from "./jsapi_types"; | ||
export declare class JetStreamNotEnabled extends Error { | ||
constructor(message: string, opts?: ErrorOptions); | ||
} | ||
export declare class JetStreamStatusError extends Error { | ||
@@ -11,2 +14,3 @@ code: number; | ||
constructor(msg: Msg); | ||
static maybeParseStatus(msg: Msg): JetStreamStatus | null; | ||
toError(): JetStreamStatusError; | ||
@@ -50,14 +54,2 @@ debug(): void; | ||
export declare function isMessageNotFound(err: Error): boolean; | ||
export declare class MessageNotFoundError extends Error { | ||
constructor(message: string, opts?: ErrorOptions); | ||
} | ||
export declare class ConsumerNotFoundError extends Error { | ||
stream: string; | ||
consumer: string; | ||
constructor(stream: string, consumer: string, opts?: ErrorOptions); | ||
} | ||
export declare class StreamNotFoundError extends Error { | ||
stream: string; | ||
constructor(stream: string, opts?: ErrorOptions); | ||
} | ||
export declare class InvalidNameError extends Error { | ||
@@ -73,2 +65,9 @@ constructor(name: string, message?: string, opts?: ErrorOptions); | ||
} | ||
export declare class ConsumerNotFoundError extends JetStreamApiError { | ||
constructor(jsErr: ApiError, opts?: ErrorOptions); | ||
} | ||
export declare class StreamNotFoundError extends JetStreamApiError { | ||
constructor(jsErr: ApiError, opts?: ErrorOptions); | ||
static fromMessage(message: string): JetStreamApiError; | ||
} | ||
export declare const jserrors: { | ||
@@ -79,2 +78,4 @@ InvalidNameError: typeof InvalidNameError; | ||
JetStreamError: typeof JetStreamError; | ||
JetStreamApiError: typeof JetStreamApiError; | ||
JetStreamNotEnabled: typeof JetStreamNotEnabled; | ||
}; |
@@ -17,5 +17,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.jserrors = exports.JetStreamApiError = exports.InvalidNameError = exports.StreamNotFoundError = exports.ConsumerNotFoundError = exports.MessageNotFoundError = exports.JetStreamApiCodes = exports.JetStreamError = exports.JetStreamStatus = exports.JetStreamStatusError = void 0; | ||
exports.jserrors = exports.StreamNotFoundError = exports.ConsumerNotFoundError = exports.JetStreamApiError = exports.InvalidNameError = exports.JetStreamApiCodes = exports.JetStreamError = exports.JetStreamStatus = exports.JetStreamStatusError = exports.JetStreamNotEnabled = void 0; | ||
exports.isMessageNotFound = isMessageNotFound; | ||
const types_1 = require("./types"); | ||
class JetStreamNotEnabled extends Error { | ||
constructor(message, opts) { | ||
super(message, opts); | ||
this.name = "JetStreamNotEnabled"; | ||
} | ||
} | ||
exports.JetStreamNotEnabled = JetStreamNotEnabled; | ||
class JetStreamStatusError extends Error { | ||
@@ -37,2 +44,6 @@ code; | ||
} | ||
static maybeParseStatus(msg) { | ||
const status = new JetStreamStatus(msg); | ||
return status.code === 0 ? null : status; | ||
} | ||
toError() { | ||
@@ -149,29 +160,2 @@ return new JetStreamStatusError(this.description, this.code); | ||
} | ||
class MessageNotFoundError extends Error { | ||
constructor(message, opts) { | ||
super(message, opts); | ||
this.name = "MessageNotFoundError"; | ||
} | ||
} | ||
exports.MessageNotFoundError = MessageNotFoundError; | ||
class ConsumerNotFoundError extends Error { | ||
stream; | ||
consumer; | ||
constructor(stream, consumer, opts) { | ||
super(`consumer not found`, opts); | ||
this.stream = stream; | ||
this.consumer = consumer; | ||
this.name = "ConsumerNotFoundError"; | ||
} | ||
} | ||
exports.ConsumerNotFoundError = ConsumerNotFoundError; | ||
class StreamNotFoundError extends Error { | ||
stream; | ||
constructor(stream, opts) { | ||
super(`stream not found`, opts); | ||
this.stream = stream; | ||
this.name = "StreamNotFoundError"; | ||
} | ||
} | ||
exports.StreamNotFoundError = StreamNotFoundError; | ||
class InvalidNameError extends Error { | ||
@@ -202,2 +186,23 @@ constructor(name, message = "", opts) { | ||
exports.JetStreamApiError = JetStreamApiError; | ||
class ConsumerNotFoundError extends JetStreamApiError { | ||
constructor(jsErr, opts) { | ||
super(jsErr, opts); | ||
this.name = "ConsumerNotFoundError"; | ||
} | ||
} | ||
exports.ConsumerNotFoundError = ConsumerNotFoundError; | ||
class StreamNotFoundError extends JetStreamApiError { | ||
constructor(jsErr, opts) { | ||
super(jsErr, opts); | ||
this.name = "StreamNotFoundError"; | ||
} | ||
static fromMessage(message) { | ||
return new StreamNotFoundError({ | ||
err_code: JetStreamApiCodes.StreamNotFound, | ||
description: message, | ||
code: 404, | ||
}); | ||
} | ||
} | ||
exports.StreamNotFoundError = StreamNotFoundError; | ||
exports.jserrors = { | ||
@@ -208,3 +213,5 @@ InvalidNameError, | ||
JetStreamError, | ||
JetStreamApiError, | ||
JetStreamNotEnabled, | ||
}; | ||
//# sourceMappingURL=jserrors.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ListerImpl = void 0; | ||
/* | ||
* Copyright 2021-2024 The NATS Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
const internal_1 = require("@nats-io/nats-core/internal"); | ||
class ListerImpl { | ||
@@ -14,3 +29,3 @@ err; | ||
if (!subject) { | ||
throw new Error("subject is required"); | ||
throw internal_1.errors.InvalidArgumentError.format("subject", "is required"); | ||
} | ||
@@ -17,0 +32,0 @@ this.subject = subject; |
@@ -63,3 +63,3 @@ "use strict"; | ||
if (!Array.isArray(opts.multi_last) || opts.multi_last.length === 0) { | ||
return Promise.reject("multi_last is required"); | ||
return Promise.reject(internal_1.errors.InvalidArgumentError.format("multi_last", "is required")); | ||
} | ||
@@ -79,9 +79,8 @@ const payload = JSON.stringify(opts, (key, value) => { | ||
let badServer = false; | ||
let badRequest; | ||
let status = null; | ||
for await (const m of raw) { | ||
if (!gotFirst) { | ||
gotFirst = true; | ||
const code = m.headers?.code || 0; | ||
if (code !== 0 && code < 200 || code > 299) { | ||
badRequest = m.headers?.description.toLowerCase(); | ||
status = jserrors_1.JetStreamStatus.maybeParseStatus(m); | ||
if (status) { | ||
break; | ||
@@ -106,8 +105,10 @@ } | ||
} | ||
if (badRequest) { | ||
throw new Error(`bad request: ${badRequest}`); | ||
if (status) { | ||
throw status.toError(); | ||
} | ||
iter.stop(); | ||
}); | ||
})(); | ||
})().catch((err) => { | ||
iter.stop(err); | ||
}); | ||
return Promise.resolve(iter); | ||
@@ -114,0 +115,0 @@ } |
@@ -30,6 +30,6 @@ "use strict"; | ||
if (cfg.deliver_group && cfg.flow_control) { | ||
throw new Error("jetstream flow control is not supported with queue groups"); | ||
throw internal_1.InvalidArgumentError.format(["flow_control", "deliver_group"], "are mutually exclusive"); | ||
} | ||
if (cfg.deliver_group && cfg.idle_heartbeat) { | ||
throw new Error("jetstream idle heartbeat is not supported with queue groups"); | ||
throw internal_1.InvalidArgumentError.format(["idle_heartbeat", "deliver_group"], "are mutually exclusive"); | ||
} | ||
@@ -47,3 +47,3 @@ const cr = {}; | ||
if (name && !newAPI) { | ||
throw new Error(`consumer 'name' requires server ${min}`); | ||
throw internal_1.InvalidArgumentError.format("name", `requires server ${min}`); | ||
} | ||
@@ -72,3 +72,3 @@ if (name) { | ||
if (!ok) { | ||
throw new Error(`consumer 'filter_subjects' requires server ${min}`); | ||
throw internal_1.InvalidArgumentError.format("filter_subjects", `requires server ${min}`); | ||
} | ||
@@ -80,3 +80,3 @@ newAPI = false; | ||
if (!ok) { | ||
throw new Error(`consumer 'metadata' requires server ${min}`); | ||
throw internal_1.InvalidArgumentError.format("metadata", `requires server ${min}`); | ||
} | ||
@@ -83,0 +83,0 @@ } |
@@ -24,3 +24,2 @@ "use strict"; | ||
const types_1 = require("./types"); | ||
const types_2 = require("./types"); | ||
const jsapi_types_1 = require("./jsapi_types"); | ||
@@ -44,3 +43,3 @@ const consumer_1 = require("./consumer"); | ||
if (copy.external) { | ||
throw new Error("domain and external are both set"); | ||
throw internal_1.InvalidArgumentError.format(["domain", "external"], "are mutually exclusive"); | ||
} | ||
@@ -127,3 +126,3 @@ copy.external = { api: `$JS.${domain}.API` }; | ||
getBoundPushConsumer(opts) { | ||
if ((0, types_2.isBoundPushConsumerOptions)(opts)) { | ||
if ((0, types_1.isBoundPushConsumerOptions)(opts)) { | ||
const ci = { config: opts }; | ||
@@ -133,3 +132,3 @@ return Promise.resolve(new pushconsumer_1.PushConsumerImpl(this.api, ci, { bound: true })); | ||
else { | ||
return Promise.reject(new Error("deliver_subject is required")); | ||
return Promise.reject(internal_1.errors.InvalidArgumentError.format("deliver_subject", "is required")); | ||
} | ||
@@ -429,3 +428,3 @@ } | ||
if (typeof keep === "number" && typeof seq === "number") { | ||
throw new internal_1.errors.InvalidArgumentError(internal_1.errors.InvalidArgumentError.formatMultiple(["keep", "seq"], "are mutually exclusive")); | ||
throw internal_1.InvalidArgumentError.format(["keep", "seq"], "are mutually exclusive"); | ||
} | ||
@@ -432,0 +431,0 @@ } |
@@ -102,2 +102,7 @@ "use strict"; | ||
c.then(() => { | ||
if (!this.done) { | ||
this.reset(); | ||
} | ||
}).catch(() => { }) | ||
.finally(() => { | ||
const idx = this.cancelables.indexOf(c); | ||
@@ -107,8 +112,2 @@ if (idx !== -1) { | ||
} | ||
if (!this.done) { | ||
this.reset(); | ||
} | ||
}) | ||
.catch((_) => { | ||
// canceled | ||
}); | ||
@@ -115,0 +114,0 @@ this.cancelables.push(c); |
{ | ||
"name": "@nats-io/jetstream", | ||
"version": "3.0.0-19", | ||
"version": "3.0.0-20", | ||
"files": [ | ||
@@ -37,3 +37,3 @@ "lib/", | ||
"dependencies": { | ||
"@nats-io/nats-core": "3.0.0-32" | ||
"@nats-io/nats-core": "3.0.0-34" | ||
}, | ||
@@ -40,0 +40,0 @@ "devDependencies": { |
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
331706
5544
+ Added@nats-io/nats-core@3.0.0-34(transitive)
- Removed@nats-io/nats-core@3.0.0-32(transitive)
Updated@nats-io/nats-core@3.0.0-34