From da3fefb58e85f88fe5131875e5b82222bb3fcc69 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 12 Jun 2020 10:21:10 -0700 Subject: [PATCH 01/45] proto-loader: Add TypeScript generator --- .../bin/proto-loader-gen-types.ts | 587 ++++++++++++++++++ packages/proto-loader/package.json | 19 +- packages/proto-loader/src/index.ts | 2 + packages/proto-loader/tsconfig.json | 5 +- 4 files changed, 608 insertions(+), 5 deletions(-) create mode 100644 packages/proto-loader/bin/proto-loader-gen-types.ts 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..1de198c50 --- /dev/null +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -0,0 +1,587 @@ +#!/usr/bin/env node +/** + * @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 mkdirp from 'mkdirp'; +import * as Protobuf from 'protobufjs'; +import * as yargs from 'yargs'; + +import camelCase = require('lodash.camelcase'); + +type GeneratorOptions = Protobuf.IParseOptions & Protobuf.IConversionOptions & { + includeDirs?: string[]; + grpcLib: string; + outDir: string; +} + +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(''); + } +} + +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) { + return stripLeadingPeriod(to.fullName).replace(/\./g, '/'); +} + +function getPath(to: Protobuf.Type | Protobuf.Enum) { + return stripLeadingPeriod(to.fullName).replace(/\./g, '/') + '.d.ts'; +} + +function getRelativeImportPath(from: Protobuf.Type, to: Protobuf.Type | Protobuf.Enum) { + const depth = stripLeadingPeriod(from.fullName).split('.').length - 1; + let path = ''; + for (let i = 0; i < depth; i++) { + path += '../'; + } + return path + getImportPath(to); +} + +function getTypeInterfaceName(type: Protobuf.Type | Protobuf.Enum) { + return type.fullName.replace(/\./g, '_'); +} + +function getImportLine(dependency: Protobuf.Type | Protobuf.Enum, from?: Protobuf.Type) { + const filePath = from === undefined ? './' + getImportPath(dependency) : getRelativeImportPath(from, dependency); + const typeInterfaceName = getTypeInterfaceName(dependency); + const importedTypes = dependency instanceof Protobuf.Type ? `${dependency.name} as ${typeInterfaceName}, ${dependency.name}__Output as ${typeInterfaceName}__Output` : `${dependency.name} as ${typeInterfaceName}`; + return `import { ${importedTypes} } from '${filePath}';` +} + +function generatePermissiveMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type) { + formatter.writeLine(`export interface ${messageType.name} {`); + formatter.indent(); + for (const field of messageType.fieldsArray) { + const repeatedString = field.repeated ? '[]' : ''; + let type: string; + switch (field.type) { + case 'double': + case 'float': + case 'int32': + case 'uint32': + case 'sint32': + case 'fixed32': + case 'sfixed32': + type = 'number'; + break; + case 'int64': + case 'uint64': + case 'sint64': + case 'fixed64': + case 'sfixed64': + type = 'number | string | Long'; + break; + case 'bool': + type = 'boolean'; + break; + case 'string': + type = 'string'; + break; + case 'bytes': + type = 'Buffer | UInt8Array | String'; + break; + default: + if (field.resolvedType === null) { + throw new Error('Found field with no usable type'); + } + const typeInterfaceName = getTypeInterfaceName(field.resolvedType); + if (field.resolvedType instanceof Protobuf.Type) { + type = typeInterfaceName; + } else { + type = `${typeInterfaceName} | keyof typeof ${typeInterfaceName}`; + } + } + formatter.writeLine(`${field.name}?: (${type})${repeatedString};`); + } + for (const oneof of messageType.oneofsArray) { + const typeString = oneof.fieldsArray.map(field => `"${field.name}"`).join('|'); + formatter.writeLine(`${oneof.name}?: ${typeString};`); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateRestrictedMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions) { + formatter.writeLine(`export interface ${messageType.name}__Output {`); + formatter.indent(); + for (const field of messageType.fieldsArray) { + const repeatedString = field.repeated ? '[]' : ''; + let fieldGuaranteed = options.defaults || (field.repeated && options.arrays); + let type: string; + switch (field.type) { + case 'double': + case 'float': + case 'int32': + case 'uint32': + case 'sint32': + case 'fixed32': + case 'sfixed32': + type = 'number'; + break; + case 'int64': + case 'uint64': + case 'sint64': + case 'fixed64': + case 'sfixed64': + if (options.longs === Number) { + type = 'number'; + } else if (options.longs === String) { + type = 'string'; + } else { + type = 'Long'; + } + break; + case 'bool': + type = 'boolean'; + break; + case 'string': + type = 'string'; + break; + case 'bytes': + if (options.bytes === Array) { + type = 'Uint8Array'; + } else if (options.bytes === String) { + type = 'String'; + } else { + type = 'Buffer'; + } + break; + default: + if (field.resolvedType === null) { + throw new Error('Found field with no usable type'); + } + const typeInterfaceName = getTypeInterfaceName(field.resolvedType); + if (field.resolvedType instanceof Protobuf.Type) { + fieldGuaranteed = fieldGuaranteed || options.objects; + type = typeInterfaceName + '__Output'; + } else { + if (options.enums == String) { + type = `keyof typeof ${typeInterfaceName}`; + } else { + type = typeInterfaceName; + } + } + } + if (field.partOf) { + fieldGuaranteed = false; + } + const optionalString = fieldGuaranteed ? '' : '?'; + 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('|'); + formatter.writeLine(`${oneof.name}: ${typeString};`); + } + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateMessageInterfaces(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions) { + let usesLong: boolean = false; + let seenDeps: Set = new Set(); + for (const field of messageType.fieldsArray) { + if (field.resolvedType) { + 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 { Long } from '@grpc/proto-loader';"); + } + formatter.writeLine(''); + + generatePermissiveMessageInterface(formatter, messageType); + formatter.writeLine(''); + generateRestrictedMessageInterface(formatter, messageType, options); +} + +function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum) { + formatter.writeLine(`export enum ${enumType.name} {`); + formatter.indent(); + for (const key of Object.keys(enumType.values)) { + formatter.writeLine(`${key} = ${enumType.values[key]},`); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateMessageAndEnumImports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { + for (const nested of namespace.nestedArray) { + if (nested instanceof Protobuf.Type || nested instanceof Protobuf.Enum) { + formatter.writeLine(getImportLine(nested)); + } + if (isNamespaceBase(nested)) { + generateMessageAndEnumImports(formatter, nested); + } + } +} + +function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { + formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); + formatter.indent(); + for (const nested of namespace.nestedArray) { + if (nested instanceof Protobuf.Enum || nested instanceof Protobuf.Type) { + formatter.writeLine(`export type ${nested.name} = ${getTypeInterfaceName(nested)};`); + if (nested instanceof Protobuf.Type) { + formatter.writeLine(`export type ${nested.name}__Output = ${getTypeInterfaceName(nested)}__Output;`); + } + } else if (isNamespaceBase(nested)) { + generateMessageAndEnumExports(formatter, nested); + } + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateServiceClientInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { + formatter.writeLine(`interface ${serviceType.name}Client extends grpc.Client {`); + formatter.indent(); + for (const methodName of Object.keys(serviceType.methods)) { + const method = serviceType.methods[methodName]; + for (const name of [methodName, camelCase(methodName)]) { + const requestType = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName); + const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName) + '__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<${responseType}>`; + formatter.writeLine(`${name}(metadata: grpc.Metadata, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(metadata: grpc.Metadata, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(metadata: grpc.Metadata, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(metadata: grpc.Metadata, 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}, metadata: grpc.Metadata, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); + formatter.writeLine(`${name}(argument: ${requestType}, metadata: grpc.Metadata, callback: ${callbackType}): ${callType};`); + } + } + } + formatter.writeLine(''); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { + for (const nested of namespace.nestedArray) { + if (nested instanceof Protobuf.Service) { + generateServiceClientInterface(formatter, nested); + } else if (isNamespaceBase(nested)) { + generateAllServiceClientInterfaces(formatter, nested); + } + } +} + +function generateSingleLoadedDefinitionType(formatter: TextFormatter, nested: Protobuf.ReflectionObject) { + if (nested instanceof Protobuf.Service) { + 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); + } +} + +function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { + formatter.writeLine(`${namespace.name}: {`); + formatter.indent(); + for (const nested of namespace.nestedArray) { + generateSingleLoadedDefinitionType(formatter, nested); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { + formatter.writeLine(`export interface ${serviceType.name} {`); + formatter.indent(); + for (const methodName of Object.keys(serviceType.methods)) { + const method = serviceType.methods[methodName]; + const requestType = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName) + '__Output'; + const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName); + if (method.requestStream) { + if (method.responseStream) { + // Bidi streaming + formatter.writeLine(`${methodName}(call: grpc.ServerDuplexStream<${requestType}, ${responseType}>): void;`); + } else { + // Client streaming + formatter.writeLine(`${methodName}(call: grpc.ServerReadableStream<${requestType}>, callback: grpc.SendUnaryData<${responseType}>): void;`); + } + } else { + if (method.responseStream) { + // Server streaming + formatter.writeLine(`${methodName}(call: grpc.ServerWriteableStream<${requestType}, ${responseType}>): void;`); + } else { + // Unary + formatter.writeLine(`${methodName}(call: grpc.ServerUnaryCall<${requestType}>, callback: grpc.SendUnaryData<${responseType}>): void;`); + } + } + formatter.writeLine(''); + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateAllServiceHandlerInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { + formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); + formatter.indent(); + for (const nested of namespace.nestedArray) { + if (nested instanceof Protobuf.Service) { + generateServiceHandlerInterface(formatter, nested); + } else if (isNamespaceBase(nested)) { + generateAllServiceHandlerInterfaces(formatter, nested); + } + } + formatter.unindent(); + formatter.writeLine('}'); +} + +function generateMasterFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) { + formatter.writeLine(`import * as grpc from '${options.grpcLib}';`); + formatter.writeLine("import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';"); + formatter.writeLine(''); + + generateMessageAndEnumImports(formatter, root); + formatter.writeLine(''); + + generateMessageAndEnumExports(formatter, root, 'messages'); + formatter.writeLine(''); + + generateAllServiceClientInterfaces(formatter, root); + formatter.writeLine(''); + + formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); + formatter.writeLine('type SubtypeConstructor = {'); + formatter.writeLine(' new(args: ConstructorArguments): Subtype;'); + formatter.writeLine('}'); + formatter.writeLine(''); + + formatter.writeLine('export interface ProtoGrpcType {'); + formatter.indent(); + for (const nested of root.nestedArray) { + generateSingleLoadedDefinitionType(formatter, nested); + } + formatter.unindent(); + formatter.writeLine('}'); + formatter.writeLine(''); + + generateAllServiceHandlerInterfaces(formatter, root, 'ServiceHandlers'); +} + +function writeFile(filename: string, contents: string): Promise { + return mkdirp(path.dirname(filename)).then( + () => 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); + console.log(`Writing ${options.outDir}/${getPath(nested)}`); + filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); + } else if (nested instanceof Protobuf.Enum) { + generateEnumInterface(fileFormatter, nested); + console.log(`Writing ${options.outDir}/${getPath(nested)}`); + filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); + } + 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(); + generateMasterFile(masterFileFormatter, root, options); + console.log(`Writing ${options.outDir}/${masterFileName}`); + filePromises.push(writeFile(`${options.outDir}/${masterFileName}`, masterFileFormatter.getFullText())); + + filePromises.push(...generateFilesForNamespace(root, options)); + + return filePromises; +} + +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); + }; +} + +async function writeAllFiles(protoFiles: string[], options: GeneratorOptions) { + await mkdirp(options.outDir); + for (const filename of protoFiles) { + console.log(`Processing ${filename}`); + 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 = await root.load(filename, options); + root.resolveAll(); + writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.d.ts'), options); + } +} + +function runScript() { + const argv = yargs + .string(['includeDirs', 'grpcLib']) + .normalize(['includeDirs', 'outDir']) + .array('includeDirs') + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs']) +// .choices('longs', ['String', 'Number']) +// .choices('enums', ['String']) +// .choices('bytes', ['Array', 'String']) + .string(['longs', 'enums', 'bytes']) + .middleware(argv => { + if (argv.longs) { + switch (argv.longs) { + case 'String': argv.longsArg = String; + } + } + }) + .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' + }).describe({ + keepCase: 'Preserve the case of field names', + longs: 'The type that should be used to output 64 bit integer values', + enums: 'The type that should be used to output enum fields', + bytes: 'The type that should be used to output bytes fields', + 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', + 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; + console.log(argv); + writeAllFiles(argv._, argv).then(() => { + console.log('Success'); + }, (error) => { + throw error; + }) +} + +if (require.main === module) { + runScript(); +} \ No newline at end of file diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 022eb41c3..423769919 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -36,19 +36,30 @@ "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", + "mkdirp": "^1.0.4", + "protobufjs": "^6.8.6", + "yargs": "^15.3.1" }, "devDependencies": { "@types/lodash.camelcase": "^4.3.4", - "@types/node": "^10.12.5", + "@types/mkdirp": "^1.0.1", + "@types/mocha": "^7.0.2", + "@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 b29e26f33..45b6f150a 100644 --- a/packages/proto-loader/src/index.ts +++ b/packages/proto-loader/src/index.ts @@ -20,6 +20,8 @@ import * as path from 'path'; import * as Protobuf from 'protobufjs'; import * as descriptor from 'protobufjs/ext/descriptor'; +export { Long } from 'long'; + import camelCase = require('lodash.camelcase'); declare module 'protobufjs' { 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" ] From 3d369e9f564ddf1744fb61db9f7ef59ef96774bd Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 12 Jun 2020 10:58:42 -0700 Subject: [PATCH 02/45] Update to prerelease version, fix copyright date --- packages/proto-loader/bin/proto-loader-gen-types.ts | 2 +- packages/proto-loader/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 1de198c50..4b11cc300 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node /** * @license - * Copyright 2018 gRPC authors. + * 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. diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 423769919..849e01469 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.5.4", + "version": "0.6.0-pre1", "author": "Google Inc.", "contributors": [ { From 8bfa472df0f748997e5dfebfe0157a68e3da2f35 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 12 Jun 2020 11:22:07 -0700 Subject: [PATCH 03/45] Fix a couple of type name errors --- packages/proto-loader/bin/proto-loader-gen-types.ts | 4 ++-- packages/proto-loader/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 4b11cc300..0f3b82e87 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -125,7 +125,7 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp type = 'string'; break; case 'bytes': - type = 'Buffer | UInt8Array | String'; + type = 'Buffer | Uint8Array | string'; break; default: if (field.resolvedType === null) { @@ -188,7 +188,7 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp if (options.bytes === Array) { type = 'Uint8Array'; } else if (options.bytes === String) { - type = 'String'; + type = 'string'; } else { type = 'Buffer'; } diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 849e01469..2bf93d42a 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre1", + "version": "0.6.0-pre2", "author": "Google Inc.", "contributors": [ { From c6e17f2758e204b18e6c4650f86ee71d46eb1c1a Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 18 Jun 2020 10:14:55 -0700 Subject: [PATCH 04/45] Fix constructor argument declaration --- packages/proto-loader/bin/proto-loader-gen-types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 0f3b82e87..6342d2bdc 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -426,7 +426,7 @@ function generateMasterFile(formatter: TextFormatter, root: Protobuf.Root, optio formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); formatter.writeLine('type SubtypeConstructor = {'); - formatter.writeLine(' new(args: ConstructorArguments): Subtype;'); + formatter.writeLine(' new(...args: ConstructorArguments): Subtype;'); formatter.writeLine('}'); formatter.writeLine(''); From c7bbf045b6774e3fdf70cb7aec49b01019b3644b Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 18 Jun 2020 15:52:37 -0700 Subject: [PATCH 05/45] Add json option and google.protobuf.Any wrapper type --- packages/proto-loader/README.md | 1 + .../bin/proto-loader-gen-types.ts | 46 +++++++++++++++++-- packages/proto-loader/package.json | 2 +- packages/proto-loader/src/index.ts | 35 ++++++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/packages/proto-loader/README.md b/packages/proto-loader/README.md index 481b86297..07f28907c 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`: diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 6342d2bdc..7c70cd200 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -96,6 +96,15 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum, from?: Protobu } function generatePermissiveMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type) { + if (messageType.fullName === '.google.protobuf.Any') { + /* This describes the behavior of the Protobuf.js Any wrapper fromObject + * replacement function */ + formatter.writeLine('export type Any__Output = AnyExtension | {'); + formatter.writeLine(' type_url: string;'); + formatter.writeLine(' value: Buffer | Uint8Array | string;'); + formatter.writeLine('}'); + return; + } formatter.writeLine(`export interface ${messageType.name} {`); formatter.indent(); for (const field of messageType.fieldsArray) { @@ -104,6 +113,8 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp switch (field.type) { case 'double': case 'float': + type = 'number | string'; + break; case 'int32': case 'uint32': case 'sint32': @@ -149,6 +160,23 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp } function generateRestrictedMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions) { + if (messageType.fullName === '.google.protobuf.Any' && options.json) { + /* This describes the behavior of the Protobuf.js Any wrapper toObject + * replacement function */ + formatter.writeLine('export type Any__Output = AnyExtension | {'); + formatter.writeLine(' type_url: string;'); + let type: string; + if (options.bytes === Array) { + type = 'Uint8Array'; + } else if (options.bytes === String) { + type = 'string'; + } else { + type = 'Buffer'; + } + formatter.writeLine(` value: ${type};`); + formatter.writeLine('}'); + return; + } formatter.writeLine(`export interface ${messageType.name}__Output {`); formatter.indent(); for (const field of messageType.fieldsArray) { @@ -158,6 +186,12 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp switch (field.type) { case 'double': case 'float': + if (options.json) { + type = 'number | string'; + } else { + type = 'number'; + } + break; case 'int32': case 'uint32': case 'sint32': @@ -244,6 +278,9 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob if (usesLong) { formatter.writeLine("import { Long } from '@grpc/proto-loader';"); } + if (messageType.fullName === '.google.protobuf.Any') { + formatter.writeLine("import { AnyExtension } from '@grpc/proto-loader';") + } formatter.writeLine(''); generatePermissiveMessageInterface(formatter, messageType); @@ -524,7 +561,7 @@ function runScript() { .string(['includeDirs', 'grpcLib']) .normalize(['includeDirs', 'outDir']) .array('includeDirs') - .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs']) + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json']) // .choices('longs', ['String', 'Number']) // .choices('enums', ['String']) // .choices('bytes', ['Array', 'String']) @@ -559,13 +596,14 @@ function runScript() { outDir: 'O' }).describe({ keepCase: 'Preserve the case of field names', - longs: 'The type that should be used to output 64 bit integer values', - enums: 'The type that should be used to output enum fields', - bytes: 'The type that should be used to output bytes fields', + 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', 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' diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 2bf93d42a..b84b79779 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre2", + "version": "0.6.0-pre3", "author": "Google Inc.", "contributors": [ { diff --git a/packages/proto-loader/src/index.ts b/packages/proto-loader/src/index.ts index 45b6f150a..2e8507603 100644 --- a/packages/proto-loader/src/index.ts +++ b/packages/proto-loader/src/index.ts @@ -22,6 +22,39 @@ import * as descriptor from 'protobufjs/ext/descriptor'; export { Long } from 'long'; +/** + * 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'); +} + import camelCase = require('lodash.camelcase'); declare module 'protobufjs' { @@ -331,6 +364,8 @@ function addIncludePathResolver(root: Protobuf.Root, includePaths: string[]) { * `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( From f37e7d43bf9b8a98e4e7c0e93d97e4e0b90f437a Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 24 Jun 2020 16:36:26 -0700 Subject: [PATCH 06/45] A few more fixes to make the generated code compile --- .../bin/proto-loader-gen-types.ts | 80 ++++++++++++++----- packages/proto-loader/package.json | 4 +- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 7c70cd200..9f9e0bd66 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -95,17 +95,30 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum, from?: Protobu return `import { ${importedTypes} } from '${filePath}';` } -function generatePermissiveMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type) { +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 generatePermissiveMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, nameOverride?: string) { if (messageType.fullName === '.google.protobuf.Any') { /* This describes the behavior of the Protobuf.js Any wrapper fromObject * replacement function */ - formatter.writeLine('export type Any__Output = AnyExtension | {'); + formatter.writeLine('export type Any = AnyExtension | {'); formatter.writeLine(' type_url: string;'); formatter.writeLine(' value: Buffer | Uint8Array | string;'); formatter.writeLine('}'); return; } - formatter.writeLine(`export interface ${messageType.name} {`); + formatter.writeLine(`export interface ${nameOverride ?? messageType.name} {`); formatter.indent(); for (const field of messageType.fieldsArray) { const repeatedString = field.repeated ? '[]' : ''; @@ -149,17 +162,17 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp type = `${typeInterfaceName} | keyof typeof ${typeInterfaceName}`; } } - formatter.writeLine(`${field.name}?: (${type})${repeatedString};`); + formatter.writeLine(`'${field.name}'?: (${type})${repeatedString};`); } for (const oneof of messageType.oneofsArray) { const typeString = oneof.fieldsArray.map(field => `"${field.name}"`).join('|'); - formatter.writeLine(`${oneof.name}?: ${typeString};`); + formatter.writeLine(`'${oneof.name}'?: ${typeString};`); } formatter.unindent(); formatter.writeLine('}'); } -function generateRestrictedMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions) { +function generateRestrictedMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions, nameOverride?: string) { if (messageType.fullName === '.google.protobuf.Any' && options.json) { /* This describes the behavior of the Protobuf.js Any wrapper toObject * replacement function */ @@ -177,7 +190,7 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp formatter.writeLine('}'); return; } - formatter.writeLine(`export interface ${messageType.name}__Output {`); + formatter.writeLine(`export interface ${nameOverride ?? messageType.name}__Output {`); formatter.indent(); for (const field of messageType.fieldsArray) { const repeatedString = field.repeated ? '[]' : ''; @@ -247,12 +260,12 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp fieldGuaranteed = false; } const optionalString = fieldGuaranteed ? '' : '?'; - formatter.writeLine(`${field.name}${optionalString}: (${type})${repeatedString};`); + 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('|'); - formatter.writeLine(`${oneof.name}: ${typeString};`); + formatter.writeLine(`'${oneof.name}': ${typeString};`); } } formatter.unindent(); @@ -262,8 +275,11 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp function generateMessageInterfaces(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions) { let usesLong: boolean = false; let seenDeps: Set = new Set(); + const childTypes = getChildMessagesAndEnums(messageType); + formatter.writeLine(`// Original file: ${messageType.filename}`); + formatter.writeLine(''); for (const field of messageType.fieldsArray) { - if (field.resolvedType) { + if (field.resolvedType && childTypes.indexOf(field.resolvedType) < 0) { const dependency = field.resolvedType; if (seenDeps.has(dependency.fullName)) { continue; @@ -275,6 +291,23 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob 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 { Long } from '@grpc/proto-loader';"); } @@ -282,14 +315,27 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob formatter.writeLine("import { AnyExtension } from '@grpc/proto-loader';") } formatter.writeLine(''); + for (const childType of childTypes) { + const nameOverride = getTypeInterfaceName(childType); + if (childType instanceof Protobuf.Type) { + generatePermissiveMessageInterface(formatter, childType, nameOverride); + formatter.writeLine(''); + generateRestrictedMessageInterface(formatter, childType, options, nameOverride); + } else { + generateEnumInterface(formatter, childType, nameOverride); + } + formatter.writeLine(''); + } generatePermissiveMessageInterface(formatter, messageType); formatter.writeLine(''); generateRestrictedMessageInterface(formatter, messageType, options); } -function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum) { - formatter.writeLine(`export enum ${enumType.name} {`); +function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum, nameOverride?: string) { + formatter.writeLine(`// Original file: ${enumType.filename}`); + formatter.writeLine(''); + formatter.writeLine(`export enum ${nameOverride ?? enumType.name} {`); formatter.indent(); for (const key of Object.keys(enumType.values)) { formatter.writeLine(`${key} = ${enumType.values[key]},`); @@ -302,8 +348,7 @@ function generateMessageAndEnumImports(formatter: TextFormatter, namespace: Prot for (const nested of namespace.nestedArray) { if (nested instanceof Protobuf.Type || nested instanceof Protobuf.Enum) { formatter.writeLine(getImportLine(nested)); - } - if (isNamespaceBase(nested)) { + } else if (isNamespaceBase(nested)) { generateMessageAndEnumImports(formatter, nested); } } @@ -491,14 +536,13 @@ function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: G const fileFormatter = new TextFormatter(); if (nested instanceof Protobuf.Type) { generateMessageInterfaces(fileFormatter, nested, options); - console.log(`Writing ${options.outDir}/${getPath(nested)}`); + 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); - console.log(`Writing ${options.outDir}/${getPath(nested)}`); + console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); - } - if (isNamespaceBase(nested)) { + } else if (isNamespaceBase(nested)) { filePromises.push(...generateFilesForNamespace(nested, options)); } } diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index b84b79779..ac2e84a6b 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre3", + "version": "0.6.0-pre4", "author": "Google Inc.", "contributors": [ { @@ -47,7 +47,7 @@ "lodash.camelcase": "^4.3.0", "long": "^4.0.0", "mkdirp": "^1.0.4", - "protobufjs": "^6.8.6", + "protobufjs": "^6.9.0", "yargs": "^15.3.1" }, "devDependencies": { From 110cb2f1b8950deec8032a69ad130f598ec1e606 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 25 Jun 2020 12:45:46 -0700 Subject: [PATCH 07/45] Export service client interfaces --- packages/proto-loader/bin/proto-loader-gen-types.ts | 12 ++++++++---- packages/proto-loader/package.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 9f9e0bd66..cfb5bd5b2 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -372,7 +372,7 @@ function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Prot } function generateServiceClientInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { - formatter.writeLine(`interface ${serviceType.name}Client extends grpc.Client {`); + formatter.writeLine(`export interface ${serviceType.name}Client extends grpc.Client {`); formatter.indent(); for (const methodName of Object.keys(serviceType.methods)) { const method = serviceType.methods[methodName]; @@ -416,7 +416,9 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P formatter.writeLine('}'); } -function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { +function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { + formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); + formatter.indent(); for (const nested of namespace.nestedArray) { if (nested instanceof Protobuf.Service) { generateServiceClientInterface(formatter, nested); @@ -424,11 +426,13 @@ function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: generateAllServiceClientInterfaces(formatter, nested); } } + formatter.unindent(); + formatter.writeLine('}'); } function generateSingleLoadedDefinitionType(formatter: TextFormatter, nested: Protobuf.ReflectionObject) { if (nested instanceof Protobuf.Service) { - formatter.writeLine(`${nested.name}: SubtypeConstructor & { service: ServiceDefinition }`) + formatter.writeLine(`${nested.name}: SubtypeConstructor & { service: ServiceDefinition }`) } else if (nested instanceof Protobuf.Enum) { formatter.writeLine(`${nested.name}: EnumTypeDefinition`); } else if (nested instanceof Protobuf.Type) { @@ -503,7 +507,7 @@ function generateMasterFile(formatter: TextFormatter, root: Protobuf.Root, optio generateMessageAndEnumExports(formatter, root, 'messages'); formatter.writeLine(''); - generateAllServiceClientInterfaces(formatter, root); + generateAllServiceClientInterfaces(formatter, root, 'ClientInterfaces'); formatter.writeLine(''); formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index ac2e84a6b..688a41aaf 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre4", + "version": "0.6.0-pre5", "author": "Google Inc.", "contributors": [ { From c6d4ea5a0235592378918ad48a14c545c17ce62c Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 3 Jul 2020 09:22:02 +0100 Subject: [PATCH 08/45] Fix some type issues in the server interface --- packages/proto-loader/bin/proto-loader-gen-types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 9f9e0bd66..177ff4d97 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -461,15 +461,15 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: formatter.writeLine(`${methodName}(call: grpc.ServerDuplexStream<${requestType}, ${responseType}>): void;`); } else { // Client streaming - formatter.writeLine(`${methodName}(call: grpc.ServerReadableStream<${requestType}>, callback: grpc.SendUnaryData<${responseType}>): void;`); + formatter.writeLine(`${methodName}(call: grpc.ServerReadableStream<${requestType}>, callback: grpc.sendUnaryData<${responseType}>): void;`); } } else { if (method.responseStream) { // Server streaming - formatter.writeLine(`${methodName}(call: grpc.ServerWriteableStream<${requestType}, ${responseType}>): void;`); + formatter.writeLine(`${methodName}(call: grpc.ServerWritableStream<${requestType}, ${responseType}>): void;`); } else { // Unary - formatter.writeLine(`${methodName}(call: grpc.ServerUnaryCall<${requestType}>, callback: grpc.SendUnaryData<${responseType}>): void;`); + formatter.writeLine(`${methodName}(call: grpc.ServerUnaryCall<${requestType}, ${responseType}>, callback: grpc.sendUnaryData<${responseType}>): void;`); } } formatter.writeLine(''); From f64599f7edcba42c531a2b8baacc199cc457e769 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 6 Jul 2020 09:03:59 -0700 Subject: [PATCH 09/45] Bump to 0.6.0-pre6 --- packages/proto-loader/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 688a41aaf..0d7512159 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre5", + "version": "0.6.0-pre6", "author": "Google Inc.", "contributors": [ { From e03118d8cba177e476ef68393d6f648e93e48ec1 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 10 Jul 2020 08:46:03 -0700 Subject: [PATCH 10/45] Generate .ts files instead of .d.ts for better handling by tsc --- packages/proto-loader/bin/proto-loader-gen-types.ts | 4 ++-- packages/proto-loader/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index fd81e5db8..551281de0 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -72,7 +72,7 @@ function getImportPath(to: Protobuf.Type | Protobuf.Enum) { } function getPath(to: Protobuf.Type | Protobuf.Enum) { - return stripLeadingPeriod(to.fullName).replace(/\./g, '/') + '.d.ts'; + return stripLeadingPeriod(to.fullName).replace(/\./g, '/') + '.ts'; } function getRelativeImportPath(from: Protobuf.Type, to: Protobuf.Type | Protobuf.Enum) { @@ -600,7 +600,7 @@ async function writeAllFiles(protoFiles: string[], options: GeneratorOptions) { } const loadedRoot = await root.load(filename, options); root.resolveAll(); - writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.d.ts'), options); + writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.ts'), options); } } diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 0d7512159..c7036bb2a 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre6", + "version": "0.6.0-pre7", "author": "Google Inc.", "contributors": [ { From e80d89479e931e2a92db6962028c356b02a51c18 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 10 Jul 2020 12:48:53 -0700 Subject: [PATCH 11/45] Refactor shared code, remove mkdirp, sort some things for stable output, add verbose option --- .../bin/proto-loader-gen-types.ts | 99 +++++++-------- packages/proto-loader/package.json | 1 - packages/proto-loader/src/index.ts | 89 ++------------ packages/proto-loader/src/util.ts | 113 ++++++++++++++++++ 4 files changed, 169 insertions(+), 133 deletions(-) create mode 100644 packages/proto-loader/src/util.ts diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 551281de0..8b12a878a 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -20,16 +20,27 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as mkdirp from 'mkdirp'; import * as Protobuf from 'protobufjs'; import * as yargs from 'yargs'; import camelCase = require('lodash.camelcase'); +import { loadProtosWithOptions, addCommonProtos } from '../src/util'; + +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; + } +} type GeneratorOptions = Protobuf.IParseOptions & Protobuf.IConversionOptions & { includeDirs?: string[]; grpcLib: string; outDir: string; + verbose?: boolean; } class TextFormatter { @@ -278,6 +289,7 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob 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; @@ -345,7 +357,7 @@ function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum } function generateMessageAndEnumImports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { - for (const nested of namespace.nestedArray) { + for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Type || nested instanceof Protobuf.Enum) { formatter.writeLine(getImportLine(nested)); } else if (isNamespaceBase(nested)) { @@ -357,7 +369,7 @@ function generateMessageAndEnumImports(formatter: TextFormatter, namespace: Prot function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); formatter.indent(); - for (const nested of namespace.nestedArray) { + for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Enum || nested instanceof Protobuf.Type) { formatter.writeLine(`export type ${nested.name} = ${getTypeInterfaceName(nested)};`); if (nested instanceof Protobuf.Type) { @@ -374,7 +386,7 @@ function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Prot function generateServiceClientInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { formatter.writeLine(`export interface ${serviceType.name}Client extends grpc.Client {`); formatter.indent(); - for (const methodName of Object.keys(serviceType.methods)) { + for (const methodName of Object.keys(serviceType.methods).sort()) { const method = serviceType.methods[methodName]; for (const name of [methodName, camelCase(methodName)]) { const requestType = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName); @@ -419,7 +431,7 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); formatter.indent(); - for (const nested of namespace.nestedArray) { + for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Service) { generateServiceClientInterface(formatter, nested); } else if (isNamespaceBase(nested)) { @@ -445,7 +457,7 @@ function generateSingleLoadedDefinitionType(formatter: TextFormatter, nested: Pr function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { formatter.writeLine(`${namespace.name}: {`); formatter.indent(); - for (const nested of namespace.nestedArray) { + for (const nested of namespace.nestedArray.sort(compareName)) { generateSingleLoadedDefinitionType(formatter, nested); } formatter.unindent(); @@ -455,7 +467,7 @@ function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Prot function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { formatter.writeLine(`export interface ${serviceType.name} {`); formatter.indent(); - for (const methodName of Object.keys(serviceType.methods)) { + for (const methodName of Object.keys(serviceType.methods).sort()) { const method = serviceType.methods[methodName]; const requestType = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName) + '__Output'; const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName); @@ -485,7 +497,7 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: function generateAllServiceHandlerInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); formatter.indent(); - for (const nested of namespace.nestedArray) { + for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Service) { generateServiceHandlerInterface(formatter, nested); } else if (isNamespaceBase(nested)) { @@ -496,7 +508,7 @@ function generateAllServiceHandlerInterfaces(formatter: TextFormatter, namespace formatter.writeLine('}'); } -function generateMasterFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) { +function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) { formatter.writeLine(`import * as grpc from '${options.grpcLib}';`); formatter.writeLine("import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';"); formatter.writeLine(''); @@ -528,10 +540,9 @@ function generateMasterFile(formatter: TextFormatter, root: Protobuf.Root, optio generateAllServiceHandlerInterfaces(formatter, root, 'ServiceHandlers'); } -function writeFile(filename: string, contents: string): Promise { - return mkdirp(path.dirname(filename)).then( - () => fs.promises.writeFile(filename, contents) - ); +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[] { @@ -540,11 +551,15 @@ function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: G const fileFormatter = new TextFormatter(); if (nested instanceof Protobuf.Type) { generateMessageInterfaces(fileFormatter, nested, options); - console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); + 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); - console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); + 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)); @@ -557,8 +572,10 @@ function writeFilesForRoot(root: Protobuf.Root, masterFileName: string, options: const filePromises: Promise[] = []; const masterFileFormatter = new TextFormatter(); - generateMasterFile(masterFileFormatter, root, options); - console.log(`Writing ${options.outDir}/${masterFileName}`); + 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)); @@ -566,40 +583,10 @@ function writeFilesForRoot(root: Protobuf.Root, masterFileName: string, options: return filePromises; } -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); - }; -} - async function writeAllFiles(protoFiles: string[], options: GeneratorOptions) { - await mkdirp(options.outDir); + await fs.promises.mkdir(options.outDir, {recursive: true}); for (const filename of protoFiles) { - console.log(`Processing ${filename}`); - 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 = await root.load(filename, options); - root.resolveAll(); + const loadedRoot = await loadProtosWithOptions(filename, options); writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.ts'), options); } } @@ -609,7 +596,7 @@ function runScript() { .string(['includeDirs', 'grpcLib']) .normalize(['includeDirs', 'outDir']) .array('includeDirs') - .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json']) + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose']) // .choices('longs', ['String', 'Number']) // .choices('enums', ['String']) // .choices('bytes', ['Array', 'String']) @@ -641,7 +628,8 @@ function runScript() { } }).alias({ includeDirs: 'I', - outDir: 'O' + 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', @@ -660,9 +648,14 @@ function runScript() { .usage('$0 [options] filenames...') .epilogue('WARNING: This tool is in alpha. The CLI and generated code are subject to change') .argv; - console.log(argv); + if (argv.verbose) { + console.log('Parsed arguments:', argv); + } + addCommonProtos(); writeAllFiles(argv._, argv).then(() => { - console.log('Success'); + if (argv.verbose) { + console.log('Success'); + } }, (error) => { throw error; }) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index c7036bb2a..cba1fa556 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -46,7 +46,6 @@ "@types/long": "^4.0.1", "lodash.camelcase": "^4.3.0", "long": "^4.0.0", - "mkdirp": "^1.0.4", "protobufjs": "^6.9.0", "yargs": "^15.3.1" }, diff --git a/packages/proto-loader/src/index.ts b/packages/proto-loader/src/index.ts index 03c9512aa..a830ac3eb 100644 --- a/packages/proto-loader/src/index.ts +++ b/packages/proto-loader/src/index.ts @@ -15,11 +15,13 @@ * 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 { loadProtosWithOptionsSync, loadProtosWithOptions, Options, addCommonProtos } from './util'; + export { Long } from 'long'; /** @@ -55,8 +57,6 @@ export function isAnyExtension(obj: object): obj is AnyExtension { return ('@type' in obj) && (typeof (obj as AnyExtension)['@type'] === 'string'); } -import camelCase = require('lodash.camelcase'); - declare module 'protobufjs' { interface Type { toDescriptor( @@ -128,10 +128,7 @@ export interface PackageDefinition { [index: string]: AnyDefinition; } -export type Options = Protobuf.IParseOptions & - Protobuf.IConversionOptions & { - includeDirs?: string[]; - }; +export { Options }; const descriptorOptions: Protobuf.IConversionOptions = { longs: String, @@ -322,26 +319,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); - }; -} - /** * Load a .proto file with the specified options. * @param filename One or multiple file paths to load. Can be an absolute path @@ -372,19 +349,8 @@ 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!); }); } @@ -392,43 +358,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!); } -// 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 From e14667207e2b009b849f27876d029f02a8a4fd02 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 10 Jul 2020 12:49:37 -0700 Subject: [PATCH 12/45] Bump prerelease version again --- packages/proto-loader/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index cba1fa556..eda794253 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre7", + "version": "0.6.0-pre8", "author": "Google Inc.", "contributors": [ { From 8e6dae7bb768b5d8125ab021c2a0112818bc00ee Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Fri, 10 Jul 2020 14:14:24 -0700 Subject: [PATCH 13/45] Add option to generate comments --- .../bin/proto-loader-gen-types.ts | 137 +++++++++++++----- packages/proto-loader/package.json | 2 +- 2 files changed, 100 insertions(+), 39 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 8b12a878a..ea035d6cd 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -26,21 +26,12 @@ import * as yargs from 'yargs'; import camelCase = require('lodash.camelcase'); import { loadProtosWithOptions, addCommonProtos } from '../src/util'; -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; - } -} - type GeneratorOptions = Protobuf.IParseOptions & Protobuf.IConversionOptions & { includeDirs?: string[]; grpcLib: string; outDir: string; verbose?: boolean; + includeComments?: boolean; } class TextFormatter { @@ -70,6 +61,18 @@ class TextFormatter { } } +// 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); } @@ -119,7 +122,23 @@ function getChildMessagesAndEnums(namespace: Protobuf.NamespaceBase): (Protobuf. return messageList; } -function generatePermissiveMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, nameOverride?: string) { +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 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 */ @@ -173,17 +192,26 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp type = `${typeInterfaceName} | keyof typeof ${typeInterfaceName}`; } } + 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 generateRestrictedMessageInterface(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions, nameOverride?: string) { +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 */ @@ -271,11 +299,17 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp fieldGuaranteed = false; } const optionalString = fieldGuaranteed ? '' : '?'; + 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};`); } } @@ -283,7 +317,7 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp formatter.writeLine('}'); } -function generateMessageInterfaces(formatter: TextFormatter, messageType: Protobuf.Type, options: Protobuf.IConversionOptions) { +function generateMessageInterfaces(formatter: TextFormatter, messageType: Protobuf.Type, options: GeneratorOptions) { let usesLong: boolean = false; let seenDeps: Set = new Set(); const childTypes = getChildMessagesAndEnums(messageType); @@ -330,26 +364,32 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob for (const childType of childTypes) { const nameOverride = getTypeInterfaceName(childType); if (childType instanceof Protobuf.Type) { - generatePermissiveMessageInterface(formatter, childType, nameOverride); + generatePermissiveMessageInterface(formatter, childType, options, nameOverride); formatter.writeLine(''); generateRestrictedMessageInterface(formatter, childType, options, nameOverride); } else { - generateEnumInterface(formatter, childType, nameOverride); + generateEnumInterface(formatter, childType, options, nameOverride); } formatter.writeLine(''); } - generatePermissiveMessageInterface(formatter, messageType); + generatePermissiveMessageInterface(formatter, messageType, options); formatter.writeLine(''); generateRestrictedMessageInterface(formatter, messageType, options); } -function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum, nameOverride?: string) { +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(); @@ -366,29 +406,41 @@ function generateMessageAndEnumImports(formatter: TextFormatter, namespace: Prot } } -function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { +function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions, nameOverride?: string) { formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); formatter.indent(); for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Enum || nested instanceof Protobuf.Type) { + if (options.includeComments) { + formatComment(formatter, nested.comment); + } formatter.writeLine(`export type ${nested.name} = ${getTypeInterfaceName(nested)};`); if (nested instanceof Protobuf.Type) { + if (options.includeComments) { + formatComment(formatter, nested.comment); + } formatter.writeLine(`export type ${nested.name}__Output = ${getTypeInterfaceName(nested)}__Output;`); } } else if (isNamespaceBase(nested)) { - generateMessageAndEnumExports(formatter, nested); + generateMessageAndEnumExports(formatter, nested, options); } } formatter.unindent(); formatter.writeLine('}'); } -function generateServiceClientInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { +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 = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName); const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName) + '__Output'; const callbackType = `(error?: grpc.ServiceError, result?: ${responseType}) => void`; @@ -428,47 +480,56 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P formatter.writeLine('}'); } -function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { +function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions, nameOverride?: string) { formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); formatter.indent(); for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Service) { - generateServiceClientInterface(formatter, nested); + generateServiceClientInterface(formatter, nested, options); } else if (isNamespaceBase(nested)) { - generateAllServiceClientInterfaces(formatter, nested); + generateAllServiceClientInterfaces(formatter, nested, options); } } formatter.unindent(); formatter.writeLine('}'); } -function generateSingleLoadedDefinitionType(formatter: TextFormatter, nested: Protobuf.ReflectionObject) { +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); + generateLoadedDefinitionTypes(formatter, nested, options); } } -function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { +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); + generateSingleLoadedDefinitionType(formatter, nested, options); } formatter.unindent(); formatter.writeLine('}'); } -function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: Protobuf.Service) { +function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: Protobuf.Service, options: GeneratorOptions) { + if (options.includeComments) { + formatComment(formatter, serviceType.comment); + } formatter.writeLine(`export interface ${serviceType.name} {`); 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 = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName) + '__Output'; const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName); if (method.requestStream) { @@ -494,14 +555,14 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: formatter.writeLine('}'); } -function generateAllServiceHandlerInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, nameOverride?: string) { +function generateAllServiceHandlerInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions, nameOverride?: string) { formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); formatter.indent(); for (const nested of namespace.nestedArray.sort(compareName)) { if (nested instanceof Protobuf.Service) { - generateServiceHandlerInterface(formatter, nested); + generateServiceHandlerInterface(formatter, nested, options); } else if (isNamespaceBase(nested)) { - generateAllServiceHandlerInterfaces(formatter, nested); + generateAllServiceHandlerInterfaces(formatter, nested, options); } } formatter.unindent(); @@ -516,10 +577,10 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options generateMessageAndEnumImports(formatter, root); formatter.writeLine(''); - generateMessageAndEnumExports(formatter, root, 'messages'); + generateMessageAndEnumExports(formatter, root, options, 'messages'); formatter.writeLine(''); - generateAllServiceClientInterfaces(formatter, root, 'ClientInterfaces'); + generateAllServiceClientInterfaces(formatter, root, options, 'ClientInterfaces'); formatter.writeLine(''); formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); @@ -531,13 +592,13 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options formatter.writeLine('export interface ProtoGrpcType {'); formatter.indent(); for (const nested of root.nestedArray) { - generateSingleLoadedDefinitionType(formatter, nested); + generateSingleLoadedDefinitionType(formatter, nested, options); } formatter.unindent(); formatter.writeLine('}'); formatter.writeLine(''); - generateAllServiceHandlerInterfaces(formatter, root, 'ServiceHandlers'); + generateAllServiceHandlerInterfaces(formatter, root, options, 'ServiceHandlers'); } async function writeFile(filename: string, contents: string): Promise { @@ -556,7 +617,7 @@ function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: G } filePromises.push(writeFile(`${options.outDir}/${getPath(nested)}`, fileFormatter.getFullText())); } else if (nested instanceof Protobuf.Enum) { - generateEnumInterface(fileFormatter, nested); + generateEnumInterface(fileFormatter, nested, options); if (options.verbose) { console.log(`Writing ${options.outDir}/${getPath(nested)} from file ${nested.filename}`); } @@ -596,7 +657,7 @@ function runScript() { .string(['includeDirs', 'grpcLib']) .normalize(['includeDirs', 'outDir']) .array('includeDirs') - .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose']) + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'generateComments']) // .choices('longs', ['String', 'Number']) // .choices('enums', ['String']) // .choices('bytes', ['Array', 'String']) @@ -652,7 +713,7 @@ function runScript() { console.log('Parsed arguments:', argv); } addCommonProtos(); - writeAllFiles(argv._, argv).then(() => { + writeAllFiles(argv._, {...argv, alternateCommentMode: true}).then(() => { if (argv.verbose) { console.log('Success'); } diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index eda794253..3ebcd21b0 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre8", + "version": "0.6.0-pre9", "author": "Google Inc.", "contributors": [ { From cca10597d5707bee1cd4e4a81882e43a4c5ea224 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 13 Jul 2020 13:13:39 -0700 Subject: [PATCH 14/45] Add files for service definitions, remove redundant exports from root files --- .../bin/proto-loader-gen-types.ts | 183 ++++++++---------- packages/proto-loader/package.json | 2 +- 2 files changed, 83 insertions(+), 102 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index ea035d6cd..2fb72436e 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -81,31 +81,44 @@ function stripLeadingPeriod(name: string) { return name.startsWith('.') ? name.substring(1) : name; } -function getImportPath(to: Protobuf.Type | Protobuf.Enum) { +function getImportPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { return stripLeadingPeriod(to.fullName).replace(/\./g, '/'); } -function getPath(to: Protobuf.Type | Protobuf.Enum) { +function getPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { return stripLeadingPeriod(to.fullName).replace(/\./g, '/') + '.ts'; } -function getRelativeImportPath(from: Protobuf.Type, to: Protobuf.Type | Protobuf.Enum) { +function getPathToRoot(from: Protobuf.NamespaceBase) { const depth = stripLeadingPeriod(from.fullName).split('.').length - 1; let path = ''; for (let i = 0; i < depth; i++) { path += '../'; } - return path + getImportPath(to); + return path; } -function getTypeInterfaceName(type: Protobuf.Type | Protobuf.Enum) { +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, from?: Protobuf.Type) { +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); - const importedTypes = dependency instanceof Protobuf.Type ? `${dependency.name} as ${typeInterfaceName}, ${dependency.name}__Output as ${typeInterfaceName}__Output` : `${dependency.name} as ${typeInterfaceName}`; + let importedTypes: string; + 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 { ${importedTypes} } from '${filePath}';` } @@ -361,7 +374,7 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob formatter.writeLine("import { AnyExtension } from '@grpc/proto-loader';") } formatter.writeLine(''); - for (const childType of childTypes) { + for (const childType of childTypes.sort(compareName)) { const nameOverride = getTypeInterfaceName(childType); if (childType instanceof Protobuf.Type) { generatePermissiveMessageInterface(formatter, childType, options, nameOverride); @@ -396,39 +409,6 @@ function generateEnumInterface(formatter: TextFormatter, enumType: Protobuf.Enum formatter.writeLine('}'); } -function generateMessageAndEnumImports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase) { - for (const nested of namespace.nestedArray.sort(compareName)) { - if (nested instanceof Protobuf.Type || nested instanceof Protobuf.Enum) { - formatter.writeLine(getImportLine(nested)); - } else if (isNamespaceBase(nested)) { - generateMessageAndEnumImports(formatter, nested); - } - } -} - -function generateMessageAndEnumExports(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions, nameOverride?: string) { - formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); - formatter.indent(); - for (const nested of namespace.nestedArray.sort(compareName)) { - if (nested instanceof Protobuf.Enum || nested instanceof Protobuf.Type) { - if (options.includeComments) { - formatComment(formatter, nested.comment); - } - formatter.writeLine(`export type ${nested.name} = ${getTypeInterfaceName(nested)};`); - if (nested instanceof Protobuf.Type) { - if (options.includeComments) { - formatComment(formatter, nested.comment); - } - formatter.writeLine(`export type ${nested.name}__Output = ${getTypeInterfaceName(nested)}__Output;`); - } - } else if (isNamespaceBase(nested)) { - generateMessageAndEnumExports(formatter, nested, options); - } - } - formatter.unindent(); - formatter.writeLine('}'); -} - function generateServiceClientInterface(formatter: TextFormatter, serviceType: Protobuf.Service, options: GeneratorOptions) { if (options.includeComments) { formatComment(formatter, serviceType.comment); @@ -441,8 +421,8 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P if (options.includeComments) { formatComment(formatter, method.comment); } - const requestType = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName); - const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName) + '__Output'; + 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) { @@ -480,58 +460,19 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P formatter.writeLine('}'); } -function generateAllServiceClientInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions, nameOverride?: string) { - formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); - formatter.indent(); - for (const nested of namespace.nestedArray.sort(compareName)) { - if (nested instanceof Protobuf.Service) { - generateServiceClientInterface(formatter, nested, options); - } else if (isNamespaceBase(nested)) { - generateAllServiceClientInterfaces(formatter, nested, options); - } - } - formatter.unindent(); - formatter.writeLine('}'); -} - -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 generateServiceHandlerInterface(formatter: TextFormatter, serviceType: Protobuf.Service, options: GeneratorOptions) { if (options.includeComments) { formatComment(formatter, serviceType.comment); } - formatter.writeLine(`export interface ${serviceType.name} {`); + formatter.writeLine(`export interface ${serviceType.name}Handlers {`); 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 = 'messages.' + stripLeadingPeriod(method.resolvedRequestType!.fullName) + '__Output'; - const responseType = 'messages.' + stripLeadingPeriod(method.resolvedResponseType!.fullName); + const requestType = getTypeInterfaceName(method.resolvedRequestType!); + const responseType = getTypeInterfaceName(method.resolvedResponseType!) + '__Output'; if (method.requestStream) { if (method.responseStream) { // Bidi streaming @@ -555,15 +496,57 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: formatter.writeLine('}'); } -function generateAllServiceHandlerInterfaces(formatter: TextFormatter, namespace: Protobuf.NamespaceBase, options: GeneratorOptions, nameOverride?: string) { - formatter.writeLine(`export namespace ${nameOverride ?? namespace.name} {`); - formatter.indent(); +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 * 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) { - generateServiceHandlerInterface(formatter, nested, options); - } else if (isNamespaceBase(nested)) { - generateAllServiceHandlerInterfaces(formatter, nested, options); + 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('}'); @@ -573,14 +556,8 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options formatter.writeLine(`import * as grpc from '${options.grpcLib}';`); formatter.writeLine("import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';"); formatter.writeLine(''); - - generateMessageAndEnumImports(formatter, root); - formatter.writeLine(''); - - generateMessageAndEnumExports(formatter, root, options, 'messages'); - formatter.writeLine(''); - - generateAllServiceClientInterfaces(formatter, root, options, 'ClientInterfaces'); + + generateServiceImports(formatter, root, options); formatter.writeLine(''); formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); @@ -597,8 +574,6 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options formatter.unindent(); formatter.writeLine('}'); formatter.writeLine(''); - - generateAllServiceHandlerInterfaces(formatter, root, options, 'ServiceHandlers'); } async function writeFile(filename: string, contents: string): Promise { @@ -622,6 +597,12 @@ function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: G 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)); } diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 3ebcd21b0..26b97d07e 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre9", + "version": "0.6.0-pre10", "author": "Google Inc.", "contributors": [ { From 4963b0d9f8f0eda7025cf70ac0cc07bcb857bbb0 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 20 Jul 2020 14:06:42 -0700 Subject: [PATCH 15/45] Update protobufjs dependency to ^6.10.0 --- packages/proto-loader/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 26b97d07e..22e28f73f 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -46,7 +46,7 @@ "@types/long": "^4.0.1", "lodash.camelcase": "^4.3.0", "long": "^4.0.0", - "protobufjs": "^6.9.0", + "protobufjs": "^6.10.0", "yargs": "^15.3.1" }, "devDependencies": { From b96cb3b8cc89d6494174a9f51dba280d778512f2 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 20 Jul 2020 14:26:38 -0700 Subject: [PATCH 16/45] Make messages always optional, fix map type generation --- .../bin/proto-loader-gen-types.ts | 255 +++++++++--------- packages/proto-loader/package.json | 2 +- 2 files changed, 136 insertions(+), 121 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 2fb72436e..23ac5f841 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -148,6 +148,52 @@ function formatComment(formatter: TextFormatter, comment?: string | null) { // 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); @@ -165,46 +211,7 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp formatter.indent(); for (const field of messageType.fieldsArray) { const repeatedString = field.repeated ? '[]' : ''; - let type: string; - switch (field.type) { - case 'double': - case 'float': - type = 'number | string'; - break; - case 'int32': - case 'uint32': - case 'sint32': - case 'fixed32': - case 'sfixed32': - type = 'number'; - break; - case 'int64': - case 'uint64': - case 'sint64': - case 'fixed64': - case 'sfixed64': - type = 'number | string | Long'; - break; - case 'bool': - type = 'boolean'; - break; - case 'string': - type = 'string'; - break; - case 'bytes': - type = 'Buffer | Uint8Array | string'; - break; - default: - if (field.resolvedType === null) { - throw new Error('Found field with no usable type'); - } - const typeInterfaceName = getTypeInterfaceName(field.resolvedType); - if (field.resolvedType instanceof Protobuf.Type) { - type = typeInterfaceName; - } else { - type = `${typeInterfaceName} | keyof typeof ${typeInterfaceName}`; - } - } + const type: string = getFieldTypePermissive(field); if (options.includeComments) { formatComment(formatter, field.comment); } @@ -221,6 +228,72 @@ function generatePermissiveMessageInterface(formatter: TextFormatter, messageTyp 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); @@ -228,90 +301,39 @@ function generateRestrictedMessageInterface(formatter: TextFormatter, messageTyp 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: string;'); - let type: string; - if (options.bytes === Array) { - type = 'Uint8Array'; - } else if (options.bytes === String) { - type = 'string'; - } else { - type = 'Buffer'; - } - formatter.writeLine(` value: ${type};`); + 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) { - const repeatedString = field.repeated ? '[]' : ''; - let fieldGuaranteed = options.defaults || (field.repeated && options.arrays); - let type: string; - switch (field.type) { - case 'double': - case 'float': - if (options.json) { - type = 'number | string'; - } else { - type = 'number'; - } - break; - case 'int32': - case 'uint32': - case 'sint32': - case 'fixed32': - case 'sfixed32': - type = 'number'; - break; - case 'int64': - case 'uint64': - case 'sint64': - case 'fixed64': - case 'sfixed64': - if (options.longs === Number) { - type = 'number'; - } else if (options.longs === String) { - type = 'string'; - } else { - type = 'Long'; - } - break; - case 'bool': - type = 'boolean'; - break; - case 'string': - type = 'string'; - break; - case 'bytes': - if (options.bytes === Array) { - type = 'Uint8Array'; - } else if (options.bytes === String) { - type = 'string'; - } else { - type = 'Buffer'; - } - break; - default: - if (field.resolvedType === null) { - throw new Error('Found field with no usable type'); - } - const typeInterfaceName = getTypeInterfaceName(field.resolvedType); - if (field.resolvedType instanceof Protobuf.Type) { - fieldGuaranteed = fieldGuaranteed || options.objects; - type = typeInterfaceName + '__Output'; - } else { - if (options.enums == String) { - type = `keyof typeof ${typeInterfaceName}`; - } else { - type = typeInterfaceName; - } - } - } + 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); } @@ -643,13 +665,6 @@ function runScript() { // .choices('enums', ['String']) // .choices('bytes', ['Array', 'String']) .string(['longs', 'enums', 'bytes']) - .middleware(argv => { - if (argv.longs) { - switch (argv.longs) { - case 'String': argv.longsArg = String; - } - } - }) .coerce('longs', value => { switch (value) { case 'String': return String; diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 22e28f73f..b0897cf6b 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre10", + "version": "0.6.0-pre11", "author": "Google Inc.", "contributors": [ { From 59471863bfd72a06f54f5db4c70684e10aac6d53 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 21 Jul 2020 10:31:19 -0700 Subject: [PATCH 17/45] Add 'golden' generator output from a file in gapic-showcase --- .gitmodules | 6 ++ packages/proto-loader/deps/gapic-showcase | 1 + packages/proto-loader/deps/googleapis | 1 + .../proto-loader/golden-generated/echo.ts | 78 +++++++++++++++++ .../google/api/CustomHttpPattern.ts | 12 +++ .../google/api/FieldBehavior.ts | 10 +++ .../golden-generated/google/api/Http.ts | 13 +++ .../golden-generated/google/api/HttpRule.ts | 32 +++++++ .../longrunning/CancelOperationRequest.ts | 10 +++ .../longrunning/DeleteOperationRequest.ts | 10 +++ .../google/longrunning/GetOperationRequest.ts | 10 +++ .../longrunning/ListOperationsRequest.ts | 16 ++++ .../longrunning/ListOperationsResponse.ts | 13 +++ .../google/longrunning/Operation.ts | 22 +++++ .../google/longrunning/OperationInfo.ts | 12 +++ .../google/longrunning/Operations.ts | 72 +++++++++++++++ .../longrunning/WaitOperationRequest.ts | 13 +++ .../golden-generated/google/protobuf/Any.ts | 13 +++ .../google/protobuf/DescriptorProto.ts | 53 +++++++++++ .../google/protobuf/Duration.ts | 13 +++ .../golden-generated/google/protobuf/Empty.ts | 8 ++ .../google/protobuf/EnumDescriptorProto.ts | 16 ++++ .../google/protobuf/EnumOptions.ts | 15 ++++ .../protobuf/EnumValueDescriptorProto.ts | 15 ++++ .../google/protobuf/EnumValueOptions.ts | 13 +++ .../google/protobuf/FieldDescriptorProto.ts | 60 +++++++++++++ .../google/protobuf/FieldOptions.ts | 42 +++++++++ .../google/protobuf/FileDescriptorProto.ts | 38 ++++++++ .../google/protobuf/FileDescriptorSet.ts | 11 +++ .../google/protobuf/FileOptions.ts | 47 ++++++++++ .../google/protobuf/GeneratedCodeInfo.ts | 24 +++++ .../google/protobuf/MessageOptions.ts | 19 ++++ .../google/protobuf/MethodDescriptorProto.ts | 21 +++++ .../google/protobuf/MethodOptions.ts | 21 +++++ .../google/protobuf/OneofDescriptorProto.ts | 13 +++ .../google/protobuf/OneofOptions.ts | 11 +++ .../google/protobuf/ServiceDescriptorProto.ts | 16 ++++ .../google/protobuf/ServiceOptions.ts | 17 ++++ .../google/protobuf/SourceCodeInfo.ts | 26 ++++++ .../google/protobuf/Timestamp.ts | 13 +++ .../google/protobuf/UninterpretedOption.ts | 33 +++++++ .../golden-generated/google/rpc/Status.ts | 15 ++++ .../google/showcase/v1beta1/BlockRequest.ts | 19 ++++ .../google/showcase/v1beta1/BlockResponse.ts | 10 +++ .../google/showcase/v1beta1/Echo.ts | 87 +++++++++++++++++++ .../google/showcase/v1beta1/EchoRequest.ts | 18 ++++ .../google/showcase/v1beta1/EchoResponse.ts | 13 +++ .../google/showcase/v1beta1/ExpandRequest.ts | 13 +++ .../showcase/v1beta1/PagedExpandRequest.ts | 14 +++ .../showcase/v1beta1/PagedExpandResponse.ts | 13 +++ .../google/showcase/v1beta1/Severity.ts | 8 ++ .../google/showcase/v1beta1/WaitMetadata.ts | 11 +++ .../google/showcase/v1beta1/WaitRequest.ts | 24 +++++ .../google/showcase/v1beta1/WaitResponse.ts | 10 +++ packages/proto-loader/gulpfile.ts | 4 +- packages/proto-loader/package.json | 4 +- 56 files changed, 1150 insertions(+), 2 deletions(-) create mode 160000 packages/proto-loader/deps/gapic-showcase create mode 160000 packages/proto-loader/deps/googleapis create mode 100644 packages/proto-loader/golden-generated/echo.ts create mode 100644 packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts create mode 100644 packages/proto-loader/golden-generated/google/api/FieldBehavior.ts create mode 100644 packages/proto-loader/golden-generated/google/api/Http.ts create mode 100644 packages/proto-loader/golden-generated/google/api/HttpRule.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/Operation.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/Operations.ts create mode 100644 packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/Any.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/Duration.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/Empty.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/GeneratedCodeInfo.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/SourceCodeInfo.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts create mode 100644 packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts create mode 100644 packages/proto-loader/golden-generated/google/rpc/Status.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts create mode 100644 packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts diff --git a/.gitmodules b/.gitmodules index c17c34644..28faf1a38 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,9 @@ [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 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..c5e2bd540 --- /dev/null +++ b/packages/proto-loader/golden-generated/echo.ts @@ -0,0 +1,78 @@ +import * as grpc from '@grpc/grpc-js'; +import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader'; + +import { OperationsClient as _google_longrunning_OperationsClient } from './google/longrunning/Operations'; +import { EchoClient as _google_showcase_v1beta1_EchoClient } from './google/showcase/v1beta1/Echo'; + +type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never; +type SubtypeConstructor = { + new(...args: ConstructorArguments): 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 + 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 + 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..ebdc3e39a --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts @@ -0,0 +1,12 @@ +// Original file: deps/googleapis/google/api/http.proto + + +export interface CustomHttpPattern { + 'kind'?: (string); + 'path'?: (string); +} + +export interface CustomHttpPattern__Output { + 'kind': (string); + '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..5d6ae4cbf --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/FieldBehavior.ts @@ -0,0 +1,10 @@ +// Original file: deps/googleapis/google/api/field_behavior.proto + +export enum FieldBehavior { + FIELD_BEHAVIOR_UNSPECIFIED = 0, + OPTIONAL = 1, + REQUIRED = 2, + OUTPUT_ONLY = 3, + INPUT_ONLY = 4, + 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..fc3839eb1 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/Http.ts @@ -0,0 +1,13 @@ +// Original file: deps/googleapis/google/api/http.proto + +import { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; + +export interface Http { + 'rules'?: (_google_api_HttpRule)[]; + 'fully_decode_reserved_expansion'?: (boolean); +} + +export interface Http__Output { + 'rules': (_google_api_HttpRule__Output)[]; + '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..3b268a026 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/api/HttpRule.ts @@ -0,0 +1,32 @@ +// Original file: deps/googleapis/google/api/http.proto + +import { CustomHttpPattern as _google_api_CustomHttpPattern, CustomHttpPattern__Output as _google_api_CustomHttpPattern__Output } from '../../google/api/CustomHttpPattern'; +import { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; + +export interface HttpRule { + 'selector'?: (string); + 'get'?: (string); + 'put'?: (string); + 'post'?: (string); + 'delete'?: (string); + 'patch'?: (string); + 'body'?: (string); + 'custom'?: (_google_api_CustomHttpPattern); + 'additional_bindings'?: (_google_api_HttpRule)[]; + 'response_body'?: (string); + 'pattern'?: "get"|"put"|"post"|"delete"|"patch"|"custom"; +} + +export interface HttpRule__Output { + 'selector': (string); + 'get'?: (string); + 'put'?: (string); + 'post'?: (string); + 'delete'?: (string); + 'patch'?: (string); + 'body': (string); + 'custom'?: (_google_api_CustomHttpPattern__Output); + 'additional_bindings': (_google_api_HttpRule__Output)[]; + 'response_body': (string); + '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..274c762b5 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts @@ -0,0 +1,10 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +export interface CancelOperationRequest { + 'name'?: (string); +} + +export interface CancelOperationRequest__Output { + '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..43fbebf8d --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts @@ -0,0 +1,10 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +export interface DeleteOperationRequest { + 'name'?: (string); +} + +export interface DeleteOperationRequest__Output { + '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..995426cb0 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts @@ -0,0 +1,10 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +export interface GetOperationRequest { + 'name'?: (string); +} + +export interface GetOperationRequest__Output { + '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..2e8dfcf0e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts @@ -0,0 +1,16 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +export interface ListOperationsRequest { + 'filter'?: (string); + 'page_size'?: (number); + 'page_token'?: (string); + 'name'?: (string); +} + +export interface ListOperationsRequest__Output { + 'filter': (string); + 'page_size': (number); + 'page_token': (string); + '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..a94557fe9 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts @@ -0,0 +1,13 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; + +export interface ListOperationsResponse { + 'operations'?: (_google_longrunning_Operation)[]; + 'next_page_token'?: (string); +} + +export interface ListOperationsResponse__Output { + 'operations': (_google_longrunning_Operation__Output)[]; + '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..3c1c8c88d --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/Operation.ts @@ -0,0 +1,22 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; +import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../google/rpc/Status'; + +export interface Operation { + 'name'?: (string); + 'metadata'?: (_google_protobuf_Any); + 'done'?: (boolean); + 'error'?: (_google_rpc_Status); + 'response'?: (_google_protobuf_Any); + 'result'?: "error"|"response"; +} + +export interface Operation__Output { + 'name': (string); + 'metadata'?: (_google_protobuf_Any__Output); + 'done': (boolean); + 'error'?: (_google_rpc_Status__Output); + 'response'?: (_google_protobuf_Any__Output); + '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..a185e3d6e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts @@ -0,0 +1,12 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + + +export interface OperationInfo { + 'response_type'?: (string); + 'metadata_type'?: (string); +} + +export interface OperationInfo__Output { + 'response_type': (string); + '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..3991739b0 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -0,0 +1,72 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import * as grpc from '@grpc/grpc-js' +import { CancelOperationRequest as _google_longrunning_CancelOperationRequest, CancelOperationRequest__Output as _google_longrunning_CancelOperationRequest__Output } from '../../google/longrunning/CancelOperationRequest'; +import { DeleteOperationRequest as _google_longrunning_DeleteOperationRequest, DeleteOperationRequest__Output as _google_longrunning_DeleteOperationRequest__Output } from '../../google/longrunning/DeleteOperationRequest'; +import { Empty as _google_protobuf_Empty, Empty__Output as _google_protobuf_Empty__Output } from '../../google/protobuf/Empty'; +import { GetOperationRequest as _google_longrunning_GetOperationRequest, GetOperationRequest__Output as _google_longrunning_GetOperationRequest__Output } from '../../google/longrunning/GetOperationRequest'; +import { ListOperationsRequest as _google_longrunning_ListOperationsRequest, ListOperationsRequest__Output as _google_longrunning_ListOperationsRequest__Output } from '../../google/longrunning/ListOperationsRequest'; +import { ListOperationsResponse as _google_longrunning_ListOperationsResponse, ListOperationsResponse__Output as _google_longrunning_ListOperationsResponse__Output } from '../../google/longrunning/ListOperationsResponse'; +import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; +import { WaitOperationRequest as _google_longrunning_WaitOperationRequest, WaitOperationRequest__Output as _google_longrunning_WaitOperationRequest__Output } from '../../google/longrunning/WaitOperationRequest'; + +export interface OperationsClient extends grpc.Client { + 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, 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, 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, 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; + + 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, 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, 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, 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; + + 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, 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, 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, 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; + + 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, 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, 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, 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; + + 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, 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, 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, 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; + +} + +export interface OperationsHandlers { + CancelOperation(call: grpc.ServerUnaryCall<_google_longrunning_CancelOperationRequest, _google_protobuf_Empty__Output>, callback: grpc.sendUnaryData<_google_protobuf_Empty__Output>): void; + + DeleteOperation(call: grpc.ServerUnaryCall<_google_longrunning_DeleteOperationRequest, _google_protobuf_Empty__Output>, callback: grpc.sendUnaryData<_google_protobuf_Empty__Output>): void; + + GetOperation(call: grpc.ServerUnaryCall<_google_longrunning_GetOperationRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + + ListOperations(call: grpc.ServerUnaryCall<_google_longrunning_ListOperationsRequest, _google_longrunning_ListOperationsResponse__Output>, callback: grpc.sendUnaryData<_google_longrunning_ListOperationsResponse__Output>): void; + + WaitOperation(call: grpc.ServerUnaryCall<_google_longrunning_WaitOperationRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + +} 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..ae8364169 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts @@ -0,0 +1,13 @@ +// Original file: deps/googleapis/google/longrunning/operations.proto + +import { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../google/protobuf/Duration'; + +export interface WaitOperationRequest { + 'name'?: (string); + 'timeout'?: (_google_protobuf_Duration); +} + +export interface WaitOperationRequest__Output { + 'name': (string); + '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..b592af4ba --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Any.ts @@ -0,0 +1,13 @@ +// Original file: null + +import { 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..8ab286897 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts @@ -0,0 +1,53 @@ +// Original file: null + +import { FieldDescriptorProto as _google_protobuf_FieldDescriptorProto, FieldDescriptorProto__Output as _google_protobuf_FieldDescriptorProto__Output } from '../../google/protobuf/FieldDescriptorProto'; +import { DescriptorProto as _google_protobuf_DescriptorProto, DescriptorProto__Output as _google_protobuf_DescriptorProto__Output } from '../../google/protobuf/DescriptorProto'; +import { EnumDescriptorProto as _google_protobuf_EnumDescriptorProto, EnumDescriptorProto__Output as _google_protobuf_EnumDescriptorProto__Output } from '../../google/protobuf/EnumDescriptorProto'; +import { MessageOptions as _google_protobuf_MessageOptions, MessageOptions__Output as _google_protobuf_MessageOptions__Output } from '../../google/protobuf/MessageOptions'; +import { 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..78610b80a --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Duration.ts @@ -0,0 +1,13 @@ +// Original file: null + +import { 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..1971fccb0 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts @@ -0,0 +1,16 @@ +// Original file: null + +import { EnumValueDescriptorProto as _google_protobuf_EnumValueDescriptorProto, EnumValueDescriptorProto__Output as _google_protobuf_EnumValueDescriptorProto__Output } from '../../google/protobuf/EnumValueDescriptorProto'; +import { 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..56c8db7df --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts @@ -0,0 +1,15 @@ +// Original file: null + +import { 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..919b7aa38 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts @@ -0,0 +1,15 @@ +// Original file: null + +import { 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..6bbd4951f --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts @@ -0,0 +1,13 @@ +// Original file: null + +import { 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..e0a1f4580 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts @@ -0,0 +1,60 @@ +// Original file: null + +import { 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..ebed365b7 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts @@ -0,0 +1,42 @@ +// Original file: null + +import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import { 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..65315a644 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts @@ -0,0 +1,38 @@ +// Original file: null + +import { DescriptorProto as _google_protobuf_DescriptorProto, DescriptorProto__Output as _google_protobuf_DescriptorProto__Output } from '../../google/protobuf/DescriptorProto'; +import { EnumDescriptorProto as _google_protobuf_EnumDescriptorProto, EnumDescriptorProto__Output as _google_protobuf_EnumDescriptorProto__Output } from '../../google/protobuf/EnumDescriptorProto'; +import { ServiceDescriptorProto as _google_protobuf_ServiceDescriptorProto, ServiceDescriptorProto__Output as _google_protobuf_ServiceDescriptorProto__Output } from '../../google/protobuf/ServiceDescriptorProto'; +import { FieldDescriptorProto as _google_protobuf_FieldDescriptorProto, FieldDescriptorProto__Output as _google_protobuf_FieldDescriptorProto__Output } from '../../google/protobuf/FieldDescriptorProto'; +import { FileOptions as _google_protobuf_FileOptions, FileOptions__Output as _google_protobuf_FileOptions__Output } from '../../google/protobuf/FileOptions'; +import { 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..f01cabc4c --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts @@ -0,0 +1,11 @@ +// Original file: null + +import { 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..5a1d270c5 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts @@ -0,0 +1,47 @@ +// Original file: null + +import { 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..40bf29272 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts @@ -0,0 +1,19 @@ +// Original file: null + +import { 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..b62d45731 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts @@ -0,0 +1,21 @@ +// Original file: null + +import { 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..7a4943367 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts @@ -0,0 +1,21 @@ +// Original file: null + +import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import { OperationInfo as _google_longrunning_OperationInfo, OperationInfo__Output as _google_longrunning_OperationInfo__Output } from '../../google/longrunning/OperationInfo'; +import { 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..5d1512003 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts @@ -0,0 +1,13 @@ +// Original file: null + +import { 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..02353a0a4 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts @@ -0,0 +1,11 @@ +// Original file: null + +import { 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..fe5cab5b4 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts @@ -0,0 +1,16 @@ +// Original file: null + +import { MethodDescriptorProto as _google_protobuf_MethodDescriptorProto, MethodDescriptorProto__Output as _google_protobuf_MethodDescriptorProto__Output } from '../../google/protobuf/MethodDescriptorProto'; +import { 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..7754279c5 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts @@ -0,0 +1,17 @@ +// Original file: null + +import { 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..f8747e93e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts @@ -0,0 +1,13 @@ +// Original file: null + +import { 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..91e3b99bc --- /dev/null +++ b/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts @@ -0,0 +1,33 @@ +// Original file: null + +import { 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..f1d6ecbcf --- /dev/null +++ b/packages/proto-loader/golden-generated/google/rpc/Status.ts @@ -0,0 +1,15 @@ +// Original file: deps/googleapis/google/rpc/status.proto + +import { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; + +export interface Status { + 'code'?: (number); + 'message'?: (string); + 'details'?: (_google_protobuf_Any)[]; +} + +export interface Status__Output { + 'code': (number); + 'message': (string); + '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..8c3bf3e7e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts @@ -0,0 +1,19 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; +import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +import { BlockResponse as _google_showcase_v1beta1_BlockResponse, BlockResponse__Output as _google_showcase_v1beta1_BlockResponse__Output } from '../../../google/showcase/v1beta1/BlockResponse'; + +export interface BlockRequest { + 'response_delay'?: (_google_protobuf_Duration); + 'error'?: (_google_rpc_Status); + 'success'?: (_google_showcase_v1beta1_BlockResponse); + 'response'?: "error"|"success"; +} + +export interface BlockRequest__Output { + 'response_delay'?: (_google_protobuf_Duration__Output); + 'error'?: (_google_rpc_Status__Output); + '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..b328154fc --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts @@ -0,0 +1,10 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + + +export interface BlockResponse { + 'content'?: (string); +} + +export interface BlockResponse__Output { + '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..d9d7eaf79 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -0,0 +1,87 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import * as grpc from '@grpc/grpc-js' +import { BlockRequest as _google_showcase_v1beta1_BlockRequest, BlockRequest__Output as _google_showcase_v1beta1_BlockRequest__Output } from '../../../google/showcase/v1beta1/BlockRequest'; +import { BlockResponse as _google_showcase_v1beta1_BlockResponse, BlockResponse__Output as _google_showcase_v1beta1_BlockResponse__Output } from '../../../google/showcase/v1beta1/BlockResponse'; +import { EchoRequest as _google_showcase_v1beta1_EchoRequest, EchoRequest__Output as _google_showcase_v1beta1_EchoRequest__Output } from '../../../google/showcase/v1beta1/EchoRequest'; +import { EchoResponse as _google_showcase_v1beta1_EchoResponse, EchoResponse__Output as _google_showcase_v1beta1_EchoResponse__Output } from '../../../google/showcase/v1beta1/EchoResponse'; +import { ExpandRequest as _google_showcase_v1beta1_ExpandRequest, ExpandRequest__Output as _google_showcase_v1beta1_ExpandRequest__Output } from '../../../google/showcase/v1beta1/ExpandRequest'; +import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../../google/longrunning/Operation'; +import { PagedExpandRequest as _google_showcase_v1beta1_PagedExpandRequest, PagedExpandRequest__Output as _google_showcase_v1beta1_PagedExpandRequest__Output } from '../../../google/showcase/v1beta1/PagedExpandRequest'; +import { PagedExpandResponse as _google_showcase_v1beta1_PagedExpandResponse, PagedExpandResponse__Output as _google_showcase_v1beta1_PagedExpandResponse__Output } from '../../../google/showcase/v1beta1/PagedExpandResponse'; +import { WaitRequest as _google_showcase_v1beta1_WaitRequest, WaitRequest__Output as _google_showcase_v1beta1_WaitRequest__Output } from '../../../google/showcase/v1beta1/WaitRequest'; + +export interface EchoClient extends grpc.Client { + 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, 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, 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, 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; + + 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>; + 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>; + + Collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + Collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + + 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, 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, 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, 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; + + 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>; + 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>; + + 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, 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, 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, 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; + + 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, 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, 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, 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; + +} + +export interface EchoHandlers { + Block(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_BlockRequest, _google_showcase_v1beta1_BlockResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_BlockResponse__Output>): void; + + Chat(call: grpc.ServerDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>): void; + + Collect(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse__Output>): void; + + Echo(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse__Output>): void; + + Expand(call: grpc.ServerWritableStream<_google_showcase_v1beta1_ExpandRequest, _google_showcase_v1beta1_EchoResponse__Output>): void; + + PagedExpand(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_PagedExpandRequest, _google_showcase_v1beta1_PagedExpandResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_PagedExpandResponse__Output>): void; + + Wait(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_WaitRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + +} 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..242c4c487 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts @@ -0,0 +1,18 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +import { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; + +export interface EchoRequest { + 'content'?: (string); + 'error'?: (_google_rpc_Status); + 'severity'?: (_google_showcase_v1beta1_Severity | keyof typeof _google_showcase_v1beta1_Severity); + 'response'?: "content"|"error"; +} + +export interface EchoRequest__Output { + 'content'?: (string); + 'error'?: (_google_rpc_Status__Output); + '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..2297bad57 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts @@ -0,0 +1,13 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; + +export interface EchoResponse { + 'content'?: (string); + 'severity'?: (_google_showcase_v1beta1_Severity | keyof typeof _google_showcase_v1beta1_Severity); +} + +export interface EchoResponse__Output { + 'content': (string); + '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..29acdeb34 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts @@ -0,0 +1,13 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; + +export interface ExpandRequest { + 'content'?: (string); + 'error'?: (_google_rpc_Status); +} + +export interface ExpandRequest__Output { + 'content': (string); + '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..9a6dca3ae --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts @@ -0,0 +1,14 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + + +export interface PagedExpandRequest { + 'content'?: (string); + 'page_size'?: (number); + 'page_token'?: (string); +} + +export interface PagedExpandRequest__Output { + 'content': (string); + 'page_size': (number); + '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..e784165a6 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts @@ -0,0 +1,13 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { EchoResponse as _google_showcase_v1beta1_EchoResponse, EchoResponse__Output as _google_showcase_v1beta1_EchoResponse__Output } from '../../../google/showcase/v1beta1/EchoResponse'; + +export interface PagedExpandResponse { + 'responses'?: (_google_showcase_v1beta1_EchoResponse)[]; + 'next_page_token'?: (string); +} + +export interface PagedExpandResponse__Output { + 'responses': (_google_showcase_v1beta1_EchoResponse__Output)[]; + '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..2cd0ea19f --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts @@ -0,0 +1,8 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +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..848f38d8e --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts @@ -0,0 +1,11 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; + +export interface WaitMetadata { + 'end_time'?: (_google_protobuf_Timestamp); +} + +export interface WaitMetadata__Output { + '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..e44c77b8b --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts @@ -0,0 +1,24 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + +import { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; +import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +import { WaitResponse as _google_showcase_v1beta1_WaitResponse, WaitResponse__Output as _google_showcase_v1beta1_WaitResponse__Output } from '../../../google/showcase/v1beta1/WaitResponse'; +import { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; + +export interface WaitRequest { + 'end_time'?: (_google_protobuf_Timestamp); + 'error'?: (_google_rpc_Status); + 'success'?: (_google_showcase_v1beta1_WaitResponse); + 'ttl'?: (_google_protobuf_Duration); + 'end'?: "end_time"|"ttl"; + 'response'?: "error"|"success"; +} + +export interface WaitRequest__Output { + 'end_time'?: (_google_protobuf_Timestamp__Output); + 'error'?: (_google_rpc_Status__Output); + 'success'?: (_google_showcase_v1beta1_WaitResponse__Output); + '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..a08d8b299 --- /dev/null +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts @@ -0,0 +1,10 @@ +// Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto + + +export interface WaitResponse { + 'content'?: (string); +} + +export interface WaitResponse__Output { + 'content': (string); +} diff --git a/packages/proto-loader/gulpfile.ts b/packages/proto-loader/gulpfile.ts index ff8f08552..1b27eaa84 100644 --- a/packages/proto-loader/gulpfile.ts +++ b/packages/proto-loader/gulpfile.ts @@ -69,7 +69,9 @@ const runTests = () => { } } -const test = gulp.series(install, runTests); +const testGeneratorGolden = () => execNpmCommand('validate-golden'); + +const test = gulp.series(install, runTests, testGeneratorGolden); export { install, diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index b0897cf6b..25a0dd1cf 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -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 -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", From 8438fc7a12d4f2d936dc6634931dd1f2dd14d2e4 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 21 Jul 2020 13:25:43 -0700 Subject: [PATCH 18/45] Fix golden file test --- packages/proto-loader/gulpfile.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/proto-loader/gulpfile.ts b/packages/proto-loader/gulpfile.ts index 1b27eaa84..60a843416 100644 --- a/packages/proto-loader/gulpfile.ts +++ b/packages/proto-loader/gulpfile.ts @@ -69,7 +69,11 @@ const runTests = () => { } } -const testGeneratorGolden = () => execNpmCommand('validate-golden'); +const testGeneratorGolden = () => { + if (semver.satisfies(process.version, ">=10")) { + return execNpmCommand('validate-golden'); + } +} const test = gulp.series(install, runTests, testGeneratorGolden); From 437f5349309925b76aaab7563fdc36c53941ed7e Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 21 Jul 2020 13:43:30 -0700 Subject: [PATCH 19/45] Generate comments in golden files --- .../bin/proto-loader-gen-types.ts | 3 +- .../proto-loader/golden-generated/echo.ts | 18 + .../google/api/CustomHttpPattern.ts | 18 + .../google/api/FieldBehavior.ts | 37 + .../golden-generated/google/api/Http.ts | 36 + .../golden-generated/google/api/HttpRule.ts | 648 ++++++++++++++++++ .../longrunning/CancelOperationRequest.ts | 12 + .../longrunning/DeleteOperationRequest.ts | 12 + .../google/longrunning/GetOperationRequest.ts | 12 + .../longrunning/ListOperationsRequest.ts | 30 + .../longrunning/ListOperationsResponse.ts | 18 + .../google/longrunning/Operation.ts | 76 ++ .../google/longrunning/OperationInfo.ts | 64 ++ .../google/longrunning/Operations.ts | 160 +++++ .../longrunning/WaitOperationRequest.ts | 22 + .../golden-generated/google/rpc/Status.ts | 42 ++ .../google/showcase/v1beta1/BlockRequest.ts | 26 + .../google/showcase/v1beta1/BlockResponse.ts | 14 + .../google/showcase/v1beta1/Echo.ts | 104 +++ .../google/showcase/v1beta1/EchoRequest.ts | 30 + .../google/showcase/v1beta1/EchoResponse.ts | 18 + .../google/showcase/v1beta1/ExpandRequest.ts | 18 + .../showcase/v1beta1/PagedExpandRequest.ts | 24 + .../showcase/v1beta1/PagedExpandResponse.ts | 18 + .../google/showcase/v1beta1/Severity.ts | 3 + .../google/showcase/v1beta1/WaitMetadata.ts | 12 + .../google/showcase/v1beta1/WaitRequest.ts | 32 + .../google/showcase/v1beta1/WaitResponse.ts | 12 + packages/proto-loader/package.json | 2 +- 29 files changed, 1519 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 23ac5f841..74e95ac52 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -660,7 +660,7 @@ function runScript() { .string(['includeDirs', 'grpcLib']) .normalize(['includeDirs', 'outDir']) .array('includeDirs') - .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'generateComments']) + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'includeComments']) // .choices('longs', ['String', 'Number']) // .choices('enums', ['String']) // .choices('bytes', ['Array', 'String']) @@ -697,6 +697,7 @@ function runScript() { 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' diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts index c5e2bd540..f4b07e5a2 100644 --- a/packages/proto-loader/golden-generated/echo.ts +++ b/packages/proto-loader/golden-generated/echo.ts @@ -25,6 +25,17 @@ export interface ProtoGrpcType { 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 } @@ -61,6 +72,13 @@ export interface ProtoGrpcType { 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 diff --git a/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts b/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts index ebdc3e39a..2b6490be6 100644 --- a/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts +++ b/packages/proto-loader/golden-generated/google/api/CustomHttpPattern.ts @@ -1,12 +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 index 5d6ae4cbf..8ab676709 100644 --- a/packages/proto-loader/golden-generated/google/api/FieldBehavior.ts +++ b/packages/proto-loader/golden-generated/google/api/FieldBehavior.ts @@ -1,10 +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 index fc3839eb1..038c57e5e 100644 --- a/packages/proto-loader/golden-generated/google/api/Http.ts +++ b/packages/proto-loader/golden-generated/google/api/Http.ts @@ -2,12 +2,48 @@ import { 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 index 3b268a026..ed9921e5e 100644 --- a/packages/proto-loader/golden-generated/google/api/HttpRule.ts +++ b/packages/proto-loader/golden-generated/google/api/HttpRule.ts @@ -3,30 +3,678 @@ import { CustomHttpPattern as _google_api_CustomHttpPattern, CustomHttpPattern__Output as _google_api_CustomHttpPattern__Output } from '../../google/api/CustomHttpPattern'; import { 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 index 274c762b5..05fbc842e 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/CancelOperationRequest.ts @@ -1,10 +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 index 43fbebf8d..0ad87cde9 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/DeleteOperationRequest.ts @@ -1,10 +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 index 995426cb0..039f01674 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/GetOperationRequest.ts @@ -1,10 +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 index 2e8dfcf0e..294ec6773 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsRequest.ts @@ -1,16 +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 index a94557fe9..4d893c45f 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts @@ -2,12 +2,30 @@ import { 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 index 3c1c8c88d..095b77799 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operation.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operation.ts @@ -3,20 +3,96 @@ import { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; import { 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 index a185e3d6e..343e2f8c9 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/OperationInfo.ts @@ -1,12 +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 index 3991739b0..64cc32ba9 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -10,47 +10,150 @@ import { ListOperationsResponse as _google_longrunning_ListOperationsResponse, L import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; import { 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; @@ -58,15 +161,72 @@ export interface OperationsClient extends grpc.Client { } +/** + * 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 { + /** + * 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(call: grpc.ServerUnaryCall<_google_longrunning_CancelOperationRequest, _google_protobuf_Empty__Output>, callback: grpc.sendUnaryData<_google_protobuf_Empty__Output>): void; + /** + * 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(call: grpc.ServerUnaryCall<_google_longrunning_DeleteOperationRequest, _google_protobuf_Empty__Output>, callback: grpc.sendUnaryData<_google_protobuf_Empty__Output>): void; + /** + * 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(call: grpc.ServerUnaryCall<_google_longrunning_GetOperationRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + /** + * 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(call: grpc.ServerUnaryCall<_google_longrunning_ListOperationsRequest, _google_longrunning_ListOperationsResponse__Output>, callback: grpc.sendUnaryData<_google_longrunning_ListOperationsResponse__Output>): void; + /** + * 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(call: grpc.ServerUnaryCall<_google_longrunning_WaitOperationRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; } diff --git a/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts index ae8364169..865e180cf 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts @@ -2,12 +2,34 @@ import { 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/rpc/Status.ts b/packages/proto-loader/golden-generated/google/rpc/Status.ts index f1d6ecbcf..7da370379 100644 --- a/packages/proto-loader/golden-generated/google/rpc/Status.ts +++ b/packages/proto-loader/golden-generated/google/rpc/Status.ts @@ -2,14 +2,56 @@ import { 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 index 8c3bf3e7e..39cde368c 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts @@ -4,16 +4,42 @@ import { Duration as _google_protobuf_Duration, Duration__Output as _google_prot import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; import { 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 index b328154fc..5634b19d4 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockResponse.ts @@ -1,10 +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 index d9d7eaf79..e518665d5 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -11,57 +11,124 @@ import { PagedExpandRequest as _google_showcase_v1beta1_PagedExpandRequest, Page import { PagedExpandResponse as _google_showcase_v1beta1_PagedExpandResponse, PagedExpandResponse__Output as _google_showcase_v1beta1_PagedExpandResponse__Output } from '../../../google/showcase/v1beta1/PagedExpandResponse'; import { 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, 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; + /** + * 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, 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; + /** + * 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_EchoResponse__Output>; Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; Collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_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_EchoResponse__Output>; collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, 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; + /** + * 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, metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_longrunning_Operation__Output) => void): grpc.ClientUnaryCall; @@ -69,19 +136,56 @@ export interface EchoClient extends grpc.Client { } +/** + * 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 { + /** + * 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(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_BlockRequest, _google_showcase_v1beta1_BlockResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_BlockResponse__Output>): void; + /** + * 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(call: grpc.ServerDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>): void; + /** + * 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(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse__Output>): void; + /** + * This method simply echos the request. This method is showcases unary rpcs. + */ Echo(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse__Output>): void; + /** + * 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(call: grpc.ServerWritableStream<_google_showcase_v1beta1_ExpandRequest, _google_showcase_v1beta1_EchoResponse__Output>): void; + /** + * 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(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_PagedExpandRequest, _google_showcase_v1beta1_PagedExpandResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_PagedExpandResponse__Output>): void; + /** + * This method will wait the requested amount of and then return. + * This method showcases how a client handles a request timing out. + */ Wait(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_WaitRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; } diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts index 242c4c487..c5060cdfd 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts @@ -3,16 +3,46 @@ import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; import { 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 index 2297bad57..97028b22a 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts @@ -2,12 +2,30 @@ import { 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 index 29acdeb34..8db54519d 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts @@ -2,12 +2,30 @@ import { 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 index 9a6dca3ae..13c945134 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandRequest.ts @@ -1,14 +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 index e784165a6..4c37e4401 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts @@ -2,12 +2,30 @@ import { 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 index 2cd0ea19f..fc3fe6415 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Severity.ts @@ -1,5 +1,8 @@ // 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, diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts index 848f38d8e..481d38412 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts @@ -2,10 +2,22 @@ import { 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 index e44c77b8b..fe6081203 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts @@ -5,19 +5,51 @@ import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Out import { WaitResponse as _google_showcase_v1beta1_WaitResponse, WaitResponse__Output as _google_showcase_v1beta1_WaitResponse__Output } from '../../../google/showcase/v1beta1/WaitResponse'; import { 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 index a08d8b299..84b804f6b 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitResponse.ts @@ -1,10 +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/package.json b/packages/proto-loader/package.json index 852b4a315..7dbb89d0d 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -24,7 +24,7 @@ "fix": "gts fix", "pretest": "npm run compile", "posttest": "npm run check", - "generate-golden": "node ./build/bin/proto-loader-gen-types.js --keepCase --longs=String --enums=String --defaults --oneofs --json -I deps/gapic-showcase/schema/ deps/googleapis/ -O ./golden-generated --grpcLib @grpc/grpc-js google/showcase/v1beta1/echo.proto", + "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": { From 71e5cb9c4f84388d245c4f3f66e02af012878afc Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 21 Jul 2020 13:58:16 -0700 Subject: [PATCH 20/45] Update submodules in test script --- run-tests.sh | 2 ++ 1 file changed, 2 insertions(+) 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 From d329387c8f285361be6fad034fa527d03df9d230 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 21 Jul 2020 15:07:39 -0700 Subject: [PATCH 21/45] Skip test properly on older versions --- packages/proto-loader/gulpfile.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/proto-loader/gulpfile.ts b/packages/proto-loader/gulpfile.ts index 60a843416..f8d47c800 100644 --- a/packages/proto-loader/gulpfile.ts +++ b/packages/proto-loader/gulpfile.ts @@ -72,6 +72,9 @@ const 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); } } From d8e035445cab44e73e6753f3a9a07330f9d2e112 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 3 Aug 2020 10:59:10 -0700 Subject: [PATCH 22/45] Fix imports of messages defined in other messages, add missing comma --- .../bin/proto-loader-gen-types.ts | 37 ++++++++++++++----- .../proto-loader/golden-generated/echo.ts | 2 +- packages/proto-loader/package.json | 2 +- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 74e95ac52..a01004ef8 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -81,7 +81,12 @@ function stripLeadingPeriod(name: string) { return name.startsWith('.') ? name.substring(1) : name; } -function getImportPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { +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, '/'); } @@ -110,14 +115,28 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv const filePath = from === undefined ? './' + getImportPath(dependency) : getRelativeImportPath(from, dependency); const typeInterfaceName = getTypeInterfaceName(dependency); let importedTypes: string; - 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`; + /* If the dependenc 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 { - throw new Error('Invalid object passed to getImportLine'); + 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 { ${importedTypes} } from '${filePath}';` } @@ -585,7 +604,7 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); formatter.writeLine('type SubtypeConstructor = {'); formatter.writeLine(' new(...args: ConstructorArguments): Subtype;'); - formatter.writeLine('}'); + formatter.writeLine('};'); formatter.writeLine(''); formatter.writeLine('export interface ProtoGrpcType {'); diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts index f4b07e5a2..e875e5076 100644 --- a/packages/proto-loader/golden-generated/echo.ts +++ b/packages/proto-loader/golden-generated/echo.ts @@ -7,7 +7,7 @@ import { EchoClient as _google_showcase_v1beta1_EchoClient } from './google/show type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never; type SubtypeConstructor = { new(...args: ConstructorArguments): Subtype; -} +}; export interface ProtoGrpcType { google: { diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 7dbb89d0d..a5fda1101 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre11", + "version": "0.6.0-pre12", "author": "Google Inc.", "contributors": [ { From 128d4e90831fe7592386fab3d7e617b8f06d4b73 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 4 Aug 2020 13:23:02 -0700 Subject: [PATCH 23/45] Add TS generator information to README --- packages/proto-loader/README.md | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/proto-loader/README.md b/packages/proto-loader/README.md index 07f28907c..7a97a3b1b 100644 --- a/packages/proto-loader/README.md +++ b/packages/proto-loader/README.md @@ -52,3 +52,37 @@ 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: + +``` +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] + --longs The type that should be used to output 64 bit integer + values. Can be String, Number [string] + --enums The type that should be used to output enum fields. Can be + String [string] + --bytes The type that should be used to output bytes fields. Can be + String, Array [string] + --defaults Output default values for omitted fields [boolean] + --arrays Output default values for omitted repeated fields even if + --defaults is not set [boolean] + --objects Output default values for omitted message fields even if + --defaults is not set [boolean] + --oneofs Output virtual oneof fields set to the present field's name + [boolean] + --json Represent Infinity and NaN as strings in float fields. Also + decode google.protobuf.Any automatically [boolean] + --includeComments Generate doc comments from comments in the original files + [boolean] + --includeDirs, -I Directories to search for included files [array] + --outDir, -O Directory in which to output files [string] [required] + --grpcLib The gRPC implementation library that these types will be + used with [string] [required] +``` \ No newline at end of file From bbff8cb449c6994f6b010b423b502ebc1edb64cc Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 10 Aug 2020 11:35:26 -0700 Subject: [PATCH 24/45] A few more service type fixes --- .../bin/proto-loader-gen-types.ts | 14 ++--- .../google/longrunning/Operations.ts | 50 ++++++++--------- .../google/showcase/v1beta1/Echo.ts | 54 +++++++++---------- packages/proto-loader/package.json | 2 +- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index a01004ef8..83a91c8ee 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -476,8 +476,8 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P const callType = `grpc.ClientWritableStream<${responseType}>`; formatter.writeLine(`${name}(metadata: grpc.Metadata, options: grpc.CallOptions, callback: ${callbackType}): ${callType};`); formatter.writeLine(`${name}(metadata: grpc.Metadata, callback: ${callbackType}): ${callType};`); - 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) { @@ -490,8 +490,8 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P 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}, 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};`); } } } @@ -505,15 +505,15 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: if (options.includeComments) { formatComment(formatter, serviceType.comment); } - formatter.writeLine(`export interface ${serviceType.name}Handlers {`); + 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!); - const responseType = getTypeInterfaceName(method.resolvedResponseType!) + '__Output'; + const requestType = getTypeInterfaceName(method.resolvedRequestType!) + '__Output'; + const responseType = getTypeInterfaceName(method.resolvedResponseType!); if (method.requestStream) { if (method.responseStream) { // Bidi streaming diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts index 64cc32ba9..d9db95847 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -36,8 +36,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -52,8 +52,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -63,8 +63,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -73,8 +73,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -83,8 +83,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -92,8 +92,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -109,8 +109,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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`. @@ -125,8 +125,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -141,8 +141,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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 @@ -156,8 +156,8 @@ export interface OperationsClient extends grpc.Client { */ 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, 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; } @@ -185,7 +185,7 @@ export interface OperationsHandlers { * 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(call: grpc.ServerUnaryCall<_google_longrunning_CancelOperationRequest, _google_protobuf_Empty__Output>, callback: grpc.sendUnaryData<_google_protobuf_Empty__Output>): void; + CancelOperation(call: grpc.ServerUnaryCall<_google_longrunning_CancelOperationRequest__Output, _google_protobuf_Empty>, callback: grpc.sendUnaryData<_google_protobuf_Empty>): void; /** * Deletes a long-running operation. This method indicates that the client is @@ -193,14 +193,14 @@ export interface OperationsHandlers { * operation. If the server doesn't support this method, it returns * `google.rpc.Code.UNIMPLEMENTED`. */ - DeleteOperation(call: grpc.ServerUnaryCall<_google_longrunning_DeleteOperationRequest, _google_protobuf_Empty__Output>, callback: grpc.sendUnaryData<_google_protobuf_Empty__Output>): void; + DeleteOperation(call: grpc.ServerUnaryCall<_google_longrunning_DeleteOperationRequest__Output, _google_protobuf_Empty>, callback: grpc.sendUnaryData<_google_protobuf_Empty>): void; /** * 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(call: grpc.ServerUnaryCall<_google_longrunning_GetOperationRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + GetOperation(call: grpc.ServerUnaryCall<_google_longrunning_GetOperationRequest__Output, _google_longrunning_Operation>, callback: grpc.sendUnaryData<_google_longrunning_Operation>): void; /** * Lists operations that match the specified filter in the request. If the @@ -214,7 +214,7 @@ export interface OperationsHandlers { * collection id, however overriding users must ensure the name binding * is the parent resource, without the operations collection id. */ - ListOperations(call: grpc.ServerUnaryCall<_google_longrunning_ListOperationsRequest, _google_longrunning_ListOperationsResponse__Output>, callback: grpc.sendUnaryData<_google_longrunning_ListOperationsResponse__Output>): void; + ListOperations(call: grpc.ServerUnaryCall<_google_longrunning_ListOperationsRequest__Output, _google_longrunning_ListOperationsResponse>, callback: grpc.sendUnaryData<_google_longrunning_ListOperationsResponse>): void; /** * Waits for the specified long-running operation until it is done or reaches @@ -227,6 +227,6 @@ export interface OperationsHandlers { * state before the specified timeout (including immediately), meaning even an * immediate response is no guarantee that the operation is done. */ - WaitOperation(call: grpc.ServerUnaryCall<_google_longrunning_WaitOperationRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + WaitOperation(call: grpc.ServerUnaryCall<_google_longrunning_WaitOperationRequest__Output, _google_longrunning_Operation>, callback: grpc.sendUnaryData<_google_longrunning_Operation>): void; } diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index e518665d5..d33ff1893 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -26,8 +26,8 @@ export interface EchoClient extends grpc.Client { */ 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, 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. @@ -35,8 +35,8 @@ export interface EchoClient extends grpc.Client { */ 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, 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 @@ -60,8 +60,8 @@ export interface EchoClient extends grpc.Client { */ Collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - Collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + Collect(options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + Collect(callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_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 @@ -69,23 +69,23 @@ export interface EchoClient extends grpc.Client { */ collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - collect(metadata: grpc.Metadata, options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + collect(options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + collect(callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; /** * 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, 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, 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 @@ -106,16 +106,16 @@ export interface EchoClient extends grpc.Client { */ 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, 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, 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. @@ -123,16 +123,16 @@ export interface EchoClient extends grpc.Client { */ 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, 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, 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; } @@ -149,43 +149,43 @@ export interface EchoHandlers { * and then return the response or error. * This method showcases how a client handles delays or retries. */ - Block(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_BlockRequest, _google_showcase_v1beta1_BlockResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_BlockResponse__Output>): void; + Block(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_BlockRequest__Output, _google_showcase_v1beta1_BlockResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_BlockResponse>): void; /** * 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(call: grpc.ServerDuplexStream<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>): void; + Chat(call: grpc.ServerDuplexStream<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>): void; /** * 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(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse__Output>): void; + Collect(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse>): void; /** * This method simply echos the request. This method is showcases unary rpcs. */ - Echo(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_EchoRequest, _google_showcase_v1beta1_EchoResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse__Output>): void; + Echo(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse>): void; /** * 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(call: grpc.ServerWritableStream<_google_showcase_v1beta1_ExpandRequest, _google_showcase_v1beta1_EchoResponse__Output>): void; + Expand(call: grpc.ServerWritableStream<_google_showcase_v1beta1_ExpandRequest__Output, _google_showcase_v1beta1_EchoResponse>): void; /** * 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(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_PagedExpandRequest, _google_showcase_v1beta1_PagedExpandResponse__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_PagedExpandResponse__Output>): void; + PagedExpand(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_PagedExpandRequest__Output, _google_showcase_v1beta1_PagedExpandResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_PagedExpandResponse>): void; /** * This method will wait the requested amount of and then return. * This method showcases how a client handles a request timing out. */ - Wait(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_WaitRequest, _google_longrunning_Operation__Output>, callback: grpc.sendUnaryData<_google_longrunning_Operation__Output>): void; + Wait(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_WaitRequest__Output, _google_longrunning_Operation>, callback: grpc.sendUnaryData<_google_longrunning_Operation>): void; } diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index a5fda1101..99443d715 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre12", + "version": "0.6.0-pre13", "author": "Google Inc.", "contributors": [ { From 471c59fa276013bcdb5d40343430b46fc0b5b23a Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 10 Aug 2020 15:18:58 -0700 Subject: [PATCH 25/45] Fix missing type argument in client streaming server handler --- packages/proto-loader/bin/proto-loader-gen-types.ts | 2 +- packages/proto-loader/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 83a91c8ee..0d71e5495 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -520,7 +520,7 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: formatter.writeLine(`${methodName}(call: grpc.ServerDuplexStream<${requestType}, ${responseType}>): void;`); } else { // Client streaming - formatter.writeLine(`${methodName}(call: grpc.ServerReadableStream<${requestType}>, callback: grpc.sendUnaryData<${responseType}>): void;`); + formatter.writeLine(`${methodName}(call: grpc.ServerReadableStream<${requestType}, ${responseType}>, callback: grpc.sendUnaryData<${responseType}>): void;`); } } else { if (method.responseStream) { diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 99443d715..5751b4bae 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre13", + "version": "0.6.0-pre14", "author": "Google Inc.", "contributors": [ { From 7550c00a24e80b2dac56e15655842a6fe023c0e6 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 10 Aug 2020 15:20:13 -0700 Subject: [PATCH 26/45] Regenerate golden files --- .../golden-generated/google/longrunning/Operations.ts | 2 +- .../golden-generated/google/showcase/v1beta1/Echo.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts index d9db95847..1d1d2b070 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -172,7 +172,7 @@ export interface OperationsClient extends grpc.Client { * returns long-running operations should implement the `Operations` interface * so developers can have a consistent client experience. */ -export interface OperationsHandlers { +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 diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index d33ff1893..eb4772a1d 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -143,7 +143,7 @@ export interface EchoClient extends grpc.Client { * paginated calls. Set the 'showcase-trailer' metadata key on any method * to have the values echoed in the response trailers. */ -export interface EchoHandlers { +export interface EchoHandlers extends grpc.UntypedServiceImplementation { /** * This method will block (wait) for the requested amount of time * and then return the response or error. @@ -163,7 +163,7 @@ export interface EchoHandlers { * by the client, this method will return the a concatenation of the strings * passed to it. This method showcases client-side streaming rpcs. */ - Collect(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest__Output>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse>): void; + Collect(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse>): void; /** * This method simply echos the request. This method is showcases unary rpcs. From 6389e92c8b5aad7604707244099795a256a091fa Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 20 Aug 2020 09:54:10 -0700 Subject: [PATCH 27/45] Bump version to 0.6.0 --- packages/proto-loader/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 5751b4bae..ac76bd54d 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre14", + "version": "0.6.0", "author": "Google Inc.", "contributors": [ { From 2d1cb15dec0549cf069863e1e14df7dd72305be1 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 31 Aug 2020 09:40:17 -0700 Subject: [PATCH 28/45] Fix imports for messages without packages --- packages/proto-loader/bin/proto-loader-gen-types.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 0d71e5495..2e001e8c7 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -96,6 +96,9 @@ function getPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service) { 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 += '../'; From 677741d442c45193028ccd7ebfafdef5e5e4670f Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 2 Sep 2020 13:35:43 -0700 Subject: [PATCH 29/45] ConstructorParameters is already a TypeScript builtin --- packages/proto-loader/bin/proto-loader-gen-types.ts | 3 +-- packages/proto-loader/golden-generated/echo.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 2e001e8c7..1238e0402 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -604,9 +604,8 @@ function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options generateServiceImports(formatter, root, options); formatter.writeLine(''); - formatter.writeLine('type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never;'); formatter.writeLine('type SubtypeConstructor = {'); - formatter.writeLine(' new(...args: ConstructorArguments): Subtype;'); + formatter.writeLine(' new(...args: ConstructorParameters): Subtype;'); formatter.writeLine('};'); formatter.writeLine(''); diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts index e875e5076..f24c35ec5 100644 --- a/packages/proto-loader/golden-generated/echo.ts +++ b/packages/proto-loader/golden-generated/echo.ts @@ -4,9 +4,8 @@ import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@g import { OperationsClient as _google_longrunning_OperationsClient } from './google/longrunning/Operations'; import { EchoClient as _google_showcase_v1beta1_EchoClient } from './google/showcase/v1beta1/Echo'; -type ConstructorArguments = Constructor extends new (...args: infer Args) => any ? Args: never; type SubtypeConstructor = { - new(...args: ConstructorArguments): Subtype; + new(...args: ConstructorParameters): Subtype; }; export interface ProtoGrpcType { From acf403b7042b6c9a0097b2a065cfd681f0b90cac Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Thu, 24 Sep 2020 09:40:48 +0100 Subject: [PATCH 30/45] proto-loader: use method descriptor types to define server handlers --- packages/proto-loader/bin/proto-loader-gen-types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 1238e0402..3c972fbcf 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -520,18 +520,18 @@ function generateServiceHandlerInterface(formatter: TextFormatter, serviceType: if (method.requestStream) { if (method.responseStream) { // Bidi streaming - formatter.writeLine(`${methodName}(call: grpc.ServerDuplexStream<${requestType}, ${responseType}>): void;`); + formatter.writeLine(`${methodName}: grpc.handleBidiStreamingCall<${requestType}, ${responseType}>;`); } else { // Client streaming - formatter.writeLine(`${methodName}(call: grpc.ServerReadableStream<${requestType}, ${responseType}>, callback: grpc.sendUnaryData<${responseType}>): void;`); + formatter.writeLine(`${methodName}: grpc.handleClientStreamingCall<${requestType}, ${responseType}>;`); } } else { if (method.responseStream) { // Server streaming - formatter.writeLine(`${methodName}(call: grpc.ServerWritableStream<${requestType}, ${responseType}>): void;`); + formatter.writeLine(`${methodName}: grpc.handleServerStreamingCall<${requestType}, ${responseType}>;`); } else { // Unary - formatter.writeLine(`${methodName}(call: grpc.ServerUnaryCall<${requestType}, ${responseType}>, callback: grpc.sendUnaryData<${responseType}>): void;`); + formatter.writeLine(`${methodName}: grpc.handleUnaryCall<${requestType}, ${responseType}>;`); } } formatter.writeLine(''); From 829333c4598c0d9d9583be60cae89fbae1bfe2ed Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Thu, 24 Sep 2020 18:22:52 +0100 Subject: [PATCH 31/45] Regenerate golden types --- .../google/longrunning/Operations.ts | 10 +++++----- .../google/showcase/v1beta1/Echo.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts index 1d1d2b070..57ff8722c 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -185,7 +185,7 @@ export interface OperationsHandlers extends grpc.UntypedServiceImplementation { * 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(call: grpc.ServerUnaryCall<_google_longrunning_CancelOperationRequest__Output, _google_protobuf_Empty>, callback: grpc.sendUnaryData<_google_protobuf_Empty>): void; + CancelOperation: grpc.handleUnaryCall<_google_longrunning_CancelOperationRequest__Output, _google_protobuf_Empty>; /** * Deletes a long-running operation. This method indicates that the client is @@ -193,14 +193,14 @@ export interface OperationsHandlers extends grpc.UntypedServiceImplementation { * operation. If the server doesn't support this method, it returns * `google.rpc.Code.UNIMPLEMENTED`. */ - DeleteOperation(call: grpc.ServerUnaryCall<_google_longrunning_DeleteOperationRequest__Output, _google_protobuf_Empty>, callback: grpc.sendUnaryData<_google_protobuf_Empty>): void; + 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(call: grpc.ServerUnaryCall<_google_longrunning_GetOperationRequest__Output, _google_longrunning_Operation>, callback: grpc.sendUnaryData<_google_longrunning_Operation>): void; + GetOperation: grpc.handleUnaryCall<_google_longrunning_GetOperationRequest__Output, _google_longrunning_Operation>; /** * Lists operations that match the specified filter in the request. If the @@ -214,7 +214,7 @@ export interface OperationsHandlers extends grpc.UntypedServiceImplementation { * collection id, however overriding users must ensure the name binding * is the parent resource, without the operations collection id. */ - ListOperations(call: grpc.ServerUnaryCall<_google_longrunning_ListOperationsRequest__Output, _google_longrunning_ListOperationsResponse>, callback: grpc.sendUnaryData<_google_longrunning_ListOperationsResponse>): void; + ListOperations: grpc.handleUnaryCall<_google_longrunning_ListOperationsRequest__Output, _google_longrunning_ListOperationsResponse>; /** * Waits for the specified long-running operation until it is done or reaches @@ -227,6 +227,6 @@ export interface OperationsHandlers extends grpc.UntypedServiceImplementation { * state before the specified timeout (including immediately), meaning even an * immediate response is no guarantee that the operation is done. */ - WaitOperation(call: grpc.ServerUnaryCall<_google_longrunning_WaitOperationRequest__Output, _google_longrunning_Operation>, callback: grpc.sendUnaryData<_google_longrunning_Operation>): void; + WaitOperation: grpc.handleUnaryCall<_google_longrunning_WaitOperationRequest__Output, _google_longrunning_Operation>; } diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index eb4772a1d..124ee86e5 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -149,43 +149,43 @@ export interface EchoHandlers extends grpc.UntypedServiceImplementation { * and then return the response or error. * This method showcases how a client handles delays or retries. */ - Block(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_BlockRequest__Output, _google_showcase_v1beta1_BlockResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_BlockResponse>): void; + 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(call: grpc.ServerDuplexStream<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>): void; + 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(call: grpc.ServerReadableStream<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse>): void; + 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(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_EchoRequest__Output, _google_showcase_v1beta1_EchoResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_EchoResponse>): void; + 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(call: grpc.ServerWritableStream<_google_showcase_v1beta1_ExpandRequest__Output, _google_showcase_v1beta1_EchoResponse>): void; + 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(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_PagedExpandRequest__Output, _google_showcase_v1beta1_PagedExpandResponse>, callback: grpc.sendUnaryData<_google_showcase_v1beta1_PagedExpandResponse>): void; + 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(call: grpc.ServerUnaryCall<_google_showcase_v1beta1_WaitRequest__Output, _google_longrunning_Operation>, callback: grpc.sendUnaryData<_google_longrunning_Operation>): void; + Wait: grpc.handleUnaryCall<_google_showcase_v1beta1_WaitRequest__Output, _google_longrunning_Operation>; } From 330d1835fee7718434c42a528cbf4572693bf828 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 11 Oct 2020 12:01:32 +0100 Subject: [PATCH 32/45] proto-loader: fix typescript generation callType for client streaming --- packages/proto-loader/bin/proto-loader-gen-types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 3c972fbcf..4c97a8d01 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -476,7 +476,7 @@ function generateServiceClientInterface(formatter: TextFormatter, serviceType: P formatter.writeLine(`${name}(options?: grpc.CallOptions): ${callType};`); } else { // Client streaming - const callType = `grpc.ClientWritableStream<${responseType}>`; + 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};`); From e85b72bbc45c5f0d4e8087fa9d2b7c397b3913ae Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 11 Oct 2020 12:10:52 +0100 Subject: [PATCH 33/45] Regenerate golden types --- .../google/showcase/v1beta1/Echo.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index 124ee86e5..17df522c8 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -58,19 +58,19 @@ export interface EchoClient extends grpc.Client { * 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_EchoResponse__Output>; - Collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - Collect(options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - Collect(callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + 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_EchoResponse__Output>; - collect(metadata: grpc.Metadata, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - collect(options: grpc.CallOptions, callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; - collect(callback: (error?: grpc.ServiceError, result?: _google_showcase_v1beta1_EchoResponse__Output) => void): grpc.ClientWritableStream<_google_showcase_v1beta1_EchoResponse__Output>; + 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. From 96cba74b9b07461c63692c73c63a6e3c5af3531b Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 21 Oct 2020 14:33:21 -0700 Subject: [PATCH 34/45] Use 'import type' where possible --- .../proto-loader/bin/proto-loader-gen-types.ts | 8 ++++---- packages/proto-loader/golden-generated/echo.ts | 6 +++--- .../golden-generated/google/api/Http.ts | 2 +- .../golden-generated/google/api/HttpRule.ts | 4 ++-- .../longrunning/ListOperationsResponse.ts | 2 +- .../google/longrunning/Operation.ts | 4 ++-- .../google/longrunning/Operations.ts | 16 ++++++++-------- .../google/longrunning/WaitOperationRequest.ts | 2 +- .../golden-generated/google/protobuf/Any.ts | 2 +- .../google/protobuf/DescriptorProto.ts | 10 +++++----- .../google/protobuf/Duration.ts | 2 +- .../google/protobuf/EnumDescriptorProto.ts | 4 ++-- .../google/protobuf/EnumOptions.ts | 2 +- .../protobuf/EnumValueDescriptorProto.ts | 2 +- .../google/protobuf/EnumValueOptions.ts | 2 +- .../google/protobuf/FieldDescriptorProto.ts | 2 +- .../google/protobuf/FieldOptions.ts | 4 ++-- .../google/protobuf/FileDescriptorProto.ts | 12 ++++++------ .../google/protobuf/FileDescriptorSet.ts | 2 +- .../google/protobuf/FileOptions.ts | 2 +- .../google/protobuf/MessageOptions.ts | 2 +- .../google/protobuf/MethodDescriptorProto.ts | 2 +- .../google/protobuf/MethodOptions.ts | 6 +++--- .../google/protobuf/OneofDescriptorProto.ts | 2 +- .../google/protobuf/OneofOptions.ts | 2 +- .../google/protobuf/ServiceDescriptorProto.ts | 4 ++-- .../google/protobuf/ServiceOptions.ts | 2 +- .../google/protobuf/Timestamp.ts | 2 +- .../google/protobuf/UninterpretedOption.ts | 2 +- .../golden-generated/google/rpc/Status.ts | 2 +- .../google/showcase/v1beta1/BlockRequest.ts | 6 +++--- .../google/showcase/v1beta1/Echo.ts | 18 +++++++++--------- .../google/showcase/v1beta1/EchoRequest.ts | 4 ++-- .../google/showcase/v1beta1/EchoResponse.ts | 2 +- .../google/showcase/v1beta1/ExpandRequest.ts | 2 +- .../showcase/v1beta1/PagedExpandResponse.ts | 2 +- .../google/showcase/v1beta1/WaitMetadata.ts | 2 +- .../google/showcase/v1beta1/WaitRequest.ts | 8 ++++---- packages/proto-loader/package.json | 2 +- 39 files changed, 81 insertions(+), 81 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 1238e0402..3b34f52bb 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -141,7 +141,7 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv throw new Error('Invalid object passed to getImportLine'); } } - return `import { ${importedTypes} } from '${filePath}';` + return `import type { ${importedTypes} } from '${filePath}';` } function getChildMessagesAndEnums(namespace: Protobuf.NamespaceBase): (Protobuf.Type | Protobuf.Enum)[] { @@ -412,10 +412,10 @@ function generateMessageInterfaces(formatter: TextFormatter, messageType: Protob } } if (usesLong) { - formatter.writeLine("import { Long } from '@grpc/proto-loader';"); + formatter.writeLine("import type { Long } from '@grpc/proto-loader';"); } if (messageType.fullName === '.google.protobuf.Any') { - formatter.writeLine("import { AnyExtension } from '@grpc/proto-loader';") + formatter.writeLine("import type { AnyExtension } from '@grpc/proto-loader';") } formatter.writeLine(''); for (const childType of childTypes.sort(compareName)) { @@ -598,7 +598,7 @@ function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Prot function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) { formatter.writeLine(`import * as grpc from '${options.grpcLib}';`); - formatter.writeLine("import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';"); + formatter.writeLine("import type { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';"); formatter.writeLine(''); generateServiceImports(formatter, root, options); diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts index f24c35ec5..70cb030de 100644 --- a/packages/proto-loader/golden-generated/echo.ts +++ b/packages/proto-loader/golden-generated/echo.ts @@ -1,8 +1,8 @@ import * as grpc from '@grpc/grpc-js'; -import { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader'; +import type { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader'; -import { OperationsClient as _google_longrunning_OperationsClient } from './google/longrunning/Operations'; -import { EchoClient as _google_showcase_v1beta1_EchoClient } from './google/showcase/v1beta1/Echo'; +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 = { new(...args: ConstructorParameters): Subtype; diff --git a/packages/proto-loader/golden-generated/google/api/Http.ts b/packages/proto-loader/golden-generated/google/api/Http.ts index 038c57e5e..e9b3cb309 100644 --- a/packages/proto-loader/golden-generated/google/api/Http.ts +++ b/packages/proto-loader/golden-generated/google/api/Http.ts @@ -1,6 +1,6 @@ // Original file: deps/googleapis/google/api/http.proto -import { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; +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 diff --git a/packages/proto-loader/golden-generated/google/api/HttpRule.ts b/packages/proto-loader/golden-generated/google/api/HttpRule.ts index ed9921e5e..21ad897ee 100644 --- a/packages/proto-loader/golden-generated/google/api/HttpRule.ts +++ b/packages/proto-loader/golden-generated/google/api/HttpRule.ts @@ -1,7 +1,7 @@ // Original file: deps/googleapis/google/api/http.proto -import { CustomHttpPattern as _google_api_CustomHttpPattern, CustomHttpPattern__Output as _google_api_CustomHttpPattern__Output } from '../../google/api/CustomHttpPattern'; -import { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; +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 diff --git a/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts index 4d893c45f..c295aa801 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/ListOperationsResponse.ts @@ -1,6 +1,6 @@ // Original file: deps/googleapis/google/longrunning/operations.proto -import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; +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]. diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operation.ts b/packages/proto-loader/golden-generated/google/longrunning/Operation.ts index 095b77799..2aa9b8c71 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operation.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operation.ts @@ -1,7 +1,7 @@ // Original file: deps/googleapis/google/longrunning/operations.proto -import { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; -import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../google/rpc/Status'; +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 diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts index 1d1d2b070..81a470320 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -1,14 +1,14 @@ // Original file: deps/googleapis/google/longrunning/operations.proto import * as grpc from '@grpc/grpc-js' -import { CancelOperationRequest as _google_longrunning_CancelOperationRequest, CancelOperationRequest__Output as _google_longrunning_CancelOperationRequest__Output } from '../../google/longrunning/CancelOperationRequest'; -import { DeleteOperationRequest as _google_longrunning_DeleteOperationRequest, DeleteOperationRequest__Output as _google_longrunning_DeleteOperationRequest__Output } from '../../google/longrunning/DeleteOperationRequest'; -import { Empty as _google_protobuf_Empty, Empty__Output as _google_protobuf_Empty__Output } from '../../google/protobuf/Empty'; -import { GetOperationRequest as _google_longrunning_GetOperationRequest, GetOperationRequest__Output as _google_longrunning_GetOperationRequest__Output } from '../../google/longrunning/GetOperationRequest'; -import { ListOperationsRequest as _google_longrunning_ListOperationsRequest, ListOperationsRequest__Output as _google_longrunning_ListOperationsRequest__Output } from '../../google/longrunning/ListOperationsRequest'; -import { ListOperationsResponse as _google_longrunning_ListOperationsResponse, ListOperationsResponse__Output as _google_longrunning_ListOperationsResponse__Output } from '../../google/longrunning/ListOperationsResponse'; -import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../google/longrunning/Operation'; -import { WaitOperationRequest as _google_longrunning_WaitOperationRequest, WaitOperationRequest__Output as _google_longrunning_WaitOperationRequest__Output } from '../../google/longrunning/WaitOperationRequest'; +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. diff --git a/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts index 865e180cf..2789ba33e 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/WaitOperationRequest.ts @@ -1,6 +1,6 @@ // Original file: deps/googleapis/google/longrunning/operations.proto -import { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../google/protobuf/Duration'; +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]. diff --git a/packages/proto-loader/golden-generated/google/protobuf/Any.ts b/packages/proto-loader/golden-generated/google/protobuf/Any.ts index b592af4ba..fe0d05f12 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/Any.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/Any.ts @@ -1,6 +1,6 @@ // Original file: null -import { AnyExtension } from '@grpc/proto-loader'; +import type { AnyExtension } from '@grpc/proto-loader'; export type Any = AnyExtension | { type_url: string; diff --git a/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts index 8ab286897..2f6f9f0cc 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/DescriptorProto.ts @@ -1,10 +1,10 @@ // Original file: null -import { FieldDescriptorProto as _google_protobuf_FieldDescriptorProto, FieldDescriptorProto__Output as _google_protobuf_FieldDescriptorProto__Output } from '../../google/protobuf/FieldDescriptorProto'; -import { DescriptorProto as _google_protobuf_DescriptorProto, DescriptorProto__Output as _google_protobuf_DescriptorProto__Output } from '../../google/protobuf/DescriptorProto'; -import { EnumDescriptorProto as _google_protobuf_EnumDescriptorProto, EnumDescriptorProto__Output as _google_protobuf_EnumDescriptorProto__Output } from '../../google/protobuf/EnumDescriptorProto'; -import { MessageOptions as _google_protobuf_MessageOptions, MessageOptions__Output as _google_protobuf_MessageOptions__Output } from '../../google/protobuf/MessageOptions'; -import { OneofDescriptorProto as _google_protobuf_OneofDescriptorProto, OneofDescriptorProto__Output as _google_protobuf_OneofDescriptorProto__Output } from '../../google/protobuf/OneofDescriptorProto'; +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); diff --git a/packages/proto-loader/golden-generated/google/protobuf/Duration.ts b/packages/proto-loader/golden-generated/google/protobuf/Duration.ts index 78610b80a..8595377a0 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/Duration.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/Duration.ts @@ -1,6 +1,6 @@ // Original file: null -import { Long } from '@grpc/proto-loader'; +import type { Long } from '@grpc/proto-loader'; export interface Duration { 'seconds'?: (number | string | Long); diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts index 1971fccb0..7aa40ce4d 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumDescriptorProto.ts @@ -1,7 +1,7 @@ // Original file: null -import { EnumValueDescriptorProto as _google_protobuf_EnumValueDescriptorProto, EnumValueDescriptorProto__Output as _google_protobuf_EnumValueDescriptorProto__Output } from '../../google/protobuf/EnumValueDescriptorProto'; -import { EnumOptions as _google_protobuf_EnumOptions, EnumOptions__Output as _google_protobuf_EnumOptions__Output } from '../../google/protobuf/EnumOptions'; +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); diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts index 56c8db7df..b92ade4f9 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumOptions.ts @@ -1,6 +1,6 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; export interface EnumOptions { 'allowAlias'?: (boolean); diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts index 919b7aa38..238e7fd01 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumValueDescriptorProto.ts @@ -1,6 +1,6 @@ // Original file: null -import { EnumValueOptions as _google_protobuf_EnumValueOptions, EnumValueOptions__Output as _google_protobuf_EnumValueOptions__Output } from '../../google/protobuf/EnumValueOptions'; +import type { EnumValueOptions as _google_protobuf_EnumValueOptions, EnumValueOptions__Output as _google_protobuf_EnumValueOptions__Output } from '../../google/protobuf/EnumValueOptions'; export interface EnumValueDescriptorProto { 'name'?: (string); diff --git a/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts index 6bbd4951f..e60ee6f4c 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/EnumValueOptions.ts @@ -1,6 +1,6 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; export interface EnumValueOptions { 'deprecated'?: (boolean); diff --git a/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts index e0a1f4580..b59518c4b 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/FieldDescriptorProto.ts @@ -1,6 +1,6 @@ // Original file: null -import { FieldOptions as _google_protobuf_FieldOptions, FieldOptions__Output as _google_protobuf_FieldOptions__Output } from '../../google/protobuf/FieldOptions'; +import type { FieldOptions as _google_protobuf_FieldOptions, FieldOptions__Output as _google_protobuf_FieldOptions__Output } from '../../google/protobuf/FieldOptions'; // Original file: null diff --git a/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts index ebed365b7..8304053f1 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/FieldOptions.ts @@ -1,7 +1,7 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; -import { FieldBehavior as _google_api_FieldBehavior } from '../../google/api/FieldBehavior'; +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 diff --git a/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts index 65315a644..2954e4208 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorProto.ts @@ -1,11 +1,11 @@ // Original file: null -import { DescriptorProto as _google_protobuf_DescriptorProto, DescriptorProto__Output as _google_protobuf_DescriptorProto__Output } from '../../google/protobuf/DescriptorProto'; -import { EnumDescriptorProto as _google_protobuf_EnumDescriptorProto, EnumDescriptorProto__Output as _google_protobuf_EnumDescriptorProto__Output } from '../../google/protobuf/EnumDescriptorProto'; -import { ServiceDescriptorProto as _google_protobuf_ServiceDescriptorProto, ServiceDescriptorProto__Output as _google_protobuf_ServiceDescriptorProto__Output } from '../../google/protobuf/ServiceDescriptorProto'; -import { FieldDescriptorProto as _google_protobuf_FieldDescriptorProto, FieldDescriptorProto__Output as _google_protobuf_FieldDescriptorProto__Output } from '../../google/protobuf/FieldDescriptorProto'; -import { FileOptions as _google_protobuf_FileOptions, FileOptions__Output as _google_protobuf_FileOptions__Output } from '../../google/protobuf/FileOptions'; -import { SourceCodeInfo as _google_protobuf_SourceCodeInfo, SourceCodeInfo__Output as _google_protobuf_SourceCodeInfo__Output } from '../../google/protobuf/SourceCodeInfo'; +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); diff --git a/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts index f01cabc4c..74ded2471 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/FileDescriptorSet.ts @@ -1,6 +1,6 @@ // Original file: null -import { FileDescriptorProto as _google_protobuf_FileDescriptorProto, FileDescriptorProto__Output as _google_protobuf_FileDescriptorProto__Output } from '../../google/protobuf/FileDescriptorProto'; +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)[]; diff --git a/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts index 5a1d270c5..573e847c0 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/FileOptions.ts @@ -1,6 +1,6 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; // Original file: null diff --git a/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts index 40bf29272..31f669eb0 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/MessageOptions.ts @@ -1,6 +1,6 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; export interface MessageOptions { 'messageSetWireFormat'?: (boolean); diff --git a/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts index b62d45731..bc2f0afb5 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/MethodDescriptorProto.ts @@ -1,6 +1,6 @@ // Original file: null -import { MethodOptions as _google_protobuf_MethodOptions, MethodOptions__Output as _google_protobuf_MethodOptions__Output } from '../../google/protobuf/MethodOptions'; +import type { MethodOptions as _google_protobuf_MethodOptions, MethodOptions__Output as _google_protobuf_MethodOptions__Output } from '../../google/protobuf/MethodOptions'; export interface MethodDescriptorProto { 'name'?: (string); diff --git a/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts index 7a4943367..495e22514 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/MethodOptions.ts @@ -1,8 +1,8 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; -import { OperationInfo as _google_longrunning_OperationInfo, OperationInfo__Output as _google_longrunning_OperationInfo__Output } from '../../google/longrunning/OperationInfo'; -import { HttpRule as _google_api_HttpRule, HttpRule__Output as _google_api_HttpRule__Output } from '../../google/api/HttpRule'; +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); diff --git a/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts index 5d1512003..c10ccecd3 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/OneofDescriptorProto.ts @@ -1,6 +1,6 @@ // Original file: null -import { OneofOptions as _google_protobuf_OneofOptions, OneofOptions__Output as _google_protobuf_OneofOptions__Output } from '../../google/protobuf/OneofOptions'; +import type { OneofOptions as _google_protobuf_OneofOptions, OneofOptions__Output as _google_protobuf_OneofOptions__Output } from '../../google/protobuf/OneofOptions'; export interface OneofDescriptorProto { 'name'?: (string); diff --git a/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts index 02353a0a4..d81d34797 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/OneofOptions.ts @@ -1,6 +1,6 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +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)[]; diff --git a/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts b/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts index fe5cab5b4..695a8775c 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/ServiceDescriptorProto.ts @@ -1,7 +1,7 @@ // Original file: null -import { MethodDescriptorProto as _google_protobuf_MethodDescriptorProto, MethodDescriptorProto__Output as _google_protobuf_MethodDescriptorProto__Output } from '../../google/protobuf/MethodDescriptorProto'; -import { ServiceOptions as _google_protobuf_ServiceOptions, ServiceOptions__Output as _google_protobuf_ServiceOptions__Output } from '../../google/protobuf/ServiceOptions'; +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); diff --git a/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts b/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts index 7754279c5..c0522eca3 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/ServiceOptions.ts @@ -1,6 +1,6 @@ // Original file: null -import { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; +import type { UninterpretedOption as _google_protobuf_UninterpretedOption, UninterpretedOption__Output as _google_protobuf_UninterpretedOption__Output } from '../../google/protobuf/UninterpretedOption'; export interface ServiceOptions { 'deprecated'?: (boolean); diff --git a/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts b/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts index f8747e93e..ceaa32b5f 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/Timestamp.ts @@ -1,6 +1,6 @@ // Original file: null -import { Long } from '@grpc/proto-loader'; +import type { Long } from '@grpc/proto-loader'; export interface Timestamp { 'seconds'?: (number | string | Long); diff --git a/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts b/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts index 91e3b99bc..433820f55 100644 --- a/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts +++ b/packages/proto-loader/golden-generated/google/protobuf/UninterpretedOption.ts @@ -1,6 +1,6 @@ // Original file: null -import { Long } from '@grpc/proto-loader'; +import type { Long } from '@grpc/proto-loader'; export interface _google_protobuf_UninterpretedOption_NamePart { 'namePart'?: (string); diff --git a/packages/proto-loader/golden-generated/google/rpc/Status.ts b/packages/proto-loader/golden-generated/google/rpc/Status.ts index 7da370379..4ce45b6a9 100644 --- a/packages/proto-loader/golden-generated/google/rpc/Status.ts +++ b/packages/proto-loader/golden-generated/google/rpc/Status.ts @@ -1,6 +1,6 @@ // Original file: deps/googleapis/google/rpc/status.proto -import { Any as _google_protobuf_Any, Any__Output as _google_protobuf_Any__Output } from '../../google/protobuf/Any'; +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 diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts index 39cde368c..88c8010cd 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/BlockRequest.ts @@ -1,8 +1,8 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; -import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; -import { BlockResponse as _google_showcase_v1beta1_BlockResponse, BlockResponse__Output as _google_showcase_v1beta1_BlockResponse__Output } from '../../../google/showcase/v1beta1/BlockResponse'; +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. diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index eb4772a1d..230af7011 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -1,15 +1,15 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto import * as grpc from '@grpc/grpc-js' -import { BlockRequest as _google_showcase_v1beta1_BlockRequest, BlockRequest__Output as _google_showcase_v1beta1_BlockRequest__Output } from '../../../google/showcase/v1beta1/BlockRequest'; -import { BlockResponse as _google_showcase_v1beta1_BlockResponse, BlockResponse__Output as _google_showcase_v1beta1_BlockResponse__Output } from '../../../google/showcase/v1beta1/BlockResponse'; -import { EchoRequest as _google_showcase_v1beta1_EchoRequest, EchoRequest__Output as _google_showcase_v1beta1_EchoRequest__Output } from '../../../google/showcase/v1beta1/EchoRequest'; -import { EchoResponse as _google_showcase_v1beta1_EchoResponse, EchoResponse__Output as _google_showcase_v1beta1_EchoResponse__Output } from '../../../google/showcase/v1beta1/EchoResponse'; -import { ExpandRequest as _google_showcase_v1beta1_ExpandRequest, ExpandRequest__Output as _google_showcase_v1beta1_ExpandRequest__Output } from '../../../google/showcase/v1beta1/ExpandRequest'; -import { Operation as _google_longrunning_Operation, Operation__Output as _google_longrunning_Operation__Output } from '../../../google/longrunning/Operation'; -import { PagedExpandRequest as _google_showcase_v1beta1_PagedExpandRequest, PagedExpandRequest__Output as _google_showcase_v1beta1_PagedExpandRequest__Output } from '../../../google/showcase/v1beta1/PagedExpandRequest'; -import { PagedExpandResponse as _google_showcase_v1beta1_PagedExpandResponse, PagedExpandResponse__Output as _google_showcase_v1beta1_PagedExpandResponse__Output } from '../../../google/showcase/v1beta1/PagedExpandResponse'; -import { WaitRequest as _google_showcase_v1beta1_WaitRequest, WaitRequest__Output as _google_showcase_v1beta1_WaitRequest__Output } from '../../../google/showcase/v1beta1/WaitRequest'; +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 diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts index c5060cdfd..0cf79d84f 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoRequest.ts @@ -1,7 +1,7 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; -import { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; +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. diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts index 97028b22a..3fda238a1 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/EchoResponse.ts @@ -1,6 +1,6 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; +import type { Severity as _google_showcase_v1beta1_Severity } from '../../../google/showcase/v1beta1/Severity'; /** * The response message for the Echo methods. diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts index 8db54519d..00e7d05d2 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/ExpandRequest.ts @@ -1,6 +1,6 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; +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. diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts index 4c37e4401..823de43ed 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/PagedExpandResponse.ts @@ -1,6 +1,6 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { EchoResponse as _google_showcase_v1beta1_EchoResponse, EchoResponse__Output as _google_showcase_v1beta1_EchoResponse__Output } from '../../../google/showcase/v1beta1/EchoResponse'; +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. diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts index 481d38412..38b0a083f 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitMetadata.ts @@ -1,6 +1,6 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; +import type { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; /** * The metadata for Wait operation. diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts index fe6081203..eb2d2bc19 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/WaitRequest.ts @@ -1,9 +1,9 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import { Timestamp as _google_protobuf_Timestamp, Timestamp__Output as _google_protobuf_Timestamp__Output } from '../../../google/protobuf/Timestamp'; -import { Status as _google_rpc_Status, Status__Output as _google_rpc_Status__Output } from '../../../google/rpc/Status'; -import { WaitResponse as _google_showcase_v1beta1_WaitResponse, WaitResponse__Output as _google_showcase_v1beta1_WaitResponse__Output } from '../../../google/showcase/v1beta1/WaitResponse'; -import { Duration as _google_protobuf_Duration, Duration__Output as _google_protobuf_Duration__Output } from '../../../google/protobuf/Duration'; +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. diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index ac76bd54d..2b164f03a 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0", + "version": "0.6.0-pre15", "author": "Google Inc.", "contributors": [ { From f2c82cc8e50837198b74b27b2c589e6a6c69db76 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 21 Oct 2020 14:36:50 -0700 Subject: [PATCH 35/45] Bump the version again to capture a merge --- packages/proto-loader/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 2b164f03a..02a1661ae 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre15", + "version": "0.6.0-pre16", "author": "Google Inc.", "contributors": [ { From 94391ca64df61b7ce06534d919673718b5754688 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 22 Oct 2020 11:09:23 -0700 Subject: [PATCH 36/45] import type * as grpc, fix ConstructorParameters usage --- packages/proto-loader/bin/proto-loader-gen-types.ts | 6 +++--- packages/proto-loader/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 07b287fc1..54b1475c3 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -544,7 +544,7 @@ function generateServiceInterfaces(formatter: TextFormatter, serviceType: Protob formatter.writeLine(`// Original file: ${serviceType.filename}`); formatter.writeLine(''); const grpcImportPath = options.grpcLib.startsWith('.') ? getPathToRoot(serviceType) + options.grpcLib : options.grpcLib; - formatter.writeLine(`import * as grpc from '${grpcImportPath}'`); + formatter.writeLine(`import type * as grpc from '${grpcImportPath}'`); const dependencies: Set = new Set(); for (const method of serviceType.methodsArray) { dependencies.add(method.resolvedRequestType!); @@ -597,14 +597,14 @@ function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Prot } function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) { - formatter.writeLine(`import * as grpc from '${options.grpcLib}';`); + 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 = {'); + formatter.writeLine('type SubtypeConstructor any, Subtype> = {'); formatter.writeLine(' new(...args: ConstructorParameters): Subtype;'); formatter.writeLine('};'); formatter.writeLine(''); diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 02a1661ae..7947dcf0f 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre16", + "version": "0.6.0-pre17", "author": "Google Inc.", "contributors": [ { From 4b3e0b6a8a0ceb3554ad9a31afb7a7c163c838c7 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 24 Nov 2020 16:18:47 -0800 Subject: [PATCH 37/45] Update version and dependencies for final release --- packages/proto-loader/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/package.json b/packages/proto-loader/package.json index 7947dcf0f..cfc767a9b 100644 --- a/packages/proto-loader/package.json +++ b/packages/proto-loader/package.json @@ -1,6 +1,6 @@ { "name": "@grpc/proto-loader", - "version": "0.6.0-pre17", + "version": "0.6.0", "author": "Google Inc.", "contributors": [ { @@ -49,7 +49,7 @@ "lodash.camelcase": "^4.3.0", "long": "^4.0.0", "protobufjs": "^6.10.0", - "yargs": "^15.3.1" + "yargs": "^16.1.1" }, "devDependencies": { "@types/lodash.camelcase": "^4.3.4", From d3ef8f3233738a75cb48368d9c85c8ce2b85f4fe Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 20 Dec 2020 08:01:13 +0000 Subject: [PATCH 38/45] proto-loader: Replace Windows CRLF pair with Unix LF --- .../bin/proto-loader-gen-types.ts | 1490 ++++++++--------- 1 file changed, 745 insertions(+), 745 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 54b1475c3..bd294aa66 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -1,745 +1,745 @@ -#!/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 dependenc 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}); - for (const filename of protoFiles) { - const loadedRoot = await loadProtosWithOptions(filename, options); - writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.ts'), options); - } -} - -function runScript() { - const argv = yargs - .string(['includeDirs', 'grpcLib']) - .normalize(['includeDirs', 'outDir']) - .array('includeDirs') - .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'includeComments']) -// .choices('longs', ['String', 'Number']) -// .choices('enums', ['String']) -// .choices('bytes', ['Array', 'String']) - .string(['longs', 'enums', 'bytes']) - .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._, {...argv, alternateCommentMode: true}).then(() => { - if (argv.verbose) { - console.log('Success'); - } - }, (error) => { - throw error; - }) -} - -if (require.main === module) { - runScript(); -} \ No newline at end of file +#!/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 dependenc 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}); + for (const filename of protoFiles) { + const loadedRoot = await loadProtosWithOptions(filename, options); + writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.ts'), options); + } +} + +function runScript() { + const argv = yargs + .string(['includeDirs', 'grpcLib']) + .normalize(['includeDirs', 'outDir']) + .array('includeDirs') + .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'includeComments']) +// .choices('longs', ['String', 'Number']) +// .choices('enums', ['String']) +// .choices('bytes', ['Array', 'String']) + .string(['longs', 'enums', 'bytes']) + .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._, {...argv, alternateCommentMode: true}).then(() => { + if (argv.verbose) { + console.log('Success'); + } + }, (error) => { + throw error; + }) +} + +if (require.main === module) { + runScript(); +} From ac86173a2036ab502edc9e9b94d568d0d5fc0742 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 8 Jan 2021 08:11:24 +0000 Subject: [PATCH 39/45] proto-loader: Add example usage to README --- packages/proto-loader/README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/README.md b/packages/proto-loader/README.md index 7a97a3b1b..198f9d2bf 100644 --- a/packages/proto-loader/README.md +++ b/packages/proto-loader/README.md @@ -57,7 +57,7 @@ const options = { 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: @@ -85,4 +85,33 @@ Options: --outDir, -O Directory in which to output files [string] [required] --grpcLib The gRPC implementation library that these types will be used with [string] [required] -``` \ No newline at end of file +``` + +### 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); +``` From cf9d0fd4cc16ab7547e6915bcc0f3a2941418abc Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Fri, 8 Jan 2021 08:11:35 +0000 Subject: [PATCH 40/45] proto-loader: Fix yargs types --- packages/proto-loader/bin/proto-loader-gen-types.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index bd294aa66..8a8a082d9 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -678,6 +678,9 @@ async function writeAllFiles(protoFiles: string[], options: GeneratorOptions) { function runScript() { const argv = yargs + .parserConfiguration({ + 'parse-positional-numbers': false + }) .string(['includeDirs', 'grpcLib']) .normalize(['includeDirs', 'outDir']) .array('includeDirs') @@ -731,7 +734,7 @@ function runScript() { console.log('Parsed arguments:', argv); } addCommonProtos(); - writeAllFiles(argv._, {...argv, alternateCommentMode: true}).then(() => { + writeAllFiles(argv._ as string[], {...argv, alternateCommentMode: true}).then(() => { if (argv.verbose) { console.log('Success'); } From 995540ceec4177ffb87f8464281052b2a7ab72e6 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 18 Mar 2021 13:22:03 -0700 Subject: [PATCH 41/45] Update golden generated files to match recent changes --- packages/proto-loader/golden-generated/echo.ts | 4 ++-- .../golden-generated/google/longrunning/Operations.ts | 2 +- .../golden-generated/google/showcase/v1beta1/Echo.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/proto-loader/golden-generated/echo.ts b/packages/proto-loader/golden-generated/echo.ts index 70cb030de..02514f053 100644 --- a/packages/proto-loader/golden-generated/echo.ts +++ b/packages/proto-loader/golden-generated/echo.ts @@ -1,10 +1,10 @@ -import * as grpc from '@grpc/grpc-js'; +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 = { +type SubtypeConstructor any, Subtype> = { new(...args: ConstructorParameters): Subtype; }; diff --git a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts index eafd538e5..6aa477ada 100644 --- a/packages/proto-loader/golden-generated/google/longrunning/Operations.ts +++ b/packages/proto-loader/golden-generated/google/longrunning/Operations.ts @@ -1,6 +1,6 @@ // Original file: deps/googleapis/google/longrunning/operations.proto -import * as grpc from '@grpc/grpc-js' +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'; diff --git a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts index ed3678400..33fe373a8 100644 --- a/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts +++ b/packages/proto-loader/golden-generated/google/showcase/v1beta1/Echo.ts @@ -1,6 +1,6 @@ // Original file: deps/gapic-showcase/schema/google/showcase/v1beta1/echo.proto -import * as grpc from '@grpc/grpc-js' +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'; From 5cf93cf5fdff0075bb2ec1ceff2f14008d2873e6 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 24 Mar 2021 09:35:27 -0700 Subject: [PATCH 42/45] Fix a typo in a comment Co-authored-by: Ian Edington --- packages/proto-loader/bin/proto-loader-gen-types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 8a8a082d9..c4c7c516b 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -118,7 +118,7 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv const filePath = from === undefined ? './' + getImportPath(dependency) : getRelativeImportPath(from, dependency); const typeInterfaceName = getTypeInterfaceName(dependency); let importedTypes: string; - /* If the dependenc is defined within a message, it will be generated in that + /* 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) { From 4742f9d57ee6602c81dae9439dd529dcb9701256 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 31 Mar 2021 13:04:05 -0700 Subject: [PATCH 43/45] Combine output for input files with the same basename --- packages/proto-loader/bin/proto-loader-gen-types.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 8a8a082d9..90a83bb98 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -670,9 +670,18 @@ function writeFilesForRoot(root: Protobuf.Root, masterFileName: string, options: 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 loadedRoot = await loadProtosWithOptions(filename, options); - writeFilesForRoot(loadedRoot, path.basename(filename).replace('.proto', '.ts'), options); + 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); } } From 3ac1e6ddb8787ad17b53f5c821d438eea44941fc Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Wed, 31 Mar 2021 13:22:08 -0700 Subject: [PATCH 44/45] Address review comments --- .../bin/proto-loader-gen-types.ts | 22 +++++++++---------- packages/proto-loader/src/index.ts | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 90a83bb98..d410088b8 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -694,9 +694,6 @@ function runScript() { .normalize(['includeDirs', 'outDir']) .array('includeDirs') .boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'includeComments']) -// .choices('longs', ['String', 'Number']) -// .choices('enums', ['String']) -// .choices('bytes', ['Array', 'String']) .string(['longs', 'enums', 'bytes']) .coerce('longs', value => { switch (value) { @@ -739,17 +736,18 @@ function runScript() { .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('Parsed arguments:', argv); + console.log('Success'); } - addCommonProtos(); - writeAllFiles(argv._ as string[], {...argv, alternateCommentMode: true}).then(() => { - if (argv.verbose) { - console.log('Success'); - } - }, (error) => { - throw error; - }) + }, (error) => { + console.error(error) + process.exit(1); + }); } if (require.main === module) { diff --git a/packages/proto-loader/src/index.ts b/packages/proto-loader/src/index.ts index 4e15174cc..e31a1938a 100644 --- a/packages/proto-loader/src/index.ts +++ b/packages/proto-loader/src/index.ts @@ -24,6 +24,8 @@ import { loadProtosWithOptionsSync, loadProtosWithOptions, Options, addCommonPro 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. @@ -139,8 +141,6 @@ export interface PackageDefinition { [index: string]: AnyDefinition; } -export { Options }; - type DecodedDescriptorSet = Protobuf.Message & descriptor.IFileDescriptorSet; From 65f1eb4a2983e2c38d89787be5280bc4a2a6d181 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Thu, 1 Apr 2021 11:53:30 -0700 Subject: [PATCH 45/45] Add default values to generator usage info --- packages/proto-loader/README.md | 51 ++++++++++--------- .../bin/proto-loader-gen-types.ts | 10 ++++ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/packages/proto-loader/README.md b/packages/proto-loader/README.md index 198f9d2bf..123fad111 100644 --- a/packages/proto-loader/README.md +++ b/packages/proto-loader/README.md @@ -61,30 +61,33 @@ The `proto-loader-gen-types` script distributed with this package can be used to 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] - --longs The type that should be used to output 64 bit integer - values. Can be String, Number [string] - --enums The type that should be used to output enum fields. Can be - String [string] - --bytes The type that should be used to output bytes fields. Can be - String, Array [string] - --defaults Output default values for omitted fields [boolean] - --arrays Output default values for omitted repeated fields even if - --defaults is not set [boolean] - --objects Output default values for omitted message fields even if - --defaults is not set [boolean] - --oneofs Output virtual oneof fields set to the present field's name - [boolean] - --json Represent Infinity and NaN as strings in float fields. Also - decode google.protobuf.Any automatically [boolean] - --includeComments Generate doc comments from comments in the original files - [boolean] - --includeDirs, -I Directories to search for included files [array] - --outDir, -O Directory in which to output files [string] [required] - --grpcLib The gRPC implementation library that these types will be - used with [string] [required] + --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 diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index 441f26fd9..c11befee0 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -695,6 +695,16 @@ function runScript() { .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;