UNPKG

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