Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a no-tags option to the type-registry #688

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,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=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will get extra `$type` field containing fully-qualified name.
- 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 get extra `$type` field containing fully-qualified name. If you would prefer to avoid the `$type`, you can `--ts_proto_opt=outputTypeRegistry=no-tags`

- With `--ts_proto_opt=outputServices=grpc-js`, ts-proto will output service definitions and server / client stubs in [grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) format.

Expand Down
Binary file modified integration/angular/simple-message.bin
Binary file not shown.
Binary file modified integration/async-iterable-services/simple.bin
Binary file not shown.
Binary file modified integration/avoid-import-conflicts-types-only/simple.bin
Binary file not shown.
Binary file modified integration/avoid-import-conflicts-types-only/simple2.bin
Binary file not shown.
Binary file modified integration/avoid-import-conflicts/simple.bin
Binary file not shown.
Binary file modified integration/avoid-import-conflicts/simple2.bin
Binary file not shown.
Binary file modified integration/barrel-imports/bar.bin
Binary file not shown.
Binary file modified integration/barrel-imports/foo.bin
Binary file not shown.
Binary file modified integration/batching-with-context/batching.bin
Binary file not shown.
Binary file modified integration/batching/batching.bin
Binary file not shown.
Binary file modified integration/bytes-as-base64/message.bin
Binary file not shown.
Binary file modified integration/bytes-node/point.bin
Binary file not shown.
Binary file modified integration/const-enum/const-enum.bin
Binary file not shown.
Binary file not shown.
Binary file modified integration/enums-as-literals/enums-as-literals.bin
Binary file not shown.
Binary file modified integration/fieldmask/fieldmask.bin
Binary file not shown.
Binary file modified integration/file-suffix/child.bin
Binary file not shown.
Binary file modified integration/file-suffix/parent.bin
Binary file not shown.
Binary file modified integration/generic-metadata/hero.bin
Binary file not shown.
Binary file modified integration/generic-service-definitions-and-services/simple.bin
Binary file not shown.
Binary file modified integration/generic-service-definitions/simple.bin
Binary file not shown.
Binary file modified integration/global-this/global-this.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/grpc-js/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/grpc-js/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/grpc-js/simple.bin
Binary file not shown.
Binary file modified integration/grpc-web-go-server/example.bin
Binary file not shown.
Binary file modified integration/grpc-web-no-streaming-observable/example.bin
Binary file not shown.
Binary file modified integration/grpc-web-no-streaming/example.bin
Binary file not shown.
Binary file modified integration/grpc-web/example.bin
Binary file not shown.
Binary file modified integration/import-mapping/mapping.bin
Binary file not shown.
Binary file modified integration/import-mapping/some/internal/repo/very_private.bin
Binary file not shown.
Binary file modified integration/import-suffix/child.bin
Binary file not shown.
Binary file modified integration/import-suffix/parent.bin
Binary file not shown.
Binary file modified integration/lower-case-svc-methods/math.bin
Binary file not shown.
Binary file modified integration/meta-typings/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/meta-typings/google/type/date.bin
Binary file not shown.
Binary file modified integration/meta-typings/import_dir/thing.bin
Binary file not shown.
Binary file modified integration/meta-typings/simple.bin
Binary file not shown.
Binary file modified integration/nestjs-metadata-grpc-js/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-metadata-observables/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-metadata-restparameters/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-metadata/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-restparameters/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-simple-observables/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-simple-restparameters/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-simple-usedate/hero.bin
Binary file not shown.
Binary file modified integration/nestjs-simple/hero.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/nice-grpc/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/nice-grpc/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/nice-grpc/simple.bin
Binary file not shown.
Binary file modified integration/no-proto-package/no-proto-package.bin
Binary file not shown.
Binary file modified integration/omit-optionals/simple.bin
Binary file not shown.
Binary file modified integration/oneof-properties/oneof.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/oneof-unions-snake/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/oneof-unions-snake/simple.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/oneof-unions/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/oneof-unions/oneof.bin
Binary file not shown.
Binary file not shown.
Binary file modified integration/only-types/reservation.bin
Binary file not shown.
Binary file modified integration/options/options.bin
Binary file not shown.
Binary file modified integration/options/something/something.bin
Binary file not shown.
Binary file modified integration/point/point.bin
Binary file not shown.
Binary file modified integration/reserved-words/reserved-words.bin
Binary file not shown.
Binary file modified integration/return-observable/observable.bin
Binary file not shown.
Binary file modified integration/simple-deprecated-fields/simple.bin
Binary file not shown.
Binary file modified integration/simple-esmodule-interop/simple.bin
Binary file not shown.
Binary file modified integration/simple-json-name/simple.bin
Binary file not shown.
Binary file modified integration/simple-long-string/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/simple-long-string/simple.bin
Binary file not shown.
Binary file modified integration/simple-long/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/simple-long/simple.bin
Binary file not shown.
Binary file modified integration/simple-optionals/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/simple-optionals/import_dir/thing.bin
Binary file not shown.
Binary file modified integration/simple-optionals/simple.bin
Binary file not shown.
Binary file modified integration/simple-optionals/thing.bin
Binary file not shown.
Binary file modified integration/simple-proto2/simple.bin
Binary file not shown.
Binary file not shown.
Binary file modified integration/simple-prototype-defaults/google/type/date.bin
Binary file not shown.
Binary file modified integration/simple-prototype-defaults/import_dir/thing.bin
Binary file not shown.
Binary file modified integration/simple-prototype-defaults/simple.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/simple-snake/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/simple-snake/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/simple-snake/import_dir/thing.bin
Binary file not shown.
Binary file modified integration/simple-snake/simple.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/simple-string-enums/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/simple-string-enums/simple.bin
Binary file not shown.
Binary file not shown.
Binary file modified integration/simple-unrecognized-enum/import_dir/thing.bin
Binary file not shown.
Binary file modified integration/simple-unrecognized-enum/simple.bin
Binary file not shown.
Binary file modified integration/simple/google/protobuf/wrappers.bin
Binary file not shown.
Binary file modified integration/simple/google/type/date.bin
Binary file not shown.
Binary file modified integration/simple/import_dir/thing.bin
Binary file not shown.
Binary file modified integration/simple/simple.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/struct/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export interface Struct_FieldsEntry {
/**
* `Value` represents a dynamically typed value which can be either
* null, a number, a string, a boolean, a recursive struct value, or a
* list of values. A producer of value is expected to set one of these
* variants. Absence of any variant indicates an error.
* list of values. A producer of value is expected to set one of that
* variants, absence of any variant indicates an error.
*
* The JSON representation for `Value` is JSON value.
*/
Expand Down
Binary file modified integration/struct/struct.bin
Binary file not shown.
Binary file added integration/type-registry-no-tags/bar/bar.bin
Binary file not shown.
9 changes: 9 additions & 0 deletions integration/type-registry-no-tags/bar/bar.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package foo.bar;

import "foo.proto";

message Bar {
Foo foo = 1;
}
76 changes: 76 additions & 0 deletions integration/type-registry-no-tags/bar/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable */
import * as _m0 from "protobufjs/minimal";
import { Foo } from "../foo";
import { messageTypeRegistry } from "../typeRegistry";

export const protobufPackage = "foo.bar";

export interface Bar {
foo: Foo | undefined;
}

function createBaseBar(): Bar {
return { foo: undefined };
}

export const Bar = {
$type: "foo.bar.Bar" as const,

encode(message: Bar, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.foo !== undefined) {
Foo.encode(message.foo, writer.uint32(10).fork()).ldelim();
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): Bar {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseBar();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.foo = Foo.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): Bar {
return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined };
},

toJSON(message: Bar): unknown {
const obj: any = {};
message.foo !== undefined && (obj.foo = message.foo ? Foo.toJSON(message.foo) : undefined);
return obj;
},

fromPartial<I extends Exact<DeepPartial<Bar>, I>>(object: I): Bar {
const message = createBaseBar();
message.foo = (object.foo !== undefined && object.foo !== null) ? Foo.fromPartial(object.foo) : undefined;
return message;
},
};

messageTypeRegistry.set("foo.bar.Bar", Bar);

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> | "$type">]: never };

function isSet(value: any): boolean {
return value !== null && value !== undefined;
}
Binary file added integration/type-registry-no-tags/foo.bin
Binary file not shown.
18 changes: 18 additions & 0 deletions integration/type-registry-no-tags/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package foo;

import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";

message Foo {
google.protobuf.Timestamp timestamp = 1;
}

message Foo2 {
google.protobuf.Timestamp timestamp = 1;
}

message WithStruct {
google.protobuf.Struct struct = 1;
}
Loading