Files
elasticsearch-js/test/types/connection-pool.test-d.ts
Tomas Della Vedova 6c82a4967e Refactored type definitions (#1119)
* Updated types generation script

* Refactored api method definitions

* Updated test
- Removed old test code
- Added tsd dev dependency
- Rewritten test with tsd

* Removed unused dependencies

* Fixed definition

* Updated test

* Updated docs

* Improved events type definitions

* Updated test

* Minor fixes in the type definitons

* More type test

* Improved Transport type definitions

* Updated test

* Addressed comments

* Code generation

* Use RequestBody, Response and Context everywhere, also default Context to unknown

* Updated test

* body -> hasBody

* Fixed conflicts

* Updated code generation

* Improved request body type definition

* Updated code generation

* Use BodyType for both request and reponses generics
- Use extends for defining the RequestBody generic to force the user
  following the same shape.
- BodyType and NDBodyType now accepts a generics to allow injecting
  more specific types in the future

* API generation

* Updated test

* Updated docs

* Use BodyType also in ReponseError

* Removed useless client generics

* Renamed generics and types
- prefixed all generics with a T
- BodyType => RequestBody
- NDBodyType => RequestNDBody
- Added ResponseBody

* Updated test

* Updated docs

* Test ResponseBody as well

* Simplify overloads

* API generation

* Updated test

* Updated error types
2020-03-23 11:38:18 +01:00

96 lines
2.9 KiB
TypeScript

// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
import { expectType, expectAssignable } from 'tsd'
import { URL } from 'url'
import {
BaseConnectionPool,
ConnectionPool,
CloudConnectionPool,
Connection
} from '../../'
{
const pool = new BaseConnectionPool({
Connection: Connection,
ssl: { ca: 'stirng' },
emit: (event, ...args) => true,
agent: { keepAlive: true },
auth: { username: 'username', password: 'password' }
})
expectType<BaseConnectionPool>(pool)
expectType<Connection[]>(pool.connections)
expectType<number>(pool.size)
expectType<BaseConnectionPool>(pool.markAlive(new Connection()))
expectType<BaseConnectionPool>(pool.markDead(new Connection()))
expectType<Connection | null>(pool.getConnection({
filter (node) { return true },
selector (connections) { return connections[0] },
requestId: 'id',
name: 'name',
now: Date.now()
}))
expectType<Connection>(pool.addConnection({}))
expectType<BaseConnectionPool>(pool.removeConnection(new Connection()))
expectType<BaseConnectionPool>(pool.empty())
expectType<BaseConnectionPool>(pool.update([]))
expectType<any[]>(pool.nodesToHost([], 'https'))
expectType<{ url: URL }>(pool.urlToHost('url'))
}
{
const pool = new ConnectionPool({
Connection: Connection,
ssl: { ca: 'stirng' },
emit: (event, ...args) => true,
agent: { keepAlive: true },
auth: { username: 'username', password: 'password' },
pingTimeout: 1000,
resurrectStrategy: 'ping',
sniffEnabled: true
})
expectAssignable<ConnectionPool>(pool)
expectType<Connection[]>(pool.connections)
expectType<number>(pool.size)
expectType<string[]>(pool.dead)
expectAssignable<ConnectionPool>(pool.markAlive(new Connection()))
expectAssignable<ConnectionPool>(pool.markDead(new Connection()))
expectType<Connection | null>(pool.getConnection({
filter (node) { return true },
selector (connections) { return connections[0] },
requestId: 'id',
name: 'name',
now: Date.now()
}))
expectType<Connection>(pool.addConnection({}))
expectAssignable<ConnectionPool>(pool.removeConnection(new Connection()))
expectAssignable<ConnectionPool>(pool.empty())
expectAssignable<ConnectionPool>(pool.update([]))
expectType<any[]>(pool.nodesToHost([], 'https'))
expectType<{ url: URL }>(pool.urlToHost('url'))
expectType<void>(pool.resurrect({
now: Date.now(),
requestId: 'id',
name: 'name'
}))
}
{
const pool = new CloudConnectionPool({
Connection: Connection,
ssl: { ca: 'stirng' },
emit: (event, ...args) => true,
agent: { keepAlive: true },
auth: { username: 'username', password: 'password' }
})
expectAssignable<CloudConnectionPool>(pool)
expectType<Connection | null>(pool.cloudConnection)
expectType<Connection | null>(pool.getConnection())
}