first commit
This commit is contained in:
201
node_modules/@grpc/proto-loader/LICENSE
generated
vendored
Normal file
201
node_modules/@grpc/proto-loader/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
120
node_modules/@grpc/proto-loader/README.md
generated
vendored
Normal file
120
node_modules/@grpc/proto-loader/README.md
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
# gRPC Protobuf Loader
|
||||
|
||||
A utility package for loading `.proto` files for use with gRPC, using the latest Protobuf.js package.
|
||||
Please refer to [protobuf.js' documentation](https://github.com/dcodeIO/protobuf.js/blob/master/README.md)
|
||||
to understands its features and limitations.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install @grpc/proto-loader
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const protoLoader = require('@grpc/proto-loader');
|
||||
const grpcLibrary = require('grpc');
|
||||
// OR
|
||||
const grpcLibrary = require('@grpc/grpc-js');
|
||||
|
||||
protoLoader.load(protoFileName, options).then(packageDefinition => {
|
||||
const packageObject = grpcLibrary.loadPackageDefinition(packageDefinition);
|
||||
});
|
||||
// OR
|
||||
const packageDefinition = protoLoader.loadSync(protoFileName, options);
|
||||
const packageObject = grpcLibrary.loadPackageDefinition(packageDefinition);
|
||||
```
|
||||
|
||||
The options parameter is an object that can have the following optional properties:
|
||||
|
||||
| Field name | Valid values | Description
|
||||
|------------|--------------|------------
|
||||
| `keepCase` | `true` or `false` | Preserve field names. The default is to change them to camel case.
|
||||
| `longs` | `String` or `Number` | The type to use to represent `long` values. Defaults to a `Long` object type.
|
||||
| `enums` | `String` | The type to use to represent `enum` values. Defaults to the numeric value.
|
||||
| `bytes` | `Array` or `String` | The type to use to represent `bytes` values. Defaults to `Buffer`.
|
||||
| `defaults` | `true` or `false` | Set default values on output objects. Defaults to `false`.
|
||||
| `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`:
|
||||
|
||||
```js
|
||||
const options = {
|
||||
keepCase: true,
|
||||
longs: String,
|
||||
enums: String,
|
||||
defaults: true,
|
||||
oneofs: true
|
||||
}
|
||||
```
|
||||
|
||||
## Generating TypeScript types
|
||||
|
||||
The `proto-loader-gen-types` script distributed with this package can be used to generate TypeScript type information for the objects loaded at runtime. More information about how to use it can be found in [the *@grpc/proto-loader TypeScript Type Generator CLI Tool* proposal document](https://github.com/grpc/proposal/blob/master/L70-node-proto-loader-type-generator.md). The arguments mostly match the `load` function's options; the full usage information is as follows:
|
||||
|
||||
```console
|
||||
proto-loader-gen-types.js [options] filenames...
|
||||
|
||||
Options:
|
||||
--help Show help [boolean]
|
||||
--version Show version number [boolean]
|
||||
--keepCase Preserve the case of field names
|
||||
[boolean] [default: false]
|
||||
--longs The type that should be used to output 64 bit integer
|
||||
values. Can be String, Number[string] [default: "Long"]
|
||||
--enums The type that should be used to output enum fields. Can
|
||||
be String [string] [default: "number"]
|
||||
--bytes The type that should be used to output bytes fields.
|
||||
Can be String, Array [string] [default: "Buffer"]
|
||||
--defaults Output default values for omitted fields
|
||||
[boolean] [default: false]
|
||||
--arrays Output default values for omitted repeated fields even
|
||||
if --defaults is not set [boolean] [default: false]
|
||||
--objects Output default values for omitted message fields even
|
||||
if --defaults is not set [boolean] [default: false]
|
||||
--oneofs Output virtual oneof fields set to the present field's
|
||||
name [boolean] [default: false]
|
||||
--json Represent Infinity and NaN as strings in float fields.
|
||||
Also decode google.protobuf.Any automatically
|
||||
[boolean] [default: false]
|
||||
--includeComments Generate doc comments from comments in the original
|
||||
files [boolean] [default: false]
|
||||
-I, --includeDirs Directories to search for included files [array]
|
||||
-O, --outDir Directory in which to output files [string] [required]
|
||||
--grpcLib The gRPC implementation library that these types will
|
||||
be used with [string] [required]
|
||||
```
|
||||
|
||||
### Example Usage
|
||||
|
||||
Generate the types:
|
||||
|
||||
```sh
|
||||
$(npm bin)/proto-loader-gen-types --longs=String --enums=String --defaults --oneofs --grpcLib=@grpc/grpc-js --outDir=proto/ proto/*.proto
|
||||
```
|
||||
|
||||
Consume the types:
|
||||
|
||||
```ts
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import * as protoLoader from '@grpc/proto-loader';
|
||||
import { ProtoGrpcType } from './proto/example';
|
||||
import { ExampleHandlers } from './proto/example_package/Example';
|
||||
|
||||
const exampleServer: ExampleHandlers = {
|
||||
// server handlers implementation...
|
||||
};
|
||||
|
||||
const packageDefinition = protoLoader.loadSync('./proto/example.proto');
|
||||
const proto = (grpc.loadPackageDefinition(
|
||||
packageDefinition
|
||||
) as unknown) as ProtoGrpcType;
|
||||
|
||||
const server = new grpc.Server();
|
||||
server.addService(proto.example_package.Example.service, exampleServer);
|
||||
```
|
828
node_modules/@grpc/proto-loader/build/bin/proto-loader-gen-types.js
generated
vendored
Normal file
828
node_modules/@grpc/proto-loader/build/bin/proto-loader-gen-types.js
generated
vendored
Normal file
@ -0,0 +1,828 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Protobuf = require("protobufjs");
|
||||
const yargs = require("yargs");
|
||||
const camelCase = require("lodash.camelcase");
|
||||
const util_1 = require("../src/util");
|
||||
class TextFormatter {
|
||||
constructor() {
|
||||
this.indentText = ' ';
|
||||
this.indentValue = 0;
|
||||
this.textParts = [];
|
||||
}
|
||||
indent() {
|
||||
this.indentValue += 1;
|
||||
}
|
||||
unindent() {
|
||||
this.indentValue -= 1;
|
||||
}
|
||||
writeLine(line) {
|
||||
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, y) {
|
||||
if (x.name < y.name) {
|
||||
return -1;
|
||||
}
|
||||
else if (x.name > y.name) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
function isNamespaceBase(obj) {
|
||||
return Array.isArray(obj.nestedArray);
|
||||
}
|
||||
function stripLeadingPeriod(name) {
|
||||
return name.startsWith('.') ? name.substring(1) : name;
|
||||
}
|
||||
function getImportPath(to) {
|
||||
/* 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) {
|
||||
return stripLeadingPeriod(to.fullName).replace(/\./g, '/') + '.ts';
|
||||
}
|
||||
function getPathToRoot(from) {
|
||||
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, to) {
|
||||
return getPathToRoot(from) + getImportPath(to);
|
||||
}
|
||||
function getTypeInterfaceName(type) {
|
||||
return type.fullName.replace(/\./g, '_');
|
||||
}
|
||||
function getImportLine(dependency, from) {
|
||||
const filePath = from === undefined ? './' + getImportPath(dependency) : getRelativeImportPath(from, dependency);
|
||||
const typeInterfaceName = getTypeInterfaceName(dependency);
|
||||
let importedTypes;
|
||||
/* If the dependency is defined within a message, it will be generated in that
|
||||
* message's file and exported using its typeInterfaceName. */
|
||||
if (dependency.parent instanceof Protobuf.Type) {
|
||||
if (dependency instanceof Protobuf.Type) {
|
||||
importedTypes = `${typeInterfaceName}, ${typeInterfaceName}__Output`;
|
||||
}
|
||||
else if (dependency instanceof Protobuf.Enum) {
|
||||
importedTypes = `${typeInterfaceName}`;
|
||||
}
|
||||
else if (dependency instanceof Protobuf.Service) {
|
||||
importedTypes = `${typeInterfaceName}Client, ${typeInterfaceName}Definition`;
|
||||
}
|
||||
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, ${dependency.name}Definition as ${typeInterfaceName}Definition`;
|
||||
}
|
||||
else {
|
||||
throw new Error('Invalid object passed to getImportLine');
|
||||
}
|
||||
}
|
||||
return `import type { ${importedTypes} } from '${filePath}';`;
|
||||
}
|
||||
function getChildMessagesAndEnums(namespace) {
|
||||
const messageList = [];
|
||||
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, comment) {
|
||||
if (!comment) {
|
||||
return;
|
||||
}
|
||||
formatter.writeLine('/**');
|
||||
for (const line of comment.split('\n')) {
|
||||
formatter.writeLine(` * ${line.replace(/\*\//g, '* /')}`);
|
||||
}
|
||||
formatter.writeLine(' */');
|
||||
}
|
||||
// GENERATOR FUNCTIONS
|
||||
function getTypeNamePermissive(fieldType, resolvedType, repeated, map) {
|
||||
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) {
|
||||
if (repeated || map) {
|
||||
return typeInterfaceName;
|
||||
}
|
||||
else {
|
||||
return `${typeInterfaceName} | null`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return `${typeInterfaceName} | keyof typeof ${typeInterfaceName}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
function getFieldTypePermissive(field) {
|
||||
const valueType = getTypeNamePermissive(field.type, field.resolvedType, field.repeated, field.map);
|
||||
if (field instanceof Protobuf.MapField) {
|
||||
const keyType = field.keyType === 'string' ? 'string' : 'number';
|
||||
return `{[key: ${keyType}]: ${valueType}}`;
|
||||
}
|
||||
else {
|
||||
return valueType;
|
||||
}
|
||||
}
|
||||
function generatePermissiveMessageInterface(formatter, messageType, options, nameOverride) {
|
||||
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 !== null && nameOverride !== void 0 ? nameOverride : messageType.name} {`);
|
||||
formatter.indent();
|
||||
for (const field of messageType.fieldsArray) {
|
||||
const repeatedString = field.repeated ? '[]' : '';
|
||||
const type = 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, resolvedType, repeated, map, options) {
|
||||
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) {
|
||||
/* null is only used to represent absent message values if the defaults
|
||||
* option is set, and only for non-repeated, non-map fields. */
|
||||
if (options.defaults && !repeated && !map) {
|
||||
return `${typeInterfaceName}__Output | null`;
|
||||
}
|
||||
else {
|
||||
return `${typeInterfaceName}__Output`;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (options.enums == String) {
|
||||
return `keyof typeof ${typeInterfaceName}`;
|
||||
}
|
||||
else {
|
||||
return typeInterfaceName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function getFieldTypeRestricted(field, options) {
|
||||
const valueType = getTypeNameRestricted(field.type, field.resolvedType, field.repeated, field.map, options);
|
||||
if (field instanceof Protobuf.MapField) {
|
||||
const keyType = field.keyType === 'string' ? 'string' : 'number';
|
||||
return `{[key: ${keyType}]: ${valueType}}`;
|
||||
}
|
||||
else {
|
||||
return valueType;
|
||||
}
|
||||
}
|
||||
function generateRestrictedMessageInterface(formatter, messageType, options, nameOverride) {
|
||||
var _a, _b, _c;
|
||||
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, false, false, options)};`);
|
||||
formatter.writeLine('}');
|
||||
return;
|
||||
}
|
||||
formatter.writeLine(`export interface ${nameOverride !== null && nameOverride !== void 0 ? nameOverride : messageType.name}__Output {`);
|
||||
formatter.indent();
|
||||
for (const field of messageType.fieldsArray) {
|
||||
let fieldGuaranteed;
|
||||
if (field.partOf) {
|
||||
// The field is not guaranteed populated if it is part of a oneof
|
||||
fieldGuaranteed = false;
|
||||
}
|
||||
else if (field.repeated) {
|
||||
fieldGuaranteed = (_a = (options.defaults || options.arrays)) !== null && _a !== void 0 ? _a : false;
|
||||
}
|
||||
else if (field.map) {
|
||||
fieldGuaranteed = (_b = (options.defaults || options.objects)) !== null && _b !== void 0 ? _b : false;
|
||||
}
|
||||
else {
|
||||
fieldGuaranteed = (_c = options.defaults) !== null && _c !== void 0 ? _c : 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, messageType, options) {
|
||||
var _a, _b;
|
||||
let usesLong = false;
|
||||
let seenDeps = new Set();
|
||||
const childTypes = getChildMessagesAndEnums(messageType);
|
||||
formatter.writeLine(`// Original file: ${(_b = ((_a = messageType.filename) !== null && _a !== void 0 ? _a : 'null')) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, '/')}`);
|
||||
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, enumType, options, nameOverride) {
|
||||
var _a, _b;
|
||||
formatter.writeLine(`// Original file: ${(_b = ((_a = enumType.filename) !== null && _a !== void 0 ? _a : 'null')) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, '/')}`);
|
||||
formatter.writeLine('');
|
||||
if (options.includeComments) {
|
||||
formatComment(formatter, enumType.comment);
|
||||
}
|
||||
formatter.writeLine(`export enum ${nameOverride !== null && nameOverride !== void 0 ? 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('}');
|
||||
}
|
||||
/**
|
||||
* This is a list of methods that are exist in the generic Client class in the
|
||||
* gRPC libraries. TypeScript has a problem with methods in subclasses with the
|
||||
* same names as methods in the superclass, but with mismatched APIs. So, we
|
||||
* avoid generating methods with these names in the service client interfaces.
|
||||
* We always generate two service client methods per service method: one camel
|
||||
* cased, and one with the original casing. So we will still generate one
|
||||
* service client method for any conflicting name.
|
||||
*
|
||||
* Technically, at runtime conflicting name in the service client method
|
||||
* actually shadows the original method, but TypeScript does not have a good
|
||||
* way to represent that. So this change is not 100% accurate, but it gets the
|
||||
* generated code to compile.
|
||||
*
|
||||
* This is just a list of the methods in the Client class definitions in
|
||||
* grpc@1.24.11 and @grpc/grpc-js@1.4.0.
|
||||
*/
|
||||
const CLIENT_RESERVED_METHOD_NAMES = new Set([
|
||||
'close',
|
||||
'getChannel',
|
||||
'waitForReady',
|
||||
'makeUnaryRequest',
|
||||
'makeClientStreamRequest',
|
||||
'makeServerStreamRequest',
|
||||
'makeBidiStreamRequest',
|
||||
'resolveCallInterceptors',
|
||||
/* These methods are private, but TypeScript is not happy with overriding even
|
||||
* private methods with mismatched APIs. */
|
||||
'checkOptionalUnaryResponseArguments',
|
||||
'checkMetadataAndOptions'
|
||||
]);
|
||||
function generateServiceClientInterface(formatter, serviceType, options) {
|
||||
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 (CLIENT_RESERVED_METHOD_NAMES.has(name)) {
|
||||
continue;
|
||||
}
|
||||
if (options.includeComments) {
|
||||
formatComment(formatter, method.comment);
|
||||
}
|
||||
const requestType = getTypeInterfaceName(method.resolvedRequestType);
|
||||
const responseType = getTypeInterfaceName(method.resolvedResponseType) + '__Output';
|
||||
const callbackType = `grpc.requestCallback<${responseType}>`;
|
||||
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, serviceType, options) {
|
||||
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 generateServiceDefinitionInterface(formatter, serviceType) {
|
||||
formatter.writeLine(`export interface ${serviceType.name}Definition extends grpc.ServiceDefinition {`);
|
||||
formatter.indent();
|
||||
for (const methodName of Object.keys(serviceType.methods).sort()) {
|
||||
const method = serviceType.methods[methodName];
|
||||
const requestType = getTypeInterfaceName(method.resolvedRequestType);
|
||||
const responseType = getTypeInterfaceName(method.resolvedResponseType);
|
||||
formatter.writeLine(`${methodName}: MethodDefinition<${requestType}, ${responseType}, ${requestType}__Output, ${responseType}__Output>`);
|
||||
}
|
||||
formatter.unindent();
|
||||
formatter.writeLine('}');
|
||||
}
|
||||
function generateServiceInterfaces(formatter, serviceType, options) {
|
||||
var _a, _b;
|
||||
formatter.writeLine(`// Original file: ${(_b = ((_a = serviceType.filename) !== null && _a !== void 0 ? _a : 'null')) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, '/')}`);
|
||||
formatter.writeLine('');
|
||||
const grpcImportPath = options.grpcLib.startsWith('.') ? getPathToRoot(serviceType) + options.grpcLib : options.grpcLib;
|
||||
formatter.writeLine(`import type * as grpc from '${grpcImportPath}'`);
|
||||
formatter.writeLine(`import type { MethodDefinition } from '@grpc/proto-loader'`);
|
||||
const dependencies = 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);
|
||||
formatter.writeLine('');
|
||||
generateServiceDefinitionInterface(formatter, serviceType);
|
||||
}
|
||||
function containsDefinition(definitionType, namespace) {
|
||||
for (const nested of namespace.nestedArray.sort(compareName)) {
|
||||
if (nested instanceof definitionType) {
|
||||
return true;
|
||||
}
|
||||
else if (isNamespaceBase(nested) && !(nested instanceof Protobuf.Type) && !(nested instanceof Protobuf.Enum) && containsDefinition(definitionType, nested)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function generateDefinitionImports(formatter, namespace, options) {
|
||||
const imports = [];
|
||||
if (containsDefinition(Protobuf.Enum, namespace)) {
|
||||
imports.push('EnumTypeDefinition');
|
||||
}
|
||||
if (containsDefinition(Protobuf.Type, namespace)) {
|
||||
imports.push('MessageTypeDefinition');
|
||||
}
|
||||
if (imports.length) {
|
||||
formatter.writeLine(`import type { ${imports.join(', ')} } from '@grpc/proto-loader';`);
|
||||
}
|
||||
}
|
||||
function generateServiceImports(formatter, namespace, options) {
|
||||
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, nested, options) {
|
||||
if (nested instanceof Protobuf.Service) {
|
||||
if (options.includeComments) {
|
||||
formatComment(formatter, nested.comment);
|
||||
}
|
||||
const typeInterfaceName = getTypeInterfaceName(nested);
|
||||
formatter.writeLine(`${nested.name}: SubtypeConstructor<typeof grpc.Client, ${typeInterfaceName}Client> & { service: ${typeInterfaceName}Definition }`);
|
||||
}
|
||||
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, namespace, options) {
|
||||
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, root, options) {
|
||||
formatter.writeLine(`import type * as grpc from '${options.grpcLib}';`);
|
||||
generateDefinitionImports(formatter, root, options);
|
||||
formatter.writeLine('');
|
||||
generateServiceImports(formatter, root, options);
|
||||
formatter.writeLine('');
|
||||
formatter.writeLine('type SubtypeConstructor<Constructor extends new (...args: any) => any, Subtype> = {');
|
||||
formatter.writeLine(' new(...args: ConstructorParameters<Constructor>): 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, contents) {
|
||||
await fs.promises.mkdir(path.dirname(filename), { recursive: true });
|
||||
return fs.promises.writeFile(filename, contents);
|
||||
}
|
||||
function generateFilesForNamespace(namespace, options) {
|
||||
const filePromises = [];
|
||||
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, masterFileName, options) {
|
||||
const filePromises = [];
|
||||
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, options) {
|
||||
await fs.promises.mkdir(options.outDir, { recursive: true });
|
||||
const basenameMap = new Map();
|
||||
for (const filename of protoFiles) {
|
||||
const basename = path.basename(filename).replace(/\.proto$/, '.ts');
|
||||
if (basenameMap.has(basename)) {
|
||||
basenameMap.get(basename).push(filename);
|
||||
}
|
||||
else {
|
||||
basenameMap.set(basename, [filename]);
|
||||
}
|
||||
}
|
||||
for (const [basename, filenames] of basenameMap.entries()) {
|
||||
const loadedRoot = await util_1.loadProtosWithOptions(filenames, options);
|
||||
writeFilesForRoot(loadedRoot, basename, options);
|
||||
}
|
||||
}
|
||||
async function runScript() {
|
||||
const argv = yargs
|
||||
.parserConfiguration({
|
||||
'parse-positional-numbers': false
|
||||
})
|
||||
.string(['includeDirs', 'grpcLib'])
|
||||
.normalize(['includeDirs', 'outDir'])
|
||||
.array('includeDirs')
|
||||
.boolean(['keepCase', 'defaults', 'arrays', 'objects', 'oneofs', 'json', 'verbose', 'includeComments'])
|
||||
.string(['longs', 'enums', 'bytes'])
|
||||
.default('keepCase', false)
|
||||
.default('defaults', false)
|
||||
.default('arrays', false)
|
||||
.default('objects', false)
|
||||
.default('oneofs', false)
|
||||
.default('json', false)
|
||||
.default('includeComments', false)
|
||||
.default('longs', 'Long')
|
||||
.default('enums', 'number')
|
||||
.default('bytes', 'Buffer')
|
||||
.coerce('longs', value => {
|
||||
switch (value) {
|
||||
case 'String': return String;
|
||||
case 'Number': return Number;
|
||||
default: return undefined;
|
||||
}
|
||||
}).coerce('enums', value => {
|
||||
if (value === 'String') {
|
||||
return String;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}).coerce('bytes', value => {
|
||||
switch (value) {
|
||||
case 'Array': return Array;
|
||||
case 'String': return String;
|
||||
default: return undefined;
|
||||
}
|
||||
}).alias({
|
||||
includeDirs: 'I',
|
||||
outDir: 'O',
|
||||
verbose: 'v'
|
||||
}).describe({
|
||||
keepCase: 'Preserve the case of field names',
|
||||
longs: 'The type that should be used to output 64 bit integer values. Can be String, Number',
|
||||
enums: 'The type that should be used to output enum fields. Can be String',
|
||||
bytes: 'The type that should be used to output bytes fields. Can be String, Array',
|
||||
defaults: 'Output default values for omitted fields',
|
||||
arrays: 'Output default values for omitted repeated fields even if --defaults is not set',
|
||||
objects: 'Output default values for omitted message fields even if --defaults is not set',
|
||||
oneofs: 'Output virtual oneof fields set to the present field\'s name',
|
||||
json: 'Represent Infinity and NaN as strings in float fields. Also decode google.protobuf.Any automatically',
|
||||
includeComments: 'Generate doc comments from comments in the original files',
|
||||
includeDirs: 'Directories to search for included files',
|
||||
outDir: 'Directory in which to output files',
|
||||
grpcLib: 'The gRPC implementation library that these types will be used with'
|
||||
}).demandOption(['outDir', 'grpcLib'])
|
||||
.demand(1)
|
||||
.usage('$0 [options] filenames...')
|
||||
.epilogue('WARNING: This tool is in alpha. The CLI and generated code are subject to change')
|
||||
.argv;
|
||||
if (argv.verbose) {
|
||||
console.log('Parsed arguments:', argv);
|
||||
}
|
||||
util_1.addCommonProtos();
|
||||
writeAllFiles(argv._, Object.assign(Object.assign({}, argv), { alternateCommentMode: true })).then(() => {
|
||||
if (argv.verbose) {
|
||||
console.log('Success');
|
||||
}
|
||||
}, (error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
if (require.main === module) {
|
||||
runScript();
|
||||
}
|
||||
//# sourceMappingURL=proto-loader-gen-types.js.map
|
135
node_modules/@grpc/proto-loader/build/src/index.d.ts
generated
vendored
Normal file
135
node_modules/@grpc/proto-loader/build/src/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import * as Protobuf from 'protobufjs';
|
||||
import * as descriptor from 'protobufjs/ext/descriptor';
|
||||
import { Options } from './util';
|
||||
import Long = require('long');
|
||||
export { Options, 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 declare function isAnyExtension(obj: object): obj is AnyExtension;
|
||||
declare module 'protobufjs' {
|
||||
interface Type {
|
||||
toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IDescriptorProto> & descriptor.IDescriptorProto;
|
||||
}
|
||||
interface RootConstructor {
|
||||
new (options?: Options): Root;
|
||||
fromDescriptor(descriptorSet: descriptor.IFileDescriptorSet | Protobuf.Reader | Uint8Array): Root;
|
||||
fromJSON(json: Protobuf.INamespace, root?: Root): Root;
|
||||
}
|
||||
interface Root {
|
||||
toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IFileDescriptorSet> & descriptor.IFileDescriptorSet;
|
||||
}
|
||||
interface Enum {
|
||||
toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IEnumDescriptorProto> & descriptor.IEnumDescriptorProto;
|
||||
}
|
||||
}
|
||||
export interface Serialize<T> {
|
||||
(value: T): Buffer;
|
||||
}
|
||||
export interface Deserialize<T> {
|
||||
(bytes: Buffer): T;
|
||||
}
|
||||
export interface ProtobufTypeDefinition {
|
||||
format: string;
|
||||
type: object;
|
||||
fileDescriptorProtos: Buffer[];
|
||||
}
|
||||
export interface MessageTypeDefinition extends ProtobufTypeDefinition {
|
||||
format: 'Protocol Buffer 3 DescriptorProto';
|
||||
}
|
||||
export interface EnumTypeDefinition extends ProtobufTypeDefinition {
|
||||
format: 'Protocol Buffer 3 EnumDescriptorProto';
|
||||
}
|
||||
export interface MethodDefinition<RequestType, ResponseType, OutputRequestType = RequestType, OutputResponseType = ResponseType> {
|
||||
path: string;
|
||||
requestStream: boolean;
|
||||
responseStream: boolean;
|
||||
requestSerialize: Serialize<RequestType>;
|
||||
responseSerialize: Serialize<ResponseType>;
|
||||
requestDeserialize: Deserialize<OutputRequestType>;
|
||||
responseDeserialize: Deserialize<OutputResponseType>;
|
||||
originalName?: string;
|
||||
requestType: MessageTypeDefinition;
|
||||
responseType: MessageTypeDefinition;
|
||||
}
|
||||
export interface ServiceDefinition {
|
||||
[index: string]: MethodDefinition<object, object>;
|
||||
}
|
||||
export declare type AnyDefinition = ServiceDefinition | MessageTypeDefinition | EnumTypeDefinition;
|
||||
export interface PackageDefinition {
|
||||
[index: string]: AnyDefinition;
|
||||
}
|
||||
/**
|
||||
* Load a .proto file with the specified options.
|
||||
* @param filename One or multiple file paths to load. Can be an absolute path
|
||||
* or relative to an include path.
|
||||
* @param options.keepCase Preserve field names. The default is to change them
|
||||
* to camel case.
|
||||
* @param options.longs The type that should be used to represent `long` values.
|
||||
* Valid options are `Number` and `String`. Defaults to a `Long` object type
|
||||
* from a library.
|
||||
* @param options.enums The type that should be used to represent `enum` values.
|
||||
* The only valid option is `String`. Defaults to the numeric value.
|
||||
* @param options.bytes The type that should be used to represent `bytes`
|
||||
* values. Valid options are `Array` and `String`. The default is to use
|
||||
* `Buffer`.
|
||||
* @param options.defaults Set default values on output objects. Defaults to
|
||||
* `false`.
|
||||
* @param options.arrays Set empty arrays for missing array values even if
|
||||
* `defaults` is `false`. Defaults to `false`.
|
||||
* @param options.objects Set empty objects for missing object values even if
|
||||
* `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 declare function load(filename: string | string[], options?: Options): Promise<PackageDefinition>;
|
||||
export declare function loadSync(filename: string | string[], options?: Options): PackageDefinition;
|
||||
export declare function fromJSON(json: Protobuf.INamespace, options?: Options): PackageDefinition;
|
||||
export declare function loadFileDescriptorSetFromBuffer(descriptorSet: Buffer, options?: Options): PackageDefinition;
|
||||
export declare function loadFileDescriptorSetFromObject(descriptorSet: Parameters<typeof descriptor.FileDescriptorSet.fromObject>[0], options?: Options): PackageDefinition;
|
218
node_modules/@grpc/proto-loader/build/src/index.js
generated
vendored
Normal file
218
node_modules/@grpc/proto-loader/build/src/index.js
generated
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const camelCase = require("lodash.camelcase");
|
||||
const Protobuf = require("protobufjs");
|
||||
const descriptor = require("protobufjs/ext/descriptor");
|
||||
const util_1 = require("./util");
|
||||
const Long = require("long");
|
||||
exports.Long = Long;
|
||||
function isAnyExtension(obj) {
|
||||
return ('@type' in obj) && (typeof obj['@type'] === 'string');
|
||||
}
|
||||
exports.isAnyExtension = isAnyExtension;
|
||||
const descriptorOptions = {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String,
|
||||
defaults: true,
|
||||
oneofs: true,
|
||||
json: true,
|
||||
};
|
||||
function joinName(baseName, name) {
|
||||
if (baseName === '') {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return baseName + '.' + name;
|
||||
}
|
||||
}
|
||||
function isHandledReflectionObject(obj) {
|
||||
return (obj instanceof Protobuf.Service ||
|
||||
obj instanceof Protobuf.Type ||
|
||||
obj instanceof Protobuf.Enum);
|
||||
}
|
||||
function isNamespaceBase(obj) {
|
||||
return obj instanceof Protobuf.Namespace || obj instanceof Protobuf.Root;
|
||||
}
|
||||
function getAllHandledReflectionObjects(obj, parentName) {
|
||||
const objName = joinName(parentName, obj.name);
|
||||
if (isHandledReflectionObject(obj)) {
|
||||
return [[objName, obj]];
|
||||
}
|
||||
else {
|
||||
if (isNamespaceBase(obj) && typeof obj.nested !== 'undefined') {
|
||||
return Object.keys(obj.nested)
|
||||
.map(name => {
|
||||
return getAllHandledReflectionObjects(obj.nested[name], objName);
|
||||
})
|
||||
.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function createDeserializer(cls, options) {
|
||||
return function deserialize(argBuf) {
|
||||
return cls.toObject(cls.decode(argBuf), options);
|
||||
};
|
||||
}
|
||||
function createSerializer(cls) {
|
||||
return function serialize(arg) {
|
||||
if (Array.isArray(arg)) {
|
||||
throw new Error(`Failed to serialize message: expected object with ${cls.name} structure, got array instead`);
|
||||
}
|
||||
const message = cls.fromObject(arg);
|
||||
return cls.encode(message).finish();
|
||||
};
|
||||
}
|
||||
function createMethodDefinition(method, serviceName, options, fileDescriptors) {
|
||||
/* This is only ever called after the corresponding root.resolveAll(), so we
|
||||
* can assume that the resolved request and response types are non-null */
|
||||
const requestType = method.resolvedRequestType;
|
||||
const responseType = method.resolvedResponseType;
|
||||
return {
|
||||
path: '/' + serviceName + '/' + method.name,
|
||||
requestStream: !!method.requestStream,
|
||||
responseStream: !!method.responseStream,
|
||||
requestSerialize: createSerializer(requestType),
|
||||
requestDeserialize: createDeserializer(requestType, options),
|
||||
responseSerialize: createSerializer(responseType),
|
||||
responseDeserialize: createDeserializer(responseType, options),
|
||||
// TODO(murgatroid99): Find a better way to handle this
|
||||
originalName: camelCase(method.name),
|
||||
requestType: createMessageDefinition(requestType, fileDescriptors),
|
||||
responseType: createMessageDefinition(responseType, fileDescriptors),
|
||||
};
|
||||
}
|
||||
function createServiceDefinition(service, name, options, fileDescriptors) {
|
||||
const def = {};
|
||||
for (const method of service.methodsArray) {
|
||||
def[method.name] = createMethodDefinition(method, name, options, fileDescriptors);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
function createMessageDefinition(message, fileDescriptors) {
|
||||
const messageDescriptor = message.toDescriptor('proto3');
|
||||
return {
|
||||
format: 'Protocol Buffer 3 DescriptorProto',
|
||||
type: messageDescriptor.$type.toObject(messageDescriptor, descriptorOptions),
|
||||
fileDescriptorProtos: fileDescriptors,
|
||||
};
|
||||
}
|
||||
function createEnumDefinition(enumType, fileDescriptors) {
|
||||
const enumDescriptor = enumType.toDescriptor('proto3');
|
||||
return {
|
||||
format: 'Protocol Buffer 3 EnumDescriptorProto',
|
||||
type: enumDescriptor.$type.toObject(enumDescriptor, descriptorOptions),
|
||||
fileDescriptorProtos: fileDescriptors,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* function createDefinition(obj: Protobuf.Service, name: string, options:
|
||||
* Options): ServiceDefinition; function createDefinition(obj: Protobuf.Type,
|
||||
* name: string, options: Options): MessageTypeDefinition; function
|
||||
* createDefinition(obj: Protobuf.Enum, name: string, options: Options):
|
||||
* EnumTypeDefinition;
|
||||
*/
|
||||
function createDefinition(obj, name, options, fileDescriptors) {
|
||||
if (obj instanceof Protobuf.Service) {
|
||||
return createServiceDefinition(obj, name, options, fileDescriptors);
|
||||
}
|
||||
else if (obj instanceof Protobuf.Type) {
|
||||
return createMessageDefinition(obj, fileDescriptors);
|
||||
}
|
||||
else if (obj instanceof Protobuf.Enum) {
|
||||
return createEnumDefinition(obj, fileDescriptors);
|
||||
}
|
||||
else {
|
||||
throw new Error('Type mismatch in reflection object handling');
|
||||
}
|
||||
}
|
||||
function createPackageDefinition(root, options) {
|
||||
const def = {};
|
||||
root.resolveAll();
|
||||
const descriptorList = root.toDescriptor('proto3').file;
|
||||
const bufferList = descriptorList.map(value => Buffer.from(descriptor.FileDescriptorProto.encode(value).finish()));
|
||||
for (const [name, obj] of getAllHandledReflectionObjects(root, '')) {
|
||||
def[name] = createDefinition(obj, name, options, bufferList);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
function createPackageDefinitionFromDescriptorSet(decodedDescriptorSet, options) {
|
||||
options = options || {};
|
||||
const root = Protobuf.Root.fromDescriptor(decodedDescriptorSet);
|
||||
root.resolveAll();
|
||||
return createPackageDefinition(root, options);
|
||||
}
|
||||
/**
|
||||
* Load a .proto file with the specified options.
|
||||
* @param filename One or multiple file paths to load. Can be an absolute path
|
||||
* or relative to an include path.
|
||||
* @param options.keepCase Preserve field names. The default is to change them
|
||||
* to camel case.
|
||||
* @param options.longs The type that should be used to represent `long` values.
|
||||
* Valid options are `Number` and `String`. Defaults to a `Long` object type
|
||||
* from a library.
|
||||
* @param options.enums The type that should be used to represent `enum` values.
|
||||
* The only valid option is `String`. Defaults to the numeric value.
|
||||
* @param options.bytes The type that should be used to represent `bytes`
|
||||
* values. Valid options are `Array` and `String`. The default is to use
|
||||
* `Buffer`.
|
||||
* @param options.defaults Set default values on output objects. Defaults to
|
||||
* `false`.
|
||||
* @param options.arrays Set empty arrays for missing array values even if
|
||||
* `defaults` is `false`. Defaults to `false`.
|
||||
* @param options.objects Set empty objects for missing object values even if
|
||||
* `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.
|
||||
*/
|
||||
function load(filename, options) {
|
||||
return util_1.loadProtosWithOptions(filename, options).then(loadedRoot => {
|
||||
return createPackageDefinition(loadedRoot, options);
|
||||
});
|
||||
}
|
||||
exports.load = load;
|
||||
function loadSync(filename, options) {
|
||||
const loadedRoot = util_1.loadProtosWithOptionsSync(filename, options);
|
||||
return createPackageDefinition(loadedRoot, options);
|
||||
}
|
||||
exports.loadSync = loadSync;
|
||||
function fromJSON(json, options) {
|
||||
options = options || {};
|
||||
const loadedRoot = Protobuf.Root.fromJSON(json);
|
||||
loadedRoot.resolveAll();
|
||||
return createPackageDefinition(loadedRoot, options);
|
||||
}
|
||||
exports.fromJSON = fromJSON;
|
||||
function loadFileDescriptorSetFromBuffer(descriptorSet, options) {
|
||||
const decodedDescriptorSet = descriptor.FileDescriptorSet.decode(descriptorSet);
|
||||
return createPackageDefinitionFromDescriptorSet(decodedDescriptorSet, options);
|
||||
}
|
||||
exports.loadFileDescriptorSetFromBuffer = loadFileDescriptorSetFromBuffer;
|
||||
function loadFileDescriptorSetFromObject(descriptorSet, options) {
|
||||
const decodedDescriptorSet = descriptor.FileDescriptorSet.fromObject(descriptorSet);
|
||||
return createPackageDefinitionFromDescriptorSet(decodedDescriptorSet, options);
|
||||
}
|
||||
exports.loadFileDescriptorSetFromObject = loadFileDescriptorSetFromObject;
|
||||
util_1.addCommonProtos();
|
||||
//# sourceMappingURL=index.js.map
|
27
node_modules/@grpc/proto-loader/build/src/util.d.ts
generated
vendored
Normal file
27
node_modules/@grpc/proto-loader/build/src/util.d.ts
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @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 Protobuf from 'protobufjs';
|
||||
export declare type Options = Protobuf.IParseOptions & Protobuf.IConversionOptions & {
|
||||
includeDirs?: string[];
|
||||
};
|
||||
export declare function loadProtosWithOptions(filename: string | string[], options?: Options): Promise<Protobuf.Root>;
|
||||
export declare function loadProtosWithOptionsSync(filename: string | string[], options?: Options): Protobuf.Root;
|
||||
/**
|
||||
* Load Google's well-known proto files that aren't exposed by Protobuf.js.
|
||||
*/
|
||||
export declare function addCommonProtos(): void;
|
88
node_modules/@grpc/proto-loader/build/src/util.js
generated
vendored
Normal file
88
node_modules/@grpc/proto-loader/build/src/util.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Protobuf = require("protobufjs");
|
||||
function addIncludePathResolver(root, includePaths) {
|
||||
const originalResolvePath = root.resolvePath;
|
||||
root.resolvePath = (origin, target) => {
|
||||
if (path.isAbsolute(target)) {
|
||||
return target;
|
||||
}
|
||||
for (const directory of includePaths) {
|
||||
const fullPath = 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 loadProtosWithOptions(filename, options) {
|
||||
const 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);
|
||||
}
|
||||
const loadedRoot = await root.load(filename, options);
|
||||
loadedRoot.resolveAll();
|
||||
return loadedRoot;
|
||||
}
|
||||
exports.loadProtosWithOptions = loadProtosWithOptions;
|
||||
function loadProtosWithOptionsSync(filename, options) {
|
||||
const 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);
|
||||
}
|
||||
const loadedRoot = root.loadSync(filename, options);
|
||||
loadedRoot.resolveAll();
|
||||
return loadedRoot;
|
||||
}
|
||||
exports.loadProtosWithOptionsSync = loadProtosWithOptionsSync;
|
||||
/**
|
||||
* Load Google's well-known proto files that aren't exposed by Protobuf.js.
|
||||
*/
|
||||
function addCommonProtos() {
|
||||
// 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);
|
||||
}
|
||||
exports.addCommonProtos = addCommonProtos;
|
||||
//# sourceMappingURL=util.js.map
|
98
node_modules/@grpc/proto-loader/package.json
generated
vendored
Normal file
98
node_modules/@grpc/proto-loader/package.json
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"_from": "@grpc/proto-loader",
|
||||
"_id": "@grpc/proto-loader@0.6.12",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-filTVbETFnxb9CyRX98zN18ilChTuf/C5scZ2xyaOTp0EHGq0/ufX8rjqXUcSb1Gpv7eZq4M2jDvbh9BogKnrg==",
|
||||
"_location": "/@grpc/proto-loader",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "@grpc/proto-loader",
|
||||
"name": "@grpc/proto-loader",
|
||||
"escapedName": "@grpc%2fproto-loader",
|
||||
"scope": "@grpc",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/",
|
||||
"/@grpc/grpc-js"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.6.12.tgz",
|
||||
"_shasum": "459b619b8b9b67794bf0d1cb819653a38c63e164",
|
||||
"_spec": "@grpc/proto-loader",
|
||||
"_where": "C:\\projects\\blockchain\\lighting\\lapp-crash-course\\backend",
|
||||
"author": {
|
||||
"name": "Google Inc."
|
||||
},
|
||||
"bin": {
|
||||
"proto-loader-gen-types": "build/bin/proto-loader-gen-types.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/grpc/grpc-node/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Michael Lumish",
|
||||
"email": "mlumish@google.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/long": "^4.0.1",
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"long": "^4.0.0",
|
||||
"protobufjs": "^6.10.0",
|
||||
"yargs": "^16.2.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "gRPC utility library for loading .proto files",
|
||||
"devDependencies": {
|
||||
"@types/lodash.camelcase": "^4.3.4",
|
||||
"@types/mkdirp": "^1.0.1",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "^10.17.26",
|
||||
"@types/yargs": "^16.0.4",
|
||||
"clang-format": "^1.2.2",
|
||||
"gts": "^1.1.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "~3.8.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"build/src/*.d.ts",
|
||||
"build/src/*.js",
|
||||
"build/bin/*.js"
|
||||
],
|
||||
"homepage": "https://grpc.io/",
|
||||
"license": "Apache-2.0",
|
||||
"main": "build/src/index.js",
|
||||
"name": "@grpc/proto-loader",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/grpc/grpc-node.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run compile",
|
||||
"check": "gts check",
|
||||
"clean": "rimraf ./build",
|
||||
"compile": "tsc -p .",
|
||||
"fix": "gts fix",
|
||||
"format": "clang-format -i -style=\"{Language: JavaScript, BasedOnStyle: Google, ColumnLimit: 80}\" src/*.ts test/*.ts",
|
||||
"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",
|
||||
"lint": "tslint -c node_modules/google-ts-style/tslint.json -p . -t codeFrame --type-check",
|
||||
"posttest": "npm run check",
|
||||
"prepare": "npm run compile",
|
||||
"pretest": "npm run compile",
|
||||
"test": "gulp test",
|
||||
"validate-golden": "rm -rf ./golden-generated-old && mv ./golden-generated/ ./golden-generated-old && npm run generate-golden && diff -rb ./golden-generated ./golden-generated-old"
|
||||
},
|
||||
"typings": "build/src/index.d.ts",
|
||||
"version": "0.6.12"
|
||||
}
|
Reference in New Issue
Block a user