-
Notifications
You must be signed in to change notification settings - Fork 22
refactor: remove overly strict context types #108
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { ResponseObject } from '@hapi/hapi'; | ||
import * as Wreck from '@hapi/wreck'; | ||
import Http from 'http'; | ||
import { Logger } from 'pino'; | ||
import Https from 'https'; | ||
import QueryString from 'querystring'; | ||
import * as stream from 'stream'; | ||
import { SecureContext, SecureContextOptions } from 'tls'; | ||
|
||
type Headers = { | ||
readonly [name: string]: | ||
|
@@ -16,15 +16,15 @@ type Headers = { | |
export type ServiceClientOptions = { | ||
agent?: {[key: string]: string}; | ||
connectTimeout?: number; | ||
context?: ServiceRequest; | ||
context?: any; | ||
headers?: Headers; | ||
hostPrefix?: string; | ||
maxConnectRetry?: number; | ||
method: string; | ||
operation: string; | ||
path?: string; | ||
pathParams?: {[key: string]: string}; | ||
payload?: string | Buffer | Stream.Readable | object; | ||
payload?: string | Buffer | stream.Readable | object; | ||
queryParams?: QueryString.ParsedUrlQueryInput; | ||
read?: boolean; | ||
readOptions?: { | ||
|
@@ -37,23 +37,6 @@ export type ServiceClientOptions = { | |
timeout?: number; | ||
}; | ||
|
||
export interface ServiceRequest { | ||
headers: Headers; | ||
logger: Logger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would require use of pino, which is not a requirement to use service-client |
||
auth: { | ||
isAuthenticated: boolean; | ||
credentials: { | ||
apiToken: string; | ||
principalToken: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a proprietary auth credential structure |
||
}; | ||
}; | ||
} | ||
|
||
export type ServiceContext = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type is not used anywhere |
||
dataSources: {[serviceClient: string]: ClientInstance}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would require use of graphql-component which is not a requirement to use this library |
||
request: ServiceRequest; | ||
}; | ||
|
||
type ServiceClientResponsePayload = stream.Readable | ||
| Buffer | ||
| string | ||
|
@@ -72,27 +55,34 @@ export type ClientInstance = { | |
}> | ||
}; | ||
|
||
export type GlobalConfig = { | ||
base?: { | ||
// url | ||
protocol?: string; | ||
// resiliency | ||
connectTimeout?: number; | ||
maxConnectRetry?: number; | ||
timeout?: number; | ||
maxFailures?: number; // circuit breaking | ||
resetTime?: number; // circuit breaking | ||
// agent options | ||
agentOptions?: { | ||
keepAlive?: boolean; | ||
keepAliveMsecs?: number; | ||
}; | ||
export type ServiceConfig = { | ||
protocol?: string; | ||
hostname?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed comments and added types for options that were previously missed like |
||
hostnameConfig?: any, | ||
port?: number; | ||
basePath?: string; | ||
connectTimeout?: number; | ||
maxConnectRetry?: number; | ||
timeout?: number; | ||
maxFailures?: number; | ||
resetTime?: number; | ||
agent?: Http.Agent | Https.Agent; | ||
agentOptions?: { | ||
keepAlive?: boolean; | ||
keepAliveMsecs?: number; | ||
secureContext?: SecureContext; | ||
secureContextOptions?: SecureContextOptions; | ||
}; | ||
plugins?: any; | ||
}; | ||
|
||
export type GlobalConfig = { | ||
base?: ServiceConfig; | ||
plugins?: any[]; | ||
overrides?: {}; | ||
overrides?: Record<string, ServiceConfig>; | ||
} | ||
|
||
export function create(servicename: string, overrides?: {}): ClientInstance; | ||
export function create(servicename: string, overrides?: ServiceConfig): ClientInstance; | ||
|
||
export function remove(servicename: string): void; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library has no need for any specificity in this type, used for the context option, which is passed through to plugins without being accessed by this library