UNPKG

4.29 kBTypeScriptView Raw
1import { MethodConfig, ServiceConfig } from './service-config';
2import { StatusObject } from './call-stream';
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 * Destroy the resolver. Should be called when the owning channel shuts down.
62 */
63 destroy(): void;
64}
65export interface ResolverConstructor {
66 new (target: GrpcUri, listener: ResolverListener, channelOptions: ChannelOptions): Resolver;
67 /**
68 * Get the default authority for a target. This loosely corresponds to that
69 * target's hostname. Throws an error if this resolver class cannot parse the
70 * `target`.
71 * @param target
72 */
73 getDefaultAuthority(target: GrpcUri): string;
74}
75/**
76 * Register a resolver class to handle target names prefixed with the `prefix`
77 * string. This prefix should correspond to a URI scheme name listed in the
78 * [gRPC Name Resolution document](https://github.com/grpc/grpc/blob/master/doc/naming.md)
79 * @param prefix
80 * @param resolverClass
81 */
82export declare function registerResolver(scheme: string, resolverClass: ResolverConstructor): void;
83/**
84 * Register a default resolver to handle target names that do not start with
85 * any registered prefix.
86 * @param resolverClass
87 */
88export declare function registerDefaultScheme(scheme: string): void;
89/**
90 * Create a name resolver for the specified target, if possible. Throws an
91 * error if no such name resolver can be created.
92 * @param target
93 * @param listener
94 */
95export declare function createResolver(target: GrpcUri, listener: ResolverListener, options: ChannelOptions): Resolver;
96/**
97 * Get the default authority for the specified target, if possible. Throws an
98 * error if no registered name resolver can parse that target string.
99 * @param target
100 */
101export declare function getDefaultAuthority(target: GrpcUri): string;
102export declare function mapUriDefaultScheme(target: GrpcUri): GrpcUri | null;