diff --git a/.gitmodules b/.gitmodules index 4a5a1e320..d3c1ebaf6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,12 @@ [submodule "packages/grpc-tools/deps/protobuf"] path = packages/grpc-tools/deps/protobuf url = https://github.com/protocolbuffers/protobuf +[submodule "packages/proto-loader/deps/gapic-showcase"] + path = packages/proto-loader/deps/gapic-showcase + url = https://github.com/googleapis/gapic-showcase.git +[submodule "packages/proto-loader/deps/googleapis"] + path = packages/proto-loader/deps/googleapis + url = https://github.com/googleapis/googleapis.git [submodule "packages/grpc-js-xds/deps/envoy-api"] path = packages/grpc-js-xds/deps/envoy-api url = https://github.com/envoyproxy/data-plane-api.git diff --git a/packages/proto-loader/README.md b/packages/proto-loader/README.md index 481b86297..123fad111 100644 --- a/packages/proto-loader/README.md +++ b/packages/proto-loader/README.md @@ -38,6 +38,7 @@ The options parameter is an object that can have the following optional properti | `arrays` | `true` or `false` | Set empty arrays for missing array values even if `defaults` is `false` Defaults to `false`. | `objects` | `true` or `false` | Set empty objects for missing object values even if `defaults` is `false` Defaults to `false`. | `oneofs` | `true` or `false` | Set virtual oneof properties to the present field's name. Defaults to `false`. +| `json` | `true` or `false` | Represent `Infinity` and `NaN` as strings in `float` fields, and automatically decode `google.protobuf.Any` values. Defaults to `false` | `includeDirs` | An array of strings | A list of search paths for imported `.proto` files. The following options object closely approximates the existing behavior of `grpc.load`: @@ -51,3 +52,69 @@ const options = { oneofs: true } ``` + +## Generating TypeScript types + +The `proto-loader-gen-types` script distributed with this package can be used to generate TypeScript type information for the objects loaded at runtime. More information about how to use it can be found in [the *@grpc/proto-loader TypeScript Type Generator CLI Tool* proposal document](https://github.com/grpc/proposal/blob/master/L70-node-proto-loader-type-generator.md). The arguments mostly match the `load` function's options; the full usage information is as follows: + +```console +proto-loader-gen-types.js [options] filenames... + +Options: + --help Show help [boolean] + --version Show version number [boolean] + --keepCase Preserve the case of field names + [boolean] [default: false] + --longs The type that should be used to output 64 bit integer + values. Can be String, Number[string] [default: "Long"] + --enums The type that should be used to output enum fields. Can + be String [string] [default: "number"] + --bytes The type that should be used to output bytes fields. + Can be String, Array [string] [default: "Buffer"] + --defaults Output default values for omitted fields + [boolean] [default: false] + --arrays Output default values for omitted repeated fields even + if --defaults is not set [boolean] [default: false] + --objects Output default values for omitted message fields even + if --defaults is not set [boolean] [default: false] + --oneofs Output virtual oneof fields set to the present field's + name [boolean] [default: false] + --json Represent Infinity and NaN as strings in float fields. + Also decode google.protobuf.Any automatically + [boolean] [default: false] + --includeComments Generate doc comments from comments in the original + files [boolean] [default: false] + -I, --includeDirs Directories to search for included files [array] + -O, --outDir Directory in which to output files [string] [required] + --grpcLib The gRPC implementation library that these types will + be used with [string] [required] +``` + +### Example Usage + +Generate the types: + +```sh +$(npm bin)/proto-loader-gen-types --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=proto/ proto/*.proto +``` + +Consume the types: + +```ts +import * as grpc from '@grpc/grpc-js'; +import * as protoLoader from '@grpc/proto-loader'; +import { ProtoGrpcType } from './proto/example'; +import { ExampleHandlers } from './proto/example_package/Example'; + +const exampleServer: ExampleHandlers = { + // server handlers implementation... +}; + +const packageDefinition = protoLoader.loadSync('./proto/example.proto'); +const proto = (grpc.loadPackageDefinition( + packageDefinition +) as unknown) as ProtoGrpcType; + +const server = new grpc.Server(); +server.addService(proto.example_package.Example.service, exampleServer); +``` diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts new file mode 100644 index 000000000..c11befee0 --- /dev/null +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -0,0 +1,765 @@ +#!/usr/bin/env node +/** + * @license + * Copyright 2020 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import * as fs from 'fs'; +import * as path from 'path'; + +import * as Protobuf from 'protobufjs'; +import * as yargs from 'yargs'; + +import camelCase = require('lodash.camelcase'); +import { loadProtosWithOptions, addCommonProtos } from '../src/util'; + +type GeneratorOptions = Protobuf.IParseOptions & Protobuf.IConversionOptions & { + includeDirs?: string[]; + grpcLib: string; + outDir: string; + verbose?: boolean; + includeComments?: boolean; +} + +class TextFormatter { + private readonly indentText = ' '; + private indentValue = 0; + private textParts: string[] = []; + constructor() {} + + indent() { + this.indentValue += 1; + } + + unindent() { + this.indentValue -= 1; + } + + writeLine(line: string) { + for (let i = 0; i < this.indentValue; i+=1) { + this.textParts.push(this.indentText); + } + this.textParts.push(line); + this.textParts.push('\n'); + } + + getFullText() { + return this.textParts.join(''); + } +} + +// GENERATOR UTILITY FUNCTIONS + +function compareName(x: {name: string}, y: {name: string}): number { + if (x.name < y.name) { + return -1; + } else if (x.name > y.name) { + return 1 + } else { + return 0; + } +} + +function isNamespaceBase(obj: Protobuf.ReflectionObject): obj is Protobuf.NamespaceBase { + return Array.isArray((obj as Protobuf.NamespaceBase).nestedArray); +} + +function stripLeadingPeriod(name: string) { + return name.startsWith('.') ? name.substring(1) : name; +} + +function getImportPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service): string { + /* If the thing we are importing is defined in a message, it is generated in + * the same file as that message. */ + if (to.parent instanceof Protobuf.Type) { + return getImportPath(to.parent); + } + return stripLeadingPeriod(to.fullName).replace(/\./g, '/'); +} + +function getPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { + return stripLeadingPeriod(to.fullName).replace(/\./g, '/') + '.ts'; +} + +function getPathToRoot(from: Protobuf.NamespaceBase) { + const depth = stripLeadingPeriod(from.fullName).split('.').length - 1; + if (depth === 0) { + return './'; + } + let path = ''; + for (let i = 0; i < depth; i++) { + path += '../'; + } + return path; +} + +function getRelativeImportPath(from: Protobuf.Type | Protobuf.Service, to: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { + return getPathToRoot(from) + getImportPath(to); +} + +function getTypeInterfaceName(type: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { + return type.fullName.replace(/\./g, '_'); +} + +function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Service, from?: Protobuf.Type | Protobuf.Service) { + const filePath = from === undefined ? './' + getImportPath(dependency) : getRelativeImportPath(from, dependency); + const typeInterfaceName = getTypeInterfaceName(dependency); + let importedTypes: string; + /* If the dependency is defined within a message, it will be generated in that + * message's file and exported using its typeInterfaceName. */ + if (dependency.parent instanceof Protobuf.Type) { + if (dependency instanceof Protobuf.Type) { + importedTypes = `${typeInterfaceName}, ${typeInterfaceName}__Output`; + } else if (dependency instanceof Protobuf.Enum) { + importedTypes = `${typeInterfaceName}`; + } else if (dependency instanceof Protobuf.Service) { + importedTypes = `${typeInterfaceName}Client`; + } else { + throw new Error('Invalid object passed to getImportLine'); + } + } else { + if (dependency instanceof Protobuf.Type) { + importedTypes = `${dependency.name} as ${typeInterfaceName}, ${dependency.name}__Output as ${typeInterfaceName}__Output`; + } else if (dependency instanceof Protobuf.Enum) { + importedTypes = `${dependency.name} as ${typeInterfaceName}`; + } else if (dependency instanceof Protobuf.Service) { + importedTypes = `${dependency.name}Client as ${typeInterfaceName}Client`; + } else { + throw new Error('Invalid object passed to getImportLine'); + } + } + return `import type { ${importedTypes} } from '${filePath}';` +} + +function getChildMessagesAndEnums(namespace: Protobuf.NamespaceBase): (Protobuf.Type | Protobuf.Enum)[] { + const messageList: (Protobuf.Type | Protobuf.Enum)[] = []; + for (const nested of namespace.nestedArray) { + if (nested instanceof Protobuf.Type || nested instanceof Protobuf.Enum) { + messageList.push(nested); + } + if (isNamespaceBase(nested)) { + messageList.push(...getChildMessagesAndEnums(nested)); + } + } + return messageList; +} + +function formatComment(formatter: TextFormatter, comment?: string | null) { + if (!comment) { + return; + } + formatter.writeLine('/**'); + for(const line of comment.split('\n')) { + formatter.writeLine(` * ${line.replace(/\*\//g, '* /')}`); + } + formatter.writeLine(' */'); +} + +// GENERATOR FUNCTIONS + +function getTypeNamePermissive(fieldType: string, resolvedType: Protobuf.Type | Protobuf.Enum | null): string { + switch (fieldType) { + case 'double': + case 'float': + return 'number | string'; + case 'int32': + case 'uint32': + case 'sint32': + case 'fixed32': + case 'sfixed32': + return 'number'; + case 'int64': + case 'uint64': + case 'sint64': + case 'fixed64': + case 'sfixed64': + return 'number | string | Long'; + case 'bool': + return 'boolean'; + case 'string': + return 'string'; + case 'bytes': + return 'Buffer | Uint8Array | string'; + default: + if (resolvedType === null) { + throw new Error('Found field with no usable type'); + } + const typeInterfaceName = getTypeInterfaceName(resolvedType); + if (resolvedType instanceof Protobuf.Type) { + return typeInterfaceName; + } else { + return `${typeInterfaceName} | keyof typeof ${typeInterfaceName}`; + } + } +} + +function getFieldTypePermissive(field: Protobuf.FieldBase): string { + const valueType = getTypeNamePermissive(field.type, field.resolvedType); + if (field instanceof Protobuf.MapField) { + const keyType = field.keyType === 'string' ? 'string' : 'number'; + return `{[key: ${keyType}]: ${valueType}}`; + } else { + return valueType; + } +} + +function generatePermissiveMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: GeneratorOptions, nameOverride?: string) { + if (options.includeComments) { + formatComment(formatter, messageType.comment); + } + if (messageType.fullName === '.google.protobuf.Any') { + /* This describes the behavior of the Protobuf.js Any wrapper fromObject + * replacement function */ + formatter.writeLine('export type Any = AnyExtension | {'); + formatter.writeLine(' type_url: string;'); + formatter.writeLine(' value: Buffer | Uint8Array | string;'); + formatter.writeLine('}'); + return; + } + formatter.writeLine(`export interface ${nameOverride ?? messageType.name} {`); + formatter.indent(); + for (const field of messageType.fieldsArray) { + const repeatedString = field.repeated ? '[]' : ''; + const type: string = getFieldTypePermissive(field); + if (options.includeComments) { + formatComment(formatter, field.comment); + } + formatter.writeLine(`'${field.name}'?: (${type})${repeatedString};`); + } + for (const oneof of messageType.oneofsArray) { + const typeString = oneof.fieldsArray.map(field => `"${field.name}"`).join('|'); + if (options.includeComments) { + formatComment(formatter, oneof.comment); + } + formatter.writeLine(`'${oneof.name}'?: ${typeString};`); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function getTypeNameRestricted(fieldType: string, resolvedType: Protobuf.Type | Protobuf.Enum | null, options: GeneratorOptions): string { + switch (fieldType) { + case 'double': + case 'float': + if (options.json) { + return 'number | string'; + } else { + return 'number'; + } + case 'int32': + case 'uint32': + case 'sint32': + case 'fixed32': + case 'sfixed32': + return 'number'; + case 'int64': + case 'uint64': + case 'sint64': + case 'fixed64': + case 'sfixed64': + if (options.longs === Number) { + return 'number'; + } else if (options.longs === String) { + return 'string'; + } else { + return 'Long'; + } + case 'bool': + return 'boolean'; + case 'string': + return 'string'; + case 'bytes': + if (options.bytes === Array) { + return 'Uint8Array'; + } else if (options.bytes === String) { + return 'string'; + } else { + return 'Buffer'; + } + default: + if (resolvedType === null) { + throw new Error('Found field with no usable type'); + } + const typeInterfaceName = getTypeInterfaceName(resolvedType); + if (resolvedType instanceof Protobuf.Type) { + return typeInterfaceName + '__Output'; + } else { + if (options.enums == String) { + return `keyof typeof ${typeInterfaceName}`; + } else { + return typeInterfaceName; + } + } + } +} + +function getFieldTypeRestricted(field: Protobuf.FieldBase, options: GeneratorOptions): string { + const valueType = getTypeNameRestricted(field.type, field.resolvedType, options); + if (field instanceof Protobuf.MapField) { + const keyType = field.keyType === 'string' ? 'string' : 'number'; + return `{[key: ${keyType}]: ${valueType}}`; + } else { + return valueType; + } +} + +function generateRestrictedMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: GeneratorOptions, nameOverride?: string) { + if (options.includeComments) { + formatComment(formatter, messageType.comment); + } + if (messageType.fullName === '.google.protobuf.Any' && options.json) { + /* This describes the behavior of the Protobuf.js Any wrapper toObject + * replacement function */ + let optionalString = options.defaults ? '' : '?'; + formatter.writeLine('export type Any__Output = AnyExtension | {'); + formatter.writeLine(` type_url${optionalString}: string;`); + formatter.writeLine(` value${optionalString}: ${getTypeNameRestricted('bytes', null, options)};`); + formatter.writeLine('}'); + return; + } + formatter.writeLine(`export interface ${nameOverride ?? messageType.name}__Output {`); + formatter.indent(); + for (const field of messageType.fieldsArray) { + let fieldGuaranteed: boolean; + if (field.partOf) { + // The field is not guaranteed populated if it is part of a oneof + fieldGuaranteed = false; + } else if (field.repeated) { + fieldGuaranteed = (options.defaults || options.arrays) ?? false; + } else if (field.resolvedType) { + if (field.resolvedType instanceof Protobuf.Enum) { + fieldGuaranteed = options.defaults ?? false; + } else { + // Message fields can always be omitted + fieldGuaranteed = false; + } + } else { + if (field.map) { + fieldGuaranteed = (options.defaults || options.objects) ?? false; + } else { + fieldGuaranteed = options.defaults ?? false; + } + } + const optionalString = fieldGuaranteed ? '' : '?'; + const repeatedString = field.repeated ? '[]' : ''; + const type = getFieldTypeRestricted(field, options); + if (options.includeComments) { + formatComment(formatter, field.comment); + } + formatter.writeLine(`'${field.name}'${optionalString}: (${type})${repeatedString};`); + } + if (options.oneofs) { + for (const oneof of messageType.oneofsArray) { + const typeString = oneof.fieldsArray.map(field => `"${field.name}"`).join('|'); + if (options.includeComments) { + formatComment(formatter, oneof.comment); + } + formatter.writeLine(`'${oneof.name}': ${typeString};`); + } + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateMessageInterfaces(formatter: TextFormatter, messageType: Protobuf.Type, options: GeneratorOptions) { + let usesLong: boolean = false; + let seenDeps: Set = new Set(); + const childTypes = getChildMessagesAndEnums(messageType); + formatter.writeLine(`// Original file: ${messageType.filename}`); + formatter.writeLine(''); + messageType.fieldsArray.sort((fieldA, fieldB) => fieldA.id - fieldB.id); + for (const field of messageType.fieldsArray) { + if (field.resolvedType && childTypes.indexOf(field.resolvedType) < 0) { + const dependency = field.resolvedType; + if (seenDeps.has(dependency.fullName)) { + continue; + } + seenDeps.add(dependency.fullName); + formatter.writeLine(getImportLine(dependency, messageType)); + } + if (field.type.indexOf('64') >= 0) { + usesLong = true; + } + } + for (const childType of childTypes) { + if (childType instanceof Protobuf.Type) { + for (const field of childType.fieldsArray) { + if (field.resolvedType && childTypes.indexOf(field.resolvedType) < 0) { + const dependency = field.resolvedType; + if (seenDeps.has(dependency.fullName)) { + continue; + } + seenDeps.add(dependency.fullName); + formatter.writeLine(getImportLine(dependency, messageType)); + } + if (field.type.indexOf('64') >= 0) { + usesLong = true; + } + } + } + } + if (usesLong) { + formatter.writeLine("import type { Long } from '@grpc/proto-loader';"); + } + if (messageType.fullName === '.google.protobuf.Any') { + formatter.writeLine("import type { AnyExtension } from '@grpc/proto-loader';") + } + formatter.writeLine(''); + for (const childType of childTypes.sort(compareName)) { + const nameOverride = getTypeInterfaceName(childType); + if (childType instanceof Protobuf.Type) { + generatePermissiveMessageInterface(formatter, childType, options, nameOverride); + formatter.writeLine(''); + generateRestrictedMessageInterface(formatter, childType, options, nameOverride); + } else { + generateEnumInterface(formatter, childType, options, nameOverride); + } + formatter.writeLine(''); + } + + generatePermissiveMessageInterface(formatter, messageType, options); + formatter.writeLine(''); + generateRestrictedMessageInterface(formatter, messageType, options); +} + +function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum, options: GeneratorOptions, nameOverride?: string) { + formatter.writeLine(`// Original file: ${enumType.filename}`); + formatter.writeLine(''); + if (options.includeComments) { + formatComment(formatter, enumType.comment); + } + formatter.writeLine(`export enum ${nameOverride ?? enumType.name} {`); + formatter.indent(); + for (const key of Object.keys(enumType.values)) { + if (options.includeComments) { + formatComment(formatter, enumType.comments[key]); + } + formatter.writeLine(`${key} = ${enumType.values[key]},`); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateServiceClientInterface(formatter: TextFormatter, serviceType: Protobuf.Service, options: GeneratorOptions) { + if (options.includeComments) { + formatComment(formatter, serviceType.comment); + } + formatter.writeLine(`export interface ${serviceType.name}Client extends grpc.Client {`); + formatter.indent(); + for (const methodName of Object.keys(serviceType.methods).sort()) { + const method = serviceType.methods[methodName]; + for (const name of [methodName, camelCase(methodName)]) { + if (options.includeComments) { + formatComment(formatter, method.comment); + } + const requestType = getTypeInterfaceName(method.resolvedRequestType!); + const responseType = getTypeInterfaceName(method.resolvedResponseType!) + '__Output'; + const callbackType = `(error?: grpc.ServiceError, result?: ${responseType}) => void`; + if (method.requestStream) { + if (method.responseStream) { + // Bidi streaming + const callType = `grpc.ClientDuplexStream<${requestType}, ${responseType}>`; + formatter.writeLine(`${name}(metadata: grpc.Metadata, options?: grpc.CallOptions): ${callType};`); + formatter.writeLine(`${name}(options?: grpc.CallOptions): ${callType};`); + } else { + // Client streaming + const callType = `grpc.ClientWritableStream<${requestType}>`; + formatter.writeLine(`${name}(metadata: grpc.Metadata, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(metadata: grpc.Metadata, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(callback: ${callbackType}): ${callType};`); + } + } else { + if (method.responseStream) { + // Server streaming + const callType = `grpc.ClientReadableStream<${responseType}>`; + formatter.writeLine(`${name}(argument: ${requestType}, metadata: grpc.Metadata, options?: grpc.CallOptions): ${callType};`); + formatter.writeLine(`${name}(argument: ${requestType}, options?: grpc.CallOptions): ${callType};`); + } else { + // Unary + const callType = 'grpc.ClientUnaryCall'; + formatter.writeLine(`${name}(argument: ${requestType}, metadata: grpc.Metadata, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(argument: ${requestType}, metadata: grpc.Metadata, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(argument: ${requestType}, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(argument: ${requestType}, callback: ${callbackType}): ${callType};`); + } + } + } + formatter.writeLine(''); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: Protobuf.Service, options: GeneratorOptions) { + if (options.includeComments) { + formatComment(formatter, serviceType.comment); + } + formatter.writeLine(`export interface ${serviceType.name}Handlers extends grpc.UntypedServiceImplementation {`); + formatter.indent(); + for (const methodName of Object.keys(serviceType.methods).sort()) { + const method = serviceType.methods[methodName]; + if (options.includeComments) { + formatComment(formatter, method.comment); + } + const requestType = getTypeInterfaceName(method.resolvedRequestType!) + '__Output'; + const responseType = getTypeInterfaceName(method.resolvedResponseType!); + if (method.requestStream) { + if (method.responseStream) { + // Bidi streaming + formatter.writeLine(`${methodName}: grpc.handleBidiStreamingCall<${requestType}, ${responseType}>;`); + } else { + // Client streaming + formatter.writeLine(`${methodName}: grpc.handleClientStreamingCall<${requestType}, ${responseType}>;`); + } + } else { + if (method.responseStream) { + // Server streaming + formatter.writeLine(`${methodName}: grpc.handleServerStreamingCall<${requestType}, ${responseType}>;`); + } else { + // Unary + formatter.writeLine(`${methodName}: grpc.handleUnaryCall<${requestType}, ${responseType}>;`); + } + } + formatter.writeLine(''); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateServiceInterfaces(formatter: TextFormatter, serviceType: Protobuf.Service, options: GeneratorOptions) { + formatter.writeLine(`// Original file: ${serviceType.filename}`); + formatter.writeLine(''); + const grpcImportPath = options.grpcLib.startsWith('.') ? getPathToRoot(serviceType) + options.grpcLib : options.grpcLib; + formatter.writeLine(`import type * as grpc from '${grpcImportPath}'`); + const dependencies: Set = new Set(); + for (const method of serviceType.methodsArray) { + dependencies.add(method.resolvedRequestType!); + dependencies.add(method.resolvedResponseType!); + } + for (const dep of Array.from(dependencies.values()).sort(compareName)) { + formatter.writeLine(getImportLine(dep, serviceType)); + } + formatter.writeLine(''); + + generateServiceClientInterface(formatter, serviceType, options); + formatter.writeLine(''); + + generateServiceHandlerInterface(formatter, serviceType, options); +} + +function generateServiceImports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions) { + for (const nested of namespace.nestedArray.sort(compareName)) { + if (nested instanceof Protobuf.Service) { + formatter.writeLine(getImportLine(nested)); + } else if (isNamespaceBase(nested) && !(nested instanceof Protobuf.Type) && !(nested instanceof Protobuf.Enum)) { + generateServiceImports(formatter, nested, options); + } + } +} + +function generateSingleLoadedDefinitionType(formatter: TextFormatter, nested: Protobuf.ReflectionObject, options: GeneratorOptions) { + if (nested instanceof Protobuf.Service) { + if (options.includeComments) { + formatComment(formatter, nested.comment); + } + formatter.writeLine(`${nested.name}: SubtypeConstructor & { service: ServiceDefinition }`) + } else if (nested instanceof Protobuf.Enum) { + formatter.writeLine(`${nested.name}: EnumTypeDefinition`); + } else if (nested instanceof Protobuf.Type) { + formatter.writeLine(`${nested.name}: MessageTypeDefinition`); + } else if (isNamespaceBase(nested)) { + generateLoadedDefinitionTypes(formatter, nested, options); + } +} + +function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions) { + formatter.writeLine(`${namespace.name}: {`); + formatter.indent(); + for (const nested of namespace.nestedArray.sort(compareName)) { + generateSingleLoadedDefinitionType(formatter, nested, options); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) { + formatter.writeLine(`import type * as grpc from '${options.grpcLib}';`); + formatter.writeLine("import type { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';"); + formatter.writeLine(''); + + generateServiceImports(formatter, root, options); + formatter.writeLine(''); + + formatter.writeLine('type SubtypeConstructor any, Subtype> = {'); + formatter.writeLine(' new(...args: ConstructorParameters): Subtype;'); + formatter.writeLine('};'); + formatter.writeLine(''); + + formatter.writeLine('export interface ProtoGrpcType {'); + formatter.indent(); + for (const nested of root.nestedArray) { + generateSingleLoadedDefinitionType(formatter, nested, options); + } + formatter.unindent(); + formatter.writeLine('}'); + formatter.writeLine(''); +} + +async function writeFile(filename: string, contents: string): Promise { + await fs.promises.mkdir(path.dirname(filename), {recursive: true}); + return fs.promises.writeFile(filename, contents); +} + +function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: GeneratorOptions): Promise[] { + const filePromises : Promise[] = []; + for (const nested of namespace.nestedArray) { + const fileFormatter = new TextFormatter(); + if (nested instanceof Protobuf.Type) { + generateMessageInterfaces(fileFormatter, nested, options); + if (options.verbose) { + console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); + } + filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); + } else if (nested instanceof Protobuf.Enum) { + generateEnumInterface(fileFormatter, nested, options); + if (options.verbose) { + console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); + } + filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); + } else if (nested instanceof Protobuf.Service) { + generateServiceInterfaces(fileFormatter, nested, options); + if (options.verbose) { + console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); + } + filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); + } else if (isNamespaceBase(nested)) { + filePromises.push(...generateFilesForNamespace(nested, options)); + } + } + return filePromises; +} + +function writeFilesForRoot(root: Protobuf.Root, masterFileName: string, options: GeneratorOptions): Promise[] { + const filePromises: Promise[] = []; + + const masterFileFormatter = new TextFormatter(); + generateRootFile(masterFileFormatter, root, options); + if (options.verbose) { + console.log(`Writing ${options.outDir}/${masterFileName}`); + } + filePromises.push(writeFile(`${options.outDir}/${masterFileName}`, masterFileFormatter.getFullText())); + + filePromises.push(...generateFilesForNamespace(root, options)); + + return filePromises; +} + +async function writeAllFiles(protoFiles: string[], options: GeneratorOptions) { + await fs.promises.mkdir(options.outDir, {recursive: true}); + const basenameMap = new Map(); + for (const filename of protoFiles) { + const basename = path.basename(filename).replace(/\.proto$/, '.ts'); + if (basenameMap.has(basename)) { + basenameMap.get(basename)!.push(filename); + } else { + basenameMap.set(basename, [filename]); + } + } + for (const [basename, filenames] of basenameMap.entries()) { + const loadedRoot = await loadProtosWithOptions(filenames, options); + writeFilesForRoot(loadedRoot, basename, options); + } +} + +function runScript() { + const argv = yargs + .parserConfiguration({ + 'parse-positional-numbers': false + }) + .string(['includeDirs', 'grpcLib']) + .normalize(['includeDirs', 'outDir']) + .array('includeDirs') + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'includeComments']) + .string(['longs', 'enums', 'bytes']) + .default('keepCase', false) + .default('defaults', false) + .default('arrays', false) + .default('objects', false) + .default('oneofs', false) + .default('json', false) + .default('includeComments', false) + .default('longs', 'Long') + .default('enums', 'number') + .default('bytes', 'Buffer') + .coerce('longs', value => { + switch (value) { + case 'String': return String; + case 'Number': return Number; + default: return undefined; + } + }).coerce('enums', value => { + if (value === 'String') { + return String; + } else { + return undefined; + } + }).coerce('bytes', value => { + switch (value) { + case 'Array': return Array; + case 'String': return String; + default: return undefined; + } + }).alias({ + includeDirs: 'I', + outDir: 'O', + verbose: 'v' + }).describe({ + keepCase: 'Preserve the case of field names', + longs: 'The type that should be used to output 64 bit integer values. Can be String, Number', + enums: 'The type that should be used to output enum fields. Can be String', + bytes: 'The type that should be used to output bytes fields. Can be String, Array', + defaults: 'Output default values for omitted fields', + arrays: 'Output default values for omitted repeated fields even if --defaults is not set', + objects: 'Output default values for omitted message fields even if --defaults is not set', + oneofs: 'Output virtual oneof fields set to the present field\'s name', + json: 'Represent Infinity and NaN as strings in float fields. Also decode google.protobuf.Any automatically', + includeComments: 'Generate doc comments from comments in the original files', + includeDirs: 'Directories to search for included files', + outDir: 'Directory in which to output files', + grpcLib: 'The gRPC implementation library that these types will be used with' + }).demandOption(['outDir', 'grpcLib']) + .demand(1) + .usage('$0 [options] filenames...') + .epilogue('WARNING: This tool is in alpha. The CLI and generated code are subject to change') + .argv; + if (argv.verbose) { + console.log('Parsed arguments:', argv); + } + addCommonProtos(); + writeAllFiles(argv._ as string[], {...argv, alternateCommentMode: true}).then(() => { + if (argv.verbose) { + console.log('Success'); + } + }, (error) => { + console.error(error) + process.exit(1); + }); +} + +if (require.main === module) { + runScript(); +} diff --git a/packages/proto-loader/deps/gapic-showcase b/packages/proto-loader/deps/gapic-showcase new file mode 160000 index 000000000..b09b3ba9a --- /dev/null +++ b/packages/proto-loader/deps/gapic-showcase @@ -0,0 +1 @@ +Subproject commit b09b3ba9a8db8aae7d5d7c3939853681cc97c293 diff --git a/packages/proto-loader/deps/googleapis b/packages/proto-loader/deps/googleapis new file mode 160000 index 000000000..8f2eda119 --- /dev/null +++ b/packages/proto-loader/deps/googleapis @@ -0,0 +1 @@ +Subproject commit 8f2eda119e11c8bd0c189b545da18bba9019c83e diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts new file mode 100644 index 000000000..02514f053 --- /dev/null +++ b/packages/proto-loader/golden-generated/echo.ts @@ -0,0 +1,95 @@ +import type * as grpc from '@grpc/grpc-js'; +import type { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader'; + +import type { OperationsClient as _google_longrunning_OperationsClient } from './google/longrunning/Operations'; +import type { EchoClient as _google_showcase_v1beta1_EchoClient } from './google/showcase/v1beta1/Echo'; + +type SubtypeConstructor any, Subtype> = { + new(...args: ConstructorParameters): Subtype; +}; + +export interface ProtoGrpcType { + google: { + api: { + CustomHttpPattern: MessageTypeDefinition + FieldBehavior: EnumTypeDefinition + Http: MessageTypeDefinition + HttpRule: MessageTypeDefinition + } + longrunning: { + CancelOperationRequest: MessageTypeDefinition + DeleteOperationRequest: MessageTypeDefinition + GetOperationRequest: MessageTypeDefinition + ListOperationsRequest: MessageTypeDefinition + ListOperationsResponse: MessageTypeDefinition + Operation: MessageTypeDefinition + OperationInfo: MessageTypeDefinition + /** + * Manages long-running operations with an API service. + * + * When an API method normally takes long time to complete, it can be designed + * to return [Operation][google.longrunning.Operation] to the client, and the client can use this + * interface to receive the real response asynchronously by polling the + * operation resource, or pass the operation resource to another API (such as + * Google Cloud Pub/Sub API) to receive the response. Any API service that + * returns long-running operations should implement the `Operations` interface + * so developers can have a consistent client experience. + */ + Operations: SubtypeConstructor & { service: ServiceDefinition } + WaitOperationRequest: MessageTypeDefinition + } + protobuf: { + Any: MessageTypeDefinition + DescriptorProto: MessageTypeDefinition + Duration: MessageTypeDefinition + Empty: MessageTypeDefinition + EnumDescriptorProto: MessageTypeDefinition + EnumOptions: MessageTypeDefinition + EnumValueDescriptorProto: MessageTypeDefinition + EnumValueOptions: MessageTypeDefinition + FieldDescriptorProto: MessageTypeDefinition + FieldOptions: MessageTypeDefinition + FileDescriptorProto: MessageTypeDefinition + FileDescriptorSet: MessageTypeDefinition + FileOptions: MessageTypeDefinition + GeneratedCodeInfo: MessageTypeDefinition + MessageOptions: MessageTypeDefinition + MethodDescriptorProto: MessageTypeDefinition + MethodOptions: MessageTypeDefinition + OneofDescriptorProto: MessageTypeDefinition + OneofOptions: MessageTypeDefinition + ServiceDescriptorProto: MessageTypeDefinition + ServiceOptions: MessageTypeDefinition + SourceCodeInfo: MessageTypeDefinition + Timestamp: MessageTypeDefinition + UninterpretedOption: MessageTypeDefinition + } + rpc: { + Status: MessageTypeDefinition + } + showcase: { + v1beta1: { + BlockRequest: MessageTypeDefinition + BlockResponse: MessageTypeDefinition + /** + * This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This + * service also exposes methods that explicitly implement server delay, and + * paginated calls. Set the 'showcase-trailer' metadata key on any method + * to have the values echoed in the response trailers. + */ + Echo: SubtypeConstructor & { service: ServiceDefinition } + EchoRequest: MessageTypeDefinition + EchoResponse: MessageTypeDefinition + ExpandRequest: MessageTypeDefinition + PagedExpandRequest: MessageTypeDefinition + PagedExpandResponse: MessageTypeDefinition + Severity: EnumTypeDefinition + WaitMetadata: MessageTypeDefinition + WaitRequest: MessageTypeDefinition + WaitResponse: MessageTypeDefinition + } + } + } +} + diff --git a/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts b/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts new file mode 100644 index 000000000..2b6490be6 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts @@ -0,0 +1,30 @@ +// Original file: deps/googleapis/google/api/http.proto + + +/** + * A custom pattern is used for defining custom HTTP verb. + */ +export interface CustomHttpPattern { + /** + * The name of this custom HTTP verb. + */ + 'kind'?: (string); + /** + * The path matched by this custom verb. + */ + 'path'?: (string); +} + +/** + * A custom pattern is used for defining custom HTTP verb. + */ +export interface CustomHttpPattern__Output { + /** + * The name of this custom HTTP verb. + */ + 'kind': (string); + /** + * The path matched by this custom verb. + */ + 'path': (string); +} diff --git a/packages/proto-loader/golden-generated/google/api/FieldBehavior.ts b/packages/proto-loader/golden-generated/google/api/FieldBehavior.ts new file mode 100644 index 000000000..8ab676709 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/FieldBehavior.ts @@ -0,0 +1,47 @@ +// Original file: deps/googleapis/google/api/field_behavior.proto + +/** + * An indicator of the behavior of a given field (for example, that a field + * is required in requests, or given as output but ignored as input). + * This **does not** change the behavior in protocol buffers itself; it only + * denotes the behavior and may affect how API tooling handles the field. + * + * Note: This enum **may** receive new values in the future. + */ +export enum FieldBehavior { + /** + * Conventional default for enums. Do not use this. + */ + FIELD_BEHAVIOR_UNSPECIFIED = 0, + /** + * Specifically denotes a field as optional. + * While all fields in protocol buffers are optional, this may be specified + * for emphasis if appropriate. + */ + OPTIONAL = 1, + /** + * Denotes a field as required. + * This indicates that the field **must** be provided as part of the request, + * and failure to do so will cause an error (usually `INVALID_ARGUMENT`). + */ + REQUIRED = 2, + /** + * Denotes a field as output only. + * This indicates that the field is provided in responses, but including the + * field in a request does nothing (the server *must* ignore it and + * *must not* throw an error as a result of the field's presence). + */ + OUTPUT_ONLY = 3, + /** + * Denotes a field as input only. + * This indicates that the field is provided in requests, and the + * corresponding field is not included in output. + */ + INPUT_ONLY = 4, + /** + * Denotes a field as immutable. + * This indicates that the field may be set once in a request to create a + * resource, but may not be changed thereafter. + */ + IMMUTABLE = 5, +} diff --git a/packages/proto-loader/golden-generated/google/api/Http.ts b/packages/proto-loader/golden-generated/google/api/Http.ts new file mode 100644 index 000000000..e9b3cb309 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/Http.ts @@ -0,0 +1,49 @@ +// Original file: deps/googleapis/google/api/http.proto + +import type { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; + +/** + * Defines the HTTP configuration for an API service. It contains a list of + * [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method + * to one or more HTTP REST API methods. + */ +export interface Http { + /** + * A list of HTTP configuration rules that apply to individual API methods. + * + * **NOTE:** All service configuration rules follow "last one wins" order. + */ + 'rules'?: (_google_api_HttpRule)[]; + /** + * When set to true, URL path parameters will be fully URI-decoded except in + * cases of single segment matches in reserved expansion, where "%2F" will be + * left encoded. + * + * The default behavior is to not decode RFC 6570 reserved characters in multi + * segment matches. + */ + 'fully_decode_reserved_expansion'?: (boolean); +} + +/** + * Defines the HTTP configuration for an API service. It contains a list of + * [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method + * to one or more HTTP REST API methods. + */ +export interface Http__Output { + /** + * A list of HTTP configuration rules that apply to individual API methods. + * + * **NOTE:** All service configuration rules follow "last one wins" order. + */ + 'rules': (_google_api_HttpRule__Output)[]; + /** + * When set to true, URL path parameters will be fully URI-decoded except in + * cases of single segment matches in reserved expansion, where "%2F" will be + * left encoded. + * + * The default behavior is to not decode RFC 6570 reserved characters in multi + * segment matches. + */ + 'fully_decode_reserved_expansion': (boolean); +} diff --git a/packages/proto-loader/golden-generated/google/api/HttpRule.ts b/packages/proto-loader/golden-generated/google/api/HttpRule.ts new file mode 100644 index 000000000..21ad897ee --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/HttpRule.ts @@ -0,0 +1,680 @@ +// Original file: deps/googleapis/google/api/http.proto + +import type { CustomHttpPattern as _google_api_CustomHttpPattern, CustomHttpPattern__Output as _google_api_CustomHttpPattern__Output } from '../../google/api/CustomHttpPattern'; +import type { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; + +/** + * # gRPC Transcoding + * + * gRPC Transcoding is a feature for mapping between a gRPC method and one or + * more HTTP REST endpoints. It allows developers to build a single API service + * that supports both gRPC APIs and REST APIs. Many systems, including [Google + * APIs](https://github.com/googleapis/googleapis), + * [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC + * Gateway](https://github.com/grpc-ecosystem/grpc-gateway), + * and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature + * and use it for large scale production services. + * + * `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies + * how different portions of the gRPC request message are mapped to the URL + * path, URL query parameters, and HTTP request body. It also controls how the + * gRPC response message is mapped to the HTTP response body. `HttpRule` is + * typically specified as an `google.api.http` annotation on the gRPC method. + * + * Each mapping specifies a URL path template and an HTTP method. The path + * template may refer to one or more fields in the gRPC request message, as long + * as each field is a non-repeated field with a primitive (non-message) type. + * The path template controls how fields of the request message are mapped to + * the URL path. + * + * Example: + * + * service Messaging { + * rpc GetMessage(GetMessageRequest) returns (Message) { + * option (google.api.http) = { + * get: "/v1/{name=messages/*}" + * }; + * } + * } + * message GetMessageRequest { + * string name = 1; // Mapped to URL path. + * } + * message Message { + * string text = 1; // The resource content. + * } + * + * This enables an HTTP REST to gRPC mapping as below: + * + * HTTP | gRPC + * -----|----- + * `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` + * + * Any fields in the request message which are not bound by the path template + * automatically become HTTP query parameters if there is no HTTP request body. + * For example: + * + * service Messaging { + * rpc GetMessage(GetMessageRequest) returns (Message) { + * option (google.api.http) = { + * get:"/v1/messages/{message_id}" + * }; + * } + * } + * message GetMessageRequest { + * message SubMessage { + * string subfield = 1; + * } + * string message_id = 1; // Mapped to URL path. + * int64 revision = 2; // Mapped to URL query parameter `revision`. + * SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. + * } + * + * This enables a HTTP JSON to RPC mapping as below: + * + * HTTP | gRPC + * -----|----- + * `GET /v1/messages/123456?revision=2&sub.subfield=foo` | + * `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: + * "foo"))` + * + * Note that fields which are mapped to URL query parameters must have a + * primitive type or a repeated primitive type or a non-repeated message type. + * In the case of a repeated type, the parameter can be repeated in the URL + * as `...?param=A¶m=B`. In the case of a message type, each field of the + * message is mapped to a separate parameter, such as + * `...?foo.a=A&foo.b=B&foo.c=C`. + * + * For HTTP methods that allow a request body, the `body` field + * specifies the mapping. Consider a REST update method on the + * message resource collection: + * + * service Messaging { + * rpc UpdateMessage(UpdateMessageRequest) returns (Message) { + * option (google.api.http) = { + * patch: "/v1/messages/{message_id}" + * body: "message" + * }; + * } + * } + * message UpdateMessageRequest { + * string message_id = 1; // mapped to the URL + * Message message = 2; // mapped to the body + * } + * + * The following HTTP JSON to RPC mapping is enabled, where the + * representation of the JSON in the request body is determined by + * protos JSON encoding: + * + * HTTP | gRPC + * -----|----- + * `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: + * "123456" message { text: "Hi!" })` + * + * The special name `*` can be used in the body mapping to define that + * every field not bound by the path template should be mapped to the + * request body. This enables the following alternative definition of + * the update method: + * + * service Messaging { + * rpc UpdateMessage(Message) returns (Message) { + * option (google.api.http) = { + * patch: "/v1/messages/{message_id}" + * body: "*" + * }; + * } + * } + * message Message { + * string message_id = 1; + * string text = 2; + * } + * + * + * The following HTTP JSON to RPC mapping is enabled: + * + * HTTP | gRPC + * -----|----- + * `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: + * "123456" text: "Hi!")` + * + * Note that when using `*` in the body mapping, it is not possible to + * have HTTP parameters, as all fields not bound by the path end in + * the body. This makes this option more rarely used in practice when + * defining REST APIs. The common usage of `*` is in custom methods + * which don't use the URL at all for transferring data. + * + * It is possible to define multiple HTTP methods for one RPC by using + * the `additional_bindings` option. Example: + * + * service Messaging { + * rpc GetMessage(GetMessageRequest) returns (Message) { + * option (google.api.http) = { + * get: "/v1/messages/{message_id}" + * additional_bindings { + * get: "/v1/users/{user_id}/messages/{message_id}" + * } + * }; + * } + * } + * message GetMessageRequest { + * string message_id = 1; + * string user_id = 2; + * } + * + * This enables the following two alternative HTTP JSON to RPC mappings: + * + * HTTP | gRPC + * -----|----- + * `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` + * `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: + * "123456")` + * + * ## Rules for HTTP mapping + * + * 1. Leaf request fields (recursive expansion nested messages in the request + * message) are classified into three categories: + * - Fields referred by the path template. They are passed via the URL path. + * - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They are passed via the HTTP + * request body. + * - All other fields are passed via the URL query parameters, and the + * parameter name is the field path in the request message. A repeated + * field can be represented as multiple query parameters under the same + * name. + * 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields + * are passed via URL path and HTTP request body. + * 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all + * fields are passed via URL path and URL query parameters. + * + * ### Path template syntax + * + * Template = "/" Segments [ Verb ] ; + * Segments = Segment { "/" Segment } ; + * Segment = "*" | "**" | LITERAL | Variable ; + * Variable = "{" FieldPath [ "=" Segments ] "}" ; + * FieldPath = IDENT { "." IDENT } ; + * Verb = ":" LITERAL ; + * + * The syntax `*` matches a single URL path segment. The syntax `**` matches + * zero or more URL path segments, which must be the last part of the URL path + * except the `Verb`. + * + * The syntax `Variable` matches part of the URL path as specified by its + * template. A variable template must not contain other variables. If a variable + * matches a single path segment, its template may be omitted, e.g. `{var}` + * is equivalent to `{var=*}`. + * + * The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` + * contains any reserved character, such characters should be percent-encoded + * before the matching. + * + * If a variable contains exactly one path segment, such as `"{var}"` or + * `"{var=*}"`, when such a variable is expanded into a URL path on the client + * side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The + * server side does the reverse decoding. Such variables show up in the + * [Discovery + * Document](https://developers.google.com/discovery/v1/reference/apis) as + * `{var}`. + * + * If a variable contains multiple path segments, such as `"{var=foo/*}"` + * or `"{var=**}"`, when such a variable is expanded into a URL path on the + * client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. + * The server side does the reverse decoding, except "%2F" and "%2f" are left + * unchanged. Such variables show up in the + * [Discovery + * Document](https://developers.google.com/discovery/v1/reference/apis) as + * `{+var}`. + * + * ## Using gRPC API Service Configuration + * + * gRPC API Service Configuration (service config) is a configuration language + * for configuring a gRPC service to become a user-facing product. The + * service config is simply the YAML representation of the `google.api.Service` + * proto message. + * + * As an alternative to annotating your proto file, you can configure gRPC + * transcoding in your service config YAML files. You do this by specifying a + * `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same + * effect as the proto annotation. This can be particularly useful if you + * have a proto that is reused in multiple services. Note that any transcoding + * specified in the service config will override any matching transcoding + * configuration in the proto. + * + * Example: + * + * http: + * rules: + * # Selects a gRPC method and applies HttpRule to it. + * - selector: example.v1.Messaging.GetMessage + * get: /v1/messages/{message_id}/{sub.subfield} + * + * ## Special notes + * + * When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the + * proto to JSON conversion must follow the [proto3 + * specification](https://developers.google.com/protocol-buffers/docs/proto3#json). + * + * While the single segment variable follows the semantics of + * [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String + * Expansion, the multi segment variable **does not** follow RFC 6570 Section + * 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion + * does not expand special characters like `?` and `#`, which would lead + * to invalid URLs. As the result, gRPC Transcoding uses a custom encoding + * for multi segment variables. + * + * The path variables **must not** refer to any repeated or mapped field, + * because client libraries are not capable of handling such variable expansion. + * + * The path variables **must not** capture the leading "/" character. The reason + * is that the most common use case "{var}" does not capture the leading "/" + * character. For consistency, all path variables must share the same behavior. + * + * Repeated message fields must not be mapped to URL query parameters, because + * no client library can support such complicated mapping. + * + * If an API needs to use a JSON array for request or response body, it can map + * the request or response body to a repeated field. However, some gRPC + * Transcoding implementations may not support this feature. + */ +export interface HttpRule { + /** + * Selects a method to which this rule applies. + * + * Refer to [selector][google.api.DocumentationRule.selector] for syntax details. + */ + 'selector'?: (string); + /** + * Maps to HTTP GET. Used for listing and getting information about + * resources. + */ + 'get'?: (string); + /** + * Maps to HTTP PUT. Used for replacing a resource. + */ + 'put'?: (string); + /** + * Maps to HTTP POST. Used for creating a resource or performing an action. + */ + 'post'?: (string); + /** + * Maps to HTTP DELETE. Used for deleting a resource. + */ + 'delete'?: (string); + /** + * Maps to HTTP PATCH. Used for updating a resource. + */ + 'patch'?: (string); + /** + * The name of the request field whose value is mapped to the HTTP request + * body, or `*` for mapping all request fields not captured by the path + * pattern to the HTTP body, or omitted for not having any HTTP request body. + * + * NOTE: the referred field must be present at the top-level of the request + * message type. + */ + 'body'?: (string); + /** + * The custom pattern is used for specifying an HTTP method that is not + * included in the `pattern` field, such as HEAD, or "*" to leave the + * HTTP method unspecified for this rule. The wild-card rule is useful + * for services that provide content to Web (HTML) clients. + */ + 'custom'?: (_google_api_CustomHttpPattern); + /** + * Additional HTTP bindings for the selector. Nested bindings must + * not contain an `additional_bindings` field themselves (that is, + * the nesting may only be one level deep). + */ + 'additional_bindings'?: (_google_api_HttpRule)[]; + /** + * Optional. The name of the response field whose value is mapped to the HTTP + * response body. When omitted, the entire response message will be used + * as the HTTP response body. + * + * NOTE: The referred field must be present at the top-level of the response + * message type. + */ + 'response_body'?: (string); + /** + * Determines the URL pattern is matched by this rules. This pattern can be + * used with any of the {get|put|post|delete|patch} methods. A custom method + * can be defined using the 'custom' field. + */ + 'pattern'?: "get"|"put"|"post"|"delete"|"patch"|"custom"; +} + +/** + * # gRPC Transcoding + * + * gRPC Transcoding is a feature for mapping between a gRPC method and one or + * more HTTP REST endpoints. It allows developers to build a single API service + * that supports both gRPC APIs and REST APIs. Many systems, including [Google + * APIs](https://github.com/googleapis/googleapis), + * [Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC + * Gateway](https://github.com/grpc-ecosystem/grpc-gateway), + * and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature + * and use it for large scale production services. + * + * `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies + * how different portions of the gRPC request message are mapped to the URL + * path, URL query parameters, and HTTP request body. It also controls how the + * gRPC response message is mapped to the HTTP response body. `HttpRule` is + * typically specified as an `google.api.http` annotation on the gRPC method. + * + * Each mapping specifies a URL path template and an HTTP method. The path + * template may refer to one or more fields in the gRPC request message, as long + * as each field is a non-repeated field with a primitive (non-message) type. + * The path template controls how fields of the request message are mapped to + * the URL path. + * + * Example: + * + * service Messaging { + * rpc GetMessage(GetMessageRequest) returns (Message) { + * option (google.api.http) = { + * get: "/v1/{name=messages/*}" + * }; + * } + * } + * message GetMessageRequest { + * string name = 1; // Mapped to URL path. + * } + * message Message { + * string text = 1; // The resource content. + * } + * + * This enables an HTTP REST to gRPC mapping as below: + * + * HTTP | gRPC + * -----|----- + * `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` + * + * Any fields in the request message which are not bound by the path template + * automatically become HTTP query parameters if there is no HTTP request body. + * For example: + * + * service Messaging { + * rpc GetMessage(GetMessageRequest) returns (Message) { + * option (google.api.http) = { + * get:"/v1/messages/{message_id}" + * }; + * } + * } + * message GetMessageRequest { + * message SubMessage { + * string subfield = 1; + * } + * string message_id = 1; // Mapped to URL path. + * int64 revision = 2; // Mapped to URL query parameter `revision`. + * SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. + * } + * + * This enables a HTTP JSON to RPC mapping as below: + * + * HTTP | gRPC + * -----|----- + * `GET /v1/messages/123456?revision=2&sub.subfield=foo` | + * `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: + * "foo"))` + * + * Note that fields which are mapped to URL query parameters must have a + * primitive type or a repeated primitive type or a non-repeated message type. + * In the case of a repeated type, the parameter can be repeated in the URL + * as `...?param=A¶m=B`. In the case of a message type, each field of the + * message is mapped to a separate parameter, such as + * `...?foo.a=A&foo.b=B&foo.c=C`. + * + * For HTTP methods that allow a request body, the `body` field + * specifies the mapping. Consider a REST update method on the + * message resource collection: + * + * service Messaging { + * rpc UpdateMessage(UpdateMessageRequest) returns (Message) { + * option (google.api.http) = { + * patch: "/v1/messages/{message_id}" + * body: "message" + * }; + * } + * } + * message UpdateMessageRequest { + * string message_id = 1; // mapped to the URL + * Message message = 2; // mapped to the body + * } + * + * The following HTTP JSON to RPC mapping is enabled, where the + * representation of the JSON in the request body is determined by + * protos JSON encoding: + * + * HTTP | gRPC + * -----|----- + * `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: + * "123456" message { text: "Hi!" })` + * + * The special name `*` can be used in the body mapping to define that + * every field not bound by the path template should be mapped to the + * request body. This enables the following alternative definition of + * the update method: + * + * service Messaging { + * rpc UpdateMessage(Message) returns (Message) { + * option (google.api.http) = { + * patch: "/v1/messages/{message_id}" + * body: "*" + * }; + * } + * } + * message Message { + * string message_id = 1; + * string text = 2; + * } + * + * + * The following HTTP JSON to RPC mapping is enabled: + * + * HTTP | gRPC + * -----|----- + * `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: + * "123456" text: "Hi!")` + * + * Note that when using `*` in the body mapping, it is not possible to + * have HTTP parameters, as all fields not bound by the path end in + * the body. This makes this option more rarely used in practice when + * defining REST APIs. The common usage of `*` is in custom methods + * which don't use the URL at all for transferring data. + * + * It is possible to define multiple HTTP methods for one RPC by using + * the `additional_bindings` option. Example: + * + * service Messaging { + * rpc GetMessage(GetMessageRequest) returns (Message) { + * option (google.api.http) = { + * get: "/v1/messages/{message_id}" + * additional_bindings { + * get: "/v1/users/{user_id}/messages/{message_id}" + * } + * }; + * } + * } + * message GetMessageRequest { + * string message_id = 1; + * string user_id = 2; + * } + * + * This enables the following two alternative HTTP JSON to RPC mappings: + * + * HTTP | gRPC + * -----|----- + * `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` + * `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: + * "123456")` + * + * ## Rules for HTTP mapping + * + * 1. Leaf request fields (recursive expansion nested messages in the request + * message) are classified into three categories: + * - Fields referred by the path template. They are passed via the URL path. + * - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They are passed via the HTTP + * request body. + * - All other fields are passed via the URL query parameters, and the + * parameter name is the field path in the request message. A repeated + * field can be represented as multiple query parameters under the same + * name. + * 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL query parameter, all fields + * are passed via URL path and HTTP request body. + * 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP request body, all + * fields are passed via URL path and URL query parameters. + * + * ### Path template syntax + * + * Template = "/" Segments [ Verb ] ; + * Segments = Segment { "/" Segment } ; + * Segment = "*" | "**" | LITERAL | Variable ; + * Variable = "{" FieldPath [ "=" Segments ] "}" ; + * FieldPath = IDENT { "." IDENT } ; + * Verb = ":" LITERAL ; + * + * The syntax `*` matches a single URL path segment. The syntax `**` matches + * zero or more URL path segments, which must be the last part of the URL path + * except the `Verb`. + * + * The syntax `Variable` matches part of the URL path as specified by its + * template. A variable template must not contain other variables. If a variable + * matches a single path segment, its template may be omitted, e.g. `{var}` + * is equivalent to `{var=*}`. + * + * The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` + * contains any reserved character, such characters should be percent-encoded + * before the matching. + * + * If a variable contains exactly one path segment, such as `"{var}"` or + * `"{var=*}"`, when such a variable is expanded into a URL path on the client + * side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The + * server side does the reverse decoding. Such variables show up in the + * [Discovery + * Document](https://developers.google.com/discovery/v1/reference/apis) as + * `{var}`. + * + * If a variable contains multiple path segments, such as `"{var=foo/*}"` + * or `"{var=**}"`, when such a variable is expanded into a URL path on the + * client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded. + * The server side does the reverse decoding, except "%2F" and "%2f" are left + * unchanged. Such variables show up in the + * [Discovery + * Document](https://developers.google.com/discovery/v1/reference/apis) as + * `{+var}`. + * + * ## Using gRPC API Service Configuration + * + * gRPC API Service Configuration (service config) is a configuration language + * for configuring a gRPC service to become a user-facing product. The + * service config is simply the YAML representation of the `google.api.Service` + * proto message. + * + * As an alternative to annotating your proto file, you can configure gRPC + * transcoding in your service config YAML files. You do this by specifying a + * `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same + * effect as the proto annotation. This can be particularly useful if you + * have a proto that is reused in multiple services. Note that any transcoding + * specified in the service config will override any matching transcoding + * configuration in the proto. + * + * Example: + * + * http: + * rules: + * # Selects a gRPC method and applies HttpRule to it. + * - selector: example.v1.Messaging.GetMessage + * get: /v1/messages/{message_id}/{sub.subfield} + * + * ## Special notes + * + * When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the + * proto to JSON conversion must follow the [proto3 + * specification](https://developers.google.com/protocol-buffers/docs/proto3#json). + * + * While the single segment variable follows the semantics of + * [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String + * Expansion, the multi segment variable **does not** follow RFC 6570 Section + * 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion + * does not expand special characters like `?` and `#`, which would lead + * to invalid URLs. As the result, gRPC Transcoding uses a custom encoding + * for multi segment variables. + * + * The path variables **must not** refer to any repeated or mapped field, + * because client libraries are not capable of handling such variable expansion. + * + * The path variables **must not** capture the leading "/" character. The reason + * is that the most common use case "{var}" does not capture the leading "/" + * character. For consistency, all path variables must share the same behavior. + * + * Repeated message fields must not be mapped to URL query parameters, because + * no client library can support such complicated mapping. + * + * If an API needs to use a JSON array for request or response body, it can map + * the request or response body to a repeated field. However, some gRPC + * Transcoding implementations may not support this feature. + */ +export interface HttpRule__Output { + /** + * Selects a method to which this rule applies. + * + * Refer to [selector][google.api.DocumentationRule.selector] for syntax details. + */ + 'selector': (string); + /** + * Maps to HTTP GET. Used for listing and getting information about + * resources. + */ + 'get'?: (string); + /** + * Maps to HTTP PUT. Used for replacing a resource. + */ + 'put'?: (string); + /** + * Maps to HTTP POST. Used for creating a resource or performing an action. + */ + 'post'?: (string); + /** + * Maps to HTTP DELETE. Used for deleting a resource. + */ + 'delete'?: (string); + /** + * Maps to HTTP PATCH. Used for updating a resource. + */ + 'patch'?: (string); + /** + * The name of the request field whose value is mapped to the HTTP request + * body, or `*` for mapping all request fields not captured by the path + * pattern to the HTTP body, or omitted for not having any HTTP request body. + * + * NOTE: the referred field must be present at the top-level of the request + * message type. + */ + 'body': (string); + /** + * The custom pattern is used for specifying an HTTP method that is not + * included in the `pattern` field, such as HEAD, or "*" to leave the + * HTTP method unspecified for this rule. The wild-card rule is useful + * for services that provide content to Web (HTML) clients. + */ + 'custom'?: (_google_api_CustomHttpPattern__Output); + /** + * Additional HTTP bindings for the selector. Nested bindings must + * not contain an `additional_bindings` field themselves (that is, + * the nesting may only be one level deep). + */ + 'additional_bindings': (_google_api_HttpRule__Output)[]; + /** + * Optional. The name of the response field whose value is mapped to the HTTP + * response body. When omitted, the entire response message will be used + * as the HTTP response body. + * + * NOTE: The referred field must be present at the top-level of the response + * message type. + */ + 'response_body': (string); + /** + * Determines the URL pattern is matched by this rules. This pattern can be + * used with any of the {get|put|post|delete|patch} methods. A custom method + * can be defined using the 'custom' field. + */ + 'pattern': "get"|"put"|"post"|"delete"|"patch"|"custom"; +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts new file mode 100644 index 000000000..05fbc842e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts @@ -0,0 +1,22 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +/** + * The request message for [Operations.CancelOperation][google.longrunning.Operations.CancelOperation]. + */ +export interface CancelOperationRequest { + /** + * The name of the operation resource to be cancelled. + */ + 'name'?: (string); +} + +/** + * The request message for [Operations.CancelOperation][google.longrunning.Operations.CancelOperation]. + */ +export interface CancelOperationRequest__Output { + /** + * The name of the operation resource to be cancelled. + */ + 'name': (string); +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts new file mode 100644 index 000000000..0ad87cde9 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts @@ -0,0 +1,22 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +/** + * The request message for [Operations.DeleteOperation][google.longrunning.Operations.DeleteOperation]. + */ +export interface DeleteOperationRequest { + /** + * The name of the operation resource to be deleted. + */ + 'name'?: (string); +} + +/** + * The request message for [Operations.DeleteOperation][google.longrunning.Operations.DeleteOperation]. + */ +export interface DeleteOperationRequest__Output { + /** + * The name of the operation resource to be deleted. + */ + 'name': (string); +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts new file mode 100644 index 000000000..039f01674 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts @@ -0,0 +1,22 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +/** + * The request message for [Operations.GetOperation][google.longrunning.Operations.GetOperation]. + */ +export interface GetOperationRequest { + /** + * The name of the operation resource. + */ + 'name'?: (string); +} + +/** + * The request message for [Operations.GetOperation][google.longrunning.Operations.GetOperation]. + */ +export interface GetOperationRequest__Output { + /** + * The name of the operation resource. + */ + 'name': (string); +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts new file mode 100644 index 000000000..294ec6773 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts @@ -0,0 +1,46 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +/** + * The request message for [Operations.ListOperations][google.longrunning.Operations.ListOperations]. + */ +export interface ListOperationsRequest { + /** + * The standard list filter. + */ + 'filter'?: (string); + /** + * The standard list page size. + */ + 'page_size'?: (number); + /** + * The standard list page token. + */ + 'page_token'?: (string); + /** + * The name of the operation's parent resource. + */ + 'name'?: (string); +} + +/** + * The request message for [Operations.ListOperations][google.longrunning.Operations.ListOperations]. + */ +export interface ListOperationsRequest__Output { + /** + * The standard list filter. + */ + 'filter': (string); + /** + * The standard list page size. + */ + 'page_size': (number); + /** + * The standard list page token. + */ + 'page_token': (string); + /** + * The name of the operation's parent resource. + */ + 'name': (string); +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts new file mode 100644 index 000000000..c295aa801 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts @@ -0,0 +1,31 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import type { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; + +/** + * The response message for [Operations.ListOperations][google.longrunning.Operations.ListOperations]. + */ +export interface ListOperationsResponse { + /** + * A list of operations that matches the specified filter in the request. + */ + 'operations'?: (_google_longrunning_Operation)[]; + /** + * The standard List next-page token. + */ + 'next_page_token'?: (string); +} + +/** + * The response message for [Operations.ListOperations][google.longrunning.Operations.ListOperations]. + */ +export interface ListOperationsResponse__Output { + /** + * A list of operations that matches the specified filter in the request. + */ + 'operations': (_google_longrunning_Operation__Output)[]; + /** + * The standard List next-page token. + */ + 'next_page_token': (string); +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operation.ts b/packages/proto-loader/golden-generated/google/longrunning/Operation.ts new file mode 100644 index 000000000..2aa9b8c71 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/Operation.ts @@ -0,0 +1,98 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; +import type { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../google/rpc/Status'; + +/** + * This resource represents a long-running operation that is the result of a + * network API call. + */ +export interface Operation { + /** + * The server-assigned name, which is only unique within the same service that + * originally returns it. If you use the default HTTP mapping, the + * `name` should be a resource name ending with `operations/{unique_id}`. + */ + 'name'?: (string); + /** + * Service-specific metadata associated with the operation. It typically + * contains progress information and common metadata such as create time. + * Some services might not provide such metadata. Any method that returns a + * long-running operation should document the metadata type, if any. + */ + 'metadata'?: (_google_protobuf_Any); + /** + * If the value is `false`, it means the operation is still in progress. + * If `true`, the operation is completed, and either `error` or `response` is + * available. + */ + 'done'?: (boolean); + /** + * The error result of the operation in case of failure or cancellation. + */ + 'error'?: (_google_rpc_Status); + /** + * The normal response of the operation in case of success. If the original + * method returns no data on success, such as `Delete`, the response is + * `google.protobuf.Empty`. If the original method is standard + * `Get`/`Create`/`Update`, the response should be the resource. For other + * methods, the response should have the type `XxxResponse`, where `Xxx` + * is the original method name. For example, if the original method name + * is `TakeSnapshot()`, the inferred response type is + * `TakeSnapshotResponse`. + */ + 'response'?: (_google_protobuf_Any); + /** + * The operation result, which can be either an `error` or a valid `response`. + * If `done` == `false`, neither `error` nor `response` is set. + * If `done` == `true`, exactly one of `error` or `response` is set. + */ + 'result'?: "error"|"response"; +} + +/** + * This resource represents a long-running operation that is the result of a + * network API call. + */ +export interface Operation__Output { + /** + * The server-assigned name, which is only unique within the same service that + * originally returns it. If you use the default HTTP mapping, the + * `name` should be a resource name ending with `operations/{unique_id}`. + */ + 'name': (string); + /** + * Service-specific metadata associated with the operation. It typically + * contains progress information and common metadata such as create time. + * Some services might not provide such metadata. Any method that returns a + * long-running operation should document the metadata type, if any. + */ + 'metadata'?: (_google_protobuf_Any__Output); + /** + * If the value is `false`, it means the operation is still in progress. + * If `true`, the operation is completed, and either `error` or `response` is + * available. + */ + 'done': (boolean); + /** + * The error result of the operation in case of failure or cancellation. + */ + 'error'?: (_google_rpc_Status__Output); + /** + * The normal response of the operation in case of success. If the original + * method returns no data on success, such as `Delete`, the response is + * `google.protobuf.Empty`. If the original method is standard + * `Get`/`Create`/`Update`, the response should be the resource. For other + * methods, the response should have the type `XxxResponse`, where `Xxx` + * is the original method name. For example, if the original method name + * is `TakeSnapshot()`, the inferred response type is + * `TakeSnapshotResponse`. + */ + 'response'?: (_google_protobuf_Any__Output); + /** + * The operation result, which can be either an `error` or a valid `response`. + * If `done` == `false`, neither `error` nor `response` is set. + * If `done` == `true`, exactly one of `error` or `response` is set. + */ + 'result': "error"|"response"; +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts b/packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts new file mode 100644 index 000000000..343e2f8c9 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts @@ -0,0 +1,76 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +/** + * A message representing the message types used by a long-running operation. + * + * Example: + * + * rpc LongRunningRecognize(LongRunningRecognizeRequest) + * returns (google.longrunning.Operation) { + * option (google.longrunning.operation_info) = { + * response_type: "LongRunningRecognizeResponse" + * metadata_type: "LongRunningRecognizeMetadata" + * }; + * } + */ +export interface OperationInfo { + /** + * Required. The message name of the primary return type for this + * long-running operation. + * This type will be used to deserialize the LRO's response. + * + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * + * Note: Altering this value constitutes a breaking change. + */ + 'response_type'?: (string); + /** + * Required. The message name of the metadata type for this long-running + * operation. + * + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * + * Note: Altering this value constitutes a breaking change. + */ + 'metadata_type'?: (string); +} + +/** + * A message representing the message types used by a long-running operation. + * + * Example: + * + * rpc LongRunningRecognize(LongRunningRecognizeRequest) + * returns (google.longrunning.Operation) { + * option (google.longrunning.operation_info) = { + * response_type: "LongRunningRecognizeResponse" + * metadata_type: "LongRunningRecognizeMetadata" + * }; + * } + */ +export interface OperationInfo__Output { + /** + * Required. The message name of the primary return type for this + * long-running operation. + * This type will be used to deserialize the LRO's response. + * + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * + * Note: Altering this value constitutes a breaking change. + */ + 'response_type': (string); + /** + * Required. The message name of the metadata type for this long-running + * operation. + * + * If the response is in a different package from the rpc, a fully-qualified + * message name must be used (e.g. `google.protobuf.Struct`). + * + * Note: Altering this value constitutes a breaking change. + */ + 'metadata_type': (string); +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts new file mode 100644 index 000000000..6aa477ada --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -0,0 +1,232 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import type * as grpc from '@grpc/grpc-js' +import type { CancelOperationRequest as _google_longrunning_CancelOperationRequest, CancelOperationRequest__Output as _google_longrunning_CancelOperationRequest__Output } from '../../google/longrunning/CancelOperationRequest'; +import type { DeleteOperationRequest as _google_longrunning_DeleteOperationRequest, DeleteOperationRequest__Output as _google_longrunning_DeleteOperationRequest__Output } from '../../google/longrunning/DeleteOperationRequest'; +import type { Empty as _google_protobuf_Empty, Empty__Output as _google_protobuf_Empty__Output } from '../../google/protobuf/Empty'; +import type { GetOperationRequest as _google_longrunning_GetOperationRequest, GetOperationRequest__Output as _google_longrunning_GetOperationRequest__Output } from '../../google/longrunning/GetOperationRequest'; +import type { ListOperationsRequest as _google_longrunning_ListOperationsRequest, ListOperationsRequest__Output as _google_longrunning_ListOperationsRequest__Output } from '../../google/longrunning/ListOperationsRequest'; +import type { ListOperationsResponse as _google_longrunning_ListOperationsResponse, ListOperationsResponse__Output as _google_longrunning_ListOperationsResponse__Output } from '../../google/longrunning/ListOperationsResponse'; +import type { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; +import type { WaitOperationRequest as _google_longrunning_WaitOperationRequest, WaitOperationRequest__Output as _google_longrunning_WaitOperationRequest__Output } from '../../google/longrunning/WaitOperationRequest'; + +/** + * Manages long-running operations with an API service. + * + * When an API method normally takes long time to complete, it can be designed + * to return [Operation][google.longrunning.Operation] to the client, and the client can use this + * interface to receive the real response asynchronously by polling the + * operation resource, or pass the operation resource to another API (such as + * Google Cloud Pub/Sub API) to receive the response. Any API service that + * returns long-running operations should implement the `Operations` interface + * so developers can have a consistent client experience. + */ +export interface OperationsClient extends grpc.Client { + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, + * corresponding to `Code.CANCELLED`. + */ + CancelOperation(argument: _google_longrunning_CancelOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + CancelOperation(argument: _google_longrunning_CancelOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + CancelOperation(argument: _google_longrunning_CancelOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + CancelOperation(argument: _google_longrunning_CancelOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, + * corresponding to `Code.CANCELLED`. + */ + cancelOperation(argument: _google_longrunning_CancelOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + cancelOperation(argument: _google_longrunning_CancelOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + cancelOperation(argument: _google_longrunning_CancelOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + cancelOperation(argument: _google_longrunning_CancelOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + */ + DeleteOperation(argument: _google_longrunning_DeleteOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + DeleteOperation(argument: _google_longrunning_DeleteOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + DeleteOperation(argument: _google_longrunning_DeleteOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + DeleteOperation(argument: _google_longrunning_DeleteOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + */ + deleteOperation(argument: _google_longrunning_DeleteOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + deleteOperation(argument: _google_longrunning_DeleteOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + deleteOperation(argument: _google_longrunning_DeleteOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + deleteOperation(argument: _google_longrunning_DeleteOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_protobuf_Empty__Output) => void): grpc.ClientUnaryCall; + + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + */ + GetOperation(argument: _google_longrunning_GetOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + GetOperation(argument: _google_longrunning_GetOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + GetOperation(argument: _google_longrunning_GetOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + GetOperation(argument: _google_longrunning_GetOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + */ + getOperation(argument: _google_longrunning_GetOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + getOperation(argument: _google_longrunning_GetOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + getOperation(argument: _google_longrunning_GetOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + getOperation(argument: _google_longrunning_GetOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. + * + * NOTE: the `name` binding allows API services to override the binding + * to use different resource name schemes, such as `users/* /operations`. To + * override the binding, API services can add a binding such as + * `"/v1/{name=users/*}/operations"` to their service configuration. + * For backwards compatibility, the default name includes the operations + * collection id, however overriding users must ensure the name binding + * is the parent resource, without the operations collection id. + */ + ListOperations(argument: _google_longrunning_ListOperationsRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + ListOperations(argument: _google_longrunning_ListOperationsRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + ListOperations(argument: _google_longrunning_ListOperationsRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + ListOperations(argument: _google_longrunning_ListOperationsRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. + * + * NOTE: the `name` binding allows API services to override the binding + * to use different resource name schemes, such as `users/* /operations`. To + * override the binding, API services can add a binding such as + * `"/v1/{name=users/*}/operations"` to their service configuration. + * For backwards compatibility, the default name includes the operations + * collection id, however overriding users must ensure the name binding + * is the parent resource, without the operations collection id. + */ + listOperations(argument: _google_longrunning_ListOperationsRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + listOperations(argument: _google_longrunning_ListOperationsRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + listOperations(argument: _google_longrunning_ListOperationsRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + listOperations(argument: _google_longrunning_ListOperationsRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_ListOperationsResponse__Output) => void): grpc.ClientUnaryCall; + + /** + * Waits for the specified long-running operation until it is done or reaches + * at most a specified timeout, returning the latest state. If the operation + * is already done, the latest state is immediately returned. If the timeout + * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + * timeout is used. If the server does not support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * Note that this method is on a best-effort basis. It may return the latest + * state before the specified timeout (including immediately), meaning even an + * immediate response is no guarantee that the operation is done. + */ + WaitOperation(argument: _google_longrunning_WaitOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + WaitOperation(argument: _google_longrunning_WaitOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + WaitOperation(argument: _google_longrunning_WaitOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + WaitOperation(argument: _google_longrunning_WaitOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + /** + * Waits for the specified long-running operation until it is done or reaches + * at most a specified timeout, returning the latest state. If the operation + * is already done, the latest state is immediately returned. If the timeout + * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + * timeout is used. If the server does not support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * Note that this method is on a best-effort basis. It may return the latest + * state before the specified timeout (including immediately), meaning even an + * immediate response is no guarantee that the operation is done. + */ + waitOperation(argument: _google_longrunning_WaitOperationRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + waitOperation(argument: _google_longrunning_WaitOperationRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + waitOperation(argument: _google_longrunning_WaitOperationRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + waitOperation(argument: _google_longrunning_WaitOperationRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + +} + +/** + * Manages long-running operations with an API service. + * + * When an API method normally takes long time to complete, it can be designed + * to return [Operation][google.longrunning.Operation] to the client, and the client can use this + * interface to receive the real response asynchronously by polling the + * operation resource, or pass the operation resource to another API (such as + * Google Cloud Pub/Sub API) to receive the response. Any API service that + * returns long-running operations should implement the `Operations` interface + * so developers can have a consistent client experience. + */ +export interface OperationsHandlers extends grpc.UntypedServiceImplementation { + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * [Operations.GetOperation][google.longrunning.Operations.GetOperation] or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, + * corresponding to `Code.CANCELLED`. + */ + CancelOperation: grpc.handleUnaryCall<_google_longrunning_CancelOperationRequest__Output, _google_protobuf_Empty>; + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + */ + DeleteOperation: grpc.handleUnaryCall<_google_longrunning_DeleteOperationRequest__Output, _google_protobuf_Empty>; + + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + */ + GetOperation: grpc.handleUnaryCall<_google_longrunning_GetOperationRequest__Output, _google_longrunning_Operation>; + + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. + * + * NOTE: the `name` binding allows API services to override the binding + * to use different resource name schemes, such as `users/* /operations`. To + * override the binding, API services can add a binding such as + * `"/v1/{name=users/*}/operations"` to their service configuration. + * For backwards compatibility, the default name includes the operations + * collection id, however overriding users must ensure the name binding + * is the parent resource, without the operations collection id. + */ + ListOperations: grpc.handleUnaryCall<_google_longrunning_ListOperationsRequest__Output, _google_longrunning_ListOperationsResponse>; + + /** + * Waits for the specified long-running operation until it is done or reaches + * at most a specified timeout, returning the latest state. If the operation + * is already done, the latest state is immediately returned. If the timeout + * specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + * timeout is used. If the server does not support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * Note that this method is on a best-effort basis. It may return the latest + * state before the specified timeout (including immediately), meaning even an + * immediate response is no guarantee that the operation is done. + */ + WaitOperation: grpc.handleUnaryCall<_google_longrunning_WaitOperationRequest__Output, _google_longrunning_Operation>; + +} diff --git a/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts new file mode 100644 index 000000000..2789ba33e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts @@ -0,0 +1,35 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../google/protobuf/Duration'; + +/** + * The request message for [Operations.WaitOperation][google.longrunning.Operations.WaitOperation]. + */ +export interface WaitOperationRequest { + /** + * The name of the operation resource to wait on. + */ + 'name'?: (string); + /** + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + */ + 'timeout'?: (_google_protobuf_Duration); +} + +/** + * The request message for [Operations.WaitOperation][google.longrunning.Operations.WaitOperation]. + */ +export interface WaitOperationRequest__Output { + /** + * The name of the operation resource to wait on. + */ + 'name': (string); + /** + * The maximum duration to wait before timing out. If left blank, the wait + * will be at most the time permitted by the underlying HTTP/RPC protocol. + * If RPC context deadline is also specified, the shorter one will be used. + */ + 'timeout'?: (_google_protobuf_Duration__Output); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/Any.ts b/packages/proto-loader/golden-generated/google/protobuf/Any.ts new file mode 100644 index 000000000..fe0d05f12 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Any.ts @@ -0,0 +1,13 @@ +// Original file: null + +import type { AnyExtension } from '@grpc/proto-loader'; + +export type Any = AnyExtension | { + type_url: string; + value: Buffer | Uint8Array | string; +} + +export type Any__Output = AnyExtension | { + type_url: string; + value: Buffer; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts new file mode 100644 index 000000000..2f6f9f0cc --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts @@ -0,0 +1,53 @@ +// Original file: null + +import type { FieldDescriptorProto as _google_protobuf_FieldDescriptorProto, FieldDescriptorProto__Output as _google_protobuf_FieldDescriptorProto__Output } from '../../google/protobuf/FieldDescriptorProto'; +import type { DescriptorProto as _google_protobuf_DescriptorProto, DescriptorProto__Output as _google_protobuf_DescriptorProto__Output } from '../../google/protobuf/DescriptorProto'; +import type { EnumDescriptorProto as _google_protobuf_EnumDescriptorProto, EnumDescriptorProto__Output as _google_protobuf_EnumDescriptorProto__Output } from '../../google/protobuf/EnumDescriptorProto'; +import type { MessageOptions as _google_protobuf_MessageOptions, MessageOptions__Output as _google_protobuf_MessageOptions__Output } from '../../google/protobuf/MessageOptions'; +import type { OneofDescriptorProto as _google_protobuf_OneofDescriptorProto, OneofDescriptorProto__Output as _google_protobuf_OneofDescriptorProto__Output } from '../../google/protobuf/OneofDescriptorProto'; + +export interface _google_protobuf_DescriptorProto_ExtensionRange { + 'start'?: (number); + 'end'?: (number); +} + +export interface _google_protobuf_DescriptorProto_ExtensionRange__Output { + 'start': (number); + 'end': (number); +} + +export interface _google_protobuf_DescriptorProto_ReservedRange { + 'start'?: (number); + 'end'?: (number); +} + +export interface _google_protobuf_DescriptorProto_ReservedRange__Output { + 'start': (number); + 'end': (number); +} + +export interface DescriptorProto { + 'name'?: (string); + 'field'?: (_google_protobuf_FieldDescriptorProto)[]; + 'nestedType'?: (_google_protobuf_DescriptorProto)[]; + 'enumType'?: (_google_protobuf_EnumDescriptorProto)[]; + 'extensionRange'?: (_google_protobuf_DescriptorProto_ExtensionRange)[]; + 'extension'?: (_google_protobuf_FieldDescriptorProto)[]; + 'options'?: (_google_protobuf_MessageOptions); + 'oneofDecl'?: (_google_protobuf_OneofDescriptorProto)[]; + 'reservedRange'?: (_google_protobuf_DescriptorProto_ReservedRange)[]; + 'reservedName'?: (string)[]; +} + +export interface DescriptorProto__Output { + 'name': (string); + 'field': (_google_protobuf_FieldDescriptorProto__Output)[]; + 'nestedType': (_google_protobuf_DescriptorProto__Output)[]; + 'enumType': (_google_protobuf_EnumDescriptorProto__Output)[]; + 'extensionRange': (_google_protobuf_DescriptorProto_ExtensionRange__Output)[]; + 'extension': (_google_protobuf_FieldDescriptorProto__Output)[]; + 'options'?: (_google_protobuf_MessageOptions__Output); + 'oneofDecl': (_google_protobuf_OneofDescriptorProto__Output)[]; + 'reservedRange': (_google_protobuf_DescriptorProto_ReservedRange__Output)[]; + 'reservedName': (string)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/Duration.ts b/packages/proto-loader/golden-generated/google/protobuf/Duration.ts new file mode 100644 index 000000000..8595377a0 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Duration.ts @@ -0,0 +1,13 @@ +// Original file: null + +import type { Long } from '@grpc/proto-loader'; + +export interface Duration { + 'seconds'?: (number | string | Long); + 'nanos'?: (number); +} + +export interface Duration__Output { + 'seconds': (string); + 'nanos': (number); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/Empty.ts b/packages/proto-loader/golden-generated/google/protobuf/Empty.ts new file mode 100644 index 000000000..f32c2a284 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Empty.ts @@ -0,0 +1,8 @@ +// Original file: null + + +export interface Empty { +} + +export interface Empty__Output { +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts new file mode 100644 index 000000000..7aa40ce4d --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts @@ -0,0 +1,16 @@ +// Original file: null + +import type { EnumValueDescriptorProto as _google_protobuf_EnumValueDescriptorProto, EnumValueDescriptorProto__Output as _google_protobuf_EnumValueDescriptorProto__Output } from '../../google/protobuf/EnumValueDescriptorProto'; +import type { EnumOptions as _google_protobuf_EnumOptions, EnumOptions__Output as _google_protobuf_EnumOptions__Output } from '../../google/protobuf/EnumOptions'; + +export interface EnumDescriptorProto { + 'name'?: (string); + 'value'?: (_google_protobuf_EnumValueDescriptorProto)[]; + 'options'?: (_google_protobuf_EnumOptions); +} + +export interface EnumDescriptorProto__Output { + 'name': (string); + 'value': (_google_protobuf_EnumValueDescriptorProto__Output)[]; + 'options'?: (_google_protobuf_EnumOptions__Output); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts new file mode 100644 index 000000000..b92ade4f9 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts @@ -0,0 +1,15 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; + +export interface EnumOptions { + 'allowAlias'?: (boolean); + 'deprecated'?: (boolean); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; +} + +export interface EnumOptions__Output { + 'allowAlias': (boolean); + 'deprecated': (boolean); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts new file mode 100644 index 000000000..238e7fd01 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts @@ -0,0 +1,15 @@ +// Original file: null + +import type { EnumValueOptions as _google_protobuf_EnumValueOptions, EnumValueOptions__Output as _google_protobuf_EnumValueOptions__Output } from '../../google/protobuf/EnumValueOptions'; + +export interface EnumValueDescriptorProto { + 'name'?: (string); + 'number'?: (number); + 'options'?: (_google_protobuf_EnumValueOptions); +} + +export interface EnumValueDescriptorProto__Output { + 'name': (string); + 'number': (number); + 'options'?: (_google_protobuf_EnumValueOptions__Output); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts new file mode 100644 index 000000000..e60ee6f4c --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts @@ -0,0 +1,13 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; + +export interface EnumValueOptions { + 'deprecated'?: (boolean); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; +} + +export interface EnumValueOptions__Output { + 'deprecated': (boolean); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts new file mode 100644 index 000000000..b59518c4b --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts @@ -0,0 +1,60 @@ +// Original file: null + +import type { FieldOptions as _google_protobuf_FieldOptions, FieldOptions__Output as _google_protobuf_FieldOptions__Output } from '../../google/protobuf/FieldOptions'; + +// Original file: null + +export enum _google_protobuf_FieldDescriptorProto_Label { + LABEL_OPTIONAL = 1, + LABEL_REQUIRED = 2, + LABEL_REPEATED = 3, +} + +// Original file: null + +export enum _google_protobuf_FieldDescriptorProto_Type { + TYPE_DOUBLE = 1, + TYPE_FLOAT = 2, + TYPE_INT64 = 3, + TYPE_UINT64 = 4, + TYPE_INT32 = 5, + TYPE_FIXED64 = 6, + TYPE_FIXED32 = 7, + TYPE_BOOL = 8, + TYPE_STRING = 9, + TYPE_GROUP = 10, + TYPE_MESSAGE = 11, + TYPE_BYTES = 12, + TYPE_UINT32 = 13, + TYPE_ENUM = 14, + TYPE_SFIXED32 = 15, + TYPE_SFIXED64 = 16, + TYPE_SINT32 = 17, + TYPE_SINT64 = 18, +} + +export interface FieldDescriptorProto { + 'name'?: (string); + 'extendee'?: (string); + 'number'?: (number); + 'label'?: (_google_protobuf_FieldDescriptorProto_Label | keyof typeof _google_protobuf_FieldDescriptorProto_Label); + 'type'?: (_google_protobuf_FieldDescriptorProto_Type | keyof typeof _google_protobuf_FieldDescriptorProto_Type); + 'typeName'?: (string); + 'defaultValue'?: (string); + 'options'?: (_google_protobuf_FieldOptions); + 'oneofIndex'?: (number); + 'jsonName'?: (string); +} + +export interface FieldDescriptorProto__Output { + 'name': (string); + 'extendee': (string); + 'number': (number); + 'label': (keyof typeof _google_protobuf_FieldDescriptorProto_Label); + 'type': (keyof typeof _google_protobuf_FieldDescriptorProto_Type); + 'typeName': (string); + 'defaultValue': (string); + 'options'?: (_google_protobuf_FieldOptions__Output); + 'oneofIndex': (number); + 'jsonName': (string); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts new file mode 100644 index 000000000..8304053f1 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts @@ -0,0 +1,42 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { FieldBehavior as _google_api_FieldBehavior } from '../../google/api/FieldBehavior'; + +// Original file: null + +export enum _google_protobuf_FieldOptions_CType { + STRING = 0, + CORD = 1, + STRING_PIECE = 2, +} + +// Original file: null + +export enum _google_protobuf_FieldOptions_JSType { + JS_NORMAL = 0, + JS_STRING = 1, + JS_NUMBER = 2, +} + +export interface FieldOptions { + 'ctype'?: (_google_protobuf_FieldOptions_CType | keyof typeof _google_protobuf_FieldOptions_CType); + 'packed'?: (boolean); + 'deprecated'?: (boolean); + 'lazy'?: (boolean); + 'jstype'?: (_google_protobuf_FieldOptions_JSType | keyof typeof _google_protobuf_FieldOptions_JSType); + 'weak'?: (boolean); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; + '.google.api.field_behavior'?: (_google_api_FieldBehavior | keyof typeof _google_api_FieldBehavior)[]; +} + +export interface FieldOptions__Output { + 'ctype': (keyof typeof _google_protobuf_FieldOptions_CType); + 'packed': (boolean); + 'deprecated': (boolean); + 'lazy': (boolean); + 'jstype': (keyof typeof _google_protobuf_FieldOptions_JSType); + 'weak': (boolean); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; + '.google.api.field_behavior': (keyof typeof _google_api_FieldBehavior)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts new file mode 100644 index 000000000..2954e4208 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts @@ -0,0 +1,38 @@ +// Original file: null + +import type { DescriptorProto as _google_protobuf_DescriptorProto, DescriptorProto__Output as _google_protobuf_DescriptorProto__Output } from '../../google/protobuf/DescriptorProto'; +import type { EnumDescriptorProto as _google_protobuf_EnumDescriptorProto, EnumDescriptorProto__Output as _google_protobuf_EnumDescriptorProto__Output } from '../../google/protobuf/EnumDescriptorProto'; +import type { ServiceDescriptorProto as _google_protobuf_ServiceDescriptorProto, ServiceDescriptorProto__Output as _google_protobuf_ServiceDescriptorProto__Output } from '../../google/protobuf/ServiceDescriptorProto'; +import type { FieldDescriptorProto as _google_protobuf_FieldDescriptorProto, FieldDescriptorProto__Output as _google_protobuf_FieldDescriptorProto__Output } from '../../google/protobuf/FieldDescriptorProto'; +import type { FileOptions as _google_protobuf_FileOptions, FileOptions__Output as _google_protobuf_FileOptions__Output } from '../../google/protobuf/FileOptions'; +import type { SourceCodeInfo as _google_protobuf_SourceCodeInfo, SourceCodeInfo__Output as _google_protobuf_SourceCodeInfo__Output } from '../../google/protobuf/SourceCodeInfo'; + +export interface FileDescriptorProto { + 'name'?: (string); + 'package'?: (string); + 'dependency'?: (string)[]; + 'messageType'?: (_google_protobuf_DescriptorProto)[]; + 'enumType'?: (_google_protobuf_EnumDescriptorProto)[]; + 'service'?: (_google_protobuf_ServiceDescriptorProto)[]; + 'extension'?: (_google_protobuf_FieldDescriptorProto)[]; + 'options'?: (_google_protobuf_FileOptions); + 'sourceCodeInfo'?: (_google_protobuf_SourceCodeInfo); + 'publicDependency'?: (number)[]; + 'weakDependency'?: (number)[]; + 'syntax'?: (string); +} + +export interface FileDescriptorProto__Output { + 'name': (string); + 'package': (string); + 'dependency': (string)[]; + 'messageType': (_google_protobuf_DescriptorProto__Output)[]; + 'enumType': (_google_protobuf_EnumDescriptorProto__Output)[]; + 'service': (_google_protobuf_ServiceDescriptorProto__Output)[]; + 'extension': (_google_protobuf_FieldDescriptorProto__Output)[]; + 'options'?: (_google_protobuf_FileOptions__Output); + 'sourceCodeInfo'?: (_google_protobuf_SourceCodeInfo__Output); + 'publicDependency': (number)[]; + 'weakDependency': (number)[]; + 'syntax': (string); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts new file mode 100644 index 000000000..74ded2471 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts @@ -0,0 +1,11 @@ +// Original file: null + +import type { FileDescriptorProto as _google_protobuf_FileDescriptorProto, FileDescriptorProto__Output as _google_protobuf_FileDescriptorProto__Output } from '../../google/protobuf/FileDescriptorProto'; + +export interface FileDescriptorSet { + 'file'?: (_google_protobuf_FileDescriptorProto)[]; +} + +export interface FileDescriptorSet__Output { + 'file': (_google_protobuf_FileDescriptorProto__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts new file mode 100644 index 000000000..573e847c0 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts @@ -0,0 +1,47 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; + +// Original file: null + +export enum _google_protobuf_FileOptions_OptimizeMode { + SPEED = 1, + CODE_SIZE = 2, + LITE_RUNTIME = 3, +} + +export interface FileOptions { + 'javaPackage'?: (string); + 'javaOuterClassname'?: (string); + 'optimizeFor'?: (_google_protobuf_FileOptions_OptimizeMode | keyof typeof _google_protobuf_FileOptions_OptimizeMode); + 'javaMultipleFiles'?: (boolean); + 'goPackage'?: (string); + 'ccGenericServices'?: (boolean); + 'javaGenericServices'?: (boolean); + 'pyGenericServices'?: (boolean); + 'javaGenerateEqualsAndHash'?: (boolean); + 'deprecated'?: (boolean); + 'javaStringCheckUtf8'?: (boolean); + 'ccEnableArenas'?: (boolean); + 'objcClassPrefix'?: (string); + 'csharpNamespace'?: (string); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; +} + +export interface FileOptions__Output { + 'javaPackage': (string); + 'javaOuterClassname': (string); + 'optimizeFor': (keyof typeof _google_protobuf_FileOptions_OptimizeMode); + 'javaMultipleFiles': (boolean); + 'goPackage': (string); + 'ccGenericServices': (boolean); + 'javaGenericServices': (boolean); + 'pyGenericServices': (boolean); + 'javaGenerateEqualsAndHash': (boolean); + 'deprecated': (boolean); + 'javaStringCheckUtf8': (boolean); + 'ccEnableArenas': (boolean); + 'objcClassPrefix': (string); + 'csharpNamespace': (string); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/GeneratedCodeInfo.ts b/packages/proto-loader/golden-generated/google/protobuf/GeneratedCodeInfo.ts new file mode 100644 index 000000000..019fb0e15 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/GeneratedCodeInfo.ts @@ -0,0 +1,24 @@ +// Original file: null + + +export interface _google_protobuf_GeneratedCodeInfo_Annotation { + 'path'?: (number)[]; + 'sourceFile'?: (string); + 'begin'?: (number); + 'end'?: (number); +} + +export interface _google_protobuf_GeneratedCodeInfo_Annotation__Output { + 'path': (number)[]; + 'sourceFile': (string); + 'begin': (number); + 'end': (number); +} + +export interface GeneratedCodeInfo { + 'annotation'?: (_google_protobuf_GeneratedCodeInfo_Annotation)[]; +} + +export interface GeneratedCodeInfo__Output { + 'annotation': (_google_protobuf_GeneratedCodeInfo_Annotation__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts new file mode 100644 index 000000000..31f669eb0 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts @@ -0,0 +1,19 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; + +export interface MessageOptions { + 'messageSetWireFormat'?: (boolean); + 'noStandardDescriptorAccessor'?: (boolean); + 'deprecated'?: (boolean); + 'mapEntry'?: (boolean); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; +} + +export interface MessageOptions__Output { + 'messageSetWireFormat': (boolean); + 'noStandardDescriptorAccessor': (boolean); + 'deprecated': (boolean); + 'mapEntry': (boolean); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts new file mode 100644 index 000000000..bc2f0afb5 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts @@ -0,0 +1,21 @@ +// Original file: null + +import type { MethodOptions as _google_protobuf_MethodOptions, MethodOptions__Output as _google_protobuf_MethodOptions__Output } from '../../google/protobuf/MethodOptions'; + +export interface MethodDescriptorProto { + 'name'?: (string); + 'inputType'?: (string); + 'outputType'?: (string); + 'options'?: (_google_protobuf_MethodOptions); + 'clientStreaming'?: (boolean); + 'serverStreaming'?: (boolean); +} + +export interface MethodDescriptorProto__Output { + 'name': (string); + 'inputType': (string); + 'outputType': (string); + 'options'?: (_google_protobuf_MethodOptions__Output); + 'clientStreaming': (boolean); + 'serverStreaming': (boolean); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts new file mode 100644 index 000000000..495e22514 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts @@ -0,0 +1,21 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { OperationInfo as _google_longrunning_OperationInfo, OperationInfo__Output as _google_longrunning_OperationInfo__Output } from '../../google/longrunning/OperationInfo'; +import type { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; + +export interface MethodOptions { + 'deprecated'?: (boolean); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; + '.google.longrunning.operation_info'?: (_google_longrunning_OperationInfo); + '.google.api.method_signature'?: (string)[]; + '.google.api.http'?: (_google_api_HttpRule); +} + +export interface MethodOptions__Output { + 'deprecated': (boolean); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; + '.google.longrunning.operation_info'?: (_google_longrunning_OperationInfo__Output); + '.google.api.method_signature': (string)[]; + '.google.api.http'?: (_google_api_HttpRule__Output); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts new file mode 100644 index 000000000..c10ccecd3 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts @@ -0,0 +1,13 @@ +// Original file: null + +import type { OneofOptions as _google_protobuf_OneofOptions, OneofOptions__Output as _google_protobuf_OneofOptions__Output } from '../../google/protobuf/OneofOptions'; + +export interface OneofDescriptorProto { + 'name'?: (string); + 'options'?: (_google_protobuf_OneofOptions); +} + +export interface OneofDescriptorProto__Output { + 'name': (string); + 'options'?: (_google_protobuf_OneofOptions__Output); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts new file mode 100644 index 000000000..d81d34797 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts @@ -0,0 +1,11 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; + +export interface OneofOptions { + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; +} + +export interface OneofOptions__Output { + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts new file mode 100644 index 000000000..695a8775c --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts @@ -0,0 +1,16 @@ +// Original file: null + +import type { MethodDescriptorProto as _google_protobuf_MethodDescriptorProto, MethodDescriptorProto__Output as _google_protobuf_MethodDescriptorProto__Output } from '../../google/protobuf/MethodDescriptorProto'; +import type { ServiceOptions as _google_protobuf_ServiceOptions, ServiceOptions__Output as _google_protobuf_ServiceOptions__Output } from '../../google/protobuf/ServiceOptions'; + +export interface ServiceDescriptorProto { + 'name'?: (string); + 'method'?: (_google_protobuf_MethodDescriptorProto)[]; + 'options'?: (_google_protobuf_ServiceOptions); +} + +export interface ServiceDescriptorProto__Output { + 'name': (string); + 'method': (_google_protobuf_MethodDescriptorProto__Output)[]; + 'options'?: (_google_protobuf_ServiceOptions__Output); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts new file mode 100644 index 000000000..c0522eca3 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts @@ -0,0 +1,17 @@ +// Original file: null + +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; + +export interface ServiceOptions { + 'deprecated'?: (boolean); + 'uninterpretedOption'?: (_google_protobuf_UninterpretedOption)[]; + '.google.api.default_host'?: (string); + '.google.api.oauth_scopes'?: (string); +} + +export interface ServiceOptions__Output { + 'deprecated': (boolean); + 'uninterpretedOption': (_google_protobuf_UninterpretedOption__Output)[]; + '.google.api.default_host': (string); + '.google.api.oauth_scopes': (string); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/SourceCodeInfo.ts b/packages/proto-loader/golden-generated/google/protobuf/SourceCodeInfo.ts new file mode 100644 index 000000000..d30e59b4f --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/SourceCodeInfo.ts @@ -0,0 +1,26 @@ +// Original file: null + + +export interface _google_protobuf_SourceCodeInfo_Location { + 'path'?: (number)[]; + 'span'?: (number)[]; + 'leadingComments'?: (string); + 'trailingComments'?: (string); + 'leadingDetachedComments'?: (string)[]; +} + +export interface _google_protobuf_SourceCodeInfo_Location__Output { + 'path': (number)[]; + 'span': (number)[]; + 'leadingComments': (string); + 'trailingComments': (string); + 'leadingDetachedComments': (string)[]; +} + +export interface SourceCodeInfo { + 'location'?: (_google_protobuf_SourceCodeInfo_Location)[]; +} + +export interface SourceCodeInfo__Output { + 'location': (_google_protobuf_SourceCodeInfo_Location__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts b/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts new file mode 100644 index 000000000..ceaa32b5f --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts @@ -0,0 +1,13 @@ +// Original file: null + +import type { Long } from '@grpc/proto-loader'; + +export interface Timestamp { + 'seconds'?: (number | string | Long); + 'nanos'?: (number); +} + +export interface Timestamp__Output { + 'seconds': (string); + 'nanos': (number); +} diff --git a/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts b/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts new file mode 100644 index 000000000..433820f55 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts @@ -0,0 +1,33 @@ +// Original file: null + +import type { Long } from '@grpc/proto-loader'; + +export interface _google_protobuf_UninterpretedOption_NamePart { + 'namePart'?: (string); + 'isExtension'?: (boolean); +} + +export interface _google_protobuf_UninterpretedOption_NamePart__Output { + 'namePart': (string); + 'isExtension': (boolean); +} + +export interface UninterpretedOption { + 'name'?: (_google_protobuf_UninterpretedOption_NamePart)[]; + 'identifierValue'?: (string); + 'positiveIntValue'?: (number | string | Long); + 'negativeIntValue'?: (number | string | Long); + 'doubleValue'?: (number | string); + 'stringValue'?: (Buffer | Uint8Array | string); + 'aggregateValue'?: (string); +} + +export interface UninterpretedOption__Output { + 'name': (_google_protobuf_UninterpretedOption_NamePart__Output)[]; + 'identifierValue': (string); + 'positiveIntValue': (string); + 'negativeIntValue': (string); + 'doubleValue': (number | string); + 'stringValue': (Buffer); + 'aggregateValue': (string); +} diff --git a/packages/proto-loader/golden-generated/google/rpc/Status.ts b/packages/proto-loader/golden-generated/google/rpc/Status.ts new file mode 100644 index 000000000..4ce45b6a9 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/rpc/Status.ts @@ -0,0 +1,57 @@ +// Original file: deps/googleapis/google/rpc/status.proto + +import type { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; + +/** + * The `Status` type defines a logical error model that is suitable for + * different programming environments, including REST APIs and RPC APIs. It is + * used by [gRPC](https://github.com/grpc). Each `Status` message contains + * three pieces of data: error code, error message, and error details. + * + * You can find out more about this error model and how to work with it in the + * [API Design Guide](https://cloud.google.com/apis/design/errors). + */ +export interface Status { + /** + * The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. + */ + 'code'?: (number); + /** + * A developer-facing error message, which should be in English. Any + * user-facing error message should be localized and sent in the + * [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. + */ + 'message'?: (string); + /** + * A list of messages that carry the error details. There is a common set of + * message types for APIs to use. + */ + 'details'?: (_google_protobuf_Any)[]; +} + +/** + * The `Status` type defines a logical error model that is suitable for + * different programming environments, including REST APIs and RPC APIs. It is + * used by [gRPC](https://github.com/grpc). Each `Status` message contains + * three pieces of data: error code, error message, and error details. + * + * You can find out more about this error model and how to work with it in the + * [API Design Guide](https://cloud.google.com/apis/design/errors). + */ +export interface Status__Output { + /** + * The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. + */ + 'code': (number); + /** + * A developer-facing error message, which should be in English. Any + * user-facing error message should be localized and sent in the + * [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. + */ + 'message': (string); + /** + * A list of messages that carry the error details. There is a common set of + * message types for APIs to use. + */ + 'details': (_google_protobuf_Any__Output)[]; +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts new file mode 100644 index 000000000..88c8010cd --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts @@ -0,0 +1,45 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; +import type { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +import type { BlockResponse as _google_showcase_v1beta1_BlockResponse, BlockResponse__Output as _google_showcase_v1beta1_BlockResponse__Output } from '../../../google/showcase/v1beta1/BlockResponse'; + +/** + * The request for Block method. + */ +export interface BlockRequest { + /** + * The amount of time to block before returning a response. + */ + 'response_delay'?: (_google_protobuf_Duration); + /** + * The error that will be returned by the server. If this code is specified + * to be the OK rpc code, an empty response will be returned. + */ + 'error'?: (_google_rpc_Status); + /** + * The response to be returned that will signify successful method call. + */ + 'success'?: (_google_showcase_v1beta1_BlockResponse); + 'response'?: "error"|"success"; +} + +/** + * The request for Block method. + */ +export interface BlockRequest__Output { + /** + * The amount of time to block before returning a response. + */ + 'response_delay'?: (_google_protobuf_Duration__Output); + /** + * The error that will be returned by the server. If this code is specified + * to be the OK rpc code, an empty response will be returned. + */ + 'error'?: (_google_rpc_Status__Output); + /** + * The response to be returned that will signify successful method call. + */ + 'success'?: (_google_showcase_v1beta1_BlockResponse__Output); + 'response': "error"|"success"; +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts new file mode 100644 index 000000000..5634b19d4 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts @@ -0,0 +1,24 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + + +/** + * The response for Block method. + */ +export interface BlockResponse { + /** + * This content can contain anything, the server will not depend on a value + * here. + */ + 'content'?: (string); +} + +/** + * The response for Block method. + */ +export interface BlockResponse__Output { + /** + * This content can contain anything, the server will not depend on a value + * here. + */ + 'content': (string); +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts new file mode 100644 index 000000000..33fe373a8 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -0,0 +1,191 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type * as grpc from '@grpc/grpc-js' +import type { BlockRequest as _google_showcase_v1beta1_BlockRequest, BlockRequest__Output as _google_showcase_v1beta1_BlockRequest__Output } from '../../../google/showcase/v1beta1/BlockRequest'; +import type { BlockResponse as _google_showcase_v1beta1_BlockResponse, BlockResponse__Output as _google_showcase_v1beta1_BlockResponse__Output } from '../../../google/showcase/v1beta1/BlockResponse'; +import type { EchoRequest as _google_showcase_v1beta1_EchoRequest, EchoRequest__Output as _google_showcase_v1beta1_EchoRequest__Output } from '../../../google/showcase/v1beta1/EchoRequest'; +import type { EchoResponse as _google_showcase_v1beta1_EchoResponse, EchoResponse__Output as _google_showcase_v1beta1_EchoResponse__Output } from '../../../google/showcase/v1beta1/EchoResponse'; +import type { ExpandRequest as _google_showcase_v1beta1_ExpandRequest, ExpandRequest__Output as _google_showcase_v1beta1_ExpandRequest__Output } from '../../../google/showcase/v1beta1/ExpandRequest'; +import type { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../../google/longrunning/Operation'; +import type { PagedExpandRequest as _google_showcase_v1beta1_PagedExpandRequest, PagedExpandRequest__Output as _google_showcase_v1beta1_PagedExpandRequest__Output } from '../../../google/showcase/v1beta1/PagedExpandRequest'; +import type { PagedExpandResponse as _google_showcase_v1beta1_PagedExpandResponse, PagedExpandResponse__Output as _google_showcase_v1beta1_PagedExpandResponse__Output } from '../../../google/showcase/v1beta1/PagedExpandResponse'; +import type { WaitRequest as _google_showcase_v1beta1_WaitRequest, WaitRequest__Output as _google_showcase_v1beta1_WaitRequest__Output } from '../../../google/showcase/v1beta1/WaitRequest'; + +/** + * This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This + * service also exposes methods that explicitly implement server delay, and + * paginated calls. Set the 'showcase-trailer' metadata key on any method + * to have the values echoed in the response trailers. + */ +export interface EchoClient extends grpc.Client { + /** + * This method will block (wait) for the requested amount of time + * and then return the response or error. + * This method showcases how a client handles delays or retries. + */ + Block(argument: _google_showcase_v1beta1_BlockRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + Block(argument: _google_showcase_v1beta1_BlockRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + Block(argument: _google_showcase_v1beta1_BlockRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + Block(argument: _google_showcase_v1beta1_BlockRequest, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + /** + * This method will block (wait) for the requested amount of time + * and then return the response or error. + * This method showcases how a client handles delays or retries. + */ + block(argument: _google_showcase_v1beta1_BlockRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + block(argument: _google_showcase_v1beta1_BlockRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + block(argument: _google_showcase_v1beta1_BlockRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + block(argument: _google_showcase_v1beta1_BlockRequest, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_BlockResponse__Output) => void): grpc.ClientUnaryCall; + + /** + * This method, upon receiving a request on the stream, the same content will + * be passed back on the stream. This method showcases bidirectional + * streaming rpcs. + */ + Chat(metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>; + Chat(options?: grpc.CallOptions): grpc.ClientDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>; + /** + * This method, upon receiving a request on the stream, the same content will + * be passed back on the stream. This method showcases bidirectional + * streaming rpcs. + */ + chat(metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>; + chat(options?: grpc.CallOptions): grpc.ClientDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>; + + /** + * This method will collect the words given to it. When the stream is closed + * by the client, this method will return the a concatenation of the strings + * passed to it. This method showcases client-side streaming rpcs. + */ + Collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + Collect(options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + Collect(callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + /** + * This method will collect the words given to it. When the stream is closed + * by the client, this method will return the a concatenation of the strings + * passed to it. This method showcases client-side streaming rpcs. + */ + collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + collect(options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + collect(callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoRequest>; + + /** + * This method simply echos the request. This method is showcases unary rpcs. + */ + Echo(argument: _google_showcase_v1beta1_EchoRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + Echo(argument: _google_showcase_v1beta1_EchoRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + Echo(argument: _google_showcase_v1beta1_EchoRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + Echo(argument: _google_showcase_v1beta1_EchoRequest, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + /** + * This method simply echos the request. This method is showcases unary rpcs. + */ + echo(argument: _google_showcase_v1beta1_EchoRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + echo(argument: _google_showcase_v1beta1_EchoRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + echo(argument: _google_showcase_v1beta1_EchoRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + echo(argument: _google_showcase_v1beta1_EchoRequest, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientUnaryCall; + + /** + * This method split the given content into words and will pass each word back + * through the stream. This method showcases server-side streaming rpcs. + */ + Expand(argument: _google_showcase_v1beta1_ExpandRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_google_showcase_v1beta1_EchoResponse__Output>; + Expand(argument: _google_showcase_v1beta1_ExpandRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_google_showcase_v1beta1_EchoResponse__Output>; + /** + * This method split the given content into words and will pass each word back + * through the stream. This method showcases server-side streaming rpcs. + */ + expand(argument: _google_showcase_v1beta1_ExpandRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_google_showcase_v1beta1_EchoResponse__Output>; + expand(argument: _google_showcase_v1beta1_ExpandRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_google_showcase_v1beta1_EchoResponse__Output>; + + /** + * This is similar to the Expand method but instead of returning a stream of + * expanded words, this method returns a paged list of expanded words. + */ + PagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + PagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + PagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + PagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + /** + * This is similar to the Expand method but instead of returning a stream of + * expanded words, this method returns a paged list of expanded words. + */ + pagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + pagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + pagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + pagedExpand(argument: _google_showcase_v1beta1_PagedExpandRequest, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_PagedExpandResponse__Output) => void): grpc.ClientUnaryCall; + + /** + * This method will wait the requested amount of and then return. + * This method showcases how a client handles a request timing out. + */ + Wait(argument: _google_showcase_v1beta1_WaitRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + Wait(argument: _google_showcase_v1beta1_WaitRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + Wait(argument: _google_showcase_v1beta1_WaitRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + Wait(argument: _google_showcase_v1beta1_WaitRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + /** + * This method will wait the requested amount of and then return. + * This method showcases how a client handles a request timing out. + */ + wait(argument: _google_showcase_v1beta1_WaitRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + wait(argument: _google_showcase_v1beta1_WaitRequest, metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + wait(argument: _google_showcase_v1beta1_WaitRequest, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + wait(argument: _google_showcase_v1beta1_WaitRequest, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; + +} + +/** + * This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This + * service also exposes methods that explicitly implement server delay, and + * paginated calls. Set the 'showcase-trailer' metadata key on any method + * to have the values echoed in the response trailers. + */ +export interface EchoHandlers extends grpc.UntypedServiceImplementation { + /** + * This method will block (wait) for the requested amount of time + * and then return the response or error. + * This method showcases how a client handles delays or retries. + */ + Block: grpc.handleUnaryCall<_google_showcase_v1beta1_BlockRequest__Output, _google_showcase_v1beta1_BlockResponse>; + + /** + * This method, upon receiving a request on the stream, the same content will + * be passed back on the stream. This method showcases bidirectional + * streaming rpcs. + */ + Chat: grpc.handleBidiStreamingCall<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>; + + /** + * This method will collect the words given to it. When the stream is closed + * by the client, this method will return the a concatenation of the strings + * passed to it. This method showcases client-side streaming rpcs. + */ + Collect: grpc.handleClientStreamingCall<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>; + + /** + * This method simply echos the request. This method is showcases unary rpcs. + */ + Echo: grpc.handleUnaryCall<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>; + + /** + * This method split the given content into words and will pass each word back + * through the stream. This method showcases server-side streaming rpcs. + */ + Expand: grpc.handleServerStreamingCall<_google_showcase_v1beta1_ExpandRequest__Output, _google_showcase_v1beta1_EchoResponse>; + + /** + * This is similar to the Expand method but instead of returning a stream of + * expanded words, this method returns a paged list of expanded words. + */ + PagedExpand: grpc.handleUnaryCall<_google_showcase_v1beta1_PagedExpandRequest__Output, _google_showcase_v1beta1_PagedExpandResponse>; + + /** + * This method will wait the requested amount of and then return. + * This method showcases how a client handles a request timing out. + */ + Wait: grpc.handleUnaryCall<_google_showcase_v1beta1_WaitRequest__Output, _google_longrunning_Operation>; + +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts new file mode 100644 index 000000000..0cf79d84f --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts @@ -0,0 +1,48 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +import type { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; + +/** + * The request message used for the Echo, Collect and Chat methods. + * If content or opt are set in this message then the request will succeed. + * If status is set in this message + * then the status will be returned as an error. + */ +export interface EchoRequest { + /** + * The content to be echoed by the server. + */ + 'content'?: (string); + /** + * The error to be thrown by the server. + */ + 'error'?: (_google_rpc_Status); + /** + * The severity to be echoed by the server. + */ + 'severity'?: (_google_showcase_v1beta1_Severity | keyof typeof _google_showcase_v1beta1_Severity); + 'response'?: "content"|"error"; +} + +/** + * The request message used for the Echo, Collect and Chat methods. + * If content or opt are set in this message then the request will succeed. + * If status is set in this message + * then the status will be returned as an error. + */ +export interface EchoRequest__Output { + /** + * The content to be echoed by the server. + */ + 'content'?: (string); + /** + * The error to be thrown by the server. + */ + 'error'?: (_google_rpc_Status__Output); + /** + * The severity to be echoed by the server. + */ + 'severity': (keyof typeof _google_showcase_v1beta1_Severity); + 'response': "content"|"error"; +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts new file mode 100644 index 000000000..3fda238a1 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts @@ -0,0 +1,31 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; + +/** + * The response message for the Echo methods. + */ +export interface EchoResponse { + /** + * The content specified in the request. + */ + 'content'?: (string); + /** + * The severity specified in the request. + */ + 'severity'?: (_google_showcase_v1beta1_Severity | keyof typeof _google_showcase_v1beta1_Severity); +} + +/** + * The response message for the Echo methods. + */ +export interface EchoResponse__Output { + /** + * The content specified in the request. + */ + 'content': (string); + /** + * The severity specified in the request. + */ + 'severity': (keyof typeof _google_showcase_v1beta1_Severity); +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts new file mode 100644 index 000000000..00e7d05d2 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts @@ -0,0 +1,31 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; + +/** + * The request message for the Expand method. + */ +export interface ExpandRequest { + /** + * The content that will be split into words and returned on the stream. + */ + 'content'?: (string); + /** + * The error that is thrown after all words are sent on the stream. + */ + 'error'?: (_google_rpc_Status); +} + +/** + * The request message for the Expand method. + */ +export interface ExpandRequest__Output { + /** + * The content that will be split into words and returned on the stream. + */ + 'content': (string); + /** + * The error that is thrown after all words are sent on the stream. + */ + 'error'?: (_google_rpc_Status__Output); +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts new file mode 100644 index 000000000..13c945134 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts @@ -0,0 +1,38 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + + +/** + * The request for the PagedExpand method. + */ +export interface PagedExpandRequest { + /** + * The string to expand. + */ + 'content'?: (string); + /** + * The amount of words to returned in each page. + */ + 'page_size'?: (number); + /** + * The position of the page to be returned. + */ + 'page_token'?: (string); +} + +/** + * The request for the PagedExpand method. + */ +export interface PagedExpandRequest__Output { + /** + * The string to expand. + */ + 'content': (string); + /** + * The amount of words to returned in each page. + */ + 'page_size': (number); + /** + * The position of the page to be returned. + */ + 'page_token': (string); +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts new file mode 100644 index 000000000..823de43ed --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts @@ -0,0 +1,31 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { EchoResponse as _google_showcase_v1beta1_EchoResponse, EchoResponse__Output as _google_showcase_v1beta1_EchoResponse__Output } from '../../../google/showcase/v1beta1/EchoResponse'; + +/** + * The response for the PagedExpand method. + */ +export interface PagedExpandResponse { + /** + * The words that were expanded. + */ + 'responses'?: (_google_showcase_v1beta1_EchoResponse)[]; + /** + * The next page token. + */ + 'next_page_token'?: (string); +} + +/** + * The response for the PagedExpand method. + */ +export interface PagedExpandResponse__Output { + /** + * The words that were expanded. + */ + 'responses': (_google_showcase_v1beta1_EchoResponse__Output)[]; + /** + * The next page token. + */ + 'next_page_token': (string); +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts new file mode 100644 index 000000000..fc3fe6415 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts @@ -0,0 +1,11 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +/** + * A severity enum used to test enum capabilities in GAPIC surfaces + */ +export enum Severity { + UNNECESSARY = 0, + NECESSARY = 1, + URGENT = 2, + CRITICAL = 3, +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts new file mode 100644 index 000000000..38b0a083f --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts @@ -0,0 +1,23 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; + +/** + * The metadata for Wait operation. + */ +export interface WaitMetadata { + /** + * The time that this operation will complete. + */ + 'end_time'?: (_google_protobuf_Timestamp); +} + +/** + * The metadata for Wait operation. + */ +export interface WaitMetadata__Output { + /** + * The time that this operation will complete. + */ + 'end_time'?: (_google_protobuf_Timestamp__Output); +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts new file mode 100644 index 000000000..eb2d2bc19 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts @@ -0,0 +1,56 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; +import type { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +import type { WaitResponse as _google_showcase_v1beta1_WaitResponse, WaitResponse__Output as _google_showcase_v1beta1_WaitResponse__Output } from '../../../google/showcase/v1beta1/WaitResponse'; +import type { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; + +/** + * The request for Wait method. + */ +export interface WaitRequest { + /** + * The time that this operation will complete. + */ + 'end_time'?: (_google_protobuf_Timestamp); + /** + * The error that will be returned by the server. If this code is specified + * to be the OK rpc code, an empty response will be returned. + */ + 'error'?: (_google_rpc_Status); + /** + * The response to be returned on operation completion. + */ + 'success'?: (_google_showcase_v1beta1_WaitResponse); + /** + * The duration of this operation. + */ + 'ttl'?: (_google_protobuf_Duration); + 'end'?: "end_time"|"ttl"; + 'response'?: "error"|"success"; +} + +/** + * The request for Wait method. + */ +export interface WaitRequest__Output { + /** + * The time that this operation will complete. + */ + 'end_time'?: (_google_protobuf_Timestamp__Output); + /** + * The error that will be returned by the server. If this code is specified + * to be the OK rpc code, an empty response will be returned. + */ + 'error'?: (_google_rpc_Status__Output); + /** + * The response to be returned on operation completion. + */ + 'success'?: (_google_showcase_v1beta1_WaitResponse__Output); + /** + * The duration of this operation. + */ + 'ttl'?: (_google_protobuf_Duration__Output); + 'end': "end_time"|"ttl"; + 'response': "error"|"success"; +} diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts new file mode 100644 index 000000000..84b804f6b --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts @@ -0,0 +1,22 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + + +/** + * The result of the Wait operation. + */ +export interface WaitResponse { + /** + * This content of the result. + */ + 'content'?: (string); +} + +/** + * The result of the Wait operation. + */ +export interface WaitResponse__Output { + /** + * This content of the result. + */ + 'content': (string); +} diff --git a/packages/proto-loader/gulpfile.ts b/packages/proto-loader/gulpfile.ts index ff8f08552..f8d47c800 100644 --- a/packages/proto-loader/gulpfile.ts +++ b/packages/proto-loader/gulpfile.ts @@ -69,7 +69,16 @@ const runTests = () => { } } -const test = gulp.series(install, runTests); +const testGeneratorGolden = () => { + if (semver.satisfies(process.version, ">=10")) { + return execNpmCommand('validate-golden'); + } else { + console.log(`Skipping generator test for Node ${process.version}`); + return Promise.resolve(null); + } +} + +const test = gulp.series(install, runTests, testGeneratorGolden); export { install, diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index f0611b2b5..cfc767a9b 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.5.6", + "version": "0.6.0", "author": "Google Inc.", "contributors": [ { @@ -23,7 +23,9 @@ "check": "gts check", "fix": "gts fix", "pretest": "npm run compile", - "posttest": "npm run check" + "posttest": "npm run check", + "generate-golden": "node ./build/bin/proto-loader-gen-types.js --keepCase --longs=String --enums=String --defaults --oneofs --json --includeComments -I deps/gapic-showcase/schema/ deps/googleapis/ -O ./golden-generated --grpcLib @grpc/grpc-js google/showcase/v1beta1/echo.proto", + "validate-golden": "rm -rf ./golden-generated-old && mv ./golden-generated/ ./golden-generated-old && npm run generate-golden && diff -r ./golden-generated ./golden-generated-old" }, "repository": { "type": "git", @@ -36,20 +38,29 @@ "files": [ "LICENSE", "build/src/*.d.ts", - "build/src/*.js" + "build/src/*.js", + "build/bin/*.js" ], + "bin": { + "proto-loader-gen-types": "./build/bin/proto-loader-gen-types.js" + }, "dependencies": { + "@types/long": "^4.0.1", "lodash.camelcase": "^4.3.0", - "protobufjs": "^6.8.6" + "long": "^4.0.0", + "protobufjs": "^6.10.0", + "yargs": "^16.1.1" }, "devDependencies": { "@types/lodash.camelcase": "^4.3.4", + "@types/mkdirp": "^1.0.1", "@types/mocha": "^5.2.7", - "@types/node": "^10.12.5", + "@types/node": "^10.17.26", + "@types/yargs": "^15.0.5", "clang-format": "^1.2.2", "gts": "^1.1.0", "rimraf": "^3.0.2", - "typescript": "~3.3.3333" + "typescript": "~3.8.3" }, "engines": { "node": ">=6" diff --git a/packages/proto-loader/src/index.ts b/packages/proto-loader/src/index.ts index c51bc0110..e31a1938a 100644 --- a/packages/proto-loader/src/index.ts +++ b/packages/proto-loader/src/index.ts @@ -15,12 +15,49 @@ * limitations under the License. * */ -import * as fs from 'fs'; -import * as path from 'path'; + +import camelCase = require('lodash.camelcase'); import * as Protobuf from 'protobufjs'; import * as descriptor from 'protobufjs/ext/descriptor'; -import camelCase = require('lodash.camelcase'); +import { loadProtosWithOptionsSync, loadProtosWithOptions, Options, addCommonProtos } from './util'; + +export { Long } from 'long'; + +export { Options }; + +/** + * This type exists for use with code generated by the proto-loader-gen-types + * tool. This type should be used with another interface, e.g. + * MessageType & AnyExtension for an object that is converted to or from a + * google.protobuf.Any message. + * For example, when processing an Any message: + * + * ```ts + * if (isAnyExtension(message)) { + * switch (message['@type']) { + * case TYPE1_URL: + * handleType1(message as AnyExtension & Type1); + * break; + * case TYPE2_URL: + * handleType2(message as AnyExtension & Type2); + * break; + * // ... + * } + * } + * ``` + */ +export interface AnyExtension { + /** + * The fully qualified name of the message type that this object represents, + * possibly including a URL prefix. + */ + '@type': string; +} + +export function isAnyExtension(obj: object): obj is AnyExtension { + return ('@type' in obj) && (typeof (obj as AnyExtension)['@type'] === 'string'); +} declare module 'protobufjs' { interface Type { @@ -104,11 +141,6 @@ export interface PackageDefinition { [index: string]: AnyDefinition; } -export type Options = Protobuf.IParseOptions & - Protobuf.IConversionOptions & { - includeDirs?: string[]; - }; - type DecodedDescriptorSet = Protobuf.Message & descriptor.IFileDescriptorSet; @@ -301,26 +333,6 @@ function createPackageDefinition( return def; } -function addIncludePathResolver(root: Protobuf.Root, includePaths: string[]) { - const originalResolvePath = root.resolvePath; - root.resolvePath = (origin: string, target: string) => { - if (path.isAbsolute(target)) { - return target; - } - for (const directory of includePaths) { - const fullPath: string = path.join(directory, target); - try { - fs.accessSync(fullPath, fs.constants.R_OK); - return fullPath; - } catch (err) { - continue; - } - } - process.emitWarning(`${target} not found in any of the include paths ${includePaths}`); - return originalResolvePath(origin, target); - }; -} - function createPackageDefinitionFromDescriptorSet( decodedDescriptorSet: DecodedDescriptorSet, options?: Options @@ -356,25 +368,16 @@ function createPackageDefinitionFromDescriptorSet( * `defaults` is `false`. Defaults to `false`. * @param options.oneofs Set virtual oneof properties to the present field's * name + * @param options.json Represent Infinity and NaN as strings in float fields, + * and automatically decode google.protobuf.Any values. * @param options.includeDirs Paths to search for imported `.proto` files. */ export function load( filename: string | string[], options?: Options ): Promise { - const root: Protobuf.Root = new Protobuf.Root(); - options = options || {}; - if (!!options.includeDirs) { - if (!Array.isArray(options.includeDirs)) { - return Promise.reject( - new Error('The includeDirs option must be an array') - ); - } - addIncludePathResolver(root, options.includeDirs as string[]); - } - return root.load(filename, options).then(loadedRoot => { - loadedRoot.resolveAll(); - return createPackageDefinition(root, options!); + return loadProtosWithOptions(filename, options).then(loadedRoot => { + return createPackageDefinition(loadedRoot, options!); }); } @@ -382,17 +385,8 @@ export function loadSync( filename: string | string[], options?: Options ): PackageDefinition { - const root: Protobuf.Root = new Protobuf.Root(); - options = options || {}; - if (!!options.includeDirs) { - if (!Array.isArray(options.includeDirs)) { - throw new Error('The includeDirs option must be an array'); - } - addIncludePathResolver(root, options.includeDirs as string[]); - } - const loadedRoot = root.loadSync(filename, options); - loadedRoot.resolveAll(); - return createPackageDefinition(root, options!); + const loadedRoot = loadProtosWithOptionsSync(filename, options); + return createPackageDefinition(loadedRoot, options!); } export function loadFileDescriptorSetFromBuffer( @@ -423,30 +417,4 @@ export function loadFileDescriptorSetFromObject( ); } -// Load Google's well-known proto files that aren't exposed by Protobuf.js. - -// Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp, -// and wrappers. compiler/plugin is excluded in Protobuf.js and here. - -// Using constant strings for compatibility with tools like Webpack -const apiDescriptor = require('protobufjs/google/protobuf/api.json'); -const descriptorDescriptor = require('protobufjs/google/protobuf/descriptor.json'); -const sourceContextDescriptor = require('protobufjs/google/protobuf/source_context.json'); -const typeDescriptor = require('protobufjs/google/protobuf/type.json'); - -Protobuf.common( - 'api', - apiDescriptor.nested.google.nested.protobuf.nested -); -Protobuf.common( - 'descriptor', - descriptorDescriptor.nested.google.nested.protobuf.nested -); -Protobuf.common( - 'source_context', - sourceContextDescriptor.nested.google.nested.protobuf.nested -); -Protobuf.common( - 'type', - typeDescriptor.nested.google.nested.protobuf.nested -); +addCommonProtos(); diff --git a/packages/proto-loader/src/util.ts b/packages/proto-loader/src/util.ts new file mode 100644 index 000000000..a4a8502b6 --- /dev/null +++ b/packages/proto-loader/src/util.ts @@ -0,0 +1,113 @@ +/** + * @license + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import * as fs from 'fs'; +import * as path from 'path'; +import * as Protobuf from 'protobufjs'; + +function addIncludePathResolver(root: Protobuf.Root, includePaths: string[]) { + const originalResolvePath = root.resolvePath; + root.resolvePath = (origin: string, target: string) => { + if (path.isAbsolute(target)) { + return target; + } + for (const directory of includePaths) { + const fullPath: string = path.join(directory, target); + try { + fs.accessSync(fullPath, fs.constants.R_OK); + return fullPath; + } catch (err) { + continue; + } + } + process.emitWarning(`${target} not found in any of the include paths ${includePaths}`); + return originalResolvePath(origin, target); + }; +} + +export type Options = Protobuf.IParseOptions & + Protobuf.IConversionOptions & { + includeDirs?: string[]; + }; + +export async function loadProtosWithOptions( + filename: string | string[], + options?: Options +): Promise { + const root: Protobuf.Root = new Protobuf.Root(); + options = options || {}; + if (!!options.includeDirs) { + if (!Array.isArray(options.includeDirs)) { + return Promise.reject( + new Error('The includeDirs option must be an array') + ); + } + addIncludePathResolver(root, options.includeDirs as string[]); + } + const loadedRoot = await root.load(filename, options); + loadedRoot.resolveAll(); + return loadedRoot; +} + +export function loadProtosWithOptionsSync( + filename: string | string[], + options?: Options +): Protobuf.Root { + const root: Protobuf.Root = new Protobuf.Root(); + options = options || {}; + if (!!options.includeDirs) { + if (!Array.isArray(options.includeDirs)) { + throw new Error('The includeDirs option must be an array'); + } + addIncludePathResolver(root, options.includeDirs as string[]); + } + const loadedRoot = root.loadSync(filename, options); + loadedRoot.resolveAll(); + return loadedRoot; +} + +/** + * Load Google's well-known proto files that aren't exposed by Protobuf.js. + */ +export function addCommonProtos(): void { + // Protobuf.js exposes: any, duration, empty, field_mask, struct, timestamp, + // and wrappers. compiler/plugin is excluded in Protobuf.js and here. + + // Using constant strings for compatibility with tools like Webpack + const apiDescriptor = require('protobufjs/google/protobuf/api.json'); + const descriptorDescriptor = require('protobufjs/google/protobuf/descriptor.json'); + const sourceContextDescriptor = require('protobufjs/google/protobuf/source_context.json'); + const typeDescriptor = require('protobufjs/google/protobuf/type.json'); + + Protobuf.common( + 'api', + apiDescriptor.nested.google.nested.protobuf.nested + ); + Protobuf.common( + 'descriptor', + descriptorDescriptor.nested.google.nested.protobuf.nested + ); + Protobuf.common( + 'source_context', + sourceContextDescriptor.nested.google.nested.protobuf.nested + ); + Protobuf.common( + 'type', + typeDescriptor.nested.google.nested.protobuf.nested + ); +} \ No newline at end of file diff --git a/packages/proto-loader/tsconfig.json b/packages/proto-loader/tsconfig.json index d1646f011..e46980866 100644 --- a/packages/proto-loader/tsconfig.json +++ b/packages/proto-loader/tsconfig.json @@ -2,9 +2,12 @@ "extends": "./node_modules/gts/tsconfig-google.json", "compilerOptions": { "rootDir": ".", - "outDir": "build" + "outDir": "build", + "lib": ["es2017"], + "target": "es2017" }, "include": [ + "bin/**/*.ts", "src/**/*.ts", "test/**/*.ts" ] diff --git a/run-tests.sh b/run-tests.sh index f23475b90..c4bffacda 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -25,6 +25,8 @@ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | b set -ex cd $ROOT +git submodule update --init --recursive + if [ ! -n "$node_versions" ] ; then node_versions="8 10 12" fi