@gravity-ui/gateway 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +269 -0
- package/bin/patch.js +13 -0
- package/build/components/grpc.d.ts +24 -0
- package/build/components/grpc.js +664 -0
- package/build/components/mixed.d.ts +11 -0
- package/build/components/mixed.js +66 -0
- package/build/components/rest.d.ts +7 -0
- package/build/components/rest.js +291 -0
- package/build/constants.d.ts +46 -0
- package/build/constants.js +101 -0
- package/build/index.d.ts +11 -0
- package/build/index.js +285 -0
- package/build/models/common.d.ts +241 -0
- package/build/models/common.js +8 -0
- package/build/models/context.d.ts +22 -0
- package/build/models/context.js +2 -0
- package/build/models/error.d.ts +12 -0
- package/build/models/error.js +2 -0
- package/build/utils/axios.d.ts +2 -0
- package/build/utils/axios.js +24 -0
- package/build/utils/common.d.ts +15 -0
- package/build/utils/common.js +50 -0
- package/build/utils/create-context-api.d.ts +4 -0
- package/build/utils/create-context-api.js +45 -0
- package/build/utils/grpc-reflection.d.ts +22 -0
- package/build/utils/grpc-reflection.js +56 -0
- package/build/utils/grpc.d.ts +15 -0
- package/build/utils/grpc.js +55 -0
- package/build/utils/overrideEndpoints/index.d.ts +2 -0
- package/build/utils/overrideEndpoints/index.js +4 -0
- package/build/utils/overrideEndpoints/overrideEndpoints.d.ts +17 -0
- package/build/utils/overrideEndpoints/overrideEndpoints.js +103 -0
- package/build/utils/parse-error.d.ts +32 -0
- package/build/utils/parse-error.js +224 -0
- package/build/utils/redact-sensitive-headers.d.ts +4 -0
- package/build/utils/redact-sensitive-headers.js +16 -0
- package/build/utils/typed-api.d.ts +2 -0
- package/build/utils/typed-api.js +7 -0
- package/build/utils/validate.d.ts +4 -0
- package/build/utils/validate.js +56 -0
- package/package.json +91 -0
- package/patches/grpc-reflection-js+0.1.2.patch +87 -0
- package/patches/protobufjs+6.11.4.patch +121 -0
- package/proto/google/api/annotations.proto +31 -0
- package/proto/google/api/http.proto +291 -0
- package/proto/google/protobuf/any.proto +158 -0
- package/proto/google/protobuf/api.proto +208 -0
- package/proto/google/protobuf/compiler/plugin.proto +183 -0
- package/proto/google/protobuf/descriptor.proto +909 -0
- package/proto/google/protobuf/duration.proto +116 -0
- package/proto/google/protobuf/empty.proto +52 -0
- package/proto/google/protobuf/field_mask.proto +245 -0
- package/proto/google/protobuf/source_context.proto +48 -0
- package/proto/google/protobuf/struct.proto +95 -0
- package/proto/google/protobuf/timestamp.proto +147 -0
- package/proto/google/protobuf/type.proto +187 -0
- package/proto/google/protobuf/wrappers.proto +123 -0
- package/proto/google/rpc/README.md +5 -0
- package/proto/google/rpc/code.proto +186 -0
- package/proto/google/rpc/error_details.proto +200 -0
- package/proto/google/rpc/status.proto +92 -0
- package/proto/google/type/dayofweek.proto +51 -0
- package/proto/google/type/timeofday.proto +45 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function validateArgs<TParams>(args: TParams, schema: object): string | false;
|
|
2
|
+
export declare function encodePathParams<TParams extends {}>(params: TParams): Record<string, any>;
|
|
3
|
+
export declare function getPathParam(value: string): string;
|
|
4
|
+
export declare function getPathArgsProxy<TParams extends {}>(args: TParams, encodePathArgs?: boolean): TParams;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPathArgsProxy = exports.getPathParam = exports.encodePathParams = exports.validateArgs = void 0;
|
|
7
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
+
function validateArgs(args, schema) {
|
|
9
|
+
const ajv = new ajv_1.default();
|
|
10
|
+
const validate = ajv.compile(schema);
|
|
11
|
+
return validate(args) ? false : ajv.errorsText(validate.errors);
|
|
12
|
+
}
|
|
13
|
+
exports.validateArgs = validateArgs;
|
|
14
|
+
function encodePathParams(params) {
|
|
15
|
+
const encodedParams = {};
|
|
16
|
+
Object.keys(params).forEach((key) => {
|
|
17
|
+
const value = params[key];
|
|
18
|
+
if (value instanceof Buffer) {
|
|
19
|
+
encodedParams[key] = value;
|
|
20
|
+
}
|
|
21
|
+
else if (typeof value === 'object' && value !== null) {
|
|
22
|
+
encodedParams[key] = encodePathParams(value);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
encodedParams[key] = encodeURIComponent(value);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return encodedParams;
|
|
29
|
+
}
|
|
30
|
+
exports.encodePathParams = encodePathParams;
|
|
31
|
+
function getPathParam(value) {
|
|
32
|
+
return /^((?!(\.\.|\?|#|\\|\/)).)*$/i.test(value) ? value : '';
|
|
33
|
+
}
|
|
34
|
+
exports.getPathParam = getPathParam;
|
|
35
|
+
function getPathArgsProxy(args, encodePathArgs) {
|
|
36
|
+
if (!args) {
|
|
37
|
+
return args;
|
|
38
|
+
}
|
|
39
|
+
return new Proxy(args, {
|
|
40
|
+
get: (object, key) => {
|
|
41
|
+
const value = object[key];
|
|
42
|
+
if (value instanceof Buffer) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === 'object' && value !== null) {
|
|
46
|
+
return getPathArgsProxy(value);
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
const pathParam = getPathParam(value);
|
|
50
|
+
return encodePathArgs ? encodeURIComponent(pathParam) : pathParam;
|
|
51
|
+
}
|
|
52
|
+
return value; // TODO return error INVALID_PARAMS
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.getPathArgsProxy = getPathArgsProxy;
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gravity-ui/gateway",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "build/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"build",
|
|
9
|
+
"proto",
|
|
10
|
+
"bin",
|
|
11
|
+
"patches"
|
|
12
|
+
],
|
|
13
|
+
"bin": {
|
|
14
|
+
"gateway-reflection-patch": "bin/patch.js"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/gravity-ui/gateway.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/gravity-ui/gateway/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/gravity-ui/gateway#readme",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prepare": "husky install",
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"build-integration": "sh integration-test/build.sh",
|
|
28
|
+
"start-integration-server": "node build-integration/integration-test/server",
|
|
29
|
+
"build-and-run-integration": "npm run build-integration && npm run start-integration-server",
|
|
30
|
+
"clean": "rm -rf build && rm -rf build-integration",
|
|
31
|
+
"lint": "eslint \"lib/**/*.{js,ts}\" --quiet",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "npm run build",
|
|
34
|
+
"test": "jest --colors",
|
|
35
|
+
"test-integration": "npx patch-package && start-server-and-test build-and-run-integration http://127.0.0.1:3000 test-integration-no-server",
|
|
36
|
+
"test-integration-no-server": "jest --colors --config=jest.config-integration.js"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@grpc/grpc-js": "^1.8.12",
|
|
40
|
+
"@grpc/proto-loader": "^0.6.13",
|
|
41
|
+
"ajv": "^8.12.0",
|
|
42
|
+
"axios": "^1.3.5",
|
|
43
|
+
"axios-retry": "^3.4.0",
|
|
44
|
+
"lodash": "^4.17.21",
|
|
45
|
+
"object-sizeof": "^2.6.1",
|
|
46
|
+
"protobufjs": "^6.11.4",
|
|
47
|
+
"uuid": "^9.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@commitlint/cli": "^17.7.1",
|
|
51
|
+
"@commitlint/config-conventional": "^17.7.0",
|
|
52
|
+
"@gravity-ui/eslint-config": "^2.0.0",
|
|
53
|
+
"@gravity-ui/prettier-config": "^1.0.1",
|
|
54
|
+
"@gravity-ui/tsconfig": "^1.0.0",
|
|
55
|
+
"@types/express": "^4.17.17",
|
|
56
|
+
"@types/jest": "^29.5.0",
|
|
57
|
+
"@types/lodash": "^4.14.192",
|
|
58
|
+
"@types/node": "^18.15.11",
|
|
59
|
+
"@types/uuid": "^9.0.1",
|
|
60
|
+
"axios-mock-adapter": "^1.21.2",
|
|
61
|
+
"eslint": "^8.44.0",
|
|
62
|
+
"eslint-plugin-import": "^2.27.5",
|
|
63
|
+
"grpc-reflection-js": "^0.1.2",
|
|
64
|
+
"grpc-server-reflection": "^0.1.5",
|
|
65
|
+
"grpc-tools": "^1.12.4",
|
|
66
|
+
"husky": "^8.0.3",
|
|
67
|
+
"jest": "^29.5.0",
|
|
68
|
+
"nano-staged": "^0.8.0",
|
|
69
|
+
"prettier": "^2.8.6",
|
|
70
|
+
"start-server-and-test": "^2.0.0",
|
|
71
|
+
"ts-jest": "^29.1.1",
|
|
72
|
+
"tsc-watch": "^6.0.0",
|
|
73
|
+
"typescript": "^5.0.2"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"grpc-reflection-js": "^0.1.2"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"grpc-reflection-js": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"nano-staged": {
|
|
84
|
+
"*.{js,jsx,ts,tsx}": [
|
|
85
|
+
"eslint --fix --quiet"
|
|
86
|
+
],
|
|
87
|
+
"*.md": [
|
|
88
|
+
"prettier --write"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
diff --git a/node_modules/grpc-reflection-js/build/src/client.d.ts b/node_modules/grpc-reflection-js/build/src/client.d.ts
|
|
2
|
+
index e8acad8..9919874 100644
|
|
3
|
+
--- a/node_modules/grpc-reflection-js/build/src/client.d.ts
|
|
4
|
+
+++ b/node_modules/grpc-reflection-js/build/src/client.d.ts
|
|
5
|
+
@@ -3,7 +3,7 @@ import * as services from './reflection_grpc_pb';
|
|
6
|
+
import { Root } from 'protobufjs';
|
|
7
|
+
export declare class Client {
|
|
8
|
+
grpcClient: services.IServerReflectionClient;
|
|
9
|
+
- constructor(url: string, credentials: ChannelCredentials, options?: object);
|
|
10
|
+
+ constructor(url: string, credentials: ChannelCredentials, options?: object, descriptorExtensionProto?: string[]);
|
|
11
|
+
listServices(): Promise<string[] | void[]>;
|
|
12
|
+
fileContainingSymbol(symbol: string): Promise<Root>;
|
|
13
|
+
fileByFilename(filename: string): Promise<Root>;
|
|
14
|
+
diff --git a/node_modules/grpc-reflection-js/build/src/client.js b/node_modules/grpc-reflection-js/build/src/client.js
|
|
15
|
+
index d21ff4d..0f10f0b 100644
|
|
16
|
+
--- a/node_modules/grpc-reflection-js/build/src/client.js
|
|
17
|
+
+++ b/node_modules/grpc-reflection-js/build/src/client.js
|
|
18
|
+
@@ -26,11 +26,17 @@ exports.Client = void 0;
|
|
19
|
+
const descriptor_1 = require("./descriptor");
|
|
20
|
+
const services = __importStar(require("./reflection_grpc_pb"));
|
|
21
|
+
const reflection_pb_1 = require("./reflection_pb");
|
|
22
|
+
-const descriptor_2 = require("protobufjs/ext/descriptor");
|
|
23
|
+
+const pb = require("protobufjs");
|
|
24
|
+
const lodash_set_1 = __importDefault(require("lodash.set"));
|
|
25
|
+
class Client {
|
|
26
|
+
- constructor(url, credentials, options) {
|
|
27
|
+
+ constructor(url, credentials, options, descriptorExtensionProto) {
|
|
28
|
+
this.grpcClient = new services.ServerReflectionClient(url, credentials, options);
|
|
29
|
+
+
|
|
30
|
+
+ const descriptorRoot = pb.Root.fromJSON(require("protobufjs/google/protobuf/descriptor.json"));
|
|
31
|
+
+ if (descriptorExtensionProto) {
|
|
32
|
+
+ descriptorExtensionProto.forEach((proto) => descriptorRoot.loadSync(proto));
|
|
33
|
+
+ }
|
|
34
|
+
+ this.descriptor = descriptorRoot.lookup(".google.protobuf");
|
|
35
|
+
}
|
|
36
|
+
listServices() {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
@@ -74,15 +80,15 @@ class Client {
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async resolveFileDescriptorSet(fileDescriptorProtoBytes) {
|
|
42
|
+
- const fileDescriptorSet = descriptor_2.FileDescriptorSet.create();
|
|
43
|
+
+ const fileDescriptorSet = this.descriptor.FileDescriptorSet.create();
|
|
44
|
+
const fileDescriptorProtos = await this.resolveDescriptorRecursive(fileDescriptorProtoBytes);
|
|
45
|
+
lodash_set_1.default(fileDescriptorSet, 'file', Array.from(fileDescriptorProtos.values()));
|
|
46
|
+
- return descriptor_1.getDescriptorRootFromDescriptorSet(fileDescriptorSet);
|
|
47
|
+
+ return descriptor_1.getDescriptorRootFromDescriptorSet(fileDescriptorSet, this.descriptor);
|
|
48
|
+
}
|
|
49
|
+
async resolveDescriptorRecursive(fileDescriptorProtoBytes) {
|
|
50
|
+
let fileDescriptorProtos = new Map();
|
|
51
|
+
for (const descriptorByte of fileDescriptorProtoBytes) {
|
|
52
|
+
- const fileDescriptorProto = descriptor_2.FileDescriptorProto.decode(descriptorByte);
|
|
53
|
+
+ const fileDescriptorProto = this.descriptor.FileDescriptorProto.decode(descriptorByte);
|
|
54
|
+
if (fileDescriptorProto.dependency) {
|
|
55
|
+
const dependencies = fileDescriptorProto.dependency;
|
|
56
|
+
for (const dep of dependencies) {
|
|
57
|
+
diff --git a/node_modules/grpc-reflection-js/build/src/descriptor.js b/node_modules/grpc-reflection-js/build/src/descriptor.js
|
|
58
|
+
index a00a919..c680d3b 100644
|
|
59
|
+
--- a/node_modules/grpc-reflection-js/build/src/descriptor.js
|
|
60
|
+
+++ b/node_modules/grpc-reflection-js/build/src/descriptor.js
|
|
61
|
+
@@ -2,7 +2,7 @@
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.getDescriptorRootFromDescriptorSet = exports.getDescriptorRoot = void 0;
|
|
64
|
+
const protobuf = require('protobufjs');
|
|
65
|
+
-const Descriptor = require('protobufjs/ext/descriptor');
|
|
66
|
+
+const Descriptor_1 = require('protobufjs/ext/descriptor');
|
|
67
|
+
const set = require('lodash.set');
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {import('protobufjs').Root} Root
|
|
70
|
+
@@ -15,7 +15,7 @@ const set = require('lodash.set');
|
|
71
|
+
* @return {Root} Protobuf.js Root object
|
|
72
|
+
*/
|
|
73
|
+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
74
|
+
-function getDescriptorRoot(file_descriptor_protos) {
|
|
75
|
+
+function getDescriptorRoot(file_descriptor_protos, Descriptor = Descriptor_1) {
|
|
76
|
+
const descriptorSet = Descriptor.FileDescriptorSet.create();
|
|
77
|
+
file_descriptor_protos.forEach((descriptorByte, i) => {
|
|
78
|
+
const descriptor = Descriptor.FileDescriptorProto.decode(descriptorByte);
|
|
79
|
+
@@ -30,7 +30,7 @@ exports.getDescriptorRoot = getDescriptorRoot;
|
|
80
|
+
* @return {Root} Protobuf.js Root object
|
|
81
|
+
*/
|
|
82
|
+
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
83
|
+
-function getDescriptorRootFromDescriptorSet(file_descriptor_set) {
|
|
84
|
+
+function getDescriptorRootFromDescriptorSet(file_descriptor_set, Descriptor = Descriptor_1) {
|
|
85
|
+
return protobuf.Root.fromDescriptor(file_descriptor_set);
|
|
86
|
+
}
|
|
87
|
+
exports.getDescriptorRootFromDescriptorSet = getDescriptorRootFromDescriptorSet;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
diff --git a/node_modules/protobufjs/ext/descriptor/index.js b/node_modules/protobufjs/ext/descriptor/index.js
|
|
2
|
+
index 6aafd2a..b8e9f58 100644
|
|
3
|
+
--- a/node_modules/protobufjs/ext/descriptor/index.js
|
|
4
|
+
+++ b/node_modules/protobufjs/ext/descriptor/index.js
|
|
5
|
+
@@ -204,6 +204,8 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
6
|
+
if (typeof descriptor.length === "number")
|
|
7
|
+
descriptor = exports.DescriptorProto.decode(descriptor);
|
|
8
|
+
|
|
9
|
+
+ // record mapTypes for map fields
|
|
10
|
+
+ var mapTypes = {};
|
|
11
|
+
// Create the message type
|
|
12
|
+
var type = new Type(descriptor.name.length ? descriptor.name : "Type" + unnamedMessageIndex++, fromDescriptorOptions(descriptor.options, exports.MessageOptions)),
|
|
13
|
+
i;
|
|
14
|
+
@@ -211,9 +213,34 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
15
|
+
/* Oneofs */ if (descriptor.oneofDecl)
|
|
16
|
+
for (i = 0; i < descriptor.oneofDecl.length; ++i)
|
|
17
|
+
type.add(OneOf.fromDescriptor(descriptor.oneofDecl[i]));
|
|
18
|
+
+ /* Nested types */ if (descriptor.nestedType)
|
|
19
|
+
+ for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
20
|
+
+ if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry && descriptor.nestedType[i].field.length === 2){
|
|
21
|
+
+ mapTypes[descriptor.nestedType[i].name] = [fromDescriptorType(descriptor.nestedType[i].field[0].type), descriptor.nestedType[i].field[1].typeName ? descriptor.nestedType[i].field[1].typeName : fromDescriptorType(descriptor.nestedType[i].field[1].type)];
|
|
22
|
+
+ }else{
|
|
23
|
+
+ type.add(Type.fromDescriptor(descriptor.nestedType[i], syntax));
|
|
24
|
+
+ }
|
|
25
|
+
+ }
|
|
26
|
+
/* Fields */ if (descriptor.field)
|
|
27
|
+
for (i = 0; i < descriptor.field.length; ++i) {
|
|
28
|
+
- var field = Field.fromDescriptor(descriptor.field[i], syntax);
|
|
29
|
+
+ var field = null;
|
|
30
|
+
+ while(!field) {
|
|
31
|
+
+ if(descriptor.field[i].typeName) {
|
|
32
|
+
+ // after reflection in typeName maybe just short type name
|
|
33
|
+
+ var foundedKvType = mapTypes[descriptor.field[i].typeName];
|
|
34
|
+
+ if (!foundedKvType) {
|
|
35
|
+
+ var nameParts = descriptor.field[i].typeName.split("."+type.name+".");
|
|
36
|
+
+ if (nameParts.length===2) {
|
|
37
|
+
+ foundedKvType = mapTypes[nameParts[1]];
|
|
38
|
+
+ }
|
|
39
|
+
+ }
|
|
40
|
+
+ if(foundedKvType) {
|
|
41
|
+
+ field = Field.fromDescriptor(descriptor.field[i], syntax, foundedKvType);
|
|
42
|
+
+ break;
|
|
43
|
+
+ }
|
|
44
|
+
+ }
|
|
45
|
+
+ field = Field.fromDescriptor(descriptor.field[i], syntax);
|
|
46
|
+
+ }
|
|
47
|
+
type.add(field);
|
|
48
|
+
if (descriptor.field[i].hasOwnProperty("oneofIndex")) // eslint-disable-line no-prototype-builtins
|
|
49
|
+
type.oneofsArray[descriptor.field[i].oneofIndex].add(field);
|
|
50
|
+
@@ -221,12 +248,6 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
51
|
+
/* Extension fields */ if (descriptor.extension)
|
|
52
|
+
for (i = 0; i < descriptor.extension.length; ++i)
|
|
53
|
+
type.add(Field.fromDescriptor(descriptor.extension[i], syntax));
|
|
54
|
+
- /* Nested types */ if (descriptor.nestedType)
|
|
55
|
+
- for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
56
|
+
- type.add(Type.fromDescriptor(descriptor.nestedType[i], syntax));
|
|
57
|
+
- if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry)
|
|
58
|
+
- type.setOption("map_entry", true);
|
|
59
|
+
- }
|
|
60
|
+
/* Nested enums */ if (descriptor.enumType)
|
|
61
|
+
for (i = 0; i < descriptor.enumType.length; ++i)
|
|
62
|
+
type.add(Enum.fromDescriptor(descriptor.enumType[i]));
|
|
63
|
+
@@ -375,9 +396,10 @@ var numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
|
|
64
|
+
* Creates a field from a descriptor.
|
|
65
|
+
* @param {IFieldDescriptorProto|Reader|Uint8Array} descriptor Descriptor
|
|
66
|
+
* @param {string} [syntax="proto2"] Syntax
|
|
67
|
+
- * @returns {Field} Field instance
|
|
68
|
+
+ * @param {string[]} mapKv Key & value types for map field
|
|
69
|
+
+ * @returns {Field|MapField} Field instance
|
|
70
|
+
*/
|
|
71
|
+
-Field.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
72
|
+
+Field.fromDescriptor = function fromDescriptor(descriptor, syntax, mapKv) {
|
|
73
|
+
|
|
74
|
+
// Decode the descriptor message if specified as a buffer:
|
|
75
|
+
if (typeof descriptor.length === "number")
|
|
76
|
+
@@ -407,8 +429,16 @@ Field.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
77
|
+
if (descriptor.extendee !== undefined) {
|
|
78
|
+
extendee = extendee.length ? extendee : undefined;
|
|
79
|
+
}
|
|
80
|
+
- var field = new Field(
|
|
81
|
+
- descriptor.name.length ? descriptor.name : "field" + descriptor.number,
|
|
82
|
+
+
|
|
83
|
+
+ var rawFieldName = descriptor.name.length ? descriptor.name : "field" + descriptor.number;
|
|
84
|
+
+ var fieldName = $protobuf.util.camelCase(rawFieldName);
|
|
85
|
+
+ var field = mapKv ? new MapField(
|
|
86
|
+
+ fieldName,
|
|
87
|
+
+ descriptor.number,
|
|
88
|
+
+ mapKv[0],
|
|
89
|
+
+ mapKv[1]
|
|
90
|
+
+ ) : new Field(
|
|
91
|
+
+ fieldName,
|
|
92
|
+
descriptor.number,
|
|
93
|
+
fieldType,
|
|
94
|
+
fieldRule,
|
|
95
|
+
@@ -816,6 +846,12 @@ function fromDescriptorOptions(options, type) {
|
|
96
|
+
val = field.resolvedType.valuesById[val];
|
|
97
|
+
out.push(underScore(key), val);
|
|
98
|
+
}
|
|
99
|
+
+
|
|
100
|
+
+ for (var option in options) {
|
|
101
|
+
+ if (!type._fieldsArray.find(({name}) => name === option) && options.hasOwnProperty(option)) {
|
|
102
|
+
+ out.push(underScore(option), options[option]);
|
|
103
|
+
+ }
|
|
104
|
+
+ }
|
|
105
|
+
return out.length ? $protobuf.util.toObject(out) : undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
diff --git a/node_modules/protobufjs/src/root.js b/node_modules/protobufjs/src/root.js
|
|
109
|
+
index df6f11f..98303aa 100644
|
|
110
|
+
--- a/node_modules/protobufjs/src/root.js
|
|
111
|
+
+++ b/node_modules/protobufjs/src/root.js
|
|
112
|
+
@@ -273,6 +273,9 @@ function tryHandleExtension(root, field) {
|
|
113
|
+
var extendedType = field.parent.lookup(field.extend);
|
|
114
|
+
if (extendedType) {
|
|
115
|
+
var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
|
|
116
|
+
+ if (extendedType.get(sisterField.name)) {
|
|
117
|
+
+ return true;
|
|
118
|
+
+ }
|
|
119
|
+
sisterField.declaringField = field;
|
|
120
|
+
field.extensionField = sisterField;
|
|
121
|
+
extendedType.add(sisterField);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright (c) 2015, Google Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
syntax = "proto3";
|
|
16
|
+
|
|
17
|
+
package google.api;
|
|
18
|
+
|
|
19
|
+
import "google/api/http.proto";
|
|
20
|
+
import "google/protobuf/descriptor.proto";
|
|
21
|
+
|
|
22
|
+
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
|
|
23
|
+
option java_multiple_files = true;
|
|
24
|
+
option java_outer_classname = "AnnotationsProto";
|
|
25
|
+
option java_package = "com.google.api";
|
|
26
|
+
option objc_class_prefix = "GAPI";
|
|
27
|
+
|
|
28
|
+
extend google.protobuf.MethodOptions {
|
|
29
|
+
// See `HttpRule`.
|
|
30
|
+
HttpRule http = 72295728;
|
|
31
|
+
}
|