Skip to content

Commit

Permalink
Merge branch 'main' into lalvoeiro/do-merge
Browse files Browse the repository at this point in the history
* main:
  chore(release): 1.168.0 [skip ci]
  feat: allow `$type` to be optional (#1013)
  chore(release): 1.167.9 [skip ci]
  fix: typescript errors for struct with optional=all (#1008)
  • Loading branch information
lukealvoeiro committed Mar 12, 2024
2 parents 64387f9 + 51c3d0c commit 805ea3e
Show file tree
Hide file tree
Showing 35 changed files with 1,531 additions and 83 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [1.168.0](https://github.com/stephenh/ts-proto/compare/v1.167.9...v1.168.0) (2024-03-08)


### Features

* allow `$type` to be optional ([#1013](https://github.com/stephenh/ts-proto/issues/1013)) ([f285557](https://github.com/stephenh/ts-proto/commit/f285557a4f77d4b75327de2c13cf0917b0361f14))

## [1.167.9](https://github.com/stephenh/ts-proto/compare/v1.167.8...v1.167.9) (2024-02-28)


### Bug Fixes

* typescript errors for struct with optional=all ([#1008](https://github.com/stephenh/ts-proto/issues/1008)) ([e838e38](https://github.com/stephenh/ts-proto/commit/e838e3801e0ef5e8b5a14ead7d7dfc0ad3532cf1)), closes [#578](https://github.com/stephenh/ts-proto/issues/578)

## [1.167.8](https://github.com/stephenh/ts-proto/compare/v1.167.7...v1.167.8) (2024-02-18)


Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ Generated code will be placed in the Gradle build directory.

- With `--ts_proto_opt=outputSchema=true`, meta typings will be generated that can later be used in other code generators.

- With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name. You can use `--ts_proto_opt=outputTypeAnnotations=static-only` to omit it from the `interface` declaration.
- With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name. You can use `--ts_proto_opt=outputTypeAnnotations=static-only` to omit it from the `interface` declaration, or `--ts_proto_opt=outputTypeAnnotations=optional` to make it an optional property on the `interface` definition. The latter option may be useful if you want to use the `$type` field for runtime type checking on responses from a server.

- With `--ts_proto_opt=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will be given a `$type` field containing its fully-qualified name.

Expand Down
9 changes: 5 additions & 4 deletions integration/grpc-js/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,21 @@ export const Struct = {

wrap(object: { [key: string]: any } | undefined): Struct {
const struct = createBaseStruct();

if (object !== undefined) {
Object.keys(object).forEach((key) => {
for (const key of Object.keys(object)) {
struct.fields[key] = object[key];
});
}
}
return struct;
},

unwrap(message: Struct): { [key: string]: any } {
const object: { [key: string]: any } = {};
if (message.fields) {
Object.keys(message.fields).forEach((key) => {
for (const key of Object.keys(message.fields)) {
object[key] = message.fields[key];
});
}
}
return object;
},
Expand Down
9 changes: 5 additions & 4 deletions integration/nestjs-simple/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,21 @@ function createBaseStruct(): Struct {
export const Struct = {
wrap(object: { [key: string]: any } | undefined): Struct {
const struct = createBaseStruct();

if (object !== undefined) {
Object.keys(object).forEach((key) => {
for (const key of Object.keys(object)) {
struct.fields[key] = Value.wrap(object[key]);
});
}
}
return struct;
},

unwrap(message: Struct): { [key: string]: any } {
const object: { [key: string]: any } = {};
if (message.fields) {
Object.keys(message.fields).forEach((key) => {
for (const key of Object.keys(message.fields)) {
object[key] = Value.unwrap(message.fields[key]);
});
}
}
return object;
},
Expand Down
9 changes: 5 additions & 4 deletions integration/nice-grpc/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,21 @@ export const Struct = {

wrap(object: { [key: string]: any } | undefined): Struct {
const struct = createBaseStruct();

if (object !== undefined) {
Object.keys(object).forEach((key) => {
for (const key of Object.keys(object)) {
struct.fields[key] = object[key];
});
}
}
return struct;
},

unwrap(message: Struct): { [key: string]: any } {
const object: { [key: string]: any } = {};
if (message.fields) {
Object.keys(message.fields).forEach((key) => {
for (const key of Object.keys(message.fields)) {
object[key] = message.fields[key];
});
}
}
return object;
},
Expand Down
9 changes: 5 additions & 4 deletions integration/oneof-unions-snake/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,21 @@ export const Struct = {

wrap(object: { [key: string]: any } | undefined): Struct {
const struct = createBaseStruct();

if (object !== undefined) {
Object.keys(object).forEach((key) => {
for (const key of Object.keys(object)) {
struct.fields[key] = object[key];
});
}
}
return struct;
},

unwrap(message: Struct): { [key: string]: any } {
const object: { [key: string]: any } = {};
if (message.fields) {
Object.keys(message.fields).forEach((key) => {
for (const key of Object.keys(message.fields)) {
object[key] = message.fields[key];
});
}
}
return object;
},
Expand Down
9 changes: 5 additions & 4 deletions integration/oneof-unions/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,21 @@ export const Struct = {

wrap(object: { [key: string]: any } | undefined): Struct {
const struct = createBaseStruct();

if (object !== undefined) {
Object.keys(object).forEach((key) => {
for (const key of Object.keys(object)) {
struct.fields[key] = object[key];
});
}
}
return struct;
},

unwrap(message: Struct): { [key: string]: any } {
const object: { [key: string]: any } = {};
if (message.fields) {
Object.keys(message.fields).forEach((key) => {
for (const key of Object.keys(message.fields)) {
object[key] = message.fields[key];
});
}
}
return object;
},
Expand Down
1 change: 1 addition & 0 deletions integration/optional-type-definitions/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
outputTypeAnnotations=optional
Binary file added integration/optional-type-definitions/simple.bin
Binary file not shown.
23 changes: 23 additions & 0 deletions integration/optional-type-definitions/simple.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Adding a comment to the syntax will become the first
// comment in the output source file.
syntax = "proto3";

package simple;

// This comment is separated by a blank non-comment line, and will detach from
// the following comment on the message Simple.

/** Example comment on the Simple message */
message Simple {
// Name field
string name = 1 [deprecated = true];
/** Age field */
int32 age = 2 [deprecated = true];
Child child = 3 [deprecated = true]; // This comment will also attach;
string test_field = 4 [deprecated = true];
string test_not_deprecated = 5 [deprecated = false];
}

message Child {
string name = 1;
}
Loading

0 comments on commit 805ea3e

Please sign in to comment.