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

cockatiel

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cockatiel - npm Package Compare versions

Comparing version 3.0.0-beta.1 to 3.0.0

1

dist/backoff/Backoff.test.js

@@ -8,3 +8,2 @@ "use strict";

let backoff = backoffFactory?.next(context);
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < expected.length; i++) {

@@ -11,0 +10,0 @@ if (!backoff) {

6

dist/backoff/ConstantBackoff.d.ts
import { IBackoff, IBackoffFactory } from './Backoff';
/**
* Backoff that returns a constant interval.
*/
export declare class ConstantBackoff implements IBackoffFactory<unknown> {
private readonly interval;
/**
* Backoff that returns a constant interval.
*/
constructor(interval: number);

@@ -8,0 +8,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConstantBackoff = void 0;
/**
* Backoff that returns a constant interval.
*/
class ConstantBackoff {
/**
* Backoff that returns a constant interval.
*/
constructor(interval) {

@@ -9,0 +9,0 @@ this.interval = interval;

@@ -6,9 +6,9 @@ import { IBackoff, IBackoffFactory } from './Backoff';

} | number;
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
export declare class DelegateBackoff<T, S = void> implements IBackoffFactory<T> {
private readonly fn;
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
constructor(fn: DelegateBackoffFn<T, S>);

@@ -15,0 +15,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DelegateBackoff = void 0;
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
class DelegateBackoff {
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
constructor(fn) {

@@ -11,0 +11,0 @@ this.fn = fn;

@@ -30,9 +30,9 @@ import { IBackoff, IBackoffFactory } from './Backoff';

}
/**
* An implementation of exponential backoff.
*/
export declare class ExponentialBackoff<S> implements IBackoffFactory<unknown> {
private readonly options;
/**
* An implementation of exponential backoff.
*/
constructor(options?: Partial<IExponentialBackoffOptions<S>>);
next(): IBackoff<unknown>;
}

@@ -11,6 +11,6 @@ "use strict";

};
/**
* An implementation of exponential backoff.
*/
class ExponentialBackoff {
/**
* An implementation of exponential backoff.
*/
constructor(options) {

@@ -17,0 +17,0 @@ this.options = options ? { ...defaultOptions, ...options } : defaultOptions;

import { IBackoff, IBackoffFactory } from './Backoff';
/**
* Backoff that returns a number from an iterable.
*/
export declare class IterableBackoff implements IBackoffFactory<unknown> {
private readonly durations;
/**
* Backoff that returns a number from an iterable.
*/
constructor(durations: ReadonlyArray<number>);

@@ -8,0 +8,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IterableBackoff = void 0;
/**
* Backoff that returns a number from an iterable.
*/
class IterableBackoff {
/**
* Backoff that returns a number from an iterable.
*/
constructor(durations) {

@@ -9,0 +9,0 @@ this.durations = durations;

import { IBreaker } from './Breaker';
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
export declare class ConsecutiveBreaker implements IBreaker {
private readonly threshold;
private count;
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
constructor(threshold: number);

@@ -10,0 +10,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsecutiveBreaker = void 0;
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
class ConsecutiveBreaker {
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
constructor(threshold) {

@@ -10,0 +10,0 @@ this.threshold = threshold;

@@ -19,7 +19,2 @@ import { CircuitState } from '../CircuitBreakerPolicy';

}
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
export declare class SamplingBreaker implements IBreaker {

@@ -34,2 +29,7 @@ private readonly threshold;

private currentSuccesses;
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
constructor({ threshold, duration: samplingDuration, minimumRps }: ISamplingBreakerOptions);

@@ -36,0 +36,0 @@ /**

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

const CircuitBreakerPolicy_1 = require("../CircuitBreakerPolicy");
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
class SamplingBreaker {
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
constructor({ threshold, duration: samplingDuration, minimumRps }) {

@@ -13,0 +13,0 @@ this.windows = [];

/// <reference types="node" />
import { IDefaultPolicyContext, IPolicy } from './Policy';
/**
* Bulkhead limits concurrent requests made.
*/
export declare class BulkheadPolicy implements IPolicy {
private readonly capacity;
private readonly queueCapacity;
readonly _altReturn: never;
private active;

@@ -33,2 +31,5 @@ private readonly queue;

get queueSlots(): number;
/**
* Bulkhead limits concurrent requests made.
*/
constructor(capacity: number, queueCapacity: number);

@@ -35,0 +36,0 @@ /**

@@ -10,6 +10,6 @@ "use strict";

const Errors_1 = require("./errors/Errors");
/**
* Bulkhead limits concurrent requests made.
*/
class BulkheadPolicy {
/**
* Bulkhead limits concurrent requests made.
*/
constructor(capacity, queueCapacity) {

@@ -25,3 +25,2 @@ this.capacity = capacity;

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -31,3 +30,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -37,3 +35,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onReject = this.onRejectEmitter.addListener;

@@ -40,0 +37,0 @@ }

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

private readonly executor;
readonly _altReturn: never;
private readonly breakEmitter;

@@ -34,0 +35,0 @@ private readonly resetEmitter;

@@ -42,3 +42,2 @@ "use strict";

*/
// tslint:disable-next-line: member-ordering
this.onBreak = this.breakEmitter.addListener;

@@ -48,3 +47,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onReset = this.resetEmitter.addListener;

@@ -55,3 +53,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onHalfOpen = this.halfOpenEmitter.addListener;

@@ -61,3 +58,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onStateChange = this.stateChangeEmitter.addListener;

@@ -67,3 +63,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -73,3 +68,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -76,0 +70,0 @@ }

@@ -11,2 +11,3 @@ "use strict";

});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return { resolve: resolve, reject: reject, promise };

@@ -13,0 +14,0 @@ };

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

exports.noopDisposable = { dispose: () => undefined };
// tslint:disable-next-line: no-namespace
var Event;

@@ -9,0 +8,0 @@ (function (Event) {

@@ -31,5 +31,3 @@ "use strict";

this.failureEmitter = new Event_1.EventEmitter();
// tslint:disable-next-line: member-ordering
this.onSuccess = this.successEmitter.addListener;
// tslint:disable-next-line: member-ordering
this.onFailure = this.failureEmitter.addListener;

@@ -36,0 +34,0 @@ }

@@ -1,8 +0,8 @@

/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
export declare class BrokenCircuitError extends Error {
readonly isBrokenCircuitError = true;
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor(message?: string);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BrokenCircuitError = void 0;
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
class BrokenCircuitError extends Error {
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor(message = 'Execution prevented because the circuit breaker is open') {

@@ -10,0 +10,0 @@ super(message);

import { BrokenCircuitError } from './BrokenCircuitError';
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
export declare class IsolatedCircuitError extends BrokenCircuitError {
readonly isIsolatedCircuitError = true;
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor();
}

@@ -5,7 +5,7 @@ "use strict";

const BrokenCircuitError_1 = require("./BrokenCircuitError");
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
class IsolatedCircuitError extends BrokenCircuitError_1.BrokenCircuitError {
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor() {

@@ -12,0 +12,0 @@ super(`Execution prevented because the circuit breaker is open`);

@@ -1,8 +0,8 @@

/**
* Error thrown when a task is cancelled.
*/
export declare class TaskCancelledError extends Error {
readonly message: string;
readonly isTaskCancelledError = true;
/**
* Error thrown when a task is cancelled.
*/
constructor(message?: string);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskCancelledError = void 0;
/**
* Error thrown when a task is cancelled.
*/
class TaskCancelledError extends Error {
/**
* Error thrown when a task is cancelled.
*/
constructor(message = 'Operation cancelled') {

@@ -9,0 +9,0 @@ super(message);

@@ -5,3 +5,2 @@ import { expect } from 'chai';

let backoff = backoffFactory?.next(context);
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < expected.length; i++) {

@@ -8,0 +7,0 @@ if (!backoff) {

import { IBackoff, IBackoffFactory } from './Backoff';
/**
* Backoff that returns a constant interval.
*/
export declare class ConstantBackoff implements IBackoffFactory<unknown> {
private readonly interval;
/**
* Backoff that returns a constant interval.
*/
constructor(interval: number);

@@ -8,0 +8,0 @@ /**

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

/**
* Backoff that returns a constant interval.
*/
export class ConstantBackoff {
/**
* Backoff that returns a constant interval.
*/
constructor(interval) {

@@ -6,0 +6,0 @@ this.interval = interval;

@@ -6,9 +6,9 @@ import { IBackoff, IBackoffFactory } from './Backoff';

} | number;
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
export declare class DelegateBackoff<T, S = void> implements IBackoffFactory<T> {
private readonly fn;
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
constructor(fn: DelegateBackoffFn<T, S>);

@@ -15,0 +15,0 @@ /**

@@ -1,7 +0,7 @@

/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
export class DelegateBackoff {
/**
* Backoff that delegates to a user-provided function. The function takes
* the backoff context, and can optionally take (and return) a state value
* that will be passed into subsequent backoff requests.
*/
constructor(fn) {

@@ -8,0 +8,0 @@ this.fn = fn;

@@ -30,9 +30,9 @@ import { IBackoff, IBackoffFactory } from './Backoff';

}
/**
* An implementation of exponential backoff.
*/
export declare class ExponentialBackoff<S> implements IBackoffFactory<unknown> {
private readonly options;
/**
* An implementation of exponential backoff.
*/
constructor(options?: Partial<IExponentialBackoffOptions<S>>);
next(): IBackoff<unknown>;
}

@@ -8,6 +8,6 @@ import { decorrelatedJitterGenerator } from './ExponentialBackoffGenerators';

};
/**
* An implementation of exponential backoff.
*/
export class ExponentialBackoff {
/**
* An implementation of exponential backoff.
*/
constructor(options) {

@@ -14,0 +14,0 @@ this.options = options ? { ...defaultOptions, ...options } : defaultOptions;

import { IBackoff, IBackoffFactory } from './Backoff';
/**
* Backoff that returns a number from an iterable.
*/
export declare class IterableBackoff implements IBackoffFactory<unknown> {
private readonly durations;
/**
* Backoff that returns a number from an iterable.
*/
constructor(durations: ReadonlyArray<number>);

@@ -8,0 +8,0 @@ /**

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

/**
* Backoff that returns a number from an iterable.
*/
export class IterableBackoff {
/**
* Backoff that returns a number from an iterable.
*/
constructor(durations) {

@@ -6,0 +6,0 @@ this.durations = durations;

import { IBreaker } from './Breaker';
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
export declare class ConsecutiveBreaker implements IBreaker {
private readonly threshold;
private count;
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
constructor(threshold: number);

@@ -10,0 +10,0 @@ /**

@@ -1,6 +0,6 @@

/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
export class ConsecutiveBreaker {
/**
* ConsecutiveBreaker breaks if more than `threshold` exceptions are received
* over a time period.
*/
constructor(threshold) {

@@ -7,0 +7,0 @@ this.threshold = threshold;

@@ -19,7 +19,2 @@ import { CircuitState } from '../CircuitBreakerPolicy';

}
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
export declare class SamplingBreaker implements IBreaker {

@@ -34,2 +29,7 @@ private readonly threshold;

private currentSuccesses;
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
constructor({ threshold, duration: samplingDuration, minimumRps }: ISamplingBreakerOptions);

@@ -36,0 +36,0 @@ /**

import { CircuitState } from '../CircuitBreakerPolicy';
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
export class SamplingBreaker {
/**
* SamplingBreaker breaks if more than `threshold` percentage of calls over the
* last `samplingDuration`, so long as there's at least `minimumRps` (to avoid
* closing unnecessarily under low RPS).
*/
constructor({ threshold, duration: samplingDuration, minimumRps }) {

@@ -9,0 +9,0 @@ this.windows = [];

/// <reference types="node" />
import { IDefaultPolicyContext, IPolicy } from './Policy';
/**
* Bulkhead limits concurrent requests made.
*/
export declare class BulkheadPolicy implements IPolicy {
private readonly capacity;
private readonly queueCapacity;
readonly _altReturn: never;
private active;

@@ -33,2 +31,5 @@ private readonly queue;

get queueSlots(): number;
/**
* Bulkhead limits concurrent requests made.
*/
constructor(capacity: number, queueCapacity: number);

@@ -35,0 +36,0 @@ /**

@@ -7,6 +7,6 @@ import { neverAbortedSignal } from './common/abort';

import { TaskCancelledError } from './errors/Errors';
/**
* Bulkhead limits concurrent requests made.
*/
export class BulkheadPolicy {
/**
* Bulkhead limits concurrent requests made.
*/
constructor(capacity, queueCapacity) {

@@ -22,3 +22,2 @@ this.capacity = capacity;

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -28,3 +27,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -34,3 +32,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onReject = this.onRejectEmitter.addListener;

@@ -37,0 +34,0 @@ }

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

private readonly executor;
readonly _altReturn: never;
private readonly breakEmitter;

@@ -34,0 +35,0 @@ private readonly resetEmitter;

@@ -39,3 +39,2 @@ import { neverAbortedSignal } from './common/abort';

*/
// tslint:disable-next-line: member-ordering
this.onBreak = this.breakEmitter.addListener;

@@ -45,3 +44,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onReset = this.resetEmitter.addListener;

@@ -52,3 +50,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onHalfOpen = this.halfOpenEmitter.addListener;

@@ -58,3 +55,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onStateChange = this.stateChangeEmitter.addListener;

@@ -64,3 +60,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -70,3 +65,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -73,0 +67,0 @@ }

@@ -8,4 +8,5 @@ export const defer = () => {

});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return { resolve: resolve, reject: reject, promise };
};
//# sourceMappingURL=defer.js.map
import { TaskCancelledError } from '../errors/TaskCancelledError';
export const noopDisposable = { dispose: () => undefined };
// tslint:disable-next-line: no-namespace
export var Event;

@@ -5,0 +4,0 @@ (function (Event) {

@@ -27,5 +27,3 @@ import { EventEmitter } from './Event';

this.failureEmitter = new EventEmitter();
// tslint:disable-next-line: member-ordering
this.onSuccess = this.successEmitter.addListener;
// tslint:disable-next-line: member-ordering
this.onFailure = this.failureEmitter.addListener;

@@ -32,0 +30,0 @@ }

@@ -1,8 +0,8 @@

/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
export declare class BrokenCircuitError extends Error {
readonly isBrokenCircuitError = true;
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor(message?: string);
}

@@ -1,6 +0,6 @@

/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
export class BrokenCircuitError extends Error {
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor(message = 'Execution prevented because the circuit breaker is open') {

@@ -7,0 +7,0 @@ super(message);

import { BrokenCircuitError } from './BrokenCircuitError';
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
export declare class IsolatedCircuitError extends BrokenCircuitError {
readonly isIsolatedCircuitError = true;
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor();
}
import { BrokenCircuitError } from './BrokenCircuitError';
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
export class IsolatedCircuitError extends BrokenCircuitError {
/**
* Exception thrown from {@link CircuitBreakerPolicy.execute} when the
* circuit breaker is open.
*/
constructor() {

@@ -8,0 +8,0 @@ super(`Execution prevented because the circuit breaker is open`);

@@ -1,8 +0,8 @@

/**
* Error thrown when a task is cancelled.
*/
export declare class TaskCancelledError extends Error {
readonly message: string;
readonly isTaskCancelledError = true;
/**
* Error thrown when a task is cancelled.
*/
constructor(message?: string);
}

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

/**
* Error thrown when a task is cancelled.
*/
export class TaskCancelledError extends Error {
/**
* Error thrown when a task is cancelled.
*/
constructor(message = 'Operation cancelled') {

@@ -6,0 +6,0 @@ super(message);

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

private readonly value;
readonly _altReturn: AltReturn;
/**

@@ -9,0 +10,0 @@ * @inheritdoc

@@ -9,3 +9,2 @@ import { neverAbortedSignal } from './common/abort';

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -15,3 +14,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -18,0 +16,0 @@ }

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

export declare class NoopPolicy implements IPolicy {
readonly _altReturn: never;
private readonly executor;

@@ -9,0 +10,0 @@ readonly onSuccess: import(".").Event<import("./Policy").ISuccessEvent>;

@@ -9,5 +9,3 @@ import { neverAbortedSignal } from './common/abort';

this.executor = new ExecuteWrapper();
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -14,0 +12,0 @@ }

@@ -9,4 +9,4 @@ /// <reference types="node" />

import { NoopPolicy } from './NoopPolicy';
import { IRetryBackoffContext, IRetryContext, RetryPolicy } from './RetryPolicy';
import { ICancellationContext, TimeoutPolicy, TimeoutStrategy } from './TimeoutPolicy';
import { IRetryBackoffContext, RetryPolicy } from './RetryPolicy';
import { TimeoutPolicy, TimeoutStrategy } from './TimeoutPolicy';
declare type Constructor<T> = new (...args: any) => T;

@@ -65,2 +65,7 @@ export interface IBasePolicyOptions {

/**
* Virtual property only used for TypeScript--will not actually be defined.
* @deprecated This property does not exist
*/
readonly _altReturn: AltReturn;
/**
* Fires on the policy when a request successfully completes and some

@@ -81,10 +86,12 @@ * successful value will be returned. In a retry policy, this is fired once

}
declare type PolicyType<T> = T extends RetryPolicy ? IPolicy<IRetryContext, never> : T extends TimeoutPolicy ? IPolicy<ICancellationContext, never> : T extends FallbackPolicy<infer F> ? IPolicy<IRetryContext, F> : T extends CircuitBreakerPolicy ? IPolicy<IRetryContext, never> : T extends NoopPolicy ? IPolicy<IDefaultPolicyContext, never> : T extends IPolicy<infer ContextType, infer ReturnType> ? IPolicy<ContextType, ReturnType> : never;
declare type MergePolicies<A, B> = A extends IPolicy<infer A1, infer A2> ? B extends IPolicy<infer B1, infer B2> ? IPolicy<A1 & B1, A2 | B2> : never : never;
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
export interface IMergedPolicy<A extends IDefaultPolicyContext, B, W extends IPolicy<any, any>[]> extends IPolicy<A, B> {
readonly wrapped: W;
}
declare type MergePolicies<A, B> = A extends IPolicy<infer A1, any> ? B extends IPolicy<infer B1, any> ? IMergedPolicy<A1 & B1, A['_altReturn'] | B['_altReturn'], B extends IMergedPolicy<any, any, infer W> ? [A, ...W] : [A, B]> : never : never;
export declare class Policy {
readonly options: Readonly<IBasePolicyOptions>;
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
constructor(options: Readonly<IBasePolicyOptions>);

@@ -245,7 +252,7 @@ /**

*/
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A): PolicyType<A>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B): MergePolicies<PolicyType<A>, PolicyType<B>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C): MergePolicies<PolicyType<C>, MergePolicies<PolicyType<A>, PolicyType<B>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D): MergePolicies<PolicyType<D>, MergePolicies<PolicyType<C>, MergePolicies<PolicyType<A>, PolicyType<B>>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>, E extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D, p5: E): MergePolicies<PolicyType<E>, MergePolicies<PolicyType<D>, MergePolicies<PolicyType<C>, MergePolicies<PolicyType<A>, PolicyType<B>>>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A): A;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B): MergePolicies<A, B>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C): MergePolicies<C, MergePolicies<A, B>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D): MergePolicies<D, MergePolicies<C, MergePolicies<A, B>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>, E extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D, p5: E): MergePolicies<E, MergePolicies<D, MergePolicies<C, MergePolicies<A, B>>>>;
export declare function wrap<C extends IDefaultPolicyContext, A>(...p: Array<IPolicy<C, A>>): IPolicy<C, A>;

@@ -252,0 +259,0 @@ /**

@@ -12,7 +12,7 @@ import { ConstantBackoff } from './backoff/Backoff';

const never = () => false;
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
export class Policy {
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
constructor(options) {

@@ -175,3 +175,2 @@ this.options = options;

export function usePolicy(policy) {
// tslint:disable-next-line: variable-name
return (_target, _key, descriptor) => {

@@ -203,4 +202,6 @@ const inner = descriptor.value;

return {
_altReturn: undefined,
onFailure: p[0].onFailure,
onSuccess: p[0].onSuccess,
wrapped: p,
execute(fn, signal) {

@@ -207,0 +208,0 @@ const run = (context, i) => i === p.length

@@ -19,3 +19,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

}
// tslint:disable-next-line: variable-name
const assertNever = (_value) => {

@@ -31,3 +30,11 @@ throw new Error('unreachable');

it('wraps and keeps correct types', async () => {
const policy = wrap(retry(handleAll, { maxAttempts: 2 }), circuitBreaker(handleAll, { halfOpenAfter: 100, breaker: new ConsecutiveBreaker(2) }), fallback(handleAll, 'foo'), timeout(1000, TimeoutStrategy.Aggressive), noop);
const policies = [
retry(handleAll, { maxAttempts: 2 }),
circuitBreaker(handleAll, { halfOpenAfter: 100, breaker: new ConsecutiveBreaker(2) }),
fallback(handleAll, 'foo'),
timeout(1000, TimeoutStrategy.Aggressive),
noop,
];
const policy = wrap(...policies);
expect(policy.wrapped).to.deep.equal(policies);
const result = await policy.execute(context => {

@@ -34,0 +41,0 @@ expect(context.signal).to.be.an.instanceOf(AbortSignal);

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

private readonly executor;
readonly _altReturn: never;
private readonly onGiveUpEmitter;

@@ -38,0 +39,0 @@ private readonly onRetryEmitter;

@@ -19,3 +19,2 @@ import { ConstantBackoff } from './backoff/ConstantBackoff';

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -25,3 +24,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -32,3 +30,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onRetry = this.onRetryEmitter.addListener;

@@ -38,3 +35,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onGiveUp = this.onGiveUpEmitter.addListener;

@@ -41,0 +37,0 @@ }

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

private readonly unref;
readonly _altReturn: never;
private readonly timeoutEmitter;

@@ -26,0 +27,0 @@ /**

@@ -27,3 +27,2 @@ import { deriveAbortController } from './common/abort';

*/
// tslint:disable-next-line: member-ordering
this.onTimeout = this.timeoutEmitter.addListener;

@@ -33,3 +32,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -39,3 +37,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -42,0 +39,0 @@ }

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

private readonly value;
readonly _altReturn: AltReturn;
/**

@@ -9,0 +10,0 @@ * @inheritdoc

@@ -12,3 +12,2 @@ "use strict";

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -18,3 +17,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -21,0 +19,0 @@ }

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

export declare class NoopPolicy implements IPolicy {
readonly _altReturn: never;
private readonly executor;

@@ -9,0 +10,0 @@ readonly onSuccess: import(".").Event<import("./Policy").ISuccessEvent>;

@@ -12,5 +12,3 @@ "use strict";

this.executor = new Executor_1.ExecuteWrapper();
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -17,0 +15,0 @@ }

@@ -9,4 +9,4 @@ /// <reference types="node" />

import { NoopPolicy } from './NoopPolicy';
import { IRetryBackoffContext, IRetryContext, RetryPolicy } from './RetryPolicy';
import { ICancellationContext, TimeoutPolicy, TimeoutStrategy } from './TimeoutPolicy';
import { IRetryBackoffContext, RetryPolicy } from './RetryPolicy';
import { TimeoutPolicy, TimeoutStrategy } from './TimeoutPolicy';
declare type Constructor<T> = new (...args: any) => T;

@@ -65,2 +65,7 @@ export interface IBasePolicyOptions {

/**
* Virtual property only used for TypeScript--will not actually be defined.
* @deprecated This property does not exist
*/
readonly _altReturn: AltReturn;
/**
* Fires on the policy when a request successfully completes and some

@@ -81,10 +86,12 @@ * successful value will be returned. In a retry policy, this is fired once

}
declare type PolicyType<T> = T extends RetryPolicy ? IPolicy<IRetryContext, never> : T extends TimeoutPolicy ? IPolicy<ICancellationContext, never> : T extends FallbackPolicy<infer F> ? IPolicy<IRetryContext, F> : T extends CircuitBreakerPolicy ? IPolicy<IRetryContext, never> : T extends NoopPolicy ? IPolicy<IDefaultPolicyContext, never> : T extends IPolicy<infer ContextType, infer ReturnType> ? IPolicy<ContextType, ReturnType> : never;
declare type MergePolicies<A, B> = A extends IPolicy<infer A1, infer A2> ? B extends IPolicy<infer B1, infer B2> ? IPolicy<A1 & B1, A2 | B2> : never : never;
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
export interface IMergedPolicy<A extends IDefaultPolicyContext, B, W extends IPolicy<any, any>[]> extends IPolicy<A, B> {
readonly wrapped: W;
}
declare type MergePolicies<A, B> = A extends IPolicy<infer A1, any> ? B extends IPolicy<infer B1, any> ? IMergedPolicy<A1 & B1, A['_altReturn'] | B['_altReturn'], B extends IMergedPolicy<any, any, infer W> ? [A, ...W] : [A, B]> : never : never;
export declare class Policy {
readonly options: Readonly<IBasePolicyOptions>;
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
constructor(options: Readonly<IBasePolicyOptions>);

@@ -245,7 +252,7 @@ /**

*/
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A): PolicyType<A>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B): MergePolicies<PolicyType<A>, PolicyType<B>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C): MergePolicies<PolicyType<C>, MergePolicies<PolicyType<A>, PolicyType<B>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D): MergePolicies<PolicyType<D>, MergePolicies<PolicyType<C>, MergePolicies<PolicyType<A>, PolicyType<B>>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>, E extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D, p5: E): MergePolicies<PolicyType<E>, MergePolicies<PolicyType<D>, MergePolicies<PolicyType<C>, MergePolicies<PolicyType<A>, PolicyType<B>>>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A): A;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B): MergePolicies<A, B>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C): MergePolicies<C, MergePolicies<A, B>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D): MergePolicies<D, MergePolicies<C, MergePolicies<A, B>>>;
export declare function wrap<A extends IPolicy<IDefaultPolicyContext, unknown>, B extends IPolicy<IDefaultPolicyContext, unknown>, C extends IPolicy<IDefaultPolicyContext, unknown>, D extends IPolicy<IDefaultPolicyContext, unknown>, E extends IPolicy<IDefaultPolicyContext, unknown>>(p1: A, p2: B, p3: C, p4: D, p5: E): MergePolicies<E, MergePolicies<D, MergePolicies<C, MergePolicies<A, B>>>>;
export declare function wrap<C extends IDefaultPolicyContext, A>(...p: Array<IPolicy<C, A>>): IPolicy<C, A>;

@@ -252,0 +259,0 @@ /**

@@ -15,7 +15,7 @@ "use strict";

const never = () => false;
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
class Policy {
/**
* Factory that builds a base set of filters that can be used in circuit
* breakers, retries, etc.
*/
constructor(options) {

@@ -184,3 +184,2 @@ this.options = options;

function usePolicy(policy) {
// tslint:disable-next-line: variable-name
return (_target, _key, descriptor) => {

@@ -214,4 +213,6 @@ const inner = descriptor.value;

return {
_altReturn: undefined,
onFailure: p[0].onFailure,
onSuccess: p[0].onSuccess,
wrapped: p,
execute(fn, signal) {

@@ -218,0 +219,0 @@ const run = (context, i) => i === p.length

@@ -21,3 +21,2 @@ "use strict";

}
// tslint:disable-next-line: variable-name
const assertNever = (_value) => {

@@ -33,3 +32,11 @@ throw new Error('unreachable');

it('wraps and keeps correct types', async () => {
const policy = (0, Policy_1.wrap)((0, Policy_1.retry)(Policy_1.handleAll, { maxAttempts: 2 }), (0, Policy_1.circuitBreaker)(Policy_1.handleAll, { halfOpenAfter: 100, breaker: new Breaker_1.ConsecutiveBreaker(2) }), (0, Policy_1.fallback)(Policy_1.handleAll, 'foo'), (0, Policy_1.timeout)(1000, TimeoutPolicy_1.TimeoutStrategy.Aggressive), Policy_1.noop);
const policies = [
(0, Policy_1.retry)(Policy_1.handleAll, { maxAttempts: 2 }),
(0, Policy_1.circuitBreaker)(Policy_1.handleAll, { halfOpenAfter: 100, breaker: new Breaker_1.ConsecutiveBreaker(2) }),
(0, Policy_1.fallback)(Policy_1.handleAll, 'foo'),
(0, Policy_1.timeout)(1000, TimeoutPolicy_1.TimeoutStrategy.Aggressive),
Policy_1.noop,
];
const policy = (0, Policy_1.wrap)(...policies);
(0, chai_1.expect)(policy.wrapped).to.deep.equal(policies);
const result = await policy.execute(context => {

@@ -36,0 +43,0 @@ (0, chai_1.expect)(context.signal).to.be.an.instanceOf(AbortSignal);

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

private readonly executor;
readonly _altReturn: never;
private readonly onGiveUpEmitter;

@@ -38,0 +39,0 @@ private readonly onRetryEmitter;

@@ -22,3 +22,2 @@ "use strict";

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -28,3 +27,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -35,3 +33,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onRetry = this.onRetryEmitter.addListener;

@@ -41,3 +38,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onGiveUp = this.onGiveUpEmitter.addListener;

@@ -44,0 +40,0 @@ }

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

private readonly unref;
readonly _altReturn: never;
private readonly timeoutEmitter;

@@ -26,0 +27,0 @@ /**

@@ -30,3 +30,2 @@ "use strict";

*/
// tslint:disable-next-line: member-ordering
this.onTimeout = this.timeoutEmitter.addListener;

@@ -36,3 +35,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onFailure = this.executor.onFailure;

@@ -42,3 +40,2 @@ /**

*/
// tslint:disable-next-line: member-ordering
this.onSuccess = this.executor.onSuccess;

@@ -45,0 +42,0 @@ }

{
"name": "cockatiel",
"version": "3.0.0-beta.1",
"version": "3.0.0",
"description": "A resilience and transient-fault-handling library that allows developers to express policies such as Backoff, Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. Inspired by .NET Polly.",

@@ -13,9 +13,8 @@ "main": "dist/index.js",

"prepublishOnly": "npm run compile",
"test": "rimraf dist && tsc && npm run test:unit && npm run test:lint && npm run test:fmt && npm run test:md",
"test": "rimraf dist && tsc && npm run test:unit && npm run test:fmt && npm run test:md",
"test:cover": "rimraf dist && tsc && nyc npm run test:unit",
"test:unit": "mocha",
"test:lint": "tslint -p tsconfig.json",
"test:fmt": "prettier --list-different \"src/**/*.ts\" \"*.md\"",
"test:md": "remark -f readme.md -q",
"fmt": "remark readme.md -f -o readme.md && prettier --write \"src/**/*.ts\" \"*.md\" && npm run test:lint -- --fix",
"fmt": "remark readme.md -f -o readme.md && prettier --write \"src/**/*.ts\" \"*.md\"",
"compile": "rimraf dist && tsc && tsc -p tsconfig.esm.json",

@@ -85,5 +84,3 @@ "watch": "rimraf dist && tsc --watch"

"source-map-support": "^0.5.21",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.7.2"
"typescript": "^4.7.4"
},

@@ -90,0 +87,0 @@ "prettier": {

@@ -7,7 +7,5 @@ # Cockatiel

> This is documentation for the 3.0 beta version. For docs on 2.0, please [go here](https://github.com/connor4312/cockatiel/blob/v2.0.2/readme.md).
Cockatiel is resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback. .NET has [Polly](https://github.com/App-vNext/Polly), a wonderful one-stop shop for all your fault handling needs--I missed having such a library for my JavaScript projects, and grew tired of copy-pasting retry logic between my projects. Hence, this module!
npm install --save cockatiel@3.0.0-beta.1
npm install --save cockatiel

@@ -231,2 +229,4 @@ Then go forth with confidence:

The individual wrapped policies are accessible on the `policies` property of the policy returned from `wrap()`.
### `@usePolicy(policy)`

@@ -233,0 +233,0 @@

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

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

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

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

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