diff --git a/README.markdown b/README.markdown index 0342b6a39..1ad4191b3 100644 --- a/README.markdown +++ b/README.markdown @@ -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. diff --git a/integration/angular/simple-message.bin b/integration/angular/simple-message.bin index 7a2445434..21b89c308 100644 Binary files a/integration/angular/simple-message.bin and b/integration/angular/simple-message.bin differ diff --git a/integration/async-iterable-services/simple.bin b/integration/async-iterable-services/simple.bin index 51973c2d8..5294e4752 100644 Binary files a/integration/async-iterable-services/simple.bin and b/integration/async-iterable-services/simple.bin differ diff --git a/integration/avoid-import-conflicts-types-only/simple.bin b/integration/avoid-import-conflicts-types-only/simple.bin index 75915195a..de3374c94 100644 Binary files a/integration/avoid-import-conflicts-types-only/simple.bin and b/integration/avoid-import-conflicts-types-only/simple.bin differ diff --git a/integration/avoid-import-conflicts-types-only/simple2.bin b/integration/avoid-import-conflicts-types-only/simple2.bin index 4a0fddc47..586ddc576 100644 Binary files a/integration/avoid-import-conflicts-types-only/simple2.bin and b/integration/avoid-import-conflicts-types-only/simple2.bin differ diff --git a/integration/avoid-import-conflicts/simple.bin b/integration/avoid-import-conflicts/simple.bin index 45366f7ff..47d291687 100644 Binary files a/integration/avoid-import-conflicts/simple.bin and b/integration/avoid-import-conflicts/simple.bin differ diff --git a/integration/avoid-import-conflicts/simple2.bin b/integration/avoid-import-conflicts/simple2.bin index a172b14bd..f3d40f0b9 100644 Binary files a/integration/avoid-import-conflicts/simple2.bin and b/integration/avoid-import-conflicts/simple2.bin differ diff --git a/integration/barrel-imports/bar.bin b/integration/barrel-imports/bar.bin index 8b84bf739..5e870abc4 100644 Binary files a/integration/barrel-imports/bar.bin and b/integration/barrel-imports/bar.bin differ diff --git a/integration/barrel-imports/foo.bin b/integration/barrel-imports/foo.bin index 26df53209..47ee411d8 100644 Binary files a/integration/barrel-imports/foo.bin and b/integration/barrel-imports/foo.bin differ diff --git a/integration/batching-with-context/batching.bin b/integration/batching-with-context/batching.bin index 5d6ad57e0..0e8e85337 100644 Binary files a/integration/batching-with-context/batching.bin and b/integration/batching-with-context/batching.bin differ diff --git a/integration/batching/batching.bin b/integration/batching/batching.bin index 5d6ad57e0..0e8e85337 100644 Binary files a/integration/batching/batching.bin and b/integration/batching/batching.bin differ diff --git a/integration/bytes-as-base64/message.bin b/integration/bytes-as-base64/message.bin index b035d9e09..af5507d7e 100644 Binary files a/integration/bytes-as-base64/message.bin and b/integration/bytes-as-base64/message.bin differ diff --git a/integration/bytes-node/point.bin b/integration/bytes-node/point.bin index da2590837..b4ff5033a 100644 Binary files a/integration/bytes-node/point.bin and b/integration/bytes-node/point.bin differ diff --git a/integration/const-enum/const-enum.bin b/integration/const-enum/const-enum.bin index 978b99505..8f9416c8e 100644 Binary files a/integration/const-enum/const-enum.bin and b/integration/const-enum/const-enum.bin differ diff --git a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.bin b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.bin index b5d5687ae..de5ef01a9 100644 Binary files a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.bin and b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.bin differ diff --git a/integration/enums-as-literals/enums-as-literals.bin b/integration/enums-as-literals/enums-as-literals.bin index 890fee420..ad0e76ac9 100644 Binary files a/integration/enums-as-literals/enums-as-literals.bin and b/integration/enums-as-literals/enums-as-literals.bin differ diff --git a/integration/fieldmask/fieldmask.bin b/integration/fieldmask/fieldmask.bin index 528593715..6d6ed0ba7 100644 Binary files a/integration/fieldmask/fieldmask.bin and b/integration/fieldmask/fieldmask.bin differ diff --git a/integration/file-suffix/child.bin b/integration/file-suffix/child.bin index 7c9268976..29e6d3031 100644 Binary files a/integration/file-suffix/child.bin and b/integration/file-suffix/child.bin differ diff --git a/integration/file-suffix/parent.bin b/integration/file-suffix/parent.bin index 222ccda6a..f4da64457 100644 Binary files a/integration/file-suffix/parent.bin and b/integration/file-suffix/parent.bin differ diff --git a/integration/generic-metadata/hero.bin b/integration/generic-metadata/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/generic-metadata/hero.bin and b/integration/generic-metadata/hero.bin differ diff --git a/integration/generic-service-definitions-and-services/simple.bin b/integration/generic-service-definitions-and-services/simple.bin index f101042df..5962c6276 100644 Binary files a/integration/generic-service-definitions-and-services/simple.bin and b/integration/generic-service-definitions-and-services/simple.bin differ diff --git a/integration/generic-service-definitions/simple.bin b/integration/generic-service-definitions/simple.bin index f101042df..5962c6276 100644 Binary files a/integration/generic-service-definitions/simple.bin and b/integration/generic-service-definitions/simple.bin differ diff --git a/integration/global-this/global-this.bin b/integration/global-this/global-this.bin index 4a39e83e8..a65f58709 100644 Binary files a/integration/global-this/global-this.bin and b/integration/global-this/global-this.bin differ diff --git a/integration/grpc-js/google/protobuf/struct.ts b/integration/grpc-js/google/protobuf/struct.ts index 80a98258e..081b74075 100644 --- a/integration/grpc-js/google/protobuf/struct.ts +++ b/integration/grpc-js/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/grpc-js/google/protobuf/wrappers.bin b/integration/grpc-js/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/grpc-js/google/protobuf/wrappers.bin and b/integration/grpc-js/google/protobuf/wrappers.bin differ diff --git a/integration/grpc-js/simple.bin b/integration/grpc-js/simple.bin index a4adec606..fe10fc851 100644 Binary files a/integration/grpc-js/simple.bin and b/integration/grpc-js/simple.bin differ diff --git a/integration/grpc-web-go-server/example.bin b/integration/grpc-web-go-server/example.bin index 1c0736d42..3ad33b93b 100644 Binary files a/integration/grpc-web-go-server/example.bin and b/integration/grpc-web-go-server/example.bin differ diff --git a/integration/grpc-web-no-streaming-observable/example.bin b/integration/grpc-web-no-streaming-observable/example.bin index 0b96ce0c6..4b52601f5 100644 Binary files a/integration/grpc-web-no-streaming-observable/example.bin and b/integration/grpc-web-no-streaming-observable/example.bin differ diff --git a/integration/grpc-web-no-streaming/example.bin b/integration/grpc-web-no-streaming/example.bin index 0b96ce0c6..4b52601f5 100644 Binary files a/integration/grpc-web-no-streaming/example.bin and b/integration/grpc-web-no-streaming/example.bin differ diff --git a/integration/grpc-web/example.bin b/integration/grpc-web/example.bin index 72f331cf3..ea862e9d0 100644 Binary files a/integration/grpc-web/example.bin and b/integration/grpc-web/example.bin differ diff --git a/integration/import-mapping/mapping.bin b/integration/import-mapping/mapping.bin index 28d0434e1..20e991f85 100644 Binary files a/integration/import-mapping/mapping.bin and b/integration/import-mapping/mapping.bin differ diff --git a/integration/import-mapping/some/internal/repo/very_private.bin b/integration/import-mapping/some/internal/repo/very_private.bin index bd7bb4cb2..a89fbdf2b 100644 Binary files a/integration/import-mapping/some/internal/repo/very_private.bin and b/integration/import-mapping/some/internal/repo/very_private.bin differ diff --git a/integration/import-suffix/child.bin b/integration/import-suffix/child.bin index 7c9268976..29e6d3031 100644 Binary files a/integration/import-suffix/child.bin and b/integration/import-suffix/child.bin differ diff --git a/integration/import-suffix/parent.bin b/integration/import-suffix/parent.bin index 222ccda6a..f4da64457 100644 Binary files a/integration/import-suffix/parent.bin and b/integration/import-suffix/parent.bin differ diff --git a/integration/lower-case-svc-methods/math.bin b/integration/lower-case-svc-methods/math.bin index eddba34a4..588e6998f 100644 Binary files a/integration/lower-case-svc-methods/math.bin and b/integration/lower-case-svc-methods/math.bin differ diff --git a/integration/meta-typings/google/protobuf/wrappers.bin b/integration/meta-typings/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/meta-typings/google/protobuf/wrappers.bin and b/integration/meta-typings/google/protobuf/wrappers.bin differ diff --git a/integration/meta-typings/google/type/date.bin b/integration/meta-typings/google/type/date.bin index 680ba7e6d..79b7489a4 100644 Binary files a/integration/meta-typings/google/type/date.bin and b/integration/meta-typings/google/type/date.bin differ diff --git a/integration/meta-typings/import_dir/thing.bin b/integration/meta-typings/import_dir/thing.bin index 18377ed61..777648ff4 100644 Binary files a/integration/meta-typings/import_dir/thing.bin and b/integration/meta-typings/import_dir/thing.bin differ diff --git a/integration/meta-typings/simple.bin b/integration/meta-typings/simple.bin index 0fffa492d..4a2187e3e 100644 Binary files a/integration/meta-typings/simple.bin and b/integration/meta-typings/simple.bin differ diff --git a/integration/nestjs-metadata-grpc-js/hero.bin b/integration/nestjs-metadata-grpc-js/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/nestjs-metadata-grpc-js/hero.bin and b/integration/nestjs-metadata-grpc-js/hero.bin differ diff --git a/integration/nestjs-metadata-observables/hero.bin b/integration/nestjs-metadata-observables/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/nestjs-metadata-observables/hero.bin and b/integration/nestjs-metadata-observables/hero.bin differ diff --git a/integration/nestjs-metadata-restparameters/hero.bin b/integration/nestjs-metadata-restparameters/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/nestjs-metadata-restparameters/hero.bin and b/integration/nestjs-metadata-restparameters/hero.bin differ diff --git a/integration/nestjs-metadata/hero.bin b/integration/nestjs-metadata/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/nestjs-metadata/hero.bin and b/integration/nestjs-metadata/hero.bin differ diff --git a/integration/nestjs-restparameters/hero.bin b/integration/nestjs-restparameters/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/nestjs-restparameters/hero.bin and b/integration/nestjs-restparameters/hero.bin differ diff --git a/integration/nestjs-simple-observables/hero.bin b/integration/nestjs-simple-observables/hero.bin index ad7849d17..cef024802 100644 Binary files a/integration/nestjs-simple-observables/hero.bin and b/integration/nestjs-simple-observables/hero.bin differ diff --git a/integration/nestjs-simple-restparameters/hero.bin b/integration/nestjs-simple-restparameters/hero.bin index 0e82b21bc..709f8464c 100644 Binary files a/integration/nestjs-simple-restparameters/hero.bin and b/integration/nestjs-simple-restparameters/hero.bin differ diff --git a/integration/nestjs-simple-usedate/hero.bin b/integration/nestjs-simple-usedate/hero.bin index 3ce8c0002..72f5de73a 100644 Binary files a/integration/nestjs-simple-usedate/hero.bin and b/integration/nestjs-simple-usedate/hero.bin differ diff --git a/integration/nestjs-simple/hero.bin b/integration/nestjs-simple/hero.bin index 3ce8c0002..72f5de73a 100644 Binary files a/integration/nestjs-simple/hero.bin and b/integration/nestjs-simple/hero.bin differ diff --git a/integration/nice-grpc/google/protobuf/struct.ts b/integration/nice-grpc/google/protobuf/struct.ts index 41ef5d717..9041af0bb 100644 --- a/integration/nice-grpc/google/protobuf/struct.ts +++ b/integration/nice-grpc/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/nice-grpc/google/protobuf/wrappers.bin b/integration/nice-grpc/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/nice-grpc/google/protobuf/wrappers.bin and b/integration/nice-grpc/google/protobuf/wrappers.bin differ diff --git a/integration/nice-grpc/simple.bin b/integration/nice-grpc/simple.bin index a4adec606..fe10fc851 100644 Binary files a/integration/nice-grpc/simple.bin and b/integration/nice-grpc/simple.bin differ diff --git a/integration/no-proto-package/no-proto-package.bin b/integration/no-proto-package/no-proto-package.bin index b23df4108..06e8a111a 100644 Binary files a/integration/no-proto-package/no-proto-package.bin and b/integration/no-proto-package/no-proto-package.bin differ diff --git a/integration/omit-optionals/simple.bin b/integration/omit-optionals/simple.bin index 3d2586b14..d0a87284c 100644 Binary files a/integration/omit-optionals/simple.bin and b/integration/omit-optionals/simple.bin differ diff --git a/integration/oneof-properties/oneof.bin b/integration/oneof-properties/oneof.bin index e3c94035b..ec9d341cf 100644 Binary files a/integration/oneof-properties/oneof.bin and b/integration/oneof-properties/oneof.bin differ diff --git a/integration/oneof-unions-snake/google/protobuf/struct.ts b/integration/oneof-unions-snake/google/protobuf/struct.ts index fdf3803b1..a6fd88863 100644 --- a/integration/oneof-unions-snake/google/protobuf/struct.ts +++ b/integration/oneof-unions-snake/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/oneof-unions-snake/simple.bin b/integration/oneof-unions-snake/simple.bin index ca4927412..f6cbaf1fe 100644 Binary files a/integration/oneof-unions-snake/simple.bin and b/integration/oneof-unions-snake/simple.bin differ diff --git a/integration/oneof-unions/google/protobuf/struct.ts b/integration/oneof-unions/google/protobuf/struct.ts index 4a5c792f7..2001b6c6f 100644 --- a/integration/oneof-unions/google/protobuf/struct.ts +++ b/integration/oneof-unions/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/oneof-unions/oneof.bin b/integration/oneof-unions/oneof.bin index 999540787..0540e0e8d 100644 Binary files a/integration/oneof-unions/oneof.bin and b/integration/oneof-unions/oneof.bin differ diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin b/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin index e43e9b997..1d80a96d2 100644 Binary files a/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin and b/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin differ diff --git a/integration/only-types/reservation.bin b/integration/only-types/reservation.bin index 27024a9e9..fd75bd848 100644 Binary files a/integration/only-types/reservation.bin and b/integration/only-types/reservation.bin differ diff --git a/integration/options/options.bin b/integration/options/options.bin index a96b5e3cb..0621b2627 100644 Binary files a/integration/options/options.bin and b/integration/options/options.bin differ diff --git a/integration/options/something/something.bin b/integration/options/something/something.bin index 0950190ca..ac2de25b3 100644 Binary files a/integration/options/something/something.bin and b/integration/options/something/something.bin differ diff --git a/integration/point/point.bin b/integration/point/point.bin index a9f42b5d2..80fb1541d 100644 Binary files a/integration/point/point.bin and b/integration/point/point.bin differ diff --git a/integration/reserved-words/reserved-words.bin b/integration/reserved-words/reserved-words.bin index 9d07dc9bf..7a55377a2 100644 Binary files a/integration/reserved-words/reserved-words.bin and b/integration/reserved-words/reserved-words.bin differ diff --git a/integration/return-observable/observable.bin b/integration/return-observable/observable.bin index 267c620b9..8a42177f5 100644 Binary files a/integration/return-observable/observable.bin and b/integration/return-observable/observable.bin differ diff --git a/integration/simple-deprecated-fields/simple.bin b/integration/simple-deprecated-fields/simple.bin index edc1b92bd..6e2d774ab 100644 Binary files a/integration/simple-deprecated-fields/simple.bin and b/integration/simple-deprecated-fields/simple.bin differ diff --git a/integration/simple-esmodule-interop/simple.bin b/integration/simple-esmodule-interop/simple.bin index fd3a1d254..213807cbe 100644 Binary files a/integration/simple-esmodule-interop/simple.bin and b/integration/simple-esmodule-interop/simple.bin differ diff --git a/integration/simple-json-name/simple.bin b/integration/simple-json-name/simple.bin index 29222dfc2..7660a9176 100644 Binary files a/integration/simple-json-name/simple.bin and b/integration/simple-json-name/simple.bin differ diff --git a/integration/simple-long-string/google/protobuf/wrappers.bin b/integration/simple-long-string/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple-long-string/google/protobuf/wrappers.bin and b/integration/simple-long-string/google/protobuf/wrappers.bin differ diff --git a/integration/simple-long-string/simple.bin b/integration/simple-long-string/simple.bin index 486951c66..5793ee87c 100644 Binary files a/integration/simple-long-string/simple.bin and b/integration/simple-long-string/simple.bin differ diff --git a/integration/simple-long/google/protobuf/wrappers.bin b/integration/simple-long/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple-long/google/protobuf/wrappers.bin and b/integration/simple-long/google/protobuf/wrappers.bin differ diff --git a/integration/simple-long/simple.bin b/integration/simple-long/simple.bin index 28e779a04..1a8171469 100644 Binary files a/integration/simple-long/simple.bin and b/integration/simple-long/simple.bin differ diff --git a/integration/simple-optionals/google/protobuf/wrappers.bin b/integration/simple-optionals/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple-optionals/google/protobuf/wrappers.bin and b/integration/simple-optionals/google/protobuf/wrappers.bin differ diff --git a/integration/simple-optionals/import_dir/thing.bin b/integration/simple-optionals/import_dir/thing.bin index 18377ed61..777648ff4 100644 Binary files a/integration/simple-optionals/import_dir/thing.bin and b/integration/simple-optionals/import_dir/thing.bin differ diff --git a/integration/simple-optionals/simple.bin b/integration/simple-optionals/simple.bin index d6a2033ae..b9bddba28 100644 Binary files a/integration/simple-optionals/simple.bin and b/integration/simple-optionals/simple.bin differ diff --git a/integration/simple-optionals/thing.bin b/integration/simple-optionals/thing.bin index 132073529..188b45a58 100644 Binary files a/integration/simple-optionals/thing.bin and b/integration/simple-optionals/thing.bin differ diff --git a/integration/simple-proto2/simple.bin b/integration/simple-proto2/simple.bin index c879526ac..624b4f62c 100644 Binary files a/integration/simple-proto2/simple.bin and b/integration/simple-proto2/simple.bin differ diff --git a/integration/simple-prototype-defaults/google/protobuf/wrappers.bin b/integration/simple-prototype-defaults/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple-prototype-defaults/google/protobuf/wrappers.bin and b/integration/simple-prototype-defaults/google/protobuf/wrappers.bin differ diff --git a/integration/simple-prototype-defaults/google/type/date.bin b/integration/simple-prototype-defaults/google/type/date.bin index 680ba7e6d..79b7489a4 100644 Binary files a/integration/simple-prototype-defaults/google/type/date.bin and b/integration/simple-prototype-defaults/google/type/date.bin differ diff --git a/integration/simple-prototype-defaults/import_dir/thing.bin b/integration/simple-prototype-defaults/import_dir/thing.bin index 18377ed61..777648ff4 100644 Binary files a/integration/simple-prototype-defaults/import_dir/thing.bin and b/integration/simple-prototype-defaults/import_dir/thing.bin differ diff --git a/integration/simple-prototype-defaults/simple.bin b/integration/simple-prototype-defaults/simple.bin index 321bb33c3..5c8360ea7 100644 Binary files a/integration/simple-prototype-defaults/simple.bin and b/integration/simple-prototype-defaults/simple.bin differ diff --git a/integration/simple-snake/google/protobuf/struct.ts b/integration/simple-snake/google/protobuf/struct.ts index 802676863..196c1758e 100644 --- a/integration/simple-snake/google/protobuf/struct.ts +++ b/integration/simple-snake/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/simple-snake/google/protobuf/wrappers.bin b/integration/simple-snake/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple-snake/google/protobuf/wrappers.bin and b/integration/simple-snake/google/protobuf/wrappers.bin differ diff --git a/integration/simple-snake/import_dir/thing.bin b/integration/simple-snake/import_dir/thing.bin index 18377ed61..777648ff4 100644 Binary files a/integration/simple-snake/import_dir/thing.bin and b/integration/simple-snake/import_dir/thing.bin differ diff --git a/integration/simple-snake/simple.bin b/integration/simple-snake/simple.bin index a8fca9efd..4324b5366 100644 Binary files a/integration/simple-snake/simple.bin and b/integration/simple-snake/simple.bin differ diff --git a/integration/simple-string-enums/google/protobuf/struct.ts b/integration/simple-string-enums/google/protobuf/struct.ts index 4e88bc237..66f3c2821 100644 --- a/integration/simple-string-enums/google/protobuf/struct.ts +++ b/integration/simple-string-enums/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/simple-string-enums/simple.bin b/integration/simple-string-enums/simple.bin index 091d8c01e..f32eb0779 100644 Binary files a/integration/simple-string-enums/simple.bin and b/integration/simple-string-enums/simple.bin differ diff --git a/integration/simple-unrecognized-enum/google/protobuf/wrappers.bin b/integration/simple-unrecognized-enum/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple-unrecognized-enum/google/protobuf/wrappers.bin and b/integration/simple-unrecognized-enum/google/protobuf/wrappers.bin differ diff --git a/integration/simple-unrecognized-enum/import_dir/thing.bin b/integration/simple-unrecognized-enum/import_dir/thing.bin index 18377ed61..777648ff4 100644 Binary files a/integration/simple-unrecognized-enum/import_dir/thing.bin and b/integration/simple-unrecognized-enum/import_dir/thing.bin differ diff --git a/integration/simple-unrecognized-enum/simple.bin b/integration/simple-unrecognized-enum/simple.bin index d6a2033ae..b9bddba28 100644 Binary files a/integration/simple-unrecognized-enum/simple.bin and b/integration/simple-unrecognized-enum/simple.bin differ diff --git a/integration/simple/google/protobuf/wrappers.bin b/integration/simple/google/protobuf/wrappers.bin index 7f34d6ce0..1c3a982c9 100644 Binary files a/integration/simple/google/protobuf/wrappers.bin and b/integration/simple/google/protobuf/wrappers.bin differ diff --git a/integration/simple/google/type/date.bin b/integration/simple/google/type/date.bin index 680ba7e6d..79b7489a4 100644 Binary files a/integration/simple/google/type/date.bin and b/integration/simple/google/type/date.bin differ diff --git a/integration/simple/import_dir/thing.bin b/integration/simple/import_dir/thing.bin index 18377ed61..777648ff4 100644 Binary files a/integration/simple/import_dir/thing.bin and b/integration/simple/import_dir/thing.bin differ diff --git a/integration/simple/simple.bin b/integration/simple/simple.bin index 2d67ca34d..e34b2ef8b 100644 Binary files a/integration/simple/simple.bin and b/integration/simple/simple.bin differ diff --git a/integration/struct/google/protobuf/struct.ts b/integration/struct/google/protobuf/struct.ts index 80a98258e..081b74075 100644 --- a/integration/struct/google/protobuf/struct.ts +++ b/integration/struct/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/struct/struct.bin b/integration/struct/struct.bin index d9a1b260e..9460f80e7 100644 Binary files a/integration/struct/struct.bin and b/integration/struct/struct.bin differ diff --git a/integration/type-registry-no-tags/bar/bar.bin b/integration/type-registry-no-tags/bar/bar.bin new file mode 100644 index 000000000..15ddb6a94 Binary files /dev/null and b/integration/type-registry-no-tags/bar/bar.bin differ diff --git a/integration/type-registry-no-tags/bar/bar.proto b/integration/type-registry-no-tags/bar/bar.proto new file mode 100644 index 000000000..43aa08bd9 --- /dev/null +++ b/integration/type-registry-no-tags/bar/bar.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package foo.bar; + +import "foo.proto"; + +message Bar { + Foo foo = 1; +} diff --git a/integration/type-registry-no-tags/bar/bar.ts b/integration/type-registry-no-tags/bar/bar.ts new file mode 100644 index 000000000..d97f72277 --- /dev/null +++ b/integration/type-registry-no-tags/bar/bar.ts @@ -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>>(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 extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude | "$type">]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/type-registry-no-tags/foo.bin b/integration/type-registry-no-tags/foo.bin new file mode 100644 index 000000000..275db9054 Binary files /dev/null and b/integration/type-registry-no-tags/foo.bin differ diff --git a/integration/type-registry-no-tags/foo.proto b/integration/type-registry-no-tags/foo.proto new file mode 100644 index 000000000..24f1432fc --- /dev/null +++ b/integration/type-registry-no-tags/foo.proto @@ -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; +} \ No newline at end of file diff --git a/integration/type-registry-no-tags/foo.ts b/integration/type-registry-no-tags/foo.ts new file mode 100644 index 000000000..5a9e58db0 --- /dev/null +++ b/integration/type-registry-no-tags/foo.ts @@ -0,0 +1,213 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; +import { Struct } from "./google/protobuf/struct"; +import { Timestamp } from "./google/protobuf/timestamp"; +import { messageTypeRegistry } from "./typeRegistry"; + +export const protobufPackage = "foo"; + +export interface Foo { + timestamp: Date | undefined; +} + +export interface Foo2 { + timestamp: Date | undefined; +} + +export interface WithStruct { + struct: { [key: string]: any } | undefined; +} + +function createBaseFoo(): Foo { + return { timestamp: undefined }; +} + +export const Foo = { + $type: "foo.Foo" as const, + + encode(message: Foo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.timestamp !== undefined) { + Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Foo { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseFoo(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Foo { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + + toJSON(message: Foo): unknown { + const obj: any = {}; + message.timestamp !== undefined && (obj.timestamp = message.timestamp.toISOString()); + return obj; + }, + + fromPartial, I>>(object: I): Foo { + const message = createBaseFoo(); + message.timestamp = object.timestamp ?? undefined; + return message; + }, +}; + +messageTypeRegistry.set("foo.Foo", Foo); + +function createBaseFoo2(): Foo2 { + return { timestamp: undefined }; +} + +export const Foo2 = { + $type: "foo.Foo2" as const, + + encode(message: Foo2, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.timestamp !== undefined) { + Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Foo2 { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseFoo2(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.timestamp = fromTimestamp(Timestamp.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Foo2 { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + + toJSON(message: Foo2): unknown { + const obj: any = {}; + message.timestamp !== undefined && (obj.timestamp = message.timestamp.toISOString()); + return obj; + }, + + fromPartial, I>>(object: I): Foo2 { + const message = createBaseFoo2(); + message.timestamp = object.timestamp ?? undefined; + return message; + }, +}; + +messageTypeRegistry.set("foo.Foo2", Foo2); + +function createBaseWithStruct(): WithStruct { + return { struct: undefined }; +} + +export const WithStruct = { + $type: "foo.WithStruct" as const, + + encode(message: WithStruct, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.struct !== undefined) { + Struct.encode(Struct.wrap(message.struct), writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): WithStruct { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseWithStruct(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.struct = Struct.unwrap(Struct.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): WithStruct { + return { struct: isObject(object.struct) ? object.struct : undefined }; + }, + + toJSON(message: WithStruct): unknown { + const obj: any = {}; + message.struct !== undefined && (obj.struct = message.struct); + return obj; + }, + + fromPartial, I>>(object: I): WithStruct { + const message = createBaseWithStruct(); + message.struct = object.struct ?? undefined; + return message; + }, +}; + +messageTypeRegistry.set("foo.WithStruct", WithStruct); + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude | "$type">]: never }; + +function toTimestamp(date: Date): Timestamp { + const seconds = date.getTime() / 1_000; + const nanos = (date.getTime() % 1_000) * 1_000_000; + return { seconds, nanos }; +} + +function fromTimestamp(t: Timestamp): Date { + let millis = t.seconds * 1_000; + millis += t.nanos / 1_000_000; + return new Date(millis); +} + +function fromJsonTimestamp(o: any): Date { + if (o instanceof Date) { + return o; + } else if (typeof o === "string") { + return new Date(o); + } else { + return fromTimestamp(Timestamp.fromJSON(o)); + } +} + +function isObject(value: any): boolean { + return typeof value === "object" && value !== null; +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/type-registry-no-tags/google/protobuf/struct.ts b/integration/type-registry-no-tags/google/protobuf/struct.ts new file mode 100644 index 000000000..eae6b2530 --- /dev/null +++ b/integration/type-registry-no-tags/google/protobuf/struct.ts @@ -0,0 +1,486 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; +import { messageTypeRegistry } from "../../typeRegistry"; + +export const protobufPackage = "google.protobuf"; + +/** + * `NullValue` is a singleton enumeration to represent the null value for the + * `Value` type union. + * + * The JSON representation for `NullValue` is JSON `null`. + */ +export enum NullValue { + /** NULL_VALUE - Null value. */ + NULL_VALUE = 0, + UNRECOGNIZED = -1, +} + +export function nullValueFromJSON(object: any): NullValue { + switch (object) { + case 0: + case "NULL_VALUE": + return NullValue.NULL_VALUE; + case -1: + case "UNRECOGNIZED": + default: + return NullValue.UNRECOGNIZED; + } +} + +export function nullValueToJSON(object: NullValue): string { + switch (object) { + case NullValue.NULL_VALUE: + return "NULL_VALUE"; + case NullValue.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} + +/** + * `Struct` represents a structured data value, consisting of fields + * which map to dynamically typed values. In some languages, `Struct` + * might be supported by a native representation. For example, in + * scripting languages like JS a struct is represented as an + * object. The details of that representation are described together + * with the proto support for the language. + * + * The JSON representation for `Struct` is JSON object. + */ +export interface Struct { + /** Unordered map of dynamically typed values. */ + fields: { [key: string]: any | undefined }; +} + +export interface Struct_FieldsEntry { + key: string; + value: any | undefined; +} + +/** + * `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 that + * variants, absence of any variant indicates an error. + * + * The JSON representation for `Value` is JSON value. + */ +export interface Value { + /** Represents a null value. */ + nullValue: + | NullValue + | undefined; + /** Represents a double value. */ + numberValue: + | number + | undefined; + /** Represents a string value. */ + stringValue: + | string + | undefined; + /** Represents a boolean value. */ + boolValue: + | boolean + | undefined; + /** Represents a structured value. */ + structValue: + | { [key: string]: any } + | undefined; + /** Represents a repeated `Value`. */ + listValue: Array | undefined; +} + +/** + * `ListValue` is a wrapper around a repeated field of values. + * + * The JSON representation for `ListValue` is JSON array. + */ +export interface ListValue { + /** Repeated field of dynamically typed values. */ + values: any[]; +} + +function createBaseStruct(): Struct { + return { fields: {} }; +} + +export const Struct = { + $type: "google.protobuf.Struct" as const, + + encode(message: Struct, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + Object.entries(message.fields).forEach(([key, value]) => { + if (value !== undefined) { + Struct_FieldsEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).ldelim(); + } + }); + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Struct { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStruct(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + const entry1 = Struct_FieldsEntry.decode(reader, reader.uint32()); + if (entry1.value !== undefined) { + message.fields[entry1.key] = entry1.value; + } + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Struct { + return { + fields: isObject(object.fields) + ? Object.entries(object.fields).reduce<{ [key: string]: any | undefined }>((acc, [key, value]) => { + acc[key] = value as any | undefined; + return acc; + }, {}) + : {}, + }; + }, + + toJSON(message: Struct): unknown { + const obj: any = {}; + obj.fields = {}; + if (message.fields) { + Object.entries(message.fields).forEach(([k, v]) => { + obj.fields[k] = v; + }); + } + return obj; + }, + + fromPartial, I>>(object: I): Struct { + const message = createBaseStruct(); + message.fields = Object.entries(object.fields ?? {}).reduce<{ [key: string]: any | undefined }>( + (acc, [key, value]) => { + if (value !== undefined) { + acc[key] = value; + } + return acc; + }, + {}, + ); + return message; + }, + + wrap(object: { [key: string]: any } | undefined): Struct { + const struct = createBaseStruct(); + if (object !== undefined) { + Object.keys(object).forEach((key) => { + struct.fields[key] = object[key]; + }); + } + return struct; + }, + + unwrap(message: Struct): { [key: string]: any } { + const object: { [key: string]: any } = {}; + Object.keys(message.fields).forEach((key) => { + object[key] = message.fields[key]; + }); + return object; + }, +}; + +messageTypeRegistry.set("google.protobuf.Struct", Struct); + +function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { + return { key: "", value: undefined }; +} + +export const Struct_FieldsEntry = { + $type: "google.protobuf.Struct.FieldsEntry" as const, + + encode(message: Struct_FieldsEntry, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.key !== "") { + writer.uint32(10).string(message.key); + } + if (message.value !== undefined) { + Value.encode(Value.wrap(message.value), writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Struct_FieldsEntry { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStruct_FieldsEntry(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.string(); + break; + case 2: + message.value = Value.unwrap(Value.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + + toJSON(message: Struct_FieldsEntry): unknown { + const obj: any = {}; + message.key !== undefined && (obj.key = message.key); + message.value !== undefined && (obj.value = message.value); + return obj; + }, + + fromPartial, I>>(object: I): Struct_FieldsEntry { + const message = createBaseStruct_FieldsEntry(); + message.key = object.key ?? ""; + message.value = object.value ?? undefined; + return message; + }, +}; + +messageTypeRegistry.set("google.protobuf.Struct.FieldsEntry", Struct_FieldsEntry); + +function createBaseValue(): Value { + return { + nullValue: undefined, + numberValue: undefined, + stringValue: undefined, + boolValue: undefined, + structValue: undefined, + listValue: undefined, + }; +} + +export const Value = { + $type: "google.protobuf.Value" as const, + + encode(message: Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.nullValue !== undefined) { + writer.uint32(8).int32(message.nullValue); + } + if (message.numberValue !== undefined) { + writer.uint32(17).double(message.numberValue); + } + if (message.stringValue !== undefined) { + writer.uint32(26).string(message.stringValue); + } + if (message.boolValue !== undefined) { + writer.uint32(32).bool(message.boolValue); + } + if (message.structValue !== undefined) { + Struct.encode(Struct.wrap(message.structValue), writer.uint32(42).fork()).ldelim(); + } + if (message.listValue !== undefined) { + ListValue.encode(ListValue.wrap(message.listValue), writer.uint32(50).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Value { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.nullValue = reader.int32() as any; + break; + case 2: + message.numberValue = reader.double(); + break; + case 3: + message.stringValue = reader.string(); + break; + case 4: + message.boolValue = reader.bool(); + break; + case 5: + message.structValue = Struct.unwrap(Struct.decode(reader, reader.uint32())); + break; + case 6: + message.listValue = ListValue.unwrap(ListValue.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Value { + return { + nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : undefined, + numberValue: isSet(object.numberValue) ? Number(object.numberValue) : undefined, + stringValue: isSet(object.stringValue) ? String(object.stringValue) : undefined, + boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : undefined, + structValue: isObject(object.structValue) ? object.structValue : undefined, + listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined, + }; + }, + + toJSON(message: Value): unknown { + const obj: any = {}; + message.nullValue !== undefined && + (obj.nullValue = message.nullValue !== undefined ? nullValueToJSON(message.nullValue) : undefined); + message.numberValue !== undefined && (obj.numberValue = message.numberValue); + message.stringValue !== undefined && (obj.stringValue = message.stringValue); + message.boolValue !== undefined && (obj.boolValue = message.boolValue); + message.structValue !== undefined && (obj.structValue = message.structValue); + message.listValue !== undefined && (obj.listValue = message.listValue); + return obj; + }, + + fromPartial, I>>(object: I): Value { + const message = createBaseValue(); + message.nullValue = object.nullValue ?? undefined; + message.numberValue = object.numberValue ?? undefined; + message.stringValue = object.stringValue ?? undefined; + message.boolValue = object.boolValue ?? undefined; + message.structValue = object.structValue ?? undefined; + message.listValue = object.listValue ?? undefined; + return message; + }, + + wrap(value: any): Value { + const result = createBaseValue(); + + if (value === null) { + result.nullValue = NullValue.NULL_VALUE; + } else if (typeof value === "boolean") { + result.boolValue = value; + } else if (typeof value === "number") { + result.numberValue = value; + } else if (typeof value === "string") { + result.stringValue = value; + } else if (Array.isArray(value)) { + result.listValue = value; + } else if (typeof value === "object") { + result.structValue = value; + } else if (typeof value !== "undefined") { + throw new Error("Unsupported any value type: " + typeof value); + } + + return result; + }, + + unwrap(message: Value): string | number | boolean | Object | null | Array | undefined { + if (message?.stringValue !== undefined) { + return message.stringValue; + } else if (message?.numberValue !== undefined) { + return message.numberValue; + } else if (message?.boolValue !== undefined) { + return message.boolValue; + } else if (message?.structValue !== undefined) { + return message.structValue; + } else if (message?.listValue !== undefined) { + return message.listValue; + } else if (message?.nullValue !== undefined) { + return null; + } + return undefined; + }, +}; + +messageTypeRegistry.set("google.protobuf.Value", Value); + +function createBaseListValue(): ListValue { + return { values: [] }; +} + +export const ListValue = { + $type: "google.protobuf.ListValue" as const, + + encode(message: ListValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + for (const v of message.values) { + Value.encode(Value.wrap(v!), writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): ListValue { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseListValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.values.push(Value.unwrap(Value.decode(reader, reader.uint32()))); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + + toJSON(message: ListValue): unknown { + const obj: any = {}; + if (message.values) { + obj.values = message.values.map((e) => e); + } else { + obj.values = []; + } + return obj; + }, + + fromPartial, I>>(object: I): ListValue { + const message = createBaseListValue(); + message.values = object.values?.map((e) => e) || []; + return message; + }, + + wrap(value: Array | undefined): ListValue { + const result = createBaseListValue(); + + result.values = value ?? []; + + return result; + }, + + unwrap(message: ListValue): Array { + return message.values; + }, +}; + +messageTypeRegistry.set("google.protobuf.ListValue", ListValue); + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude | "$type">]: never }; + +function isObject(value: any): boolean { + return typeof value === "object" && value !== null; +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/type-registry-no-tags/google/protobuf/timestamp.ts b/integration/type-registry-no-tags/google/protobuf/timestamp.ts new file mode 100644 index 000000000..19e930efc --- /dev/null +++ b/integration/type-registry-no-tags/google/protobuf/timestamp.ts @@ -0,0 +1,223 @@ +/* eslint-disable */ +import * as Long from "long"; +import * as _m0 from "protobufjs/minimal"; +import { messageTypeRegistry } from "../../typeRegistry"; + +export const protobufPackage = "google.protobuf"; + +/** + * A Timestamp represents a point in time independent of any time zone or local + * calendar, encoded as a count of seconds and fractions of seconds at + * nanosecond resolution. The count is relative to an epoch at UTC midnight on + * January 1, 1970, in the proleptic Gregorian calendar which extends the + * Gregorian calendar backwards to year one. + * + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + * second table is needed for interpretation, using a [24-hour linear + * smear](https://developers.google.com/time/smear). + * + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + * restricting to that range, we ensure that we can convert to and from [RFC + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + * + * # Examples + * + * Example 1: Compute Timestamp from POSIX `time()`. + * + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * + * struct timeval tv; + * gettimeofday(&tv, NULL); + * + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * + * long millis = System.currentTimeMillis(); + * + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * Example 6: Compute Timestamp from current time in Python. + * + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required. A proto3 JSON serializer should always use UTC (as indicated by + * "Z") when printing the Timestamp type and a proto3 JSON parser should be + * able to accept both UTC and other timezones (as indicated by an offset). + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + * ) to obtain a formatter capable of generating timestamps in this format. + */ +export interface Timestamp { + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + */ + seconds: number; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + */ + nanos: number; +} + +function createBaseTimestamp(): Timestamp { + return { seconds: 0, nanos: 0 }; +} + +export const Timestamp = { + $type: "google.protobuf.Timestamp" as const, + + encode(message: Timestamp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.seconds !== 0) { + writer.uint32(8).int64(message.seconds); + } + if (message.nanos !== 0) { + writer.uint32(16).int32(message.nanos); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Timestamp { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseTimestamp(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.seconds = longToNumber(reader.int64() as Long); + break; + case 2: + message.nanos = reader.int32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + + toJSON(message: Timestamp): unknown { + const obj: any = {}; + message.seconds !== undefined && (obj.seconds = Math.round(message.seconds)); + message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)); + return obj; + }, + + fromPartial, I>>(object: I): Timestamp { + const message = createBaseTimestamp(); + message.seconds = object.seconds ?? 0; + message.nanos = object.nanos ?? 0; + return message; + }, +}; + +messageTypeRegistry.set("google.protobuf.Timestamp", Timestamp); + +declare var self: any | undefined; +declare var window: any | undefined; +declare var global: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") { + return globalThis; + } + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + if (typeof global !== "undefined") { + return global; + } + throw "Unable to locate global object"; +})(); + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude | "$type">]: never }; + +function longToNumber(long: Long): number { + if (long.gt(Number.MAX_SAFE_INTEGER)) { + throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} + +// If you get a compile-error about 'Constructor and ... have no overlap', +// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'. +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/type-registry-no-tags/parameters.txt b/integration/type-registry-no-tags/parameters.txt new file mode 100755 index 000000000..93d1b4fc2 --- /dev/null +++ b/integration/type-registry-no-tags/parameters.txt @@ -0,0 +1 @@ +outputTypeRegistry=no-tags diff --git a/integration/type-registry-no-tags/type-registry-test.ts b/integration/type-registry-no-tags/type-registry-test.ts new file mode 100644 index 000000000..53b08f945 --- /dev/null +++ b/integration/type-registry-no-tags/type-registry-test.ts @@ -0,0 +1,23 @@ +import { Foo, Foo2 } from './foo'; +import { Bar } from './bar/bar'; +import { messageTypeRegistry } from './typeRegistry'; + +describe('type-registry-no-tags', () => { + it('should not output $type field for every message', () => { + expect(Foo.fromPartial({})).toMatchInlineSnapshot(` + Object { + "timestamp": undefined, + } + `); + expect(Bar.fromPartial({})).toMatchInlineSnapshot(` + Object { + "foo": undefined, + } + `); + }); + + it('should register every type', () => { + expect(messageTypeRegistry.get('foo.Foo')).toBe(Foo); + expect(messageTypeRegistry.get('foo.bar.Bar')).toBe(Bar); + }); +}); diff --git a/integration/type-registry-no-tags/typeRegistry.ts b/integration/type-registry-no-tags/typeRegistry.ts new file mode 100644 index 000000000..b309ef5be --- /dev/null +++ b/integration/type-registry-no-tags/typeRegistry.ts @@ -0,0 +1,21 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; + +export interface MessageType { + $type: string; + encode(message: Message, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): Message; + fromJSON(object: any): Message; + toJSON(message: Message): unknown; + fromPartial(object: DeepPartial): Message; +} + +export type UnknownMessage = {}; + +export const messageTypeRegistry = new Map(); + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; diff --git a/integration/type-registry/bar/bar.bin b/integration/type-registry/bar/bar.bin index 3aa6c75d1..15ddb6a94 100644 Binary files a/integration/type-registry/bar/bar.bin and b/integration/type-registry/bar/bar.bin differ diff --git a/integration/type-registry/bar/bar.ts b/integration/type-registry/bar/bar.ts index a5829e86c..0037a4828 100644 --- a/integration/type-registry/bar/bar.ts +++ b/integration/type-registry/bar/bar.ts @@ -59,7 +59,7 @@ export const Bar = { }, }; -messageTypeRegistry.set(Bar.$type, Bar); +messageTypeRegistry.set("foo.bar.Bar", Bar); type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; diff --git a/integration/type-registry/foo.bin b/integration/type-registry/foo.bin index 85b788882..275db9054 100644 Binary files a/integration/type-registry/foo.bin and b/integration/type-registry/foo.bin differ diff --git a/integration/type-registry/foo.ts b/integration/type-registry/foo.ts index 3a72b6cec..523e0d13e 100644 --- a/integration/type-registry/foo.ts +++ b/integration/type-registry/foo.ts @@ -70,7 +70,7 @@ export const Foo = { }, }; -messageTypeRegistry.set(Foo.$type, Foo); +messageTypeRegistry.set("foo.Foo", Foo); function createBaseFoo2(): Foo2 { return { $type: "foo.Foo2", timestamp: undefined }; @@ -121,7 +121,7 @@ export const Foo2 = { }, }; -messageTypeRegistry.set(Foo2.$type, Foo2); +messageTypeRegistry.set("foo.Foo2", Foo2); function createBaseWithStruct(): WithStruct { return { $type: "foo.WithStruct", struct: undefined }; @@ -172,7 +172,7 @@ export const WithStruct = { }, }; -messageTypeRegistry.set(WithStruct.$type, WithStruct); +messageTypeRegistry.set("foo.WithStruct", WithStruct); type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; diff --git a/integration/type-registry/google/protobuf/struct.ts b/integration/type-registry/google/protobuf/struct.ts index 6f035c984..a17eeb5b1 100644 --- a/integration/type-registry/google/protobuf/struct.ts +++ b/integration/type-registry/google/protobuf/struct.ts @@ -63,8 +63,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. */ @@ -201,7 +201,7 @@ export const Struct = { }, }; -messageTypeRegistry.set(Struct.$type, Struct); +messageTypeRegistry.set("google.protobuf.Struct", Struct); function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { $type: "google.protobuf.Struct.FieldsEntry", key: "", value: undefined }; @@ -264,7 +264,7 @@ export const Struct_FieldsEntry = { }, }; -messageTypeRegistry.set(Struct_FieldsEntry.$type, Struct_FieldsEntry); +messageTypeRegistry.set("google.protobuf.Struct.FieldsEntry", Struct_FieldsEntry); function createBaseValue(): Value { return { @@ -411,7 +411,7 @@ export const Value = { }, }; -messageTypeRegistry.set(Value.$type, Value); +messageTypeRegistry.set("google.protobuf.Value", Value); function createBaseListValue(): ListValue { return { $type: "google.protobuf.ListValue", values: [] }; @@ -478,7 +478,7 @@ export const ListValue = { }, }; -messageTypeRegistry.set(ListValue.$type, ListValue); +messageTypeRegistry.set("google.protobuf.ListValue", ListValue); type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; diff --git a/integration/type-registry/google/protobuf/timestamp.ts b/integration/type-registry/google/protobuf/timestamp.ts index bec2e71ed..f7717dcd8 100644 --- a/integration/type-registry/google/protobuf/timestamp.ts +++ b/integration/type-registry/google/protobuf/timestamp.ts @@ -174,7 +174,7 @@ export const Timestamp = { }, }; -messageTypeRegistry.set(Timestamp.$type, Timestamp); +messageTypeRegistry.set("google.protobuf.Timestamp", Timestamp); declare var self: any | undefined; declare var window: any | undefined; diff --git a/integration/types-with-underscores/file.bin b/integration/types-with-underscores/file.bin index eeb5f3f23..665393a84 100644 Binary files a/integration/types-with-underscores/file.bin and b/integration/types-with-underscores/file.bin differ diff --git a/integration/unknown-fields/google/protobuf/compiler/plugin.bin b/integration/unknown-fields/google/protobuf/compiler/plugin.bin index d43fa9612..4ab5654e2 100644 Binary files a/integration/unknown-fields/google/protobuf/compiler/plugin.bin and b/integration/unknown-fields/google/protobuf/compiler/plugin.bin differ diff --git a/integration/unknown-fields/google/protobuf/descriptor.bin b/integration/unknown-fields/google/protobuf/descriptor.bin index 54bbcea7e..970a0577f 100644 Binary files a/integration/unknown-fields/google/protobuf/descriptor.bin and b/integration/unknown-fields/google/protobuf/descriptor.bin differ diff --git a/integration/unknown-fields/options.bin b/integration/unknown-fields/options.bin index 949f7217a..7c36de720 100644 Binary files a/integration/unknown-fields/options.bin and b/integration/unknown-fields/options.bin differ diff --git a/integration/unknown-fields/something/something.bin b/integration/unknown-fields/something/something.bin index 0f4e0f37a..c2fb37b5f 100644 Binary files a/integration/unknown-fields/something/something.bin and b/integration/unknown-fields/something/something.bin differ diff --git a/integration/use-date-false/metadata.bin b/integration/use-date-false/metadata.bin index c4c8c7256..3cbf03e08 100644 Binary files a/integration/use-date-false/metadata.bin and b/integration/use-date-false/metadata.bin differ diff --git a/integration/use-date-string/use-date-string.bin b/integration/use-date-string/use-date-string.bin index 79e656e01..c51c02f87 100644 Binary files a/integration/use-date-string/use-date-string.bin and b/integration/use-date-string/use-date-string.bin differ diff --git a/integration/use-date-true/use-date-true-test.ts b/integration/use-date-true/use-date-true-test.ts index b387eff35..75dd2b2f5 100644 --- a/integration/use-date-true/use-date-true-test.ts +++ b/integration/use-date-true/use-date-true-test.ts @@ -1,12 +1,12 @@ import { Todo, Clock } from './use-date-true'; - +import { Timestamp } from './google/protobuf/timestamp'; const jan1 = new Date('1970-01-01T00:00:00.000Z'); const feb1 = new Date('1970-02-01T00:00:00.000Z'); describe('useDate=true', () => { it('generates a services that compiles', () => { let c: Clock = { - Now: () => Promise.resolve(jan1), + Now: () => Promise.resolve(Timestamp.fromPartial({})), }; }); it('generates types that compile and encode', () => { diff --git a/integration/use-date-true/use-date-true.bin b/integration/use-date-true/use-date-true.bin index a5b93133c..67698706c 100644 Binary files a/integration/use-date-true/use-date-true.bin and b/integration/use-date-true/use-date-true.bin differ diff --git a/integration/use-date-true/use-date-true.ts b/integration/use-date-true/use-date-true.ts index 75efc6e36..7e0b7f33c 100644 --- a/integration/use-date-true/use-date-true.ts +++ b/integration/use-date-true/use-date-true.ts @@ -189,7 +189,7 @@ export const Todo_MapOfTimestampsEntry = { }; export interface Clock { - Now(request: Empty): Promise; + Now(request: Empty): Promise; } export class ClockClientImpl implements Clock { @@ -200,10 +200,10 @@ export class ClockClientImpl implements Clock { this.rpc = rpc; this.Now = this.Now.bind(this); } - Now(request: Empty): Promise { + Now(request: Empty): Promise { const data = Empty.encode(request).finish(); const promise = this.rpc.request(this.service, "Now", data); - return promise.then((data) => fromTimestamp(Timestamp.decode(new _m0.Reader(data)))); + return promise.then((data) => Timestamp.decode(new _m0.Reader(data))); } } diff --git a/integration/use-exact-types-false/foo.bin b/integration/use-exact-types-false/foo.bin index b98932d4b..faa9f81b6 100644 Binary files a/integration/use-exact-types-false/foo.bin and b/integration/use-exact-types-false/foo.bin differ diff --git a/integration/use-json-wire-format/use-json-wire-format.bin b/integration/use-json-wire-format/use-json-wire-format.bin index 723fabc32..0165a793c 100644 Binary files a/integration/use-json-wire-format/use-json-wire-format.bin and b/integration/use-json-wire-format/use-json-wire-format.bin differ diff --git a/integration/use-map-type/use-map-type.bin b/integration/use-map-type/use-map-type.bin index 777daacec..8de61dbd7 100644 Binary files a/integration/use-map-type/use-map-type.bin and b/integration/use-map-type/use-map-type.bin differ diff --git a/integration/use-numeric-enum-json/google/protobuf/struct.ts b/integration/use-numeric-enum-json/google/protobuf/struct.ts index d17382273..56f48c7b3 100644 --- a/integration/use-numeric-enum-json/google/protobuf/struct.ts +++ b/integration/use-numeric-enum-json/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/use-numeric-enum-json/simple.bin b/integration/use-numeric-enum-json/simple.bin index 091d8c01e..f32eb0779 100644 Binary files a/integration/use-numeric-enum-json/simple.bin and b/integration/use-numeric-enum-json/simple.bin differ diff --git a/integration/use-objectid-true-external-import/objectid/objectid.bin b/integration/use-objectid-true-external-import/objectid/objectid.bin index 4dab2c110..06e33ee36 100644 Binary files a/integration/use-objectid-true-external-import/objectid/objectid.bin and b/integration/use-objectid-true-external-import/objectid/objectid.bin differ diff --git a/integration/use-objectid-true-external-import/use-objectid-true.bin b/integration/use-objectid-true-external-import/use-objectid-true.bin index 781274c90..7b757e848 100644 Binary files a/integration/use-objectid-true-external-import/use-objectid-true.bin and b/integration/use-objectid-true-external-import/use-objectid-true.bin differ diff --git a/integration/use-optionals-all/test.bin b/integration/use-optionals-all/test.bin index 11c02597f..59d9f0feb 100644 Binary files a/integration/use-optionals-all/test.bin and b/integration/use-optionals-all/test.bin differ diff --git a/integration/value/google/protobuf/struct.ts b/integration/value/google/protobuf/struct.ts index 80a98258e..081b74075 100644 --- a/integration/value/google/protobuf/struct.ts +++ b/integration/value/google/protobuf/struct.ts @@ -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. */ diff --git a/integration/value/value.bin b/integration/value/value.bin index 3564a9fe8..0f63332d2 100644 Binary files a/integration/value/value.bin and b/integration/value/value.bin differ diff --git a/integration/vector-tile/vector_tile.bin b/integration/vector-tile/vector_tile.bin index dad36b4bb..482fd8c11 100644 Binary files a/integration/vector-tile/vector_tile.bin and b/integration/vector-tile/vector_tile.bin differ diff --git a/integration/wrappers-regression/google/protobuf/empty.ts b/integration/wrappers-regression/google/protobuf/empty.ts new file mode 100644 index 000000000..4318905c6 --- /dev/null +++ b/integration/wrappers-regression/google/protobuf/empty.ts @@ -0,0 +1,68 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; + +export const protobufPackage = "google.protobuf"; + +/** + * A generic empty message that you can re-use to avoid defining duplicated + * empty messages in your APIs. A typical example is to use it as the request + * or the response type of an API method. For instance: + * + * service Foo { + * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + * } + * + * The JSON representation for `Empty` is empty JSON object `{}`. + */ +export interface Empty { +} + +function createBaseEmpty(): Empty { + return {}; +} + +export const Empty = { + encode(_: Empty, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Empty { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseEmpty(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): Empty { + return {}; + }, + + toJSON(_: Empty): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial, I>>(_: I): Empty { + const message = createBaseEmpty(); + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; diff --git a/integration/wrappers-regression/google/protobuf/timestamp.ts b/integration/wrappers-regression/google/protobuf/timestamp.ts new file mode 100644 index 000000000..5497f7183 --- /dev/null +++ b/integration/wrappers-regression/google/protobuf/timestamp.ts @@ -0,0 +1,218 @@ +/* eslint-disable */ +import * as Long from "long"; +import * as _m0 from "protobufjs/minimal"; + +export const protobufPackage = "google.protobuf"; + +/** + * A Timestamp represents a point in time independent of any time zone or local + * calendar, encoded as a count of seconds and fractions of seconds at + * nanosecond resolution. The count is relative to an epoch at UTC midnight on + * January 1, 1970, in the proleptic Gregorian calendar which extends the + * Gregorian calendar backwards to year one. + * + * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap + * second table is needed for interpretation, using a [24-hour linear + * smear](https://developers.google.com/time/smear). + * + * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By + * restricting to that range, we ensure that we can convert to and from [RFC + * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. + * + * # Examples + * + * Example 1: Compute Timestamp from POSIX `time()`. + * + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * + * struct timeval tv; + * gettimeofday(&tv, NULL); + * + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * + * long millis = System.currentTimeMillis(); + * + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * + * Example 5: Compute Timestamp from Java `Instant.now()`. + * + * Instant now = Instant.now(); + * + * Timestamp timestamp = + * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) + * .setNanos(now.getNano()).build(); + * + * Example 6: Compute Timestamp from current time in Python. + * + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required. A proto3 JSON serializer should always use UTC (as indicated by + * "Z") when printing the Timestamp type and a proto3 JSON parser should be + * able to accept both UTC and other timezones (as indicated by an offset). + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard + * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using + * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with + * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use + * the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D + * ) to obtain a formatter capable of generating timestamps in this format. + */ +export interface Timestamp { + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + */ + seconds: number; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + */ + nanos: number; +} + +function createBaseTimestamp(): Timestamp { + return { seconds: 0, nanos: 0 }; +} + +export const Timestamp = { + encode(message: Timestamp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.seconds !== 0) { + writer.uint32(8).int64(message.seconds); + } + if (message.nanos !== 0) { + writer.uint32(16).int32(message.nanos); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Timestamp { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseTimestamp(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.seconds = longToNumber(reader.int64() as Long); + break; + case 2: + message.nanos = reader.int32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + + toJSON(message: Timestamp): unknown { + const obj: any = {}; + message.seconds !== undefined && (obj.seconds = Math.round(message.seconds)); + message.nanos !== undefined && (obj.nanos = Math.round(message.nanos)); + return obj; + }, + + fromPartial, I>>(object: I): Timestamp { + const message = createBaseTimestamp(); + message.seconds = object.seconds ?? 0; + message.nanos = object.nanos ?? 0; + return message; + }, +}; + +declare var self: any | undefined; +declare var window: any | undefined; +declare var global: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") { + return globalThis; + } + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + if (typeof global !== "undefined") { + return global; + } + throw "Unable to locate global object"; +})(); + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function longToNumber(long: Long): number { + if (long.gt(Number.MAX_SAFE_INTEGER)) { + throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} + +// If you get a compile-error about 'Constructor and ... have no overlap', +// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'. +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/wrappers-regression/google/protobuf/wrappers.ts b/integration/wrappers-regression/google/protobuf/wrappers.ts new file mode 100644 index 000000000..3145298cb --- /dev/null +++ b/integration/wrappers-regression/google/protobuf/wrappers.ts @@ -0,0 +1,592 @@ +/* eslint-disable */ +import * as Long from "long"; +import * as _m0 from "protobufjs/minimal"; + +export const protobufPackage = "google.protobuf"; + +/** + * Wrapper message for `double`. + * + * The JSON representation for `DoubleValue` is JSON number. + */ +export interface DoubleValue { + /** The double value. */ + value: number; +} + +/** + * Wrapper message for `float`. + * + * The JSON representation for `FloatValue` is JSON number. + */ +export interface FloatValue { + /** The float value. */ + value: number; +} + +/** + * Wrapper message for `int64`. + * + * The JSON representation for `Int64Value` is JSON string. + */ +export interface Int64Value { + /** The int64 value. */ + value: number; +} + +/** + * Wrapper message for `uint64`. + * + * The JSON representation for `UInt64Value` is JSON string. + */ +export interface UInt64Value { + /** The uint64 value. */ + value: number; +} + +/** + * Wrapper message for `int32`. + * + * The JSON representation for `Int32Value` is JSON number. + */ +export interface Int32Value { + /** The int32 value. */ + value: number; +} + +/** + * Wrapper message for `uint32`. + * + * The JSON representation for `UInt32Value` is JSON number. + */ +export interface UInt32Value { + /** The uint32 value. */ + value: number; +} + +/** + * Wrapper message for `bool`. + * + * The JSON representation for `BoolValue` is JSON `true` and `false`. + */ +export interface BoolValue { + /** The bool value. */ + value: boolean; +} + +/** + * Wrapper message for `string`. + * + * The JSON representation for `StringValue` is JSON string. + */ +export interface StringValue { + /** The string value. */ + value: string; +} + +/** + * Wrapper message for `bytes`. + * + * The JSON representation for `BytesValue` is JSON string. + */ +export interface BytesValue { + /** The bytes value. */ + value: Uint8Array; +} + +function createBaseDoubleValue(): DoubleValue { + return { value: 0 }; +} + +export const DoubleValue = { + encode(message: DoubleValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(9).double(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): DoubleValue { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDoubleValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.double(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + + toJSON(message: DoubleValue): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = message.value); + return obj; + }, + + fromPartial, I>>(object: I): DoubleValue { + const message = createBaseDoubleValue(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseFloatValue(): FloatValue { + return { value: 0 }; +} + +export const FloatValue = { + encode(message: FloatValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(13).float(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseFloatValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.float(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + + toJSON(message: FloatValue): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = message.value); + return obj; + }, + + fromPartial, I>>(object: I): FloatValue { + const message = createBaseFloatValue(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseInt64Value(): Int64Value { + return { value: 0 }; +} + +export const Int64Value = { + encode(message: Int64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).int64(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseInt64Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = longToNumber(reader.int64() as Long); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + + toJSON(message: Int64Value): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = Math.round(message.value)); + return obj; + }, + + fromPartial, I>>(object: I): Int64Value { + const message = createBaseInt64Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseUInt64Value(): UInt64Value { + return { value: 0 }; +} + +export const UInt64Value = { + encode(message: UInt64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).uint64(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseUInt64Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = longToNumber(reader.uint64() as Long); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + + toJSON(message: UInt64Value): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = Math.round(message.value)); + return obj; + }, + + fromPartial, I>>(object: I): UInt64Value { + const message = createBaseUInt64Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseInt32Value(): Int32Value { + return { value: 0 }; +} + +export const Int32Value = { + encode(message: Int32Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).int32(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseInt32Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.int32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + + toJSON(message: Int32Value): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = Math.round(message.value)); + return obj; + }, + + fromPartial, I>>(object: I): Int32Value { + const message = createBaseInt32Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseUInt32Value(): UInt32Value { + return { value: 0 }; +} + +export const UInt32Value = { + encode(message: UInt32Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).uint32(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseUInt32Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.uint32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + + toJSON(message: UInt32Value): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = Math.round(message.value)); + return obj; + }, + + fromPartial, I>>(object: I): UInt32Value { + const message = createBaseUInt32Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseBoolValue(): BoolValue { + return { value: false }; +} + +export const BoolValue = { + encode(message: BoolValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value === true) { + writer.uint32(8).bool(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseBoolValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + + toJSON(message: BoolValue): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = message.value); + return obj; + }, + + fromPartial, I>>(object: I): BoolValue { + const message = createBaseBoolValue(); + message.value = object.value ?? false; + return message; + }, +}; + +function createBaseStringValue(): StringValue { + return { value: "" }; +} + +export const StringValue = { + encode(message: StringValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== "") { + writer.uint32(10).string(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StringValue { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStringValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + + toJSON(message: StringValue): unknown { + const obj: any = {}; + message.value !== undefined && (obj.value = message.value); + return obj; + }, + + fromPartial, I>>(object: I): StringValue { + const message = createBaseStringValue(); + message.value = object.value ?? ""; + return message; + }, +}; + +function createBaseBytesValue(): BytesValue { + return { value: new Uint8Array() }; +} + +export const BytesValue = { + encode(message: BytesValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value.length !== 0) { + writer.uint32(10).bytes(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseBytesValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.value = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array() }; + }, + + toJSON(message: BytesValue): unknown { + const obj: any = {}; + message.value !== undefined && + (obj.value = base64FromBytes(message.value !== undefined ? message.value : new Uint8Array())); + return obj; + }, + + fromPartial, I>>(object: I): BytesValue { + const message = createBaseBytesValue(); + message.value = object.value ?? new Uint8Array(); + return message; + }, +}; + +declare var self: any | undefined; +declare var window: any | undefined; +declare var global: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") { + return globalThis; + } + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + if (typeof global !== "undefined") { + return global; + } + throw "Unable to locate global object"; +})(); + +function bytesFromBase64(b64: string): Uint8Array { + if (globalThis.Buffer) { + return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); + } else { + const bin = globalThis.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; + } +} + +function base64FromBytes(arr: Uint8Array): string { + if (globalThis.Buffer) { + return globalThis.Buffer.from(arr).toString("base64"); + } else { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(String.fromCharCode(byte)); + }); + return globalThis.btoa(bin.join("")); + } +} + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function longToNumber(long: Long): number { + if (long.gt(Number.MAX_SAFE_INTEGER)) { + throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} + +// If you get a compile-error about 'Constructor and ... have no overlap', +// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'. +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/wrappers-regression/parameters.txt b/integration/wrappers-regression/parameters.txt new file mode 100644 index 000000000..5bfbc855e --- /dev/null +++ b/integration/wrappers-regression/parameters.txt @@ -0,0 +1 @@ +useDate=true,outputServices=generic-definitions,outputServices=default diff --git a/integration/wrappers-regression/wrappers-regression-test.ts b/integration/wrappers-regression/wrappers-regression-test.ts new file mode 100644 index 000000000..eb187e2c1 --- /dev/null +++ b/integration/wrappers-regression/wrappers-regression-test.ts @@ -0,0 +1,24 @@ +import { Clock } from './wrappers-regression'; + +import { + Timestamp, +} from "./google/protobuf/timestamp"; +import { + BoolValue, + StringValue +} from "./google/protobuf/wrappers"; +import { Observable } from 'rxjs'; + +const jan1 = new Date('1970-01-01T00:00:00.000Z'); +const feb1 = new Date('1970-02-01T00:00:00.000Z'); + +describe('wrappers in service methods', () => { + it('generates a services that compiles', () => { + let c: Clock = { + Now: () => Promise.resolve(Timestamp.fromPartial({ seconds: 0, nanos: 0 })), + NowString: (inp: StringValue) => Promise.resolve(inp), + NowStringStream: (inp: Observable) => inp, + NowBool: () => Promise.resolve(BoolValue.fromPartial({ value: true })) + }; + }); +}); diff --git a/integration/wrappers-regression/wrappers-regression.bin b/integration/wrappers-regression/wrappers-regression.bin new file mode 100644 index 000000000..a22d7aaa1 Binary files /dev/null and b/integration/wrappers-regression/wrappers-regression.bin differ diff --git a/integration/wrappers-regression/wrappers-regression.proto b/integration/wrappers-regression/wrappers-regression.proto new file mode 100644 index 000000000..1f2b4a4f7 --- /dev/null +++ b/integration/wrappers-regression/wrappers-regression.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +service Clock { + rpc Now(google.protobuf.Empty) returns (google.protobuf.Timestamp); + rpc NowString(google.protobuf.StringValue) + returns (google.protobuf.StringValue); + rpc NowStringStream(stream google.protobuf.StringValue) + returns (stream google.protobuf.StringValue); + rpc NowBool(google.protobuf.Empty) returns (google.protobuf.BoolValue); +} \ No newline at end of file diff --git a/integration/wrappers-regression/wrappers-regression.ts b/integration/wrappers-regression/wrappers-regression.ts new file mode 100644 index 000000000..b8147b2fc --- /dev/null +++ b/integration/wrappers-regression/wrappers-regression.ts @@ -0,0 +1,99 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; +import { Observable } from "rxjs"; +import { map } from "rxjs/operators"; +import { Empty } from "./google/protobuf/empty"; +import { Timestamp } from "./google/protobuf/timestamp"; +import { BoolValue, StringValue } from "./google/protobuf/wrappers"; + +export const protobufPackage = ""; + +export interface Clock { + Now(request: Empty): Promise; + NowString(request: StringValue): Promise; + NowStringStream(request: Observable): Observable; + NowBool(request: Empty): Promise; +} + +export class ClockClientImpl implements Clock { + private readonly rpc: Rpc; + private readonly service: string; + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || "Clock"; + this.rpc = rpc; + this.Now = this.Now.bind(this); + this.NowString = this.NowString.bind(this); + this.NowStringStream = this.NowStringStream.bind(this); + this.NowBool = this.NowBool.bind(this); + } + Now(request: Empty): Promise { + const data = Empty.encode(request).finish(); + const promise = this.rpc.request(this.service, "Now", data); + return promise.then((data) => Timestamp.decode(new _m0.Reader(data))); + } + + NowString(request: StringValue): Promise { + const data = StringValue.encode(request).finish(); + const promise = this.rpc.request(this.service, "NowString", data); + return promise.then((data) => StringValue.decode(new _m0.Reader(data))); + } + + NowStringStream(request: Observable): Observable { + const data = request.pipe(map((request) => StringValue.encode(request).finish())); + const result = this.rpc.bidirectionalStreamingRequest(this.service, "NowStringStream", data); + return result.pipe(map((data) => StringValue.decode(new _m0.Reader(data)))); + } + + NowBool(request: Empty): Promise { + const data = Empty.encode(request).finish(); + const promise = this.rpc.request(this.service, "NowBool", data); + return promise.then((data) => BoolValue.decode(new _m0.Reader(data))); + } +} + +export type ClockDefinition = typeof ClockDefinition; +export const ClockDefinition = { + name: "Clock", + fullName: "Clock", + methods: { + now: { + name: "Now", + requestType: Empty, + requestStream: false, + responseType: Timestamp, + responseStream: false, + options: {}, + }, + nowString: { + name: "NowString", + requestType: StringValue, + requestStream: false, + responseType: StringValue, + responseStream: false, + options: {}, + }, + nowStringStream: { + name: "NowStringStream", + requestType: StringValue, + requestStream: true, + responseType: StringValue, + responseStream: true, + options: {}, + }, + nowBool: { + name: "NowBool", + requestType: Empty, + requestStream: false, + responseType: BoolValue, + responseStream: false, + options: {}, + }, + }, +} as const; + +interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; + clientStreamingRequest(service: string, method: string, data: Observable): Promise; + serverStreamingRequest(service: string, method: string, data: Uint8Array): Observable; + bidirectionalStreamingRequest(service: string, method: string, data: Observable): Observable; +} diff --git a/src/generate-generic-service-definition.ts b/src/generate-generic-service-definition.ts index 0ba118d1b..9990efce6 100644 --- a/src/generate-generic-service-definition.ts +++ b/src/generate-generic-service-definition.ts @@ -60,6 +60,10 @@ export function generateGenericServiceDefinition( return joinCode(chunks, { on: "\n" }); } +function stripDot(str: string) { + return str.startsWith(".") ? str.slice(1) : str; +} + function generateMethodDefinition(ctx: Context, methodDesc: MethodDescriptorProto) { const inputType = messageToTypeName(ctx, methodDesc.inputType, { keepValueType: true }); const outputType = messageToTypeName(ctx, methodDesc.outputType, { keepValueType: true }); diff --git a/src/generate-services.ts b/src/generate-services.ts index 66e1d43c7..6c12b722c 100644 --- a/src/generate-services.ts +++ b/src/generate-services.ts @@ -112,7 +112,7 @@ function generateRegularRpcMethod( assertInstanceOf(methodDesc, FormattedMethodDescriptor); const { options, utils } = ctx; const Reader = impFile(ctx.options, "Reader@protobufjs/minimal"); - const rawInputType = rawRequestType(ctx, methodDesc); + const rawInputType = rawRequestType(ctx, methodDesc, { keepValueType: true }); const inputType = requestType(ctx, methodDesc); const outputType = responseType(ctx, methodDesc); const rawOutputType = responseType(ctx, methodDesc, { keepValueType: true }); @@ -121,11 +121,11 @@ function generateRegularRpcMethod( const maybeCtx = options.context ? "ctx," : ""; let encode = code`${rawInputType}.encode(request).finish()`; - let decode = code`data => ${outputType}.decode(new ${Reader}(data))`; + let decode = code`data => ${rawOutputType}.decode(new ${Reader}(data))`; - if (options.useDate && rawOutputType.toString().includes("Timestamp")) { - decode = code`data => ${utils.fromTimestamp}(${rawOutputType}.decode(new ${Reader}(data)))`; - } + // if (options.useDate && rawOutputType.toString().includes("Timestamp")) { + // decode = code`data => ${utils.fromTimestamp}(${rawOutputType}.decode(new ${Reader}(data)))`; + // } if (methodDesc.clientStreaming) { if (options.useAsyncIterable) { encode = code`${rawInputType}.encodeTransform(request)`; diff --git a/src/generate-type-registry.ts b/src/generate-type-registry.ts index 8a65d18b5..7c279b9c4 100644 --- a/src/generate-type-registry.ts +++ b/src/generate-type-registry.ts @@ -7,9 +7,15 @@ export function generateTypeRegistry(ctx: Context): Code { chunks.push(generateMessageType(ctx)); - chunks.push(code` - export type UnknownMessage = {$type: string}; - `); + if (ctx.options.outputTypeRegistry == "no-tags") { + chunks.push(code` + export type UnknownMessage = {}; + `); + } else { + chunks.push(code` + export type UnknownMessage = {$type: string}; + `); + } chunks.push(code` export const messageTypeRegistry = new Map(); @@ -25,7 +31,11 @@ function generateMessageType(ctx: Context): Code { chunks.push(code`export interface MessageType {`); - chunks.push(code`$type: Message['$type'];`); + if (ctx.options.outputTypeRegistry == "no-tags") { + chunks.push(code`$type: string;`); + } else { + chunks.push(code`$type: Message['$type'];`); + } if (ctx.options.outputEncodeMethods) { const Writer = impFile(ctx.options, "Writer@protobufjs/minimal"); diff --git a/src/main.ts b/src/main.ts index 6ca0bf753..d210d68a5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -209,7 +209,7 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri const messageTypeRegistry = impFile(options, "messageTypeRegistry@./typeRegistry"); chunks.push(code` - ${messageTypeRegistry}.set(${fullName}.$type, ${fullName}); + ${messageTypeRegistry}.set("${fullTypeName}", ${fullName}); `); } }, @@ -518,7 +518,7 @@ function makeDeepPartial(options: Options, longs: ReturnType` : code`keyof T`; + const keys = options.outputTypeRegistry === true ? code`Exclude` : code`keyof T`; const DeepPartial = conditionalOutput( "DeepPartial", code` @@ -594,7 +594,7 @@ function makeTimestampMethods(options: Options, longs: ReturnType code`${type}.encode(${utils.toTimestamp}(${place}), writer.uint32(${tag}).fork()).ldelim()`; } else if (isValueType(ctx, field)) { - const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : ""; + const maybeTypeField = options.outputTypeRegistry === true ? `$type: '${field.typeName.slice(1)}',` : ""; const type = basicTypeName(ctx, field, { keepValueType: true }); const wrappedValue = (place: string): Code => { @@ -1068,7 +1068,7 @@ function generateEncode(ctx: Context, fullName: string, messageDesc: DescriptorP if (isRepeated(field)) { if (isMapType(ctx, messageDesc, field)) { const valueType = (typeMap.get(field.typeName)![2] as DescriptorProto).field[1]; - const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : ""; + const maybeTypeField = options.outputTypeRegistry === true ? `$type: '${field.typeName.slice(1)}',` : ""; const entryWriteSnippet = isValueType(ctx, valueType) ? code` if (value !== undefined) { @@ -1218,7 +1218,7 @@ function generateFromJson(ctx: Context, fullName: string, fullTypeName: string, return { `); - if (ctx.options.outputTypeRegistry) { + if (ctx.options.outputTypeRegistry === true) { chunks.push(code`$type: ${fullName}.$type,`); } diff --git a/src/options.ts b/src/options.ts index 1cbc67b70..62397a854 100644 --- a/src/options.ts +++ b/src/options.ts @@ -47,7 +47,7 @@ export type Options = { outputEncodeMethods: boolean; outputJsonMethods: boolean; outputPartialMethods: boolean; - outputTypeRegistry: boolean; + outputTypeRegistry: boolean | "no-tags"; stringEnums: boolean; constEnums: boolean; enumsAsLiterals: boolean; diff --git a/src/types.ts b/src/types.ts index ef9784ced..589adbbd0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -659,8 +659,12 @@ export function detectMapType( return undefined; } -export function rawRequestType(ctx: Context, methodDesc: MethodDescriptorProto): Code { - return messageToTypeName(ctx, methodDesc.inputType); +export function rawRequestType( + ctx: Context, + methodDesc: MethodDescriptorProto, + typeOptions: { keepValueType?: boolean; repeated?: boolean } = {} +): Code { + return messageToTypeName(ctx, methodDesc.inputType, typeOptions); } export function observableType(ctx: Context): Code { @@ -671,7 +675,7 @@ export function observableType(ctx: Context): Code { } export function requestType(ctx: Context, methodDesc: MethodDescriptorProto, partial: boolean = false): Code { - let typeName = rawRequestType(ctx, methodDesc); + let typeName = rawRequestType(ctx, methodDesc, { keepValueType: true }); if (partial) { typeName = code`${ctx.utils.DeepPartial}<${typeName}>`; @@ -688,15 +692,15 @@ export function responseType( methodDesc: MethodDescriptorProto, typeOptions: { keepValueType?: boolean; repeated?: boolean } = {} ): Code { - return messageToTypeName(ctx, methodDesc.outputType, typeOptions); + return messageToTypeName(ctx, methodDesc.outputType, { keepValueType: true }); } export function responsePromise(ctx: Context, methodDesc: MethodDescriptorProto): Code { - return code`Promise<${responseType(ctx, methodDesc)}>`; + return code`Promise<${responseType(ctx, methodDesc, { keepValueType: true })}>`; } export function responseObservable(ctx: Context, methodDesc: MethodDescriptorProto): Code { - return code`${observableType(ctx)}<${responseType(ctx, methodDesc)}>`; + return code`${observableType(ctx)}<${responseType(ctx, methodDesc, { keepValueType: true })}>`; } export function responsePromiseOrObservable(ctx: Context, methodDesc: MethodDescriptorProto): Code {