Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jul 28, 2023
1 parent d0053ea commit 2ca0498
Show file tree
Hide file tree
Showing 12 changed files with 6,894 additions and 1,963 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## TBA
## 1.2.0 2023-07-28

- **fix:** leases revoked or released before grant completes leaking
- **chore:** update dependencies

## 1.1.0 2020-11-28

Expand Down
8,678 changes: 6,780 additions & 1,898 deletions package-lock.json

Large diffs are not rendered by default.

55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,42 @@
},
"homepage": "https://github.com/microsoft/etcd3#readme",
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
"@types/chai": "^4.3.5",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-subset": "^1.3.3",
"@types/mocha": "^8.0.3",
"@types/node": "^14.11.1",
"@types/sinon": "^9.0.5",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"chai": "^4.2.0",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.5",
"@types/sinon": "^10.0.15",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"change-case": "^4.1.1",
"concurrently": "^5.3.0",
"eslint": "^7.9.0",
"eslint-plugin-header": "^3.1.0",
"lodash": "^4.17.20",
"mocha": "^8.1.3",
"change-case": "^4.1.2",
"concurrently": "^8.2.0",
"eslint": "^8.45.0",
"eslint-plugin-header": "^3.1.1",
"lodash": "^4.17.21",
"mocha": "^10.2.0",
"ncp": "^2.0.0",
"node-fetch": "^2.6.1",
"node-fetch": "^3.3.2",
"nyc": "^15.1.0",
"prettier": "^2.1.2",
"prettier": "^3.0.0",
"protobufjs": "^7.2.4",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"sinon": "^9.0.3",
"ts-node": "^9.0.0",
"typedoc": "^0.19.2",
"typedoc-plugin-no-inherit": "^1.2.0",
"typescript": "^4.0.3"
"rimraf": "^5.0.1",
"rxjs": "^7.8.1",
"sinon": "^15.2.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typedoc": "^0.24.8",
"typedoc-plugin-no-inherit": "^1.4.0",
"typescript": "^5.1.6"
},
"dependencies": {
"@grpc/grpc-js": "^1.1.7",
"@grpc/proto-loader": "^0.5.5",
"bignumber.js": "^9.0.0",
"cockatiel": "^1.1.1"
"@grpc/grpc-js": "^1.8.20",
"@grpc/proto-loader": "^0.7.8",
"bignumber.js": "^9.1.1",
"cockatiel": "^3.1.1"
},
"prettier": {
"singleQuote": true,
Expand Down
10 changes: 8 additions & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export interface IPermissionResult {
* ranges.
*/
export class Role {
constructor(private client: AuthClient, public readonly name: string) {}
constructor(
private client: AuthClient,
public readonly name: string,
) {}

/**
* Creates the role in etcd.
Expand Down Expand Up @@ -142,7 +145,10 @@ export class Role {
* be added to Roles to manage permissions.
*/
export class User {
constructor(private client: AuthClient, public readonly name: string) {}
constructor(
private client: AuthClient,
public readonly name: string,
) {}

/**
* Creates the user, with the provided password.
Expand Down
25 changes: 19 additions & 6 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export const compareTarget: { [key in keyof typeof RPC.CompareTarget]: keyof RPC
* assertWithin throws a helpful error message if the value provided isn't
* a key in the given map.
*/
function assertWithin<T>(map: T, value: keyof T, thing: string) {
function assertWithin<T extends object>(map: T, value: keyof T, thing: string) {
if (!(value in map)) {
const keys = Object.keys(map).join('" "');
throw new Error(`Unexpected "${value}" in ${thing}. Possible values are: "${keys}"`);
throw new Error(`Unexpected "${String(value)}" in ${thing}. Possible values are: "${keys}"`);
}
}

Expand Down Expand Up @@ -133,7 +133,11 @@ export abstract class RangeBuilder<T> extends PromiseWrap<T> implements IOperati
* SingleRangeBuilder is a query builder that looks up a single key.
*/
export class SingleRangeBuilder extends RangeBuilder<string | null> {
constructor(private readonly kv: RPC.KVClient, namespace: NSApplicator, key: string | Buffer) {
constructor(
private readonly kv: RPC.KVClient,
namespace: NSApplicator,
key: string | Buffer,
) {
super(namespace);
this.request.key = toBuffer(key);
this.request.limit = 1;
Expand Down Expand Up @@ -200,7 +204,10 @@ export class SingleRangeBuilder extends RangeBuilder<string | null> {
* MultiRangeBuilder is a query builder that looks up multiple keys.
*/
export class MultiRangeBuilder extends RangeBuilder<{ [key: string]: string }> {
constructor(private readonly kv: RPC.KVClient, namespace: NSApplicator) {
constructor(
private readonly kv: RPC.KVClient,
namespace: NSApplicator,
) {
super(namespace);
this.prefix(emptyBuffer);
}
Expand Down Expand Up @@ -353,7 +360,10 @@ export class DeleteBuilder extends PromiseWrap<RPC.IDeleteRangeResponse> {
private request: RPC.IDeleteRangeRequest = {};
private callOptions: grpc.CallOptions | undefined;

constructor(private readonly kv: RPC.KVClient, private readonly namespace: NSApplicator) {
constructor(
private readonly kv: RPC.KVClient,
private readonly namespace: NSApplicator,
) {
super();
}

Expand Down Expand Up @@ -577,7 +587,10 @@ export class ComparatorBuilder {
} = { compare: [], success: [], failure: [] };
private callOptions: grpc.CallOptions | undefined;

constructor(private readonly kv: RPC.KVClient, private readonly namespace: NSApplicator) {}
constructor(
private readonly kv: RPC.KVClient,
private readonly namespace: NSApplicator,
) {}

/**
* Sets the GRPC call options for this request.
Expand Down
11 changes: 8 additions & 3 deletions src/connection-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import * as grpc from '@grpc/grpc-js';
import { ChannelOptions } from '@grpc/grpc-js/build/src/channel-options';
import { loadSync } from '@grpc/proto-loader';
import {
circuitBreaker,
ConsecutiveBreaker,
handleWhen,
IDefaultPolicyContext,
IPolicy,
isBrokenCircuitError,
Policy,
retry,
} from 'cockatiel';
import {
castGrpcError,
Expand Down Expand Up @@ -157,7 +159,10 @@ class Authenticator {
}

const defaultCircuitBreaker = () =>
Policy.handleWhen(isRecoverableError).circuitBreaker(5_000, new ConsecutiveBreaker(3));
circuitBreaker(handleWhen(isRecoverableError), {
halfOpenAfter: 5_000,
breaker: new ConsecutiveBreaker(3),
});

/**
* A Host is one instance of the etcd server, which can contain multiple
Expand Down Expand Up @@ -245,7 +250,7 @@ export class ConnectionPool implements ICallable<Host> {

private readonly hosts: Host[];
private readonly globalPolicy: IPolicy<IDefaultPolicyContext> =
this.options.faultHandling?.global ?? Policy.handleWhen(isRecoverableError).retry().attempts(3);
this.options.faultHandling?.global ?? retry(handleWhen(isRecoverableError), { maxAttempts: 3 });
private mockImpl: ICallable<Host> | null;
private authenticator: Authenticator;

Expand Down
12 changes: 10 additions & 2 deletions src/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ export class Campaign extends EventEmitter {
private value: Buffer;
private pendingProclaimation?: IDeferred<void>;

constructor(private readonly namespace: Namespace, value: string | Buffer, ttl: number) {
constructor(
private readonly namespace: Namespace,
value: string | Buffer,
ttl: number,
) {
super();
this.value = toBuffer(value);
this.lease = this.namespace.lease(ttl);
Expand Down Expand Up @@ -400,7 +404,11 @@ export class Election {
/**
* @internal
*/
constructor(parent: Namespace, public readonly name: string, private readonly ttl: number = 60) {
constructor(
parent: Namespace,
public readonly name: string,
private readonly ttl: number = 60,
) {
this.namespace = parent.namespace(`${Election.prefix}/${this.name}/`);
}

Expand Down
14 changes: 9 additions & 5 deletions src/stm.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import BigNumber from 'bignumber.js';
import * as grpc from '@grpc/grpc-js';
import BigNumber from 'bignumber.js';

import * as Builder from './builder';
import { ClientRuntimeError, STMConflictError } from './errors';
Expand Down Expand Up @@ -98,7 +98,8 @@ interface CompletedReads {
* ReadSet records a set of reads in a SoftwareTransaction.
*/
class ReadSet {
private readonly reads: { [key: string]: Promise<RPC.IRangeResponse> } = Object.create(null);
private readonly reads: Record<string, Promise<RPC.IRangeResponse> | undefined> =
Object.create(null);
private readonly completedReads: CompletedReads[] = [];
private earliestMod = new BigNumber(Infinity);

Expand Down Expand Up @@ -128,8 +129,9 @@ class ReadSet {
*/
public runRequest(kv: RPC.KVClient, req: RPC.IRangeRequest): Promise<RPC.IRangeResponse> {
const key = req.key!.toString();
if (this.reads[key]) {
return this.reads[key];
const previous = this.reads[key];
if (previous) {
return previous;
}

const promise = kv.range(req).then(res => {
Expand Down Expand Up @@ -340,7 +342,9 @@ class BasicTransaction {
protected assertNoOption<T>(req: string, obj: T, keys: (keyof T)[]) {
keys.forEach(key => {
if (obj[key] !== undefined) {
throw new Error(`"${key}" is not supported in ${req} requests within STM transactions`);
throw new Error(
`"${String(key)}" is not supported in ${req} requests within STM transactions`,
);
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/connection-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { expect } from 'chai';
import { Policy } from 'cockatiel';
import { NoopPolicy, handleAll, retry } from 'cockatiel';
import { stub } from 'sinon';
import { IOptions, KVClient } from '..';
import { ConnectionPool } from '../connection-pool';
Expand Down Expand Up @@ -79,8 +79,8 @@ describe('connection pool', () => {
pool = new ConnectionPool(
getOptionsWithBadHost({
faultHandling: {
global: Policy.handleAll().retry().attempts(3),
host: () => Policy.noop,
global: retry(handleAll, { maxAttempts: 3 }),
host: () => new NoopPolicy(),
},
}),
);
Expand Down
8 changes: 4 additions & 4 deletions src/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { expect } from 'chai';
import * as fs from 'fs';
import * as tls from 'tls';

import { Etcd3, IOptions, Namespace } from '..';
import { NoopPolicy } from 'cockatiel';
import { AddressInfo } from 'net';
import { resolve } from 'path';
import { Policy } from 'cockatiel';
import { Etcd3, IOptions, Namespace } from '..';

const rootPath = resolve(__dirname, '..', '..');
const rootCertificate = fs.readFileSync(`${rootPath}/src/test/certs/certs/ca.crt`);
Expand Down Expand Up @@ -192,8 +192,8 @@ export function getOptions(defaults: Partial<IOptions> = {}): IOptions {
hosts: getHost(),
credentials: { rootCertificate },
faultHandling: {
global: Policy.noop,
host: () => Policy.noop,
global: new NoopPolicy(),
host: () => new NoopPolicy(),
},
...defaults,
};
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function delay(duration: number): Promise<void> {
/**
* Implementation of lodash forOwn, with stronger typings and no dependency ;)
*/
export function forOwn<T>(
export function forOwn<T extends object>(
obj: T,
iterator: <K extends keyof T>(value: T[K], key: K) => void,
): void {
Expand Down
Loading

0 comments on commit 2ca0498

Please sign in to comment.