Skip to content

Commit

Permalink
feat: export generic type of wrapped service client
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Zuev committed Jan 12, 2022
1 parent 2f424d6 commit bec2aca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as cloudApi from './generated/yandex/cloud';
export * from './session';
export * from './utils/operation';
export * from './utils/decode-message';
export { WrappedServiceClientType } from './types';
4 changes: 2 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GeneratedServiceClientCtor,
IamTokenCredentialsConfig,
OAuthCredentialsConfig,
ServiceAccountCredentialsConfig,
ServiceAccountCredentialsConfig, WrappedServiceClientType,
SessionConfig,
} from './types';
import { IamTokenService } from './token-service/iam-token-service';
Expand Down Expand Up @@ -94,7 +94,7 @@ export class Session {
return this.config.pollInterval;
}

client<S extends ServiceDefinition>(clientClass: GeneratedServiceClientCtor<S>) {
client<S extends ServiceDefinition>(clientClass: GeneratedServiceClientCtor<S>): WrappedServiceClientType<S> {
const endpoint = getServiceClientEndpoint(clientClass);
const channel = createChannel(endpoint, this.channelCredentials);

Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
ChannelCredentials, ChannelOptions, Client, ServiceDefinition,
} from '@grpc/grpc-js';
import { RawClient } from 'nice-grpc';
import { NormalizedServiceDefinition } from 'nice-grpc/lib/service-definitions';
import { DeadlineOptions } from 'nice-grpc-client-middleware-deadline';

export interface TokenService {
getToken: () => Promise<string>;
Expand Down Expand Up @@ -48,3 +51,5 @@ export type SessionConfig =
| IamTokenCredentialsConfig
| ServiceAccountCredentialsConfig
| GenericCredentialsConfig;

export type WrappedServiceClientType<S extends ServiceDefinition> = RawClient<NormalizedServiceDefinition<S>, DeadlineOptions>;

0 comments on commit bec2aca

Please sign in to comment.