Skip to content

Commit

Permalink
chore(dep): update and modernize dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jul 3, 2019
1 parent 291b41f commit 7691f9b
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 150 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- **feat**: allow retrieving lock lease IDs (see [#75](https://github.com/mixer/etcd3/issues/75))
- **bug**: fixed using `lease.put` in transactions not applying the lease to the target key (see [#92](https://github.com/mixer/etcd3/issues/92))
- **bug**: call `markFailed` on the mock instance, rather than the real connection pool, whilst mocking (see [#94](https://github.com/mixer/etcd3/issues/94))
- **chore**: update dependencies, including grpc and Typescript versions

## 0.2.12 2019-07-03

Expand Down
45 changes: 22 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,34 @@
},
"homepage": "https://github.com/mixer/etcd3#readme",
"devDependencies": {
"@types/bignumber.js": "^4.0.3",
"@types/chai": "^3.4.35",
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.0",
"@types/chai-subset": "^1.3.0",
"@types/mocha": "^2.2.40",
"@types/chai-subset": "^1.3.2",
"@types/mocha": "^5.2.7",
"@types/node": "^7.0.12",
"@types/sinon": "^2.1.2",
"chai": "^3.5.0",
"@types/sinon": "^7.0.13",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.5.0",
"change-case": "^3.0.1",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"node-fetch": "^1.6.3",
"npm-run-all": "^4.0.2",
"nyc": "^11.2.1",
"prettier": "^1.4.4",
"protobufjs": "^6.8.6",
"sinon": "^2.1.0",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"tslint-microsoft-contrib": "5.0.1",
"typedoc": "^0.7.1",
"typescript": "^2.7.1"
"change-case": "^3.1.0",
"lodash": "^4.17.11",
"mocha": "^6.1.4",
"node-fetch": "^2.6.0",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.1",
"prettier": "^1.18.2",
"protobufjs": "^6.8.8",
"sinon": "^7.3.2",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0",
"typedoc": "^0.14.2",
"typescript": "^3.5.2"
},
"dependencies": {
"@grpc/proto-loader": "^0.4.0",
"bignumber.js": "^4.1.0",
"grpc": "^1.19.0"
"@grpc/proto-loader": "^0.5.1",
"bignumber.js": "^5.0.0",
"grpc": "^1.21.1"
},
"prettier": {
"singleQuote": true,
Expand Down
4 changes: 2 additions & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export type IPermissionRequest =

function getRange(req: IPermissionRequest): Range {
if (req.hasOwnProperty('key')) {
return new Range(toBuffer((<{ key: Buffer | string }>req).key));
return new Range(toBuffer((req as { key: Buffer | string }).key));
}

return (<{ range: Range }>req).range;
return (req as { range: Range }).range;
}

/**
Expand Down
32 changes: 16 additions & 16 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ export class SingleRangeBuilder extends RangeBuilder<string | null> {
* string, or `null` if it isn't found.
*/
public string(encoding: string = 'utf8'): Promise<string | null> {
return this.exec().then(
res => (res.kvs.length === 0 ? null : res.kvs[0].value.toString(encoding)),
return this.exec().then(res =>
res.kvs.length === 0 ? null : res.kvs[0].value.toString(encoding),
);
}

Expand Down Expand Up @@ -304,8 +304,8 @@ export class MultiRangeBuilder extends RangeBuilder<{ [key: string]: string }> {
return this.kv
.range(this.namespace.applyToRequest(this.request), this.callOptions)
.then(res => {
for (let i = 0; i < res.kvs.length; i++) {
res.kvs[i].key = this.namespace.unprefix(res.kvs[i].key);
for (const kv of res.kvs) {
kv.key = this.namespace.unprefix(kv.key);
}

return res;
Expand All @@ -326,8 +326,8 @@ export class MultiRangeBuilder extends RangeBuilder<{ [key: string]: string }> {
private mapValues<T>(iterator: (buf: Buffer) => T): Promise<{ [key: string]: T }> {
return this.exec().then(res => {
const output: { [key: string]: T } = {};
for (let i = 0; i < res.kvs.length; i++) {
output[res.kvs[i].key.toString()] = iterator(res.kvs[i].value);
for (const kv of res.kvs) {
output[kv.key.toString()] = iterator(kv.value);
}

return output;
Expand Down Expand Up @@ -560,9 +560,9 @@ export class PutBuilder extends PromiseWrap<RPC.IPutResponse> {
*/
export class ComparatorBuilder {
private request: {
compare: Promise<RPC.ICompare>[];
success: Promise<RPC.IRequestOp>[];
failure: Promise<RPC.IRequestOp>[];
compare: Array<Promise<RPC.ICompare>>;
success: Array<Promise<RPC.IRequestOp>>;
failure: Array<Promise<RPC.IRequestOp>>;
} = { compare: [], success: [], failure: [] };
private callOptions: grpc.CallOptions | undefined;

Expand All @@ -589,7 +589,7 @@ export class ComparatorBuilder {
assertWithin(comparator, cmp, 'comparator in client.and(...)');

if (column === 'Value') {
value = toBuffer(<string | Buffer>value);
value = toBuffer(value as string | Buffer);
}

this.request.compare.push(
Expand All @@ -607,7 +607,7 @@ export class ComparatorBuilder {
* Adds one or more consequent clauses to be executed if the comparison
* is truthy.
*/
public then(...clauses: (RPC.IRequestOp | IOperation)[]): this {
public then(...clauses: Array<RPC.IRequestOp | IOperation>): this {
this.request.success = this.mapOperations(clauses);
return this;
}
Expand All @@ -616,7 +616,7 @@ export class ComparatorBuilder {
* Adds one or more consequent clauses to be executed if the comparison
* is falsey.
*/
public else(...clauses: (RPC.IRequestOp | IOperation)[]): this {
public else(...clauses: Array<RPC.IRequestOp | IOperation>): this {
this.request.failure = this.mapOperations(clauses);
return this;
}
Expand All @@ -638,13 +638,13 @@ export class ComparatorBuilder {
/**
* Low-level method to add
*/
public mapOperations(ops: (RPC.IRequestOp | IOperation)[]) {
public mapOperations(ops: Array<RPC.IRequestOp | IOperation>) {
return ops.map(op => {
if (typeof (<IOperation>op).op === 'function') {
return (<IOperation>op).op();
if (typeof (op as IOperation).op === 'function') {
return (op as IOperation).op();
}

return Promise.resolve(<RPC.IRequestOp>op);
return Promise.resolve(op as RPC.IRequestOp);
});
}
}
4 changes: 2 additions & 2 deletions src/connection-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function runServiceCall(
payload: object,
): Promise<any> {
return new Promise((resolve, reject) => {
(<any>client)[method](payload, metadata, options, (err: Error | null, res: any) => {
(client as any)[method](payload, metadata, options, (err: Error | null, res: any) => {
if (err) {
reject(castGrpcError(err));
} else {
Expand Down Expand Up @@ -254,7 +254,7 @@ export class ConnectionPool implements ICallable<Host> {
service: keyof typeof Services,
): Promise<{ resource: Host; client: grpc.Client; metadata: grpc.Metadata }> {
if (this.mockImpl) {
return Promise.resolve(<any>this.mockImpl.getConnection(service)).then(connection => ({
return Promise.resolve(this.mockImpl.getConnection(service) as any).then(connection => ({
metadata: new grpc.Metadata(),
...connection,
}));
Expand Down
7 changes: 3 additions & 4 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ export class STMConflictError extends Error {
}
}

interface IErrorCtor {
new (message: string): Error;
}
type IErrorCtor = new (message: string) => Error;

/**
* Mapping of GRPC error messages to typed error. GRPC errors are untyped
Expand All @@ -213,6 +211,7 @@ interface IErrorCtor {
const grpcMessageToError = new Map<string, IErrorCtor>([
['Connect Failed', GRPCConnectFailedError],
['Channel Disconnected', GRPCConnectFailedError],
['failed to connect to all addresses', GRPCConnectFailedError],
['Endpoint read failed', GRPCProtocolError],
['Got config after disconnection', GRPCProtocolError],
['Failed to create subchannel', GRPCProtocolError],
Expand Down Expand Up @@ -272,7 +271,7 @@ export function castGrpcErrorMessage(message: string): Error {
* consume. Yes, this method is abhorrent.
*/
export function castGrpcError(err: Error): Error {
if ((<any>err).constructor !== Error) {
if ((err as any).constructor !== Error) {
return err; // it looks like it's already some kind of typed error
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Etcd3 extends Namespace {
* ```
*/
public mock<T extends Partial<RPC.ICallable<any>>>(callable: T): T {
this.pool.mock(<any>callable);
this.pool.mock(callable as any);
return callable;
}

Expand Down
22 changes: 12 additions & 10 deletions src/lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Lease extends EventEmitter {
*/
public put(key: string | Buffer): PutBuilder {
return new PutBuilder(
new RPC.KVClient(new LeaseClientWrapper(this.pool, <any>this)),
new RPC.KVClient(new LeaseClientWrapper(this.pool, this as any)),
this.namespace,
key,
).lease(this.grant());
Expand Down Expand Up @@ -241,7 +241,7 @@ export class Lease extends EventEmitter {
/**
* Implements EventEmitter.on(...).
*/
public on(event: string, handler: Function): this {
public on(event: string, handler: (...args: any[]) => void): this {
// tslint:disable-line
return super.on(event, handler);
}
Expand Down Expand Up @@ -290,22 +290,24 @@ export class Lease extends EventEmitter {
return stream.end();
}

const keepaliveTimer = setInterval(() => this.fireKeepAlive(stream), 1000 * this.ttl / 3);
const keepaliveTimer = setInterval(() => this.fireKeepAlive(stream), (1000 * this.ttl) / 3);

this.teardown = () => {
this.teardown = () => undefined;
clearInterval(keepaliveTimer);
stream.end();
};

stream.on('error', err => this.handleKeepaliveError(err)).on('data', res => {
if (leaseExpired(res)) {
return this.handleKeepaliveError(new EtcdLeaseInvalidError(res.ID));
}
stream
.on('error', err => this.handleKeepaliveError(err))
.on('data', res => {
if (leaseExpired(res)) {
return this.handleKeepaliveError(new EtcdLeaseInvalidError(res.ID));
}

this.lastKeepAlive = Date.now();
this.emit('keepaliveSucceeded', res);
});
this.lastKeepAlive = Date.now();
this.emit('keepaliveSucceeded', res);
});

this.emit('keepaliveEstablished');
return this.fireKeepAlive(stream);
Expand Down
15 changes: 7 additions & 8 deletions src/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ function rangableIsPrefix(r: Rangable): r is { prefix: string | Buffer } {
* https://github.com/coreos/etcd/blob/c4a45c57135bf49ae701352c9151dc1be433d1dd/pkg/adt/interval_tree.go
*/
export class Range {
public readonly start: Buffer;
public readonly end: Buffer;

constructor(start: Buffer | string, end: Buffer | string = emptyKey) {
this.start = toBuffer(start);
this.end = toBuffer(end);
}

/**
* Prefix returns a Range that maps to all keys
* prefixed with the provided string.
Expand Down Expand Up @@ -67,6 +59,13 @@ export class Range {

return new Range(v.start, v.end);
}
public readonly start: Buffer;
public readonly end: Buffer;

constructor(start: Buffer | string, end: Buffer | string = emptyKey) {
this.start = toBuffer(start);
this.end = toBuffer(end);
}

/**
* Returns whether the byte range includes the provided value.
Expand Down
2 changes: 1 addition & 1 deletion src/shared-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class SharedPool<T> {
// tests simpler.
private static deterministicInsertion: false;

private resources: IResourceRecord<T>[] = [];
private resources: Array<IResourceRecord<T>> = [];
private contentionCount = 0;

public constructor(private strategy: IBackoffStrategy) {}
Expand Down
16 changes: 8 additions & 8 deletions src/stm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ function keyValueToResponse(key: string | Buffer, value?: Buffer): RPC.IRangeRes
key = toBuffer(key);

if (!value) {
return <any>{ kvs: [], more: false, count: '0' };
return { kvs: [], more: false, count: '0' } as any;
}

return <any>{
return {
kvs: [
{
key: Buffer.from(key),
Expand All @@ -83,15 +83,15 @@ function keyValueToResponse(key: string | Buffer, value?: Buffer): RPC.IRangeRes
],
more: false,
count: '1',
};
} as any;
}

/**
* ReadSet records a set of reads in a SoftwareTransaction.
*/
class ReadSet {
private readonly reads: { [key: string]: Promise<RPC.IRangeResponse> } = Object.create(null);
private readonly completedReads: { key: Buffer; res: RPC.IRangeResponse }[] = [];
private readonly completedReads: Array<{ key: Buffer; res: RPC.IRangeResponse }> = [];
private earliestMod = new BigNumber(Infinity);

/**
Expand Down Expand Up @@ -302,7 +302,7 @@ class BasicTransaction {
public put(req: RPC.IPutRequest): Promise<RPC.IPutResponse> {
this.assertNoOption('put', req, ['lease', 'prev_kv']);
this.writeSet.addPut(req);
return Promise.resolve(<any>{});
return Promise.resolve({} as any);
}

/**
Expand All @@ -312,7 +312,7 @@ class BasicTransaction {
this.assertNoOption('delete', req, ['prev_kv']);
this.writeSet.addDeletion(req);
return Promise.resolve({
header: <any>undefined,
header: undefined as any,
deleted: '1',
prev_kvs: [],
});
Expand All @@ -329,7 +329,7 @@ class BasicTransaction {
]);
}

protected assertNoOption<T>(req: string, obj: T, keys: (keyof T)[]) {
protected assertNoOption<T>(req: string, obj: T, keys: Array<keyof T>) {
keys.forEach(key => {
if (obj[key] !== undefined) {
throw new Error(`"${key}" is not supported in ${req} requests within STM transactions`);
Expand Down Expand Up @@ -430,7 +430,7 @@ export class SoftwareTransaction {
case 'deleteRange':
return (req: RPC.IDeleteRangeRequest) => this.tx.deleteRange(req);
default:
throw new ClientRuntimeError(`Unexpected kv operation in STM: ${key}`);
throw new ClientRuntimeError(`Unexpected kv operation in STM: ${key.toString()}`);
}
},
});
Expand Down
Loading

0 comments on commit 7691f9b

Please sign in to comment.