Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

refactor: remove overly strict context types #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 28 additions & 38 deletions lib/index.d.ts
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]:
Expand All @@ -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?: {
Expand All @@ -37,23 +37,6 @@ export type ServiceClientOptions = {
timeout?: number;
};

export interface ServiceRequest {
Copy link
Author

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

headers: Headers;
logger: Logger;
Copy link
Author

Choose a reason for hiding this comment

The 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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a proprietary auth credential structure

};
};
}

export type ServiceContext = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is not used anywhere

dataSources: {[serviceClient: string]: ClientInstance};
Copy link
Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed comments and added types for options that were previously missed like hostname

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;

Expand Down