diff --git a/.eslintrc.js b/.eslintrc.js index d8a520e..df365c3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,7 +19,8 @@ module.exports = { 'error', 'block', '---------------------------------------------------------\n * Copyright (C) Microsoft Corporation. All rights reserved.\n *--------------------------------------------------------', - ], + ], + '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }], // todo: clean these: '@typescript-eslint/no-explicit-any': 'off', diff --git a/changelog.md b/changelog.md index b143e35..a47d895 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ -## 1.0.1 2020-09-18 +## 1.0.2 2020-09-18 - **fix:** update version of cockatiel to fix incompatible TypeScript types (see [#128](https://github.com/microsoft/etcd3/issues/128)) +- **fix:** don't include the deadline in inherited lease call options (see [#131](https://github.com/microsoft/etcd3/issues/131)) ## 1.0.1 2020-06-21 diff --git a/src/lease.ts b/src/lease.ts index e9b404f..75f68a0 100644 --- a/src/lease.ts +++ b/src/lease.ts @@ -105,25 +105,29 @@ export class Lease extends EventEmitter { private client = new RPC.LeaseClient(this.pool); private lastKeepAlive: number; + private defaultOptions: grpc.CallOptions; constructor( private readonly pool: ConnectionPool, private readonly namespace: NSApplicator, private ttl: number, - private readonly options?: ILeaseOptions, + options: ILeaseOptions = {}, ) { super(); + const { autoKeepAlive, deadline, ...rest } = options; + this.defaultOptions = rest; + if (!ttl || ttl < 1) { throw new Error(`The TTL in an etcd lease must be at least 1 second. Got: ${ttl}`); } this.leaseID = this.client - .leaseGrant({ TTL: ttl }, this.options) + .leaseGrant({ TTL: ttl }, options) .then(res => { this.state = State.Alive; this.lastKeepAlive = Date.now(); - if (options?.autoKeepAlive !== false) { + if (autoKeepAlive !== false) { this.keepalive(); } @@ -154,7 +158,7 @@ export class Lease extends EventEmitter { * Revoke frees the lease from etcd. Keys that the lease owns will be * evicted. */ - public async revoke(options: grpc.CallOptions | undefined = this.options): Promise { + public async revoke(options: grpc.CallOptions | undefined = this.defaultOptions): Promise { this.close(); const id = await this.leaseID; @@ -196,7 +200,7 @@ export class Lease extends EventEmitter { * keepaliveOnce fires an immediate keepalive for the lease. */ public keepaliveOnce( - options: grpc.CallOptions | undefined = this.options, + options: grpc.CallOptions | undefined = this.defaultOptions, ): Promise { return Promise.all([this.client.leaseKeepAlive(options), this.grant()]).then(([stream, id]) => { return new Promise((resolve, reject) => {