From c28d21064462814d2b6af269f6156d672853d7be Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Mon, 31 Jan 2022 12:11:12 -0600 Subject: [PATCH 1/7] fix: support for nested messages and enums within group blocks --- src/parse.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/parse.js b/src/parse.js index 0e538be0b..a36a97aed 100644 --- a/src/parse.js +++ b/src/parse.js @@ -443,6 +443,14 @@ function parse(source, root, options) { } break; + case "message": + parseType(type, token); + break; + + case "enum": + parseEnum(type, token); + break; + /* istanbul ignore next */ default: throw illegal(token); // there are no groups with proto3 semantics From a75d7b8d8e118a9544071249c12be29a84319a7f Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Mon, 31 Jan 2022 12:34:17 -0600 Subject: [PATCH 2/7] test: support for nested messages and enums within group blocks --- tests/data/test.json | 55 +++++++++++++++++++++++++++++++++++++++---- tests/data/test.proto | 19 ++++++++++++--- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/tests/data/test.json b/tests/data/test.json index c91edc0fc..5186ed4a2 100644 --- a/tests/data/test.json +++ b/tests/data/test.json @@ -412,18 +412,26 @@ "type": "OptionalGroup", "id": 3 }, + "messageInGroup": { + "type": "MessageInGroup", + "id": 4 + }, + "enumInGroup": { + "type": "EnumInGroup", + "id": 5 + }, "id": { "type": "string", - "id": 4 + "id": 6 }, "requiredSimple": { "rule": "required", "type": "Simple2", - "id": 5 + "id": 7 }, "optionalSimple": { "type": "Simple2", - "id": 6 + "id": 8 } }, "nested": { @@ -464,6 +472,45 @@ } }, "group": true + }, + "MessageInGroup": { + "fields": { + "id": { + "rule": "required", + "type": "NetedMessage", + "id": 1 + } + }, + "nested": { + "NetedMessage": { + "fields": { + "id": { + "rule": "optional", + "type": "string", + "id": 1 + } + } + } + }, + "group": true + }, + "EnumInGroup": { + "fields": { + "id": { + "rule": "required", + "type": "NestedEnum", + "id": 1 + } + }, + "nested": { + "NestedEnum": { + "values": { + "first": 0, + "second": 1 + } + } + }, + "group": true } } }, @@ -1514,4 +1561,4 @@ } } } -} \ No newline at end of file +} diff --git a/tests/data/test.proto b/tests/data/test.proto index 0d73a7a49..732f975f7 100644 --- a/tests/data/test.proto +++ b/tests/data/test.proto @@ -182,9 +182,22 @@ message TestGroup { optional group OptionalGroup = 3 { required string id = 1; } - optional string id = 4; - required Simple2 required_simple = 5; - optional Simple2 optional_simple = 6; + optional group MessageInGroup = 4 { + message NestedMessage { + optional string id = 1; + } + required NestedMessage id = 1; + } + optional group EnumInGroup = 5 { + enum NestedEnum { + first = 0; + second = 1; + } + required NestedEnum id = 1; + } + optional string id = 6; + required Simple2 required_simple = 7; + optional Simple2 optional_simple = 8; } message TestGroup1 { From bb099f26739e8748074c3295177234eac6c73ca0 Mon Sep 17 00:00:00 2001 From: Udit Vasu Date: Tue, 5 Jul 2022 17:58:54 +0530 Subject: [PATCH 3/7] chore: add google/rpc protos --- google/rpc/error_details.json | 204 +++++++++++++++++++++++++++++++++ google/rpc/error_details.proto | 77 +++++++++++++ google/rpc/status.json | 45 ++++++++ google/rpc/status.proto | 11 ++ 4 files changed, 337 insertions(+) create mode 100644 google/rpc/error_details.json create mode 100644 google/rpc/error_details.proto create mode 100644 google/rpc/status.json create mode 100644 google/rpc/status.proto diff --git a/google/rpc/error_details.json b/google/rpc/error_details.json new file mode 100644 index 000000000..43aa1a5c5 --- /dev/null +++ b/google/rpc/error_details.json @@ -0,0 +1,204 @@ +{ + "nested": { + "google": { + "nested": { + "rpc": { + "nested": { + "RetryInfo": { + "fields": { + "retryDelay": { + "type": "Duration", + "id": 1 + } + }, + "nested": { + "Duration": { + "fields": { + "seconds": { + "type": "int64", + "id": 1 + }, + "nanos": { + "type": "int32", + "id": 2 + } + } + } + } + }, + "DebugInfo": { + "fields": { + "stackEntries": { + "rule": "repeated", + "type": "string", + "id": 1 + }, + "detail": { + "type": "string", + "id": 2 + } + } + }, + "QuotaFailure": { + "fields": { + "violations": { + "rule": "repeated", + "type": "Violation", + "id": 1 + } + }, + "nested": { + "Violation": { + "fields": { + "subject": { + "type": "string", + "id": 1 + }, + "description": { + "type": "string", + "id": 2 + } + } + } + } + }, + "ErrorInfo": { + "fields": { + "reason": { + "type": "string", + "id": 1 + }, + "domain": { + "type": "string", + "id": 2 + }, + "metadata": { + "keyType": "string", + "type": "string", + "id": 3 + } + } + }, + "PreconditionFailure": { + "fields": { + "violations": { + "rule": "repeated", + "type": "Violation", + "id": 1 + } + }, + "nested": { + "Violation": { + "fields": { + "type": { + "type": "string", + "id": 1 + }, + "subject": { + "type": "string", + "id": 2 + }, + "description": { + "type": "string", + "id": 3 + } + } + } + } + }, + "BadRequest": { + "fields": { + "fieldViolations": { + "rule": "repeated", + "type": "FieldViolation", + "id": 1 + } + }, + "nested": { + "FieldViolation": { + "fields": { + "field": { + "type": "string", + "id": 1 + }, + "description": { + "type": "string", + "id": 2 + } + } + } + } + }, + "RequestInfo": { + "fields": { + "requestId": { + "type": "string", + "id": 1 + }, + "servingData": { + "type": "string", + "id": 2 + } + } + }, + "ResourceInfo": { + "fields": { + "resourceType": { + "type": "string", + "id": 1 + }, + "resourceName": { + "type": "string", + "id": 2 + }, + "owner": { + "type": "string", + "id": 3 + }, + "description": { + "type": "string", + "id": 4 + } + } + }, + "Help": { + "fields": { + "links": { + "rule": "repeated", + "type": "Link", + "id": 1 + } + }, + "nested": { + "Link": { + "fields": { + "description": { + "type": "string", + "id": 1 + }, + "url": { + "type": "string", + "id": 2 + } + } + } + } + }, + "LocalizedMessage": { + "fields": { + "locale": { + "type": "string", + "id": 1 + }, + "message": { + "type": "string", + "id": 2 + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/google/rpc/error_details.proto b/google/rpc/error_details.proto new file mode 100644 index 000000000..40d90c372 --- /dev/null +++ b/google/rpc/error_details.proto @@ -0,0 +1,77 @@ +syntax = "proto3"; + +package google.rpc; + +message RetryInfo { + message Duration { + int64 seconds = 1; + int32 nanos = 2; + } + + Duration retry_delay = 1; +} + +message DebugInfo { + repeated string stack_entries = 1; + string detail = 2; +} + +message QuotaFailure { + message Violation { + string subject = 1; + string description = 2; + } + + repeated Violation violations = 1; +} + +message ErrorInfo { + string reason = 1; + string domain = 2; + map metadata = 3; +} + +message PreconditionFailure { + message Violation { + string type = 1; + string subject = 2; + string description = 3; + } + + repeated Violation violations = 1; +} + +message BadRequest { + message FieldViolation { + string field = 1; + string description = 2; + } + + repeated FieldViolation field_violations = 1; +} + +message RequestInfo { + string request_id = 1; + string serving_data = 2; +} + +message ResourceInfo { + string resource_type = 1; + string resource_name = 2; + string owner = 3; + string description = 4; +} + +message Help { + message Link { + string description = 1; + string url = 2; + } + + repeated Link links = 1; +} + +message LocalizedMessage { + string locale = 1; + string message = 2; +} diff --git a/google/rpc/status.json b/google/rpc/status.json new file mode 100644 index 000000000..18ba47f93 --- /dev/null +++ b/google/rpc/status.json @@ -0,0 +1,45 @@ +{ + "nested": { + "google": { + "nested": { + "protobuf": { + "nested": { + "Any": { + "fields": { + "type_url": { + "type": "string", + "id": 1 + }, + "value": { + "type": "bytes", + "id": 2 + } + } + } + } + }, + "rpc": { + "nested": { + "Status": { + "fields": { + "code": { + "type": "int32", + "id": 1 + }, + "message": { + "type": "string", + "id": 2 + }, + "details": { + "rule": "repeated", + "type": "google.protobuf.Any", + "id": 3 + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/google/rpc/status.proto b/google/rpc/status.proto new file mode 100644 index 000000000..50e324607 --- /dev/null +++ b/google/rpc/status.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package google.rpc; + +import "google/protobuf/any.proto"; + +message Status { + int32 code = 1; + string message = 2; + repeated google.protobuf.Any details = 3; +} From f154e215a8e09fb275d73970894146240df99646 Mon Sep 17 00:00:00 2001 From: Udit Vasu Date: Tue, 5 Jul 2022 17:59:33 +0530 Subject: [PATCH 4/7] chore: update package name --- package-lock.json | 7 ++++--- package.json | 11 +++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index c069f1c75..66ba33419 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,14 @@ { - "name": "protobufjs", + "name": "@postman/protobufjs", "version": "6.10.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "protobufjs", + "name": "@postman/protobufjs", "version": "6.10.2", "hasInstallScript": true, - "license": "BSD-3-Clause", + "license": "Apache-2.0", "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", @@ -5427,6 +5427,7 @@ "node_modules/jaguarjs-jsdoc": { "version": "0.0.1", "resolved": "git+ssh://git@github.com/dcodeIO/jaguarjs-jsdoc.git#ade85ac841f5ca8be40c60d506102039a036a8fa", + "integrity": "sha512-3FqwgUAqzFxO1FfRFvWUh3TtSrMSgtgeg5Twe64FbQTTXJ1I42K9hRnrwARv6NKUKi/74bPWaZHBlDj3b4Hx5A==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 4f53ee32a..adced47b0 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,12 @@ { - "name": "protobufjs", + "name": "@postman/protobufjs", "version": "6.10.2", "versionScheme": "~", "description": "Protocol Buffers for JavaScript (& TypeScript).", - "author": "Daniel Wirtz ", - "license": "BSD-3-Clause", - "repository": "protobufjs/protobuf.js", - "bugs": "https://github.com/dcodeIO/protobuf.js/issues", - "homepage": "https://protobufjs.github.io/protobuf.js/", + "license": "Apache-2.0", + "repository": "https://github.com/postmanlabs/protobuf.js", + "bugs": "https://github.com/postmanlabs/protobuf.js/issues", + "homepage": "https://github.com/postmanlabs/protobuf.js", "keywords": [ "protobuf", "protocol-buffers", From ed28206b5329dfb3f5ec9b327a1aaa8a917a6195 Mon Sep 17 00:00:00 2001 From: Udit Vasu Date: Tue, 5 Jul 2022 18:27:09 +0530 Subject: [PATCH 5/7] 6.11.3-postman.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 66ba33419..e02ac5998 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@postman/protobufjs", - "version": "6.10.2", + "version": "6.11.3-postman.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@postman/protobufjs", - "version": "6.10.2", + "version": "6.11.3-postman.1", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index adced47b0..0c1de5e5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@postman/protobufjs", - "version": "6.10.2", + "version": "6.11.3-postman.1", "versionScheme": "~", "description": "Protocol Buffers for JavaScript (& TypeScript).", "license": "Apache-2.0", From c87a7fd4817d168e94cc49c2e1652370c2349415 Mon Sep 17 00:00:00 2001 From: Udit Vasu Date: Wed, 10 Aug 2022 00:27:28 +0530 Subject: [PATCH 6/7] fix: lookup own properties from type, service, and namespace objects --- index.d.ts | 8 ++++++++ src/namespace.js | 2 +- src/service.js | 2 +- src/type.js | 6 +++--- src/util.js | 10 ++++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index be394f08f..49fbff132 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2147,6 +2147,14 @@ export namespace util { */ function safeProp(prop: string): string; + /** + * Returns the value of a property found directly in a given object. + * @param object Source object + * @param prop Property name + * @returns Value or `undefined` if not set + */ + function getProp(object: object, prop: string): any; + /** * Converts the first character of a string to upper case. * @param str String to convert diff --git a/src/namespace.js b/src/namespace.js index de9f4cdb0..262dc5697 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -191,7 +191,7 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) { * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist */ Namespace.prototype.get = function get(name) { - return this.nested && this.nested[name] + return util.getProp(this.nested, name) || null; }; diff --git a/src/service.js b/src/service.js index bc2c3080c..0d2b9428b 100644 --- a/src/service.js +++ b/src/service.js @@ -98,7 +98,7 @@ function clearCache(service) { * @override */ Service.prototype.get = function get(name) { - return this.methods[name] + return util.getProp(this.methods, name) || Namespace.prototype.get.call(this, name); }; diff --git a/src/type.js b/src/type.js index 2e7bda49b..7835dab57 100644 --- a/src/type.js +++ b/src/type.js @@ -312,9 +312,9 @@ Type.prototype.resolveAll = function resolveAll() { * @override */ Type.prototype.get = function get(name) { - return this.fields[name] - || this.oneofs && this.oneofs[name] - || this.nested && this.nested[name] + return util.getProp(this.fields, name) + || util.getProp(this.oneofs, name) + || util.getProp(this.nested, name) || null; }; diff --git a/src/util.js b/src/util.js index c39d33a6a..2ef38f878 100644 --- a/src/util.js +++ b/src/util.js @@ -78,6 +78,16 @@ util.safeProp = function safeProp(prop) { return "." + prop; }; +/** + * Returns the value of a property found directly in a given object. + * @param {Object} object Source object + * @param {string} prop Property name + * @returns {*} Value or `undefined` if not set + */ +util.getProp = function get(object, prop) { + return object && Object.prototype.hasOwnProperty.call(object, prop) ? object[prop] : undefined; +}; + /** * Converts the first character of a string to upper case. * @param {string} str String to convert From e9fba6ed6708d8de9f8a68e0a55b9bfbc4b9b5b6 Mon Sep 17 00:00:00 2001 From: Udit Vasu Date: Wed, 10 Aug 2022 00:43:51 +0530 Subject: [PATCH 7/7] 7.0.0-postman.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1478ebdc4..4d0680667 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@postman/protobufjs", - "version": "6.11.3-postman.1", + "version": "7.0.0-postman.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@postman/protobufjs", - "version": "6.11.3-postman.1", + "version": "7.0.0-postman.1", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 55722b7e4..4c43ee773 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@postman/protobufjs", - "version": "6.11.3-postman.1", + "version": "7.0.0-postman.1", "versionScheme": "~", "description": "Protocol Buffers for JavaScript (& TypeScript).", "license": "Apache-2.0",