UNPKG

4.22 kBTypeScriptView Raw
1import { MethodConfig, ServiceConfig } from './service-config';
2import { StatusObject } from './call-stream';
3import { SubchannelAddress } from './subchannel';
4import { GrpcUri } from './uri-parser';
5import { ChannelOptions } from './channel-options';
6import { Metadata } from './metadata';
7import { Status } from './constants';
8export interface CallConfig {
9 methodConfig: MethodConfig;
10 onCommitted?: () => void;
11 pickInformation: {
12 [key: string]: string;
13 };
14 status: Status;
15}
16/**
17 * Selects a configuration for a method given the name and metadata. Defined in
18 * https://github.com/grpc/proposal/blob/master/A31-xds-timeout-support-and-config-selector.md#new-functionality-in-grpc
19 */
20export interface ConfigSelector {
21 (methodName: string, metadata: Metadata): CallConfig;
22}
23/**
24 * A listener object passed to the resolver's constructor that provides name
25 * resolution updates back to the resolver's owner.
26 */
27export interface ResolverListener {
28 /**
29 * Called whenever the resolver has new name resolution results to report
30 * @param addressList The new list of backend addresses
31 * @param serviceConfig The new service configuration corresponding to the
32 * `addressList`. Will be `null` if no service configuration was
33 * retrieved or if the service configuration was invalid
34 * @param serviceConfigError If non-`null`, indicates that the retrieved
35 * service configuration was invalid
36 */
37 onSuccessfulResolution(addressList: SubchannelAddress[], serviceConfig: ServiceConfig | null, serviceConfigError: StatusObject | null, configSelector: ConfigSelector | null, attributes: {
38 [key: string]: unknown;
39 }): void;
40 /**
41 * Called whenever a name resolution attempt fails.
42 * @param error Describes how resolution failed
43 */
44 onError(error: StatusObject): void;
45}
46/**
47 * A resolver class that handles one or more of the name syntax schemes defined
48 * in the [gRPC Name Resolution document](https://github.com/grpc/grpc/blob/master/doc/naming.md)
49 */
50export interface Resolver {
51 /**
52 * Indicates that the caller wants new name resolution data. Calling this
53 * function may eventually result in calling one of the `ResolverListener`
54 * functions, but that is not guaranteed. Those functions will never be
55 * called synchronously with the constructor or updateResolution.
56 */
57 updateResolution(): void;
58 /**
59 * Destroy the resolver. Should be called when the owning channel shuts down.
60 */
61 destroy(): void;
62}
63export interface ResolverConstructor {
64 new (target: GrpcUri, listener: ResolverListener, channelOptions: ChannelOptions): Resolver;
65 /**
66 * Get the default authority for a target. This loosely corresponds to that
67 * target's hostname. Throws an error if this resolver class cannot parse the
68 * `target`.
69 * @param target
70 */
71 getDefaultAuthority(target: GrpcUri): string;
72}
73/**
74 * Register a resolver class to handle target names prefixed with the `prefix`
75 * string. This prefix should correspond to a URI scheme name listed in the
76 * [gRPC Name Resolution document](https://github.com/grpc/grpc/blob/master/doc/naming.md)
77 * @param prefix
78 * @param resolverClass
79 */
80export declare function registerResolver(scheme: string, resolverClass: ResolverConstructor): void;
81/**
82 * Register a default resolver to handle target names that do not start with
83 * any registered prefix.
84 * @param resolverClass
85 */
86export declare function registerDefaultScheme(scheme: string): void;
87/**
88 * Create a name resolver for the specified target, if possible. Throws an
89 * error if no such name resolver can be created.
90 * @param target
91 * @param listener
92 */
93export declare function createResolver(target: GrpcUri, listener: ResolverListener, options: ChannelOptions): Resolver;
94/**
95 * Get the default authority for the specified target, if possible. Throws an
96 * error if no registered name resolver can parse that target string.
97 * @param target
98 */
99export declare function getDefaultAuthority(target: GrpcUri): string;
100export declare function mapUriDefaultScheme(target: GrpcUri): GrpcUri | null;
101export declare function registerAll(): void;