1 /// <reference types="node" />
4 * Copyright 2018 gRPC authors.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import * as Protobuf from 'protobufjs';
20 import * as descriptor from 'protobufjs/ext/descriptor';
21 declare module 'protobufjs' {
23 toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IDescriptorProto> & descriptor.IDescriptorProto;
26 toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IFileDescriptorSet> & descriptor.IFileDescriptorSet;
29 toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IEnumDescriptorProto> & descriptor.IEnumDescriptorProto;
32 export interface Serialize<T> {
35 export interface Deserialize<T> {
38 export interface ProtobufTypeDefinition {
41 fileDescriptorProtos: Buffer[];
43 export interface MessageTypeDefinition extends ProtobufTypeDefinition {
44 format: 'Protocol Buffer 3 DescriptorProto';
46 export interface EnumTypeDefinition extends ProtobufTypeDefinition {
47 format: 'Protocol Buffer 3 EnumDescriptorProto';
49 export interface MethodDefinition<RequestType, ResponseType> {
51 requestStream: boolean;
52 responseStream: boolean;
53 requestSerialize: Serialize<RequestType>;
54 responseSerialize: Serialize<ResponseType>;
55 requestDeserialize: Deserialize<RequestType>;
56 responseDeserialize: Deserialize<ResponseType>;
57 originalName?: string;
58 requestType: MessageTypeDefinition;
59 responseType: MessageTypeDefinition;
61 export interface ServiceDefinition {
62 [index: string]: MethodDefinition<object, object>;
64 export declare type AnyDefinition = ServiceDefinition | MessageTypeDefinition | EnumTypeDefinition;
65 export interface PackageDefinition {
66 [index: string]: AnyDefinition;
68 export declare type Options = Protobuf.IParseOptions & Protobuf.IConversionOptions & {
69 includeDirs?: string[];
72 * Load a .proto file with the specified options.
73 * @param filename The file path to load. Can be an absolute path or relative to
75 * @param options.keepCase Preserve field names. The default is to change them
77 * @param options.longs The type that should be used to represent `long` values.
78 * Valid options are `Number` and `String`. Defaults to a `Long` object type
80 * @param options.enums The type that should be used to represent `enum` values.
81 * The only valid option is `String`. Defaults to the numeric value.
82 * @param options.bytes The type that should be used to represent `bytes`
83 * values. Valid options are `Array` and `String`. The default is to use
85 * @param options.defaults Set default values on output objects. Defaults to
87 * @param options.arrays Set empty arrays for missing array values even if
88 * `defaults` is `false`. Defaults to `false`.
89 * @param options.objects Set empty objects for missing object values even if
90 * `defaults` is `false`. Defaults to `false`.
91 * @param options.oneofs Set virtual oneof properties to the present field's
93 * @param options.includeDirs Paths to search for imported `.proto` files.
95 export declare function load(filename: string, options?: Options): Promise<PackageDefinition>;
96 export declare function loadSync(filename: string, options?: Options): PackageDefinition;