From bf74a09a1259207c296301f28c318bb62d702c7a Mon Sep 17 00:00:00 2001 From: Frabat Date: Tue, 18 Jul 2023 15:16:38 -0400 Subject: [PATCH 1/7] feat(ts-proto-#859): added encode-only options to toJSON methods --- .../output-decode-only-json/decode-json.ts | 0 .../output-decode-only-json/decode.proto | 7 + .../google/protobuf/wrappers.ts | 387 ++++++++++++++++++ .../output-decode-only-json/parameters.txt | 1 + .../output-encode-only-json/decode-json.ts | 0 .../output-encode-only-json/encode.proto | 7 + .../google/protobuf/wrappers.ts | 387 ++++++++++++++++++ .../output-encode-only-json/parameters.txt | 1 + src/main.ts | 12 +- src/options.ts | 2 +- 10 files changed, 801 insertions(+), 3 deletions(-) create mode 100644 integration/output-decode-only-json/decode-json.ts create mode 100644 integration/output-decode-only-json/decode.proto create mode 100644 integration/output-decode-only-json/google/protobuf/wrappers.ts create mode 100644 integration/output-decode-only-json/parameters.txt create mode 100644 integration/output-encode-only-json/decode-json.ts create mode 100644 integration/output-encode-only-json/encode.proto create mode 100644 integration/output-encode-only-json/google/protobuf/wrappers.ts create mode 100644 integration/output-encode-only-json/parameters.txt diff --git a/integration/output-decode-only-json/decode-json.ts b/integration/output-decode-only-json/decode-json.ts new file mode 100644 index 000000000..e69de29bb diff --git a/integration/output-decode-only-json/decode.proto b/integration/output-decode-only-json/decode.proto new file mode 100644 index 000000000..6d030e9a9 --- /dev/null +++ b/integration/output-decode-only-json/decode.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +import "google/protobuf/wrappers.proto"; + +message Encode { + string encode = 1; +} diff --git a/integration/output-decode-only-json/google/protobuf/wrappers.ts b/integration/output-decode-only-json/google/protobuf/wrappers.ts new file mode 100644 index 000000000..0674c218b --- /dev/null +++ b/integration/output-decode-only-json/google/protobuf/wrappers.ts @@ -0,0 +1,387 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; +import Long = require("long"); + +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 = { + decode(input: _m0.Reader | Uint8Array, length?: number): DoubleValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 9) { + break; + } + + message.value = reader.double(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseFloatValue(): FloatValue { + return { value: 0 }; +} + +export const FloatValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 13) { + break; + } + + message.value = reader.float(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseInt64Value(): Int64Value { + return { value: 0 }; +} + +export const Int64Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = longToNumber(reader.int64() as Long); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseUInt64Value(): UInt64Value { + return { value: 0 }; +} + +export const UInt64Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = longToNumber(reader.uint64() as Long); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseInt32Value(): Int32Value { + return { value: 0 }; +} + +export const Int32Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = reader.int32(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseUInt32Value(): UInt32Value { + return { value: 0 }; +} + +export const UInt32Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = reader.uint32(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseBoolValue(): BoolValue { + return { value: false }; +} + +export const BoolValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = reader.bool(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseStringValue(): StringValue { + return { value: "" }; +} + +export const StringValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): StringValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 10) { + break; + } + + message.value = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseBytesValue(): BytesValue { + return { value: new Uint8Array(0) }; +} + +export const BytesValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 10) { + break; + } + + message.value = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +declare const self: any | undefined; +declare const window: any | undefined; +declare const global: any | undefined; +const tsProtoGlobalThis: 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 longToNumber(long: Long): number { + if (long.gt(Number.MAX_SAFE_INTEGER)) { + throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} diff --git a/integration/output-decode-only-json/parameters.txt b/integration/output-decode-only-json/parameters.txt new file mode 100644 index 000000000..dc1ca49ae --- /dev/null +++ b/integration/output-decode-only-json/parameters.txt @@ -0,0 +1 @@ +outputJsonMethods=decode-only,outputPartialMethods=false,outputJsonMethods=false,nestJs=false diff --git a/integration/output-encode-only-json/decode-json.ts b/integration/output-encode-only-json/decode-json.ts new file mode 100644 index 000000000..e69de29bb diff --git a/integration/output-encode-only-json/encode.proto b/integration/output-encode-only-json/encode.proto new file mode 100644 index 000000000..6d030e9a9 --- /dev/null +++ b/integration/output-encode-only-json/encode.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +import "google/protobuf/wrappers.proto"; + +message Encode { + string encode = 1; +} diff --git a/integration/output-encode-only-json/google/protobuf/wrappers.ts b/integration/output-encode-only-json/google/protobuf/wrappers.ts new file mode 100644 index 000000000..0674c218b --- /dev/null +++ b/integration/output-encode-only-json/google/protobuf/wrappers.ts @@ -0,0 +1,387 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; +import Long = require("long"); + +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 = { + decode(input: _m0.Reader | Uint8Array, length?: number): DoubleValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 9) { + break; + } + + message.value = reader.double(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseFloatValue(): FloatValue { + return { value: 0 }; +} + +export const FloatValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 13) { + break; + } + + message.value = reader.float(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseInt64Value(): Int64Value { + return { value: 0 }; +} + +export const Int64Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = longToNumber(reader.int64() as Long); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseUInt64Value(): UInt64Value { + return { value: 0 }; +} + +export const UInt64Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = longToNumber(reader.uint64() as Long); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseInt32Value(): Int32Value { + return { value: 0 }; +} + +export const Int32Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = reader.int32(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseUInt32Value(): UInt32Value { + return { value: 0 }; +} + +export const UInt32Value = { + decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = reader.uint32(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseBoolValue(): BoolValue { + return { value: false }; +} + +export const BoolValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 8) { + break; + } + + message.value = reader.bool(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseStringValue(): StringValue { + return { value: "" }; +} + +export const StringValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): StringValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 10) { + break; + } + + message.value = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +function createBaseBytesValue(): BytesValue { + return { value: new Uint8Array(0) }; +} + +export const BytesValue = { + decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: + if (tag !== 10) { + break; + } + + message.value = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, +}; + +declare const self: any | undefined; +declare const window: any | undefined; +declare const global: any | undefined; +const tsProtoGlobalThis: 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 longToNumber(long: Long): number { + if (long.gt(Number.MAX_SAFE_INTEGER)) { + throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} diff --git a/integration/output-encode-only-json/parameters.txt b/integration/output-encode-only-json/parameters.txt new file mode 100644 index 000000000..f125b932b --- /dev/null +++ b/integration/output-encode-only-json/parameters.txt @@ -0,0 +1 @@ +outputJsonMethods=encode-only,outputPartialMethods=false,outputJsonMethods=false,nestJs=false diff --git a/src/main.ts b/src/main.ts index ec26bff5e..4d71cb9b4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -235,8 +235,16 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri staticMembers.push(generateDecodeTransform(fullName)); } if (options.outputJsonMethods) { - staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); - staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); + if(options.outputJsonMethods === true || + options.outputEncodeMethods === "encode-only" || + options.outputEncodeMethods === "encode-no-creation" + ){ + staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); + } + + if (options.outputEncodeMethods === true || options.outputEncodeMethods === "decode-only") { + staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); + } } if (options.outputPartialMethods) { staticMembers.push(generateFromPartial(ctx, fullName, message)); diff --git a/src/options.ts b/src/options.ts index 4bd4d74e6..24d042d54 100644 --- a/src/options.ts +++ b/src/options.ts @@ -46,7 +46,7 @@ export type Options = { fileSuffix: string; importSuffix: string; outputEncodeMethods: true | false | "encode-only" | "decode-only" | "encode-no-creation"; - outputJsonMethods: boolean; + outputJsonMethods: true | false | "encode-only" | "decode-only" ; outputPartialMethods: boolean; outputTypeAnnotations: boolean | "static-only"; outputTypeRegistry: boolean; From 6ff30a97c53d2b57851a2c907efa6dd478a72328 Mon Sep 17 00:00:00 2001 From: Francesco Battista Date: Tue, 18 Jul 2023 16:50:12 -0400 Subject: [PATCH 2/7] feat(ts-proto-#859): fixed error in implementation --- integration/angular/simple-message.ts | 8 +- .../simple.ts | 8 +- integration/async-iterable-services/simple.ts | 8 +- integration/avoid-import-conflicts/simple.ts | 50 +- integration/avoid-import-conflicts/simple2.ts | 8 +- integration/barrel-imports/bar.ts | 8 +- integration/barrel-imports/foo.ts | 14 +- .../batching.ts | 100 ++-- integration/batching-with-context/batching.ts | 100 ++-- integration/batching/batching.ts | 100 ++-- integration/bytes-as-base64/message.ts | 8 +- .../bytes-node/google/protobuf/wrappers.ts | 72 +-- integration/bytes-node/point.ts | 14 +- integration/const-enum/const-enum.ts | 38 +- .../enums-as-literals-with-string-enums.ts | 8 +- .../enums-as-literals/enums-as-literals.ts | 8 +- integration/extensions/test.ts | 30 +- integration/fieldmask/fieldmask.ts | 8 +- .../fieldmask/google/protobuf/field_mask.ts | 8 +- integration/file-suffix/child.pb.ts | 8 +- .../google/protobuf/timestamp.pb.ts | 14 +- integration/file-suffix/parent.pb.ts | 16 +- .../from-partial-no-initialize/test.ts | 62 +-- integration/generic-metadata/hero.ts | 32 +- .../simple.ts | 8 +- .../generic-service-definitions/simple.ts | 8 +- integration/global-this/global-this.ts | 16 +- integration/groups/test.ts | 124 ++--- .../google/protobuf/timestamp.ts | 14 +- .../grpc-js-use-date-false.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../grpc-js-use-date-string.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../grpc-js-use-date-true.ts | 8 +- integration/grpc-js/google/protobuf/empty.ts | 8 +- integration/grpc-js/google/protobuf/struct.ts | 60 +-- .../grpc-js/google/protobuf/timestamp.ts | 14 +- .../grpc-js/google/protobuf/wrappers.ts | 72 +-- integration/grpc-js/simple.ts | 8 +- integration/grpc-web-abort-signal/example.ts | 116 ++--- integration/grpc-web-go-server/example.ts | 116 ++--- .../example.ts | 52 +- integration/grpc-web-no-streaming/example.ts | 52 +- integration/grpc-web/example.ts | 116 ++--- .../google/protobuf/timestamp.ts | 14 +- integration/import-mapping/mapping.ts | 44 +- integration/import-suffix/child.pb.ts | 8 +- .../google/protobuf/timestamp.pb.ts | 14 +- integration/import-suffix/parent.pb.ts | 16 +- integration/lower-case-svc-methods/math.ts | 24 +- integration/map-bigint-optional/test.ts | 36 +- integration/map-long-optional/test.ts | 36 +- integration/map-longstring-optional/test.ts | 36 +- .../nice-grpc/google/protobuf/empty.ts | 8 +- .../nice-grpc/google/protobuf/struct.ts | 60 +-- .../nice-grpc/google/protobuf/timestamp.ts | 14 +- .../nice-grpc/google/protobuf/wrappers.ts | 72 +-- integration/nice-grpc/simple.ts | 8 +- .../no-proto-package/no-proto-package.ts | 16 +- integration/omit-optionals/simple.ts | 14 +- integration/oneof-properties/oneof.ts | 40 +- .../google/protobuf/struct.ts | 74 +-- integration/oneof-unions-snake/simple.ts | 8 +- .../oneof-unions/google/protobuf/struct.ts | 74 +-- integration/oneof-unions/oneof.ts | 80 +-- .../output-decode-only-json/decode-json.ts | 0 .../output-decode-only-json/decode.bin | Bin 0 -> 4787 bytes integration/output-decode-only-json/decode.ts | 17 + .../google/protobuf/wrappers.ts | 264 ++-------- .../output-decode-only-json/parameters.txt | 2 +- .../output-encode-only-json/decode-json.ts | 0 .../output-encode-only-json/encode.bin | Bin 0 -> 4787 bytes integration/output-encode-only-json/encode.ts | 17 + .../google/protobuf/wrappers.ts | 281 ++--------- .../output-encode-only-json/parameters.txt | 2 +- integration/output-index/a.ts | 8 +- integration/point/point.ts | 22 +- integration/reserved-words/reserved-words.ts | 8 +- integration/return-observable/observable.ts | 16 +- .../simple-deprecated-fields/simple.ts | 28 +- integration/simple-esmodule-interop/simple.ts | 42 +- .../google/protobuf/timestamp.ts | 14 +- integration/simple-json-name/simple.ts | 26 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- integration/simple-long-bigint/simple.ts | 40 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- integration/simple-long-string/simple.ts | 38 +- .../simple-long/google/protobuf/wrappers.ts | 72 +-- integration/simple-long/simple.ts | 134 ++--- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- .../simple-optionals/import_dir/thing.ts | 8 +- integration/simple-optionals/simple.ts | 290 +++++------ integration/simple-optionals/thing.ts | 8 +- integration/simple-proto2/simple.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- .../google/type/date.ts | 16 +- .../import_dir/thing.ts | 8 +- .../simple-prototype-defaults/simple.ts | 470 ++++++++--------- .../simple-snake/google/protobuf/struct.ts | 60 +-- .../simple-snake/google/protobuf/timestamp.ts | 14 +- .../simple-snake/google/protobuf/wrappers.ts | 72 +-- integration/simple-snake/import_dir/thing.ts | 8 +- integration/simple-snake/simple.ts | 298 +++++------ .../google/protobuf/struct.ts | 60 +-- integration/simple-string-enums/simple.ts | 44 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- .../import_dir/thing.ts | 8 +- .../simple-unrecognized-enum/simple.ts | 290 +++++------ .../simple/google/protobuf/timestamp.ts | 14 +- .../simple/google/protobuf/wrappers.ts | 72 +-- integration/simple/google/type/date.ts | 16 +- integration/simple/import_dir/thing.ts | 8 +- integration/simple/simple.ts | 472 +++++++++--------- .../static-only-type-registry/bar/bar.ts | 8 +- integration/static-only-type-registry/foo.ts | 24 +- .../google/protobuf/struct.ts | 60 +-- .../google/protobuf/timestamp.ts | 14 +- integration/static-only/bar/bar.ts | 8 +- integration/static-only/foo.ts | 24 +- .../static-only/google/protobuf/struct.ts | 60 +-- .../static-only/google/protobuf/timestamp.ts | 14 +- integration/struct/google/protobuf/struct.ts | 60 +-- integration/struct/struct.ts | 8 +- integration/type-annotations/bar/bar.ts | 8 +- integration/type-annotations/foo.ts | 24 +- .../google/protobuf/struct.ts | 72 +-- .../google/protobuf/timestamp.ts | 16 +- integration/type-registry/bar/bar.ts | 8 +- integration/type-registry/foo.ts | 24 +- .../type-registry/google/protobuf/struct.ts | 72 +-- .../google/protobuf/timestamp.ts | 16 +- integration/types-with-underscores/file.ts | 16 +- .../google/protobuf/timestamp.ts | 14 +- integration/use-date-false/metadata.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../use-date-string/use-date-string.ts | 48 +- .../use-date-true/google/protobuf/empty.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- integration/use-date-true/use-date-true.ts | 48 +- integration/use-exact-types-false/foo.ts | 8 +- .../use-map-type/google/protobuf/struct.ts | 60 +-- .../use-map-type/google/protobuf/timestamp.ts | 14 +- integration/use-map-type/use-map-type.ts | 138 ++--- .../google/protobuf/struct.ts | 60 +-- integration/use-numeric-enum-json/simple.ts | 44 +- .../objectid/objectid.ts | 8 +- .../use-objectid-true.ts | 44 +- .../google/protobuf/timestamp.ts | 14 +- integration/use-optionals-all/test.ts | 82 +-- .../use-optionals-no-undefined/test.ts | 84 ++-- .../google/protobuf/field_mask.ts | 8 +- .../google/protobuf/struct.ts | 74 +-- .../use-readonly-types/use-readonly-types.ts | 52 +- integration/value/google/protobuf/struct.ts | 60 +-- integration/value/google/protobuf/wrappers.ts | 72 +-- integration/value/value.ts | 20 +- integration/vector-tile/vector_tile.ts | 72 +-- .../google/protobuf/empty.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- src/main.ts | 9 +- 166 files changed, 3665 insertions(+), 4009 deletions(-) delete mode 100644 integration/output-decode-only-json/decode-json.ts create mode 100644 integration/output-decode-only-json/decode.bin create mode 100644 integration/output-decode-only-json/decode.ts delete mode 100644 integration/output-encode-only-json/decode-json.ts create mode 100644 integration/output-encode-only-json/encode.bin create mode 100644 integration/output-encode-only-json/encode.ts diff --git a/integration/angular/simple-message.ts b/integration/angular/simple-message.ts index bb230e72b..ffa20dc20 100644 --- a/integration/angular/simple-message.ts +++ b/integration/angular/simple-message.ts @@ -42,10 +42,6 @@ export const SimpleMessage = { return message; }, - fromJSON(object: any): SimpleMessage { - return { numberField: isSet(object.numberField) ? Number(object.numberField) : 0 }; - }, - toJSON(message: SimpleMessage): unknown { const obj: any = {}; if (message.numberField !== 0) { @@ -54,6 +50,10 @@ export const SimpleMessage = { return obj; }, + fromJSON(object: any): SimpleMessage { + return { numberField: isSet(object.numberField) ? Number(object.numberField) : 0 }; + }, + create, I>>(base?: I): SimpleMessage { return SimpleMessage.fromPartial(base ?? {}); }, diff --git a/integration/async-iterable-services-abort-signal/simple.ts b/integration/async-iterable-services-abort-signal/simple.ts index bcfc7f913..8dea5cc48 100644 --- a/integration/async-iterable-services-abort-signal/simple.ts +++ b/integration/async-iterable-services-abort-signal/simple.ts @@ -75,10 +75,6 @@ export const EchoMsg = { } }, - fromJSON(object: any): EchoMsg { - return { body: isSet(object.body) ? String(object.body) : "" }; - }, - toJSON(message: EchoMsg): unknown { const obj: any = {}; if (message.body !== "") { @@ -87,6 +83,10 @@ export const EchoMsg = { return obj; }, + fromJSON(object: any): EchoMsg { + return { body: isSet(object.body) ? String(object.body) : "" }; + }, + create, I>>(base?: I): EchoMsg { return EchoMsg.fromPartial(base ?? {}); }, diff --git a/integration/async-iterable-services/simple.ts b/integration/async-iterable-services/simple.ts index a06a74093..848a65bea 100644 --- a/integration/async-iterable-services/simple.ts +++ b/integration/async-iterable-services/simple.ts @@ -75,10 +75,6 @@ export const EchoMsg = { } }, - fromJSON(object: any): EchoMsg { - return { body: isSet(object.body) ? String(object.body) : "" }; - }, - toJSON(message: EchoMsg): unknown { const obj: any = {}; if (message.body !== "") { @@ -87,6 +83,10 @@ export const EchoMsg = { return obj; }, + fromJSON(object: any): EchoMsg { + return { body: isSet(object.body) ? String(object.body) : "" }; + }, + create, I>>(base?: I): EchoMsg { return EchoMsg.fromPartial(base ?? {}); }, diff --git a/integration/avoid-import-conflicts/simple.ts b/integration/avoid-import-conflicts/simple.ts index 299bbe76c..bb6172c8a 100644 --- a/integration/avoid-import-conflicts/simple.ts +++ b/integration/avoid-import-conflicts/simple.ts @@ -6,8 +6,8 @@ import { fooServiceToJSON, Simple as Simple3, SimpleEnum as SimpleEnum1, - simpleEnumFromJSON as simpleEnumFromJSON4, - simpleEnumToJSON as simpleEnumToJSON5, + simpleEnumFromJSON as simpleEnumFromJSON5, + simpleEnumToJSON as simpleEnumToJSON4, } from "./simple2"; export const protobufPackage = "simple"; @@ -114,13 +114,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - otherSimple: isSet(object.otherSimple) ? Simple3.fromJSON(object.otherSimple) : undefined, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -132,6 +125,13 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + otherSimple: isSet(object.otherSimple) ? Simple3.fromJSON(object.otherSimple) : undefined, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -191,24 +191,24 @@ export const SimpleEnums = { return message; }, - fromJSON(object: any): SimpleEnums { - return { - localEnum: isSet(object.localEnum) ? simpleEnumFromJSON(object.localEnum) : 0, - importEnum: isSet(object.importEnum) ? simpleEnumFromJSON4(object.importEnum) : 0, - }; - }, - toJSON(message: SimpleEnums): unknown { const obj: any = {}; if (message.localEnum !== 0) { obj.localEnum = simpleEnumToJSON(message.localEnum); } if (message.importEnum !== 0) { - obj.importEnum = simpleEnumToJSON5(message.importEnum); + obj.importEnum = simpleEnumToJSON4(message.importEnum); } return obj; }, + fromJSON(object: any): SimpleEnums { + return { + localEnum: isSet(object.localEnum) ? simpleEnumFromJSON(object.localEnum) : 0, + importEnum: isSet(object.importEnum) ? simpleEnumFromJSON5(object.importEnum) : 0, + }; + }, + create, I>>(base?: I): SimpleEnums { return SimpleEnums.fromPartial(base ?? {}); }, @@ -256,10 +256,6 @@ export const FooServiceCreateRequest = { return message; }, - fromJSON(object: any): FooServiceCreateRequest { - return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; - }, - toJSON(message: FooServiceCreateRequest): unknown { const obj: any = {}; if (message.kind !== 0) { @@ -268,6 +264,10 @@ export const FooServiceCreateRequest = { return obj; }, + fromJSON(object: any): FooServiceCreateRequest { + return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; + }, + create, I>>(base?: I): FooServiceCreateRequest { return FooServiceCreateRequest.fromPartial(base ?? {}); }, @@ -314,10 +314,6 @@ export const FooServiceCreateResponse = { return message; }, - fromJSON(object: any): FooServiceCreateResponse { - return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; - }, - toJSON(message: FooServiceCreateResponse): unknown { const obj: any = {}; if (message.kind !== 0) { @@ -326,6 +322,10 @@ export const FooServiceCreateResponse = { return obj; }, + fromJSON(object: any): FooServiceCreateResponse { + return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; + }, + create, I>>(base?: I): FooServiceCreateResponse { return FooServiceCreateResponse.fromPartial(base ?? {}); }, diff --git a/integration/avoid-import-conflicts/simple2.ts b/integration/avoid-import-conflicts/simple2.ts index 111f0665e..ab9c1c448 100644 --- a/integration/avoid-import-conflicts/simple2.ts +++ b/integration/avoid-import-conflicts/simple2.ts @@ -131,10 +131,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -146,6 +142,10 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, diff --git a/integration/barrel-imports/bar.ts b/integration/barrel-imports/bar.ts index 7ea77bd2a..4e98ffb1f 100644 --- a/integration/barrel-imports/bar.ts +++ b/integration/barrel-imports/bar.ts @@ -51,10 +51,6 @@ export const Bar = { return message; }, - fromJSON(object: any): Bar { - return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; - }, - toJSON(message: Bar): unknown { const obj: any = {}; if (message.name !== "") { @@ -66,6 +62,10 @@ export const Bar = { return obj; }, + fromJSON(object: any): Bar { + return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; + }, + create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/barrel-imports/foo.ts b/integration/barrel-imports/foo.ts index e5a81e984..c98443de4 100644 --- a/integration/barrel-imports/foo.ts +++ b/integration/barrel-imports/foo.ts @@ -52,13 +52,6 @@ export const Foo = { return message; }, - fromJSON(object: any): Foo { - return { - name: isSet(object.name) ? String(object.name) : "", - bar: isSet(object.bar) ? Bar.fromJSON(object.bar) : undefined, - }; - }, - toJSON(message: Foo): unknown { const obj: any = {}; if (message.name !== "") { @@ -70,6 +63,13 @@ export const Foo = { return obj; }, + fromJSON(object: any): Foo { + return { + name: isSet(object.name) ? String(object.name) : "", + bar: isSet(object.bar) ? Bar.fromJSON(object.bar) : undefined, + }; + }, + create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, diff --git a/integration/batching-with-context-esModuleInterop/batching.ts b/integration/batching-with-context-esModuleInterop/batching.ts index ff89bf541..be79ca4d4 100644 --- a/integration/batching-with-context-esModuleInterop/batching.ts +++ b/integration/batching-with-context-esModuleInterop/batching.ts @@ -81,10 +81,6 @@ export const BatchQueryRequest = { return message; }, - fromJSON(object: any): BatchQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - toJSON(message: BatchQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -93,6 +89,10 @@ export const BatchQueryRequest = { return obj; }, + fromJSON(object: any): BatchQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + create, I>>(base?: I): BatchQueryRequest { return BatchQueryRequest.fromPartial(base ?? {}); }, @@ -139,10 +139,6 @@ export const BatchQueryResponse = { return message; }, - fromJSON(object: any): BatchQueryResponse { - return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; - }, - toJSON(message: BatchQueryResponse): unknown { const obj: any = {}; if (message.entities?.length) { @@ -151,6 +147,10 @@ export const BatchQueryResponse = { return obj; }, + fromJSON(object: any): BatchQueryResponse { + return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; + }, + create, I>>(base?: I): BatchQueryResponse { return BatchQueryResponse.fromPartial(base ?? {}); }, @@ -197,10 +197,6 @@ export const BatchMapQueryRequest = { return message; }, - fromJSON(object: any): BatchMapQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - toJSON(message: BatchMapQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -209,6 +205,10 @@ export const BatchMapQueryRequest = { return obj; }, + fromJSON(object: any): BatchMapQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + create, I>>(base?: I): BatchMapQueryRequest { return BatchMapQueryRequest.fromPartial(base ?? {}); }, @@ -258,17 +258,6 @@ export const BatchMapQueryResponse = { return message; }, - fromJSON(object: any): BatchMapQueryResponse { - return { - entities: isObject(object.entities) - ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { - acc[key] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: BatchMapQueryResponse): unknown { const obj: any = {}; if (message.entities) { @@ -283,6 +272,17 @@ export const BatchMapQueryResponse = { return obj; }, + fromJSON(object: any): BatchMapQueryResponse { + return { + entities: isObject(object.entities) + ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { + acc[key] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): BatchMapQueryResponse { return BatchMapQueryResponse.fromPartial(base ?? {}); }, @@ -344,13 +344,6 @@ export const BatchMapQueryResponse_EntitiesEntry = { return message; }, - fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: BatchMapQueryResponse_EntitiesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -362,6 +355,13 @@ export const BatchMapQueryResponse_EntitiesEntry = { return obj; }, + fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): BatchMapQueryResponse_EntitiesEntry { @@ -415,10 +415,6 @@ export const GetOnlyMethodRequest = { return message; }, - fromJSON(object: any): GetOnlyMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - toJSON(message: GetOnlyMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -427,6 +423,10 @@ export const GetOnlyMethodRequest = { return obj; }, + fromJSON(object: any): GetOnlyMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + create, I>>(base?: I): GetOnlyMethodRequest { return GetOnlyMethodRequest.fromPartial(base ?? {}); }, @@ -473,10 +473,6 @@ export const GetOnlyMethodResponse = { return message; }, - fromJSON(object: any): GetOnlyMethodResponse { - return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; - }, - toJSON(message: GetOnlyMethodResponse): unknown { const obj: any = {}; if (message.entity !== undefined) { @@ -485,6 +481,10 @@ export const GetOnlyMethodResponse = { return obj; }, + fromJSON(object: any): GetOnlyMethodResponse { + return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; + }, + create, I>>(base?: I): GetOnlyMethodResponse { return GetOnlyMethodResponse.fromPartial(base ?? {}); }, @@ -533,10 +533,6 @@ export const WriteMethodRequest = { return message; }, - fromJSON(object: any): WriteMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - toJSON(message: WriteMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -545,6 +541,10 @@ export const WriteMethodRequest = { return obj; }, + fromJSON(object: any): WriteMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + create, I>>(base?: I): WriteMethodRequest { return WriteMethodRequest.fromPartial(base ?? {}); }, @@ -581,15 +581,15 @@ export const WriteMethodResponse = { return message; }, - fromJSON(_: any): WriteMethodResponse { - return {}; - }, - toJSON(_: WriteMethodResponse): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): WriteMethodResponse { + return {}; + }, + create, I>>(base?: I): WriteMethodResponse { return WriteMethodResponse.fromPartial(base ?? {}); }, @@ -645,10 +645,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== "") { @@ -660,6 +656,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, diff --git a/integration/batching-with-context/batching.ts b/integration/batching-with-context/batching.ts index 77b71e738..e81cf661f 100644 --- a/integration/batching-with-context/batching.ts +++ b/integration/batching-with-context/batching.ts @@ -81,10 +81,6 @@ export const BatchQueryRequest = { return message; }, - fromJSON(object: any): BatchQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - toJSON(message: BatchQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -93,6 +89,10 @@ export const BatchQueryRequest = { return obj; }, + fromJSON(object: any): BatchQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + create, I>>(base?: I): BatchQueryRequest { return BatchQueryRequest.fromPartial(base ?? {}); }, @@ -139,10 +139,6 @@ export const BatchQueryResponse = { return message; }, - fromJSON(object: any): BatchQueryResponse { - return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; - }, - toJSON(message: BatchQueryResponse): unknown { const obj: any = {}; if (message.entities?.length) { @@ -151,6 +147,10 @@ export const BatchQueryResponse = { return obj; }, + fromJSON(object: any): BatchQueryResponse { + return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; + }, + create, I>>(base?: I): BatchQueryResponse { return BatchQueryResponse.fromPartial(base ?? {}); }, @@ -197,10 +197,6 @@ export const BatchMapQueryRequest = { return message; }, - fromJSON(object: any): BatchMapQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - toJSON(message: BatchMapQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -209,6 +205,10 @@ export const BatchMapQueryRequest = { return obj; }, + fromJSON(object: any): BatchMapQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + create, I>>(base?: I): BatchMapQueryRequest { return BatchMapQueryRequest.fromPartial(base ?? {}); }, @@ -258,17 +258,6 @@ export const BatchMapQueryResponse = { return message; }, - fromJSON(object: any): BatchMapQueryResponse { - return { - entities: isObject(object.entities) - ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { - acc[key] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: BatchMapQueryResponse): unknown { const obj: any = {}; if (message.entities) { @@ -283,6 +272,17 @@ export const BatchMapQueryResponse = { return obj; }, + fromJSON(object: any): BatchMapQueryResponse { + return { + entities: isObject(object.entities) + ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { + acc[key] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): BatchMapQueryResponse { return BatchMapQueryResponse.fromPartial(base ?? {}); }, @@ -344,13 +344,6 @@ export const BatchMapQueryResponse_EntitiesEntry = { return message; }, - fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: BatchMapQueryResponse_EntitiesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -362,6 +355,13 @@ export const BatchMapQueryResponse_EntitiesEntry = { return obj; }, + fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): BatchMapQueryResponse_EntitiesEntry { @@ -415,10 +415,6 @@ export const GetOnlyMethodRequest = { return message; }, - fromJSON(object: any): GetOnlyMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - toJSON(message: GetOnlyMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -427,6 +423,10 @@ export const GetOnlyMethodRequest = { return obj; }, + fromJSON(object: any): GetOnlyMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + create, I>>(base?: I): GetOnlyMethodRequest { return GetOnlyMethodRequest.fromPartial(base ?? {}); }, @@ -473,10 +473,6 @@ export const GetOnlyMethodResponse = { return message; }, - fromJSON(object: any): GetOnlyMethodResponse { - return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; - }, - toJSON(message: GetOnlyMethodResponse): unknown { const obj: any = {}; if (message.entity !== undefined) { @@ -485,6 +481,10 @@ export const GetOnlyMethodResponse = { return obj; }, + fromJSON(object: any): GetOnlyMethodResponse { + return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; + }, + create, I>>(base?: I): GetOnlyMethodResponse { return GetOnlyMethodResponse.fromPartial(base ?? {}); }, @@ -533,10 +533,6 @@ export const WriteMethodRequest = { return message; }, - fromJSON(object: any): WriteMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - toJSON(message: WriteMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -545,6 +541,10 @@ export const WriteMethodRequest = { return obj; }, + fromJSON(object: any): WriteMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + create, I>>(base?: I): WriteMethodRequest { return WriteMethodRequest.fromPartial(base ?? {}); }, @@ -581,15 +581,15 @@ export const WriteMethodResponse = { return message; }, - fromJSON(_: any): WriteMethodResponse { - return {}; - }, - toJSON(_: WriteMethodResponse): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): WriteMethodResponse { + return {}; + }, + create, I>>(base?: I): WriteMethodResponse { return WriteMethodResponse.fromPartial(base ?? {}); }, @@ -645,10 +645,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== "") { @@ -660,6 +656,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, diff --git a/integration/batching/batching.ts b/integration/batching/batching.ts index ea5e6ddbb..a5595363a 100644 --- a/integration/batching/batching.ts +++ b/integration/batching/batching.ts @@ -79,10 +79,6 @@ export const BatchQueryRequest = { return message; }, - fromJSON(object: any): BatchQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - toJSON(message: BatchQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -91,6 +87,10 @@ export const BatchQueryRequest = { return obj; }, + fromJSON(object: any): BatchQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + create, I>>(base?: I): BatchQueryRequest { return BatchQueryRequest.fromPartial(base ?? {}); }, @@ -137,10 +137,6 @@ export const BatchQueryResponse = { return message; }, - fromJSON(object: any): BatchQueryResponse { - return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; - }, - toJSON(message: BatchQueryResponse): unknown { const obj: any = {}; if (message.entities?.length) { @@ -149,6 +145,10 @@ export const BatchQueryResponse = { return obj; }, + fromJSON(object: any): BatchQueryResponse { + return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; + }, + create, I>>(base?: I): BatchQueryResponse { return BatchQueryResponse.fromPartial(base ?? {}); }, @@ -195,10 +195,6 @@ export const BatchMapQueryRequest = { return message; }, - fromJSON(object: any): BatchMapQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - toJSON(message: BatchMapQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -207,6 +203,10 @@ export const BatchMapQueryRequest = { return obj; }, + fromJSON(object: any): BatchMapQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + create, I>>(base?: I): BatchMapQueryRequest { return BatchMapQueryRequest.fromPartial(base ?? {}); }, @@ -256,17 +256,6 @@ export const BatchMapQueryResponse = { return message; }, - fromJSON(object: any): BatchMapQueryResponse { - return { - entities: isObject(object.entities) - ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { - acc[key] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: BatchMapQueryResponse): unknown { const obj: any = {}; if (message.entities) { @@ -281,6 +270,17 @@ export const BatchMapQueryResponse = { return obj; }, + fromJSON(object: any): BatchMapQueryResponse { + return { + entities: isObject(object.entities) + ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { + acc[key] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): BatchMapQueryResponse { return BatchMapQueryResponse.fromPartial(base ?? {}); }, @@ -342,13 +342,6 @@ export const BatchMapQueryResponse_EntitiesEntry = { return message; }, - fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: BatchMapQueryResponse_EntitiesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -360,6 +353,13 @@ export const BatchMapQueryResponse_EntitiesEntry = { return obj; }, + fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): BatchMapQueryResponse_EntitiesEntry { @@ -413,10 +413,6 @@ export const GetOnlyMethodRequest = { return message; }, - fromJSON(object: any): GetOnlyMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - toJSON(message: GetOnlyMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -425,6 +421,10 @@ export const GetOnlyMethodRequest = { return obj; }, + fromJSON(object: any): GetOnlyMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + create, I>>(base?: I): GetOnlyMethodRequest { return GetOnlyMethodRequest.fromPartial(base ?? {}); }, @@ -471,10 +471,6 @@ export const GetOnlyMethodResponse = { return message; }, - fromJSON(object: any): GetOnlyMethodResponse { - return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; - }, - toJSON(message: GetOnlyMethodResponse): unknown { const obj: any = {}; if (message.entity !== undefined) { @@ -483,6 +479,10 @@ export const GetOnlyMethodResponse = { return obj; }, + fromJSON(object: any): GetOnlyMethodResponse { + return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; + }, + create, I>>(base?: I): GetOnlyMethodResponse { return GetOnlyMethodResponse.fromPartial(base ?? {}); }, @@ -531,10 +531,6 @@ export const WriteMethodRequest = { return message; }, - fromJSON(object: any): WriteMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - toJSON(message: WriteMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -543,6 +539,10 @@ export const WriteMethodRequest = { return obj; }, + fromJSON(object: any): WriteMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + create, I>>(base?: I): WriteMethodRequest { return WriteMethodRequest.fromPartial(base ?? {}); }, @@ -579,15 +579,15 @@ export const WriteMethodResponse = { return message; }, - fromJSON(_: any): WriteMethodResponse { - return {}; - }, - toJSON(_: WriteMethodResponse): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): WriteMethodResponse { + return {}; + }, + create, I>>(base?: I): WriteMethodResponse { return WriteMethodResponse.fromPartial(base ?? {}); }, @@ -643,10 +643,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== "") { @@ -658,6 +654,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, diff --git a/integration/bytes-as-base64/message.ts b/integration/bytes-as-base64/message.ts index 9678e3084..ced9d34b0 100644 --- a/integration/bytes-as-base64/message.ts +++ b/integration/bytes-as-base64/message.ts @@ -11,10 +11,6 @@ function createBaseMessage(): Message { } export const Message = { - fromJSON(object: any): Message { - return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0) }; - }, - toJSON(message: Message): unknown { const obj: any = {}; if (message.data.length !== 0) { @@ -23,6 +19,10 @@ export const Message = { return obj; }, + fromJSON(object: any): Message { + return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0) }; + }, + create, I>>(base?: I): Message { return Message.fromPartial(base ?? {}); }, diff --git a/integration/bytes-node/google/protobuf/wrappers.ts b/integration/bytes-node/google/protobuf/wrappers.ts index 1bbfbcb1d..045c1aba7 100644 --- a/integration/bytes-node/google/protobuf/wrappers.ts +++ b/integration/bytes-node/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? Buffer.from(bytesFromBase64(object.value)) : Buffer.alloc(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? Buffer.from(bytesFromBase64(object.value)) : Buffer.alloc(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/bytes-node/point.ts b/integration/bytes-node/point.ts index c9f0a51e0..96abb30ef 100644 --- a/integration/bytes-node/point.ts +++ b/integration/bytes-node/point.ts @@ -54,13 +54,6 @@ export const Point = { return message; }, - fromJSON(object: any): Point { - return { - data: isSet(object.data) ? Buffer.from(bytesFromBase64(object.data)) : Buffer.alloc(0), - dataWrapped: isSet(object.dataWrapped) ? new Buffer(object.dataWrapped) : undefined, - }; - }, - toJSON(message: Point): unknown { const obj: any = {}; if (message.data.length !== 0) { @@ -72,6 +65,13 @@ export const Point = { return obj; }, + fromJSON(object: any): Point { + return { + data: isSet(object.data) ? Buffer.from(bytesFromBase64(object.data)) : Buffer.alloc(0), + dataWrapped: isSet(object.dataWrapped) ? new Buffer(object.dataWrapped) : undefined, + }; + }, + create, I>>(base?: I): Point { return Point.fromPartial(base ?? {}); }, diff --git a/integration/const-enum/const-enum.ts b/integration/const-enum/const-enum.ts index c6140f96d..de3ee3841 100644 --- a/integration/const-enum/const-enum.ts +++ b/integration/const-enum/const-enum.ts @@ -122,18 +122,6 @@ export const DividerData = { return message; }, - fromJSON(object: any): DividerData { - return { - type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE, - typeMap: isObject(object.typeMap) - ? Object.entries(object.typeMap).reduce<{ [key: string]: DividerData_DividerType }>((acc, [key, value]) => { - acc[key] = dividerData_DividerTypeFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: DividerData): unknown { const obj: any = {}; if (message.type !== DividerData_DividerType.DOUBLE) { @@ -151,6 +139,18 @@ export const DividerData = { return obj; }, + fromJSON(object: any): DividerData { + return { + type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE, + typeMap: isObject(object.typeMap) + ? Object.entries(object.typeMap).reduce<{ [key: string]: DividerData_DividerType }>((acc, [key, value]) => { + acc[key] = dividerData_DividerTypeFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): DividerData { return DividerData.fromPartial(base ?? {}); }, @@ -216,13 +216,6 @@ export const DividerData_TypeMapEntry = { return message; }, - fromJSON(object: any): DividerData_TypeMapEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? dividerData_DividerTypeFromJSON(object.value) : DividerData_DividerType.DOUBLE, - }; - }, - toJSON(message: DividerData_TypeMapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -234,6 +227,13 @@ export const DividerData_TypeMapEntry = { return obj; }, + fromJSON(object: any): DividerData_TypeMapEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? dividerData_DividerTypeFromJSON(object.value) : DividerData_DividerType.DOUBLE, + }; + }, + create, I>>(base?: I): DividerData_TypeMapEntry { return DividerData_TypeMapEntry.fromPartial(base ?? {}); }, diff --git a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts index 554f21662..887f71a48 100644 --- a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts +++ b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts @@ -105,10 +105,6 @@ export const DividerData = { return message; }, - fromJSON(object: any): DividerData { - return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE }; - }, - toJSON(message: DividerData): unknown { const obj: any = {}; if (message.type !== DividerData_DividerType.DOUBLE) { @@ -117,6 +113,10 @@ export const DividerData = { return obj; }, + fromJSON(object: any): DividerData { + return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE }; + }, + create, I>>(base?: I): DividerData { return DividerData.fromPartial(base ?? {}); }, diff --git a/integration/enums-as-literals/enums-as-literals.ts b/integration/enums-as-literals/enums-as-literals.ts index 93d1914a0..48abc99f4 100644 --- a/integration/enums-as-literals/enums-as-literals.ts +++ b/integration/enums-as-literals/enums-as-literals.ts @@ -83,10 +83,6 @@ export const DividerData = { return message; }, - fromJSON(object: any): DividerData { - return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : 0 }; - }, - toJSON(message: DividerData): unknown { const obj: any = {}; if (message.type !== 0) { @@ -95,6 +91,10 @@ export const DividerData = { return obj; }, + fromJSON(object: any): DividerData { + return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : 0 }; + }, + create, I>>(base?: I): DividerData { return DividerData.fromPartial(base ?? {}); }, diff --git a/integration/extensions/test.ts b/integration/extensions/test.ts index e843bccac..00a87945d 100644 --- a/integration/extensions/test.ts +++ b/integration/extensions/test.ts @@ -173,10 +173,6 @@ export const Extendable = { return results; }, - fromJSON(object: any): Extendable { - return { field: isSet(object.field) ? String(object.field) : undefined }; - }, - toJSON(message: Extendable): unknown { const obj: any = {}; if (message.field !== undefined && message.field !== "") { @@ -185,6 +181,10 @@ export const Extendable = { return obj; }, + fromJSON(object: any): Extendable { + return { field: isSet(object.field) ? String(object.field) : undefined }; + }, + create, I>>(base?: I): Extendable { return Extendable.fromPartial(base ?? {}); }, @@ -283,10 +283,6 @@ export const Nested = { return message; }, - fromJSON(object: any): Nested { - return { field: isSet(object.field) ? String(object.field) : undefined }; - }, - toJSON(message: Nested): unknown { const obj: any = {}; if (message.field !== undefined && message.field !== "") { @@ -295,6 +291,10 @@ export const Nested = { return obj; }, + fromJSON(object: any): Nested { + return { field: isSet(object.field) ? String(object.field) : undefined }; + }, + create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -378,13 +378,6 @@ export const Group = { return message; }, - fromJSON(object: any): Group { - return { - name: isSet(object.name) ? String(object.name) : undefined, - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - toJSON(message: Group): unknown { const obj: any = {}; if (message.name !== undefined && message.name !== "") { @@ -396,6 +389,13 @@ export const Group = { return obj; }, + fromJSON(object: any): Group { + return { + name: isSet(object.name) ? String(object.name) : undefined, + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + create, I>>(base?: I): Group { return Group.fromPartial(base ?? {}); }, diff --git a/integration/fieldmask/fieldmask.ts b/integration/fieldmask/fieldmask.ts index 8b908180b..2076e88a4 100644 --- a/integration/fieldmask/fieldmask.ts +++ b/integration/fieldmask/fieldmask.ts @@ -43,10 +43,6 @@ export const FieldMaskMessage = { return message; }, - fromJSON(object: any): FieldMaskMessage { - return { fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined }; - }, - toJSON(message: FieldMaskMessage): unknown { const obj: any = {}; if (message.fieldMask !== undefined) { @@ -55,6 +51,10 @@ export const FieldMaskMessage = { return obj; }, + fromJSON(object: any): FieldMaskMessage { + return { fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined }; + }, + create, I>>(base?: I): FieldMaskMessage { return FieldMaskMessage.fromPartial(base ?? {}); }, diff --git a/integration/fieldmask/google/protobuf/field_mask.ts b/integration/fieldmask/google/protobuf/field_mask.ts index 327bf5421..6c3b36dcc 100644 --- a/integration/fieldmask/google/protobuf/field_mask.ts +++ b/integration/fieldmask/google/protobuf/field_mask.ts @@ -243,6 +243,10 @@ export const FieldMask = { return message; }, + toJSON(message: FieldMask): string { + return message.paths.join(","); + }, + fromJSON(object: any): FieldMask { return { paths: typeof (object) === "string" @@ -253,10 +257,6 @@ export const FieldMask = { }; }, - toJSON(message: FieldMask): string { - return message.paths.join(","); - }, - create, I>>(base?: I): FieldMask { return FieldMask.fromPartial(base ?? {}); }, diff --git a/integration/file-suffix/child.pb.ts b/integration/file-suffix/child.pb.ts index 8c91027c8..e55d20909 100644 --- a/integration/file-suffix/child.pb.ts +++ b/integration/file-suffix/child.pb.ts @@ -75,10 +75,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -87,6 +83,10 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/file-suffix/google/protobuf/timestamp.pb.ts b/integration/file-suffix/google/protobuf/timestamp.pb.ts index 032f4ab29..4947dacaa 100644 --- a/integration/file-suffix/google/protobuf/timestamp.pb.ts +++ b/integration/file-suffix/google/protobuf/timestamp.pb.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/file-suffix/parent.pb.ts b/integration/file-suffix/parent.pb.ts index 8cd18e863..5ec327104 100644 --- a/integration/file-suffix/parent.pb.ts +++ b/integration/file-suffix/parent.pb.ts @@ -66,14 +66,6 @@ export const Parent = { return message; }, - fromJSON(object: any): Parent { - return { - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - }; - }, - toJSON(message: Parent): unknown { const obj: any = {}; if (message.child !== undefined) { @@ -88,6 +80,14 @@ export const Parent = { return obj; }, + fromJSON(object: any): Parent { + return { + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + }; + }, + create, I>>(base?: I): Parent { return Parent.fromPartial(base ?? {}); }, diff --git a/integration/from-partial-no-initialize/test.ts b/integration/from-partial-no-initialize/test.ts index 4dc48cfcb..5ed74541a 100644 --- a/integration/from-partial-no-initialize/test.ts +++ b/integration/from-partial-no-initialize/test.ts @@ -57,10 +57,6 @@ export const TPartialMessage = { return message; }, - fromJSON(object: any): TPartialMessage { - return { field: isSet(object.field) ? String(object.field) : undefined }; - }, - toJSON(message: TPartialMessage): unknown { const obj: any = {}; if (message.field !== undefined && message.field !== "") { @@ -69,6 +65,10 @@ export const TPartialMessage = { return obj; }, + fromJSON(object: any): TPartialMessage { + return { field: isSet(object.field) ? String(object.field) : undefined }; + }, + create, I>>(base?: I): TPartialMessage { return TPartialMessage.fromPartial(base ?? {}); }, @@ -211,29 +211,6 @@ export const TPartial = { return message; }, - fromJSON(object: any): TPartial { - return { - number: isSet(object.number) ? Number(object.number) : undefined, - string: isSet(object.string) ? String(object.string) : undefined, - map: isObject(object.map) - ? Object.entries(object.map).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : undefined, - message: isSet(object.message) ? TPartialMessage.fromJSON(object.message) : undefined, - repeatedMessage: Array.isArray(object?.repeatedMessage) - ? object.repeatedMessage.map((e: any) => TPartialMessage.fromJSON(e)) - : undefined, - repeatedString: Array.isArray(object?.repeatedString) - ? object.repeatedString.map((e: any) => String(e)) - : undefined, - repeatedNumber: Array.isArray(object?.repeatedNumber) - ? object.repeatedNumber.map((e: any) => Number(e)) - : undefined, - }; - }, - toJSON(message: TPartial): unknown { const obj: any = {}; if (message.number !== undefined && message.number !== 0) { @@ -266,6 +243,29 @@ export const TPartial = { return obj; }, + fromJSON(object: any): TPartial { + return { + number: isSet(object.number) ? Number(object.number) : undefined, + string: isSet(object.string) ? String(object.string) : undefined, + map: isObject(object.map) + ? Object.entries(object.map).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : undefined, + message: isSet(object.message) ? TPartialMessage.fromJSON(object.message) : undefined, + repeatedMessage: Array.isArray(object?.repeatedMessage) + ? object.repeatedMessage.map((e: any) => TPartialMessage.fromJSON(e)) + : undefined, + repeatedString: Array.isArray(object?.repeatedString) + ? object.repeatedString.map((e: any) => String(e)) + : undefined, + repeatedNumber: Array.isArray(object?.repeatedNumber) + ? object.repeatedNumber.map((e: any) => Number(e)) + : undefined, + }; + }, + create, I>>(base?: I): TPartial { return TPartial.fromPartial(base ?? {}); }, @@ -337,10 +337,6 @@ export const TPartial_MapEntry = { return message; }, - fromJSON(object: any): TPartial_MapEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: TPartial_MapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -352,6 +348,10 @@ export const TPartial_MapEntry = { return obj; }, + fromJSON(object: any): TPartial_MapEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): TPartial_MapEntry { return TPartial_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/generic-metadata/hero.ts b/integration/generic-metadata/hero.ts index de969f6f1..a4dc27871 100644 --- a/integration/generic-metadata/hero.ts +++ b/integration/generic-metadata/hero.ts @@ -59,10 +59,6 @@ export const HeroById = { return message; }, - fromJSON(object: any): HeroById { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: HeroById): unknown { const obj: any = {}; if (message.id !== 0) { @@ -71,6 +67,10 @@ export const HeroById = { return obj; }, + fromJSON(object: any): HeroById { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): HeroById { return HeroById.fromPartial(base ?? {}); }, @@ -117,10 +117,6 @@ export const VillainById = { return message; }, - fromJSON(object: any): VillainById { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: VillainById): unknown { const obj: any = {}; if (message.id !== 0) { @@ -129,6 +125,10 @@ export const VillainById = { return obj; }, + fromJSON(object: any): VillainById { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): VillainById { return VillainById.fromPartial(base ?? {}); }, @@ -185,10 +185,6 @@ export const Hero = { return message; }, - fromJSON(object: any): Hero { - return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Hero): unknown { const obj: any = {}; if (message.id !== 0) { @@ -200,6 +196,10 @@ export const Hero = { return obj; }, + fromJSON(object: any): Hero { + return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Hero { return Hero.fromPartial(base ?? {}); }, @@ -257,10 +257,6 @@ export const Villain = { return message; }, - fromJSON(object: any): Villain { - return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Villain): unknown { const obj: any = {}; if (message.id !== 0) { @@ -272,6 +268,10 @@ export const Villain = { return obj; }, + fromJSON(object: any): Villain { + return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Villain { return Villain.fromPartial(base ?? {}); }, diff --git a/integration/generic-service-definitions-and-services/simple.ts b/integration/generic-service-definitions-and-services/simple.ts index 09d413f92..e7794da2d 100644 --- a/integration/generic-service-definitions-and-services/simple.ts +++ b/integration/generic-service-definitions-and-services/simple.ts @@ -42,10 +42,6 @@ export const TestMessage = { return message; }, - fromJSON(object: any): TestMessage { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.value !== "") { @@ -54,6 +50,10 @@ export const TestMessage = { return obj; }, + fromJSON(object: any): TestMessage { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/generic-service-definitions/simple.ts b/integration/generic-service-definitions/simple.ts index 09d413f92..e7794da2d 100644 --- a/integration/generic-service-definitions/simple.ts +++ b/integration/generic-service-definitions/simple.ts @@ -42,10 +42,6 @@ export const TestMessage = { return message; }, - fromJSON(object: any): TestMessage { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.value !== "") { @@ -54,6 +50,10 @@ export const TestMessage = { return obj; }, + fromJSON(object: any): TestMessage { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/global-this/global-this.ts b/integration/global-this/global-this.ts index 216089c26..02fa32512 100644 --- a/integration/global-this/global-this.ts +++ b/integration/global-this/global-this.ts @@ -46,10 +46,6 @@ export const Object = { return message; }, - fromJSON(object: any): Object { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Object): unknown { const obj: any = {}; if (message.name !== "") { @@ -58,6 +54,10 @@ export const Object = { return obj; }, + fromJSON(object: any): Object { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Object { return Object.fromPartial(base ?? {}); }, @@ -104,10 +104,6 @@ export const Error = { return message; }, - fromJSON(object: any): Error { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Error): unknown { const obj: any = {}; if (message.name !== "") { @@ -116,6 +112,10 @@ export const Error = { return obj; }, + fromJSON(object: any): Error { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Error { return Error.fromPartial(base ?? {}); }, diff --git a/integration/groups/test.ts b/integration/groups/test.ts index 038e37513..8f24e7b2f 100644 --- a/integration/groups/test.ts +++ b/integration/groups/test.ts @@ -133,14 +133,6 @@ export const GroupsOptionalTest = { return message; }, - fromJSON(object: any): GroupsOptionalTest { - return { - int1: isSet(object.int1) ? Number(object.int1) : undefined, - group: isSet(object.group) ? GroupsOptionalTest_Group.fromJSON(object.group) : undefined, - int3: isSet(object.int3) ? Number(object.int3) : undefined, - }; - }, - toJSON(message: GroupsOptionalTest): unknown { const obj: any = {}; if (message.int1 !== undefined && message.int1 !== 0) { @@ -155,6 +147,14 @@ export const GroupsOptionalTest = { return obj; }, + fromJSON(object: any): GroupsOptionalTest { + return { + int1: isSet(object.int1) ? Number(object.int1) : undefined, + group: isSet(object.group) ? GroupsOptionalTest_Group.fromJSON(object.group) : undefined, + int3: isSet(object.int3) ? Number(object.int3) : undefined, + }; + }, + create, I>>(base?: I): GroupsOptionalTest { return GroupsOptionalTest.fromPartial(base ?? {}); }, @@ -242,13 +242,6 @@ export const GroupsOptionalTest_Group = { return message; }, - fromJSON(object: any): GroupsOptionalTest_Group { - return { - key: isSet(object.key) ? String(object.key) : undefined, - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - toJSON(message: GroupsOptionalTest_Group): unknown { const obj: any = {}; if (message.key !== undefined && message.key !== "") { @@ -260,6 +253,13 @@ export const GroupsOptionalTest_Group = { return obj; }, + fromJSON(object: any): GroupsOptionalTest_Group { + return { + key: isSet(object.key) ? String(object.key) : undefined, + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + create, I>>(base?: I): GroupsOptionalTest_Group { return GroupsOptionalTest_Group.fromPartial(base ?? {}); }, @@ -399,16 +399,6 @@ export const GroupsRepeatedTest = { return message; }, - fromJSON(object: any): GroupsRepeatedTest { - return { - int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, - group: Array.isArray(object?.group) - ? object.group.map((e: any) => GroupsRepeatedTest_Group.fromJSON(e)) - : undefined, - int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, - }; - }, - toJSON(message: GroupsRepeatedTest): unknown { const obj: any = {}; if (message.int1?.length) { @@ -423,6 +413,16 @@ export const GroupsRepeatedTest = { return obj; }, + fromJSON(object: any): GroupsRepeatedTest { + return { + int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, + group: Array.isArray(object?.group) + ? object.group.map((e: any) => GroupsRepeatedTest_Group.fromJSON(e)) + : undefined, + int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, + }; + }, + create, I>>(base?: I): GroupsRepeatedTest { return GroupsRepeatedTest.fromPartial(base ?? {}); }, @@ -518,13 +518,6 @@ export const GroupsRepeatedTest_Group = { return message; }, - fromJSON(object: any): GroupsRepeatedTest_Group { - return { - key: Array.isArray(object?.key) ? object.key.map((e: any) => String(e)) : undefined, - value: Array.isArray(object?.value) ? object.value.map((e: any) => String(e)) : undefined, - }; - }, - toJSON(message: GroupsRepeatedTest_Group): unknown { const obj: any = {}; if (message.key?.length) { @@ -536,6 +529,13 @@ export const GroupsRepeatedTest_Group = { return obj; }, + fromJSON(object: any): GroupsRepeatedTest_Group { + return { + key: Array.isArray(object?.key) ? object.key.map((e: any) => String(e)) : undefined, + value: Array.isArray(object?.value) ? object.value.map((e: any) => String(e)) : undefined, + }; + }, + create, I>>(base?: I): GroupsRepeatedTest_Group { return GroupsRepeatedTest_Group.fromPartial(base ?? {}); }, @@ -675,16 +675,6 @@ export const GroupsNestedTest = { return message; }, - fromJSON(object: any): GroupsNestedTest { - return { - int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, - group: Array.isArray(object?.group) - ? object.group.map((e: any) => GroupsNestedTest_Group.fromJSON(e)) - : undefined, - int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, - }; - }, - toJSON(message: GroupsNestedTest): unknown { const obj: any = {}; if (message.int1?.length) { @@ -699,6 +689,16 @@ export const GroupsNestedTest = { return obj; }, + fromJSON(object: any): GroupsNestedTest { + return { + int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, + group: Array.isArray(object?.group) + ? object.group.map((e: any) => GroupsNestedTest_Group.fromJSON(e)) + : undefined, + int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, + }; + }, + create, I>>(base?: I): GroupsNestedTest { return GroupsNestedTest.fromPartial(base ?? {}); }, @@ -779,14 +779,6 @@ export const GroupsNestedTest_Group = { return message; }, - fromJSON(object: any): GroupsNestedTest_Group { - return { - nested: Array.isArray(object?.nested) - ? object.nested.map((e: any) => GroupsNestedTest_Group_Nested.fromJSON(e)) - : undefined, - }; - }, - toJSON(message: GroupsNestedTest_Group): unknown { const obj: any = {}; if (message.nested?.length) { @@ -795,6 +787,14 @@ export const GroupsNestedTest_Group = { return obj; }, + fromJSON(object: any): GroupsNestedTest_Group { + return { + nested: Array.isArray(object?.nested) + ? object.nested.map((e: any) => GroupsNestedTest_Group_Nested.fromJSON(e)) + : undefined, + }; + }, + create, I>>(base?: I): GroupsNestedTest_Group { return GroupsNestedTest_Group.fromPartial(base ?? {}); }, @@ -873,14 +873,6 @@ export const GroupsNestedTest_Group_Nested = { return message; }, - fromJSON(object: any): GroupsNestedTest_Group_Nested { - return { - nested2: Array.isArray(object?.nested2) - ? object.nested2.map((e: any) => GroupsNestedTest_Group_Nested_Nested2.fromJSON(e)) - : undefined, - }; - }, - toJSON(message: GroupsNestedTest_Group_Nested): unknown { const obj: any = {}; if (message.nested2?.length) { @@ -889,6 +881,14 @@ export const GroupsNestedTest_Group_Nested = { return obj; }, + fromJSON(object: any): GroupsNestedTest_Group_Nested { + return { + nested2: Array.isArray(object?.nested2) + ? object.nested2.map((e: any) => GroupsNestedTest_Group_Nested_Nested2.fromJSON(e)) + : undefined, + }; + }, + create, I>>(base?: I): GroupsNestedTest_Group_Nested { return GroupsNestedTest_Group_Nested.fromPartial(base ?? {}); }, @@ -964,10 +964,6 @@ export const GroupsNestedTest_Group_Nested_Nested2 = { return message; }, - fromJSON(object: any): GroupsNestedTest_Group_Nested_Nested2 { - return { string1: isSet(object.string1) ? String(object.string1) : undefined }; - }, - toJSON(message: GroupsNestedTest_Group_Nested_Nested2): unknown { const obj: any = {}; if (message.string1 !== undefined && message.string1 !== "") { @@ -976,6 +972,10 @@ export const GroupsNestedTest_Group_Nested_Nested2 = { return obj; }, + fromJSON(object: any): GroupsNestedTest_Group_Nested_Nested2 { + return { string1: isSet(object.string1) ? String(object.string1) : undefined }; + }, + create, I>>( base?: I, ): GroupsNestedTest_Group_Nested_Nested2 { diff --git a/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts b/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts index 511846364..59c3ee198 100644 --- a/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts +++ b/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts @@ -55,10 +55,6 @@ export const TimestampMessage = { return message; }, - fromJSON(object: any): TimestampMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: TimestampMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -67,6 +63,10 @@ export const TimestampMessage = { return obj; }, + fromJSON(object: any): TimestampMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): TimestampMessage { return TimestampMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts b/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts index 021ca8402..ebce875f3 100644 --- a/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts +++ b/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts @@ -55,10 +55,6 @@ export const TimestampMessage = { return message; }, - fromJSON(object: any): TimestampMessage { - return { timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined }; - }, - toJSON(message: TimestampMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -67,6 +63,10 @@ export const TimestampMessage = { return obj; }, + fromJSON(object: any): TimestampMessage { + return { timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined }; + }, + create, I>>(base?: I): TimestampMessage { return TimestampMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts b/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts index 606cf4504..0d52339db 100644 --- a/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts +++ b/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts @@ -55,10 +55,6 @@ export const TimestampMessage = { return message; }, - fromJSON(object: any): TimestampMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: TimestampMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -67,6 +63,10 @@ export const TimestampMessage = { return obj; }, + fromJSON(object: any): TimestampMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): TimestampMessage { return TimestampMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/empty.ts b/integration/grpc-js/google/protobuf/empty.ts index 1387d7ce4..d1b8ebf5b 100644 --- a/integration/grpc-js/google/protobuf/empty.ts +++ b/integration/grpc-js/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/struct.ts b/integration/grpc-js/google/protobuf/struct.ts index b2486a866..7c416eb52 100644 --- a/integration/grpc-js/google/protobuf/struct.ts +++ b/integration/grpc-js/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -165,6 +154,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,10 +249,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,6 +260,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,17 +368,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -402,6 +391,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,10 +490,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -502,6 +498,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/timestamp.ts b/integration/grpc-js/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/grpc-js/google/protobuf/timestamp.ts +++ b/integration/grpc-js/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/wrappers.ts b/integration/grpc-js/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/grpc-js/google/protobuf/wrappers.ts +++ b/integration/grpc-js/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/simple.ts b/integration/grpc-js/simple.ts index a552d77d9..986bbf920 100644 --- a/integration/grpc-js/simple.ts +++ b/integration/grpc-js/simple.ts @@ -74,10 +74,6 @@ export const TestMessage = { return message; }, - fromJSON(object: any): TestMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -86,6 +82,10 @@ export const TestMessage = { return obj; }, + fromJSON(object: any): TestMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-abort-signal/example.ts b/integration/grpc-web-abort-signal/example.ts index a0f08c644..fb1ff3f30 100644 --- a/integration/grpc-web-abort-signal/example.ts +++ b/integration/grpc-web-abort-signal/example.ts @@ -140,13 +140,6 @@ export const DashFlash = { return message; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -158,6 +151,13 @@ export const DashFlash = { return obj; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -225,14 +225,6 @@ export const DashUserSettingsState = { return message; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -247,6 +239,14 @@ export const DashUserSettingsState = { return obj; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -307,13 +307,6 @@ export const DashUserSettingsState_URLs = { return message; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -325,6 +318,13 @@ export const DashUserSettingsState_URLs = { return obj; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -402,15 +402,6 @@ export const DashCred = { return message; }, - fromJSON(object: any): DashCred { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - token: isSet(object.token) ? String(object.token) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashCred): unknown { const obj: any = {}; if (message.description !== "") { @@ -428,6 +419,15 @@ export const DashCred = { return obj; }, + fromJSON(object: any): DashCred { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + token: isSet(object.token) ? String(object.token) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashCred { return DashCred.fromPartial(base ?? {}); }, @@ -487,13 +487,6 @@ export const DashAPICredsCreateReq = { return message; }, - fromJSON(object: any): DashAPICredsCreateReq { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - }; - }, - toJSON(message: DashAPICredsCreateReq): unknown { const obj: any = {}; if (message.description !== "") { @@ -505,6 +498,13 @@ export const DashAPICredsCreateReq = { return obj; }, + fromJSON(object: any): DashAPICredsCreateReq { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + }; + }, + create, I>>(base?: I): DashAPICredsCreateReq { return DashAPICredsCreateReq.fromPartial(base ?? {}); }, @@ -582,15 +582,6 @@ export const DashAPICredsUpdateReq = { return message; }, - fromJSON(object: any): DashAPICredsUpdateReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashAPICredsUpdateReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -608,6 +599,15 @@ export const DashAPICredsUpdateReq = { return obj; }, + fromJSON(object: any): DashAPICredsUpdateReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashAPICredsUpdateReq { return DashAPICredsUpdateReq.fromPartial(base ?? {}); }, @@ -667,13 +667,6 @@ export const DashAPICredsDeleteReq = { return message; }, - fromJSON(object: any): DashAPICredsDeleteReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashAPICredsDeleteReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -685,6 +678,13 @@ export const DashAPICredsDeleteReq = { return obj; }, + fromJSON(object: any): DashAPICredsDeleteReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashAPICredsDeleteReq { return DashAPICredsDeleteReq.fromPartial(base ?? {}); }, @@ -722,15 +722,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-go-server/example.ts b/integration/grpc-web-go-server/example.ts index d1f2e05e3..c01936c78 100644 --- a/integration/grpc-web-go-server/example.ts +++ b/integration/grpc-web-go-server/example.ts @@ -138,13 +138,6 @@ export const DashFlash = { return message; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -156,6 +149,13 @@ export const DashFlash = { return obj; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -223,14 +223,6 @@ export const DashUserSettingsState = { return message; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -245,6 +237,14 @@ export const DashUserSettingsState = { return obj; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -305,13 +305,6 @@ export const DashUserSettingsState_URLs = { return message; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -323,6 +316,13 @@ export const DashUserSettingsState_URLs = { return obj; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -400,15 +400,6 @@ export const DashCred = { return message; }, - fromJSON(object: any): DashCred { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - token: isSet(object.token) ? String(object.token) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashCred): unknown { const obj: any = {}; if (message.description !== "") { @@ -426,6 +417,15 @@ export const DashCred = { return obj; }, + fromJSON(object: any): DashCred { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + token: isSet(object.token) ? String(object.token) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashCred { return DashCred.fromPartial(base ?? {}); }, @@ -485,13 +485,6 @@ export const DashAPICredsCreateReq = { return message; }, - fromJSON(object: any): DashAPICredsCreateReq { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - }; - }, - toJSON(message: DashAPICredsCreateReq): unknown { const obj: any = {}; if (message.description !== "") { @@ -503,6 +496,13 @@ export const DashAPICredsCreateReq = { return obj; }, + fromJSON(object: any): DashAPICredsCreateReq { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + }; + }, + create, I>>(base?: I): DashAPICredsCreateReq { return DashAPICredsCreateReq.fromPartial(base ?? {}); }, @@ -580,15 +580,6 @@ export const DashAPICredsUpdateReq = { return message; }, - fromJSON(object: any): DashAPICredsUpdateReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashAPICredsUpdateReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -606,6 +597,15 @@ export const DashAPICredsUpdateReq = { return obj; }, + fromJSON(object: any): DashAPICredsUpdateReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashAPICredsUpdateReq { return DashAPICredsUpdateReq.fromPartial(base ?? {}); }, @@ -665,13 +665,6 @@ export const DashAPICredsDeleteReq = { return message; }, - fromJSON(object: any): DashAPICredsDeleteReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashAPICredsDeleteReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -683,6 +676,13 @@ export const DashAPICredsDeleteReq = { return obj; }, + fromJSON(object: any): DashAPICredsDeleteReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashAPICredsDeleteReq { return DashAPICredsDeleteReq.fromPartial(base ?? {}); }, @@ -720,15 +720,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-no-streaming-observable/example.ts b/integration/grpc-web-no-streaming-observable/example.ts index 82366a50c..ecf03c576 100644 --- a/integration/grpc-web-no-streaming-observable/example.ts +++ b/integration/grpc-web-no-streaming-observable/example.ts @@ -116,13 +116,6 @@ export const DashFlash = { return message; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -134,6 +127,13 @@ export const DashFlash = { return obj; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -201,14 +201,6 @@ export const DashUserSettingsState = { return message; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -223,6 +215,14 @@ export const DashUserSettingsState = { return obj; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -283,13 +283,6 @@ export const DashUserSettingsState_URLs = { return message; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -301,6 +294,13 @@ export const DashUserSettingsState_URLs = { return obj; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -338,15 +338,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-no-streaming/example.ts b/integration/grpc-web-no-streaming/example.ts index d055a5e0c..bc07c7b32 100644 --- a/integration/grpc-web-no-streaming/example.ts +++ b/integration/grpc-web-no-streaming/example.ts @@ -114,13 +114,6 @@ export const DashFlash = { return message; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -132,6 +125,13 @@ export const DashFlash = { return obj; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -199,14 +199,6 @@ export const DashUserSettingsState = { return message; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -221,6 +213,14 @@ export const DashUserSettingsState = { return obj; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -281,13 +281,6 @@ export const DashUserSettingsState_URLs = { return message; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -299,6 +292,13 @@ export const DashUserSettingsState_URLs = { return obj; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -336,15 +336,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web/example.ts b/integration/grpc-web/example.ts index 49e312479..9453a7f1b 100644 --- a/integration/grpc-web/example.ts +++ b/integration/grpc-web/example.ts @@ -140,13 +140,6 @@ export const DashFlash = { return message; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -158,6 +151,13 @@ export const DashFlash = { return obj; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -225,14 +225,6 @@ export const DashUserSettingsState = { return message; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -247,6 +239,14 @@ export const DashUserSettingsState = { return obj; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -307,13 +307,6 @@ export const DashUserSettingsState_URLs = { return message; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -325,6 +318,13 @@ export const DashUserSettingsState_URLs = { return obj; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -402,15 +402,6 @@ export const DashCred = { return message; }, - fromJSON(object: any): DashCred { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - token: isSet(object.token) ? String(object.token) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashCred): unknown { const obj: any = {}; if (message.description !== "") { @@ -428,6 +419,15 @@ export const DashCred = { return obj; }, + fromJSON(object: any): DashCred { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + token: isSet(object.token) ? String(object.token) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashCred { return DashCred.fromPartial(base ?? {}); }, @@ -487,13 +487,6 @@ export const DashAPICredsCreateReq = { return message; }, - fromJSON(object: any): DashAPICredsCreateReq { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - }; - }, - toJSON(message: DashAPICredsCreateReq): unknown { const obj: any = {}; if (message.description !== "") { @@ -505,6 +498,13 @@ export const DashAPICredsCreateReq = { return obj; }, + fromJSON(object: any): DashAPICredsCreateReq { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + }; + }, + create, I>>(base?: I): DashAPICredsCreateReq { return DashAPICredsCreateReq.fromPartial(base ?? {}); }, @@ -582,15 +582,6 @@ export const DashAPICredsUpdateReq = { return message; }, - fromJSON(object: any): DashAPICredsUpdateReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashAPICredsUpdateReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -608,6 +599,15 @@ export const DashAPICredsUpdateReq = { return obj; }, + fromJSON(object: any): DashAPICredsUpdateReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashAPICredsUpdateReq { return DashAPICredsUpdateReq.fromPartial(base ?? {}); }, @@ -667,13 +667,6 @@ export const DashAPICredsDeleteReq = { return message; }, - fromJSON(object: any): DashAPICredsDeleteReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - toJSON(message: DashAPICredsDeleteReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -685,6 +678,13 @@ export const DashAPICredsDeleteReq = { return obj; }, + fromJSON(object: any): DashAPICredsDeleteReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + create, I>>(base?: I): DashAPICredsDeleteReq { return DashAPICredsDeleteReq.fromPartial(base ?? {}); }, @@ -722,15 +722,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/import-mapping/google/protobuf/timestamp.ts b/integration/import-mapping/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/import-mapping/google/protobuf/timestamp.ts +++ b/integration/import-mapping/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/import-mapping/mapping.ts b/integration/import-mapping/mapping.ts index 06fd3c94e..862a761d1 100644 --- a/integration/import-mapping/mapping.ts +++ b/integration/import-mapping/mapping.ts @@ -63,10 +63,6 @@ export const WithEmtpy = { return message; }, - fromJSON(object: any): WithEmtpy { - return { empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined }; - }, - toJSON(message: WithEmtpy): unknown { const obj: any = {}; if (message.empty !== undefined) { @@ -75,6 +71,10 @@ export const WithEmtpy = { return obj; }, + fromJSON(object: any): WithEmtpy { + return { empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined }; + }, + create, I>>(base?: I): WithEmtpy { return WithEmtpy.fromPartial(base ?? {}); }, @@ -121,10 +121,6 @@ export const WithStruct = { return message; }, - fromJSON(object: any): WithStruct { - return { strut: isObject(object.strut) ? object.strut : undefined }; - }, - toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.strut !== undefined) { @@ -133,6 +129,10 @@ export const WithStruct = { return obj; }, + fromJSON(object: any): WithStruct { + return { strut: isObject(object.strut) ? object.strut : undefined }; + }, + create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, @@ -179,10 +179,6 @@ export const WithTimestamp = { return message; }, - fromJSON(object: any): WithTimestamp { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: WithTimestamp): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -191,6 +187,10 @@ export const WithTimestamp = { return obj; }, + fromJSON(object: any): WithTimestamp { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): WithTimestamp { return WithTimestamp.fromPartial(base ?? {}); }, @@ -277,16 +277,6 @@ export const WithAll = { return message; }, - fromJSON(object: any): WithAll { - return { - empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined, - strut: isObject(object.strut) ? object.strut : undefined, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - duration: isSet(object.duration) ? Duration.fromJSON(object.duration) : undefined, - veryVerySecret: isSet(object.veryVerySecret) ? VeryVerySecret.fromJSON(object.veryVerySecret) : undefined, - }; - }, - toJSON(message: WithAll): unknown { const obj: any = {}; if (message.empty !== undefined) { @@ -307,6 +297,16 @@ export const WithAll = { return obj; }, + fromJSON(object: any): WithAll { + return { + empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined, + strut: isObject(object.strut) ? object.strut : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + duration: isSet(object.duration) ? Duration.fromJSON(object.duration) : undefined, + veryVerySecret: isSet(object.veryVerySecret) ? VeryVerySecret.fromJSON(object.veryVerySecret) : undefined, + }; + }, + create, I>>(base?: I): WithAll { return WithAll.fromPartial(base ?? {}); }, diff --git a/integration/import-suffix/child.pb.ts b/integration/import-suffix/child.pb.ts index 95c76a35c..4998f6748 100644 --- a/integration/import-suffix/child.pb.ts +++ b/integration/import-suffix/child.pb.ts @@ -75,10 +75,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -87,6 +83,10 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/import-suffix/google/protobuf/timestamp.pb.ts b/integration/import-suffix/google/protobuf/timestamp.pb.ts index de977dc2b..f2a10e03e 100644 --- a/integration/import-suffix/google/protobuf/timestamp.pb.ts +++ b/integration/import-suffix/google/protobuf/timestamp.pb.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/import-suffix/parent.pb.ts b/integration/import-suffix/parent.pb.ts index 0cd242d71..a59a95f59 100644 --- a/integration/import-suffix/parent.pb.ts +++ b/integration/import-suffix/parent.pb.ts @@ -66,14 +66,6 @@ export const Parent = { return message; }, - fromJSON(object: any): Parent { - return { - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - }; - }, - toJSON(message: Parent): unknown { const obj: any = {}; if (message.child !== undefined) { @@ -88,6 +80,14 @@ export const Parent = { return obj; }, + fromJSON(object: any): Parent { + return { + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + }; + }, + create, I>>(base?: I): Parent { return Parent.fromPartial(base ?? {}); }, diff --git a/integration/lower-case-svc-methods/math.ts b/integration/lower-case-svc-methods/math.ts index 8bb700a08..79d70f243 100644 --- a/integration/lower-case-svc-methods/math.ts +++ b/integration/lower-case-svc-methods/math.ts @@ -63,10 +63,6 @@ export const NumPair = { return message; }, - fromJSON(object: any): NumPair { - return { num1: isSet(object.num1) ? Number(object.num1) : 0, num2: isSet(object.num2) ? Number(object.num2) : 0 }; - }, - toJSON(message: NumPair): unknown { const obj: any = {}; if (message.num1 !== 0) { @@ -78,6 +74,10 @@ export const NumPair = { return obj; }, + fromJSON(object: any): NumPair { + return { num1: isSet(object.num1) ? Number(object.num1) : 0, num2: isSet(object.num2) ? Number(object.num2) : 0 }; + }, + create, I>>(base?: I): NumPair { return NumPair.fromPartial(base ?? {}); }, @@ -125,10 +125,6 @@ export const NumSingle = { return message; }, - fromJSON(object: any): NumSingle { - return { num: isSet(object.num) ? Number(object.num) : 0 }; - }, - toJSON(message: NumSingle): unknown { const obj: any = {}; if (message.num !== 0) { @@ -137,6 +133,10 @@ export const NumSingle = { return obj; }, + fromJSON(object: any): NumSingle { + return { num: isSet(object.num) ? Number(object.num) : 0 }; + }, + create, I>>(base?: I): NumSingle { return NumSingle.fromPartial(base ?? {}); }, @@ -195,10 +195,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { num: Array.isArray(object?.num) ? object.num.map((e: any) => Number(e)) : [] }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.num?.length) { @@ -207,6 +203,10 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { num: Array.isArray(object?.num) ? object.num.map((e: any) => Number(e)) : [] }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/map-bigint-optional/test.ts b/integration/map-bigint-optional/test.ts index e2edeac10..7865885a6 100644 --- a/integration/map-bigint-optional/test.ts +++ b/integration/map-bigint-optional/test.ts @@ -83,17 +83,6 @@ export const MapBigInt = { return message; }, - fromJSON(object: any): MapBigInt { - return { - map: isObject(object.map) - ? Object.entries(object.map).reduce>((acc, [key, value]) => { - acc.set(BigInt(key), BigInt(value as string | number | bigint | boolean)); - return acc; - }, new Map()) - : undefined, - }; - }, - toJSON(message: MapBigInt): unknown { const obj: any = {}; if (message.map?.size) { @@ -105,6 +94,17 @@ export const MapBigInt = { return obj; }, + fromJSON(object: any): MapBigInt { + return { + map: isObject(object.map) + ? Object.entries(object.map).reduce>((acc, [key, value]) => { + acc.set(BigInt(key), BigInt(value as string | number | bigint | boolean)); + return acc; + }, new Map()) + : undefined, + }; + }, + create, I>>(base?: I): MapBigInt { return MapBigInt.fromPartial(base ?? {}); }, @@ -196,13 +196,6 @@ export const MapBigInt_MapEntry = { return message; }, - fromJSON(object: any): MapBigInt_MapEntry { - return { - key: isSet(object.key) ? BigInt(object.key) : BigInt("0"), - value: isSet(object.value) ? BigInt(object.value) : BigInt("0"), - }; - }, - toJSON(message: MapBigInt_MapEntry): unknown { const obj: any = {}; if (message.key !== BigInt("0")) { @@ -214,6 +207,13 @@ export const MapBigInt_MapEntry = { return obj; }, + fromJSON(object: any): MapBigInt_MapEntry { + return { + key: isSet(object.key) ? BigInt(object.key) : BigInt("0"), + value: isSet(object.value) ? BigInt(object.value) : BigInt("0"), + }; + }, + create, I>>(base?: I): MapBigInt_MapEntry { return MapBigInt_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/map-long-optional/test.ts b/integration/map-long-optional/test.ts index ac947f4af..0dd4556d3 100644 --- a/integration/map-long-optional/test.ts +++ b/integration/map-long-optional/test.ts @@ -83,17 +83,6 @@ export const MapBigInt = { return message; }, - fromJSON(object: any): MapBigInt { - return { - map: isObject(object.map) - ? Object.entries(object.map).reduce>((acc, [key, value]) => { - acc.set(Long.fromValue(key), Long.fromValue(value as Long | string)); - return acc; - }, new Map()) - : undefined, - }; - }, - toJSON(message: MapBigInt): unknown { const obj: any = {}; if (message.map?.size) { @@ -105,6 +94,17 @@ export const MapBigInt = { return obj; }, + fromJSON(object: any): MapBigInt { + return { + map: isObject(object.map) + ? Object.entries(object.map).reduce>((acc, [key, value]) => { + acc.set(Long.fromValue(key), Long.fromValue(value as Long | string)); + return acc; + }, new Map()) + : undefined, + }; + }, + create, I>>(base?: I): MapBigInt { return MapBigInt.fromPartial(base ?? {}); }, @@ -196,13 +196,6 @@ export const MapBigInt_MapEntry = { return message; }, - fromJSON(object: any): MapBigInt_MapEntry { - return { - key: isSet(object.key) ? Long.fromValue(object.key) : Long.UZERO, - value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, - }; - }, - toJSON(message: MapBigInt_MapEntry): unknown { const obj: any = {}; if (!message.key.isZero()) { @@ -214,6 +207,13 @@ export const MapBigInt_MapEntry = { return obj; }, + fromJSON(object: any): MapBigInt_MapEntry { + return { + key: isSet(object.key) ? Long.fromValue(object.key) : Long.UZERO, + value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, + }; + }, + create, I>>(base?: I): MapBigInt_MapEntry { return MapBigInt_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/map-longstring-optional/test.ts b/integration/map-longstring-optional/test.ts index e5fccb66c..6acce601d 100644 --- a/integration/map-longstring-optional/test.ts +++ b/integration/map-longstring-optional/test.ts @@ -83,17 +83,6 @@ export const MapBigInt = { return message; }, - fromJSON(object: any): MapBigInt { - return { - map: isObject(object.map) - ? Object.entries(object.map).reduce>((acc, [key, value]) => { - acc.set(key, String(value)); - return acc; - }, new Map()) - : undefined, - }; - }, - toJSON(message: MapBigInt): unknown { const obj: any = {}; if (message.map?.size) { @@ -105,6 +94,17 @@ export const MapBigInt = { return obj; }, + fromJSON(object: any): MapBigInt { + return { + map: isObject(object.map) + ? Object.entries(object.map).reduce>((acc, [key, value]) => { + acc.set(key, String(value)); + return acc; + }, new Map()) + : undefined, + }; + }, + create, I>>(base?: I): MapBigInt { return MapBigInt.fromPartial(base ?? {}); }, @@ -196,13 +196,6 @@ export const MapBigInt_MapEntry = { return message; }, - fromJSON(object: any): MapBigInt_MapEntry { - return { - key: isSet(object.key) ? String(object.key) : "0", - value: isSet(object.value) ? String(object.value) : "0", - }; - }, - toJSON(message: MapBigInt_MapEntry): unknown { const obj: any = {}; if (message.key !== "0") { @@ -214,6 +207,13 @@ export const MapBigInt_MapEntry = { return obj; }, + fromJSON(object: any): MapBigInt_MapEntry { + return { + key: isSet(object.key) ? String(object.key) : "0", + value: isSet(object.value) ? String(object.value) : "0", + }; + }, + create, I>>(base?: I): MapBigInt_MapEntry { return MapBigInt_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/empty.ts b/integration/nice-grpc/google/protobuf/empty.ts index 89e044465..5aadfe4a4 100644 --- a/integration/nice-grpc/google/protobuf/empty.ts +++ b/integration/nice-grpc/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create(base?: DeepPartial): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/struct.ts b/integration/nice-grpc/google/protobuf/struct.ts index 1aa09a906..e9c35b23c 100644 --- a/integration/nice-grpc/google/protobuf/struct.ts +++ b/integration/nice-grpc/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -165,6 +154,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create(base?: DeepPartial): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,10 +249,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,6 +260,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create(base?: DeepPartial): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,17 +368,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -402,6 +391,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create(base?: DeepPartial): Value { return Value.fromPartial(base ?? {}); }, @@ -490,10 +490,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -502,6 +498,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create(base?: DeepPartial): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/timestamp.ts b/integration/nice-grpc/google/protobuf/timestamp.ts index a4b4415ac..669166a20 100644 --- a/integration/nice-grpc/google/protobuf/timestamp.ts +++ b/integration/nice-grpc/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create(base?: DeepPartial): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/wrappers.ts b/integration/nice-grpc/google/protobuf/wrappers.ts index aabe92a94..79a4e8b32 100644 --- a/integration/nice-grpc/google/protobuf/wrappers.ts +++ b/integration/nice-grpc/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create(base?: DeepPartial): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create(base?: DeepPartial): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create(base?: DeepPartial): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create(base?: DeepPartial): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create(base?: DeepPartial): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create(base?: DeepPartial): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create(base?: DeepPartial): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create(base?: DeepPartial): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create(base?: DeepPartial): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/simple.ts b/integration/nice-grpc/simple.ts index 109f33346..d49931be4 100644 --- a/integration/nice-grpc/simple.ts +++ b/integration/nice-grpc/simple.ts @@ -57,10 +57,6 @@ export const TestMessage = { return message; }, - fromJSON(object: any): TestMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -69,6 +65,10 @@ export const TestMessage = { return obj; }, + fromJSON(object: any): TestMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create(base?: DeepPartial): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/no-proto-package/no-proto-package.ts b/integration/no-proto-package/no-proto-package.ts index 6eeed4715..730a65a2c 100644 --- a/integration/no-proto-package/no-proto-package.ts +++ b/integration/no-proto-package/no-proto-package.ts @@ -47,10 +47,6 @@ export const User = { return message; }, - fromJSON(object: any): User { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: User): unknown { const obj: any = {}; if (message.name !== "") { @@ -59,6 +55,10 @@ export const User = { return obj; }, + fromJSON(object: any): User { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): User { return User.fromPartial(base ?? {}); }, @@ -95,15 +95,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/omit-optionals/simple.ts b/integration/omit-optionals/simple.ts index 738aa496f..01bbdc1d8 100644 --- a/integration/omit-optionals/simple.ts +++ b/integration/omit-optionals/simple.ts @@ -53,13 +53,6 @@ export const TestMessage = { return message; }, - fromJSON(object: any): TestMessage { - return { - field1: isSet(object.field1) ? Boolean(object.field1) : false, - field2: isSet(object.field2) ? Boolean(object.field2) : undefined, - }; - }, - toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.field1 === true) { @@ -71,6 +64,13 @@ export const TestMessage = { return obj; }, + fromJSON(object: any): TestMessage { + return { + field1: isSet(object.field1) ? Boolean(object.field1) : false, + field2: isSet(object.field2) ? Boolean(object.field2) : undefined, + }; + }, + create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/oneof-properties/oneof.ts b/integration/oneof-properties/oneof.ts index 4e844786c..d7d55beb2 100644 --- a/integration/oneof-properties/oneof.ts +++ b/integration/oneof-properties/oneof.ts @@ -223,22 +223,6 @@ export const PleaseChoose = { return message; }, - fromJSON(object: any): PleaseChoose { - return { - name: isSet(object.name) ? String(object.name) : "", - aNumber: isSet(object.aNumber) ? Number(object.aNumber) : undefined, - aString: isSet(object.aString) ? String(object.aString) : undefined, - aMessage: isSet(object.aMessage) ? PleaseChoose_Submessage.fromJSON(object.aMessage) : undefined, - aBool: isSet(object.aBool) ? Boolean(object.aBool) : undefined, - bunchaBytes: isSet(object.bunchaBytes) ? bytesFromBase64(object.bunchaBytes) : undefined, - anEnum: isSet(object.anEnum) ? pleaseChoose_StateEnumFromJSON(object.anEnum) : undefined, - age: isSet(object.age) ? Number(object.age) : 0, - either: isSet(object.either) ? String(object.either) : undefined, - or: isSet(object.or) ? String(object.or) : undefined, - thirdOption: isSet(object.thirdOption) ? String(object.thirdOption) : undefined, - }; - }, - toJSON(message: PleaseChoose): unknown { const obj: any = {}; if (message.name !== "") { @@ -277,6 +261,22 @@ export const PleaseChoose = { return obj; }, + fromJSON(object: any): PleaseChoose { + return { + name: isSet(object.name) ? String(object.name) : "", + aNumber: isSet(object.aNumber) ? Number(object.aNumber) : undefined, + aString: isSet(object.aString) ? String(object.aString) : undefined, + aMessage: isSet(object.aMessage) ? PleaseChoose_Submessage.fromJSON(object.aMessage) : undefined, + aBool: isSet(object.aBool) ? Boolean(object.aBool) : undefined, + bunchaBytes: isSet(object.bunchaBytes) ? bytesFromBase64(object.bunchaBytes) : undefined, + anEnum: isSet(object.anEnum) ? pleaseChoose_StateEnumFromJSON(object.anEnum) : undefined, + age: isSet(object.age) ? Number(object.age) : 0, + either: isSet(object.either) ? String(object.either) : undefined, + or: isSet(object.or) ? String(object.or) : undefined, + thirdOption: isSet(object.thirdOption) ? String(object.thirdOption) : undefined, + }; + }, + create, I>>(base?: I): PleaseChoose { return PleaseChoose.fromPartial(base ?? {}); }, @@ -335,10 +335,6 @@ export const PleaseChoose_Submessage = { return message; }, - fromJSON(object: any): PleaseChoose_Submessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: PleaseChoose_Submessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -347,6 +343,10 @@ export const PleaseChoose_Submessage = { return obj; }, + fromJSON(object: any): PleaseChoose_Submessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): PleaseChoose_Submessage { return PleaseChoose_Submessage.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions-snake/google/protobuf/struct.ts b/integration/oneof-unions-snake/google/protobuf/struct.ts index f21e1fa8b..fc6e51fc5 100644 --- a/integration/oneof-unions-snake/google/protobuf/struct.ts +++ b/integration/oneof-unions-snake/google/protobuf/struct.ts @@ -126,17 +126,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -151,6 +140,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -235,10 +235,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -250,6 +246,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -352,24 +352,6 @@ export const Value = { return message; }, - fromJSON(object: any): Value { - return { - kind: isSet(object.null_value) - ? { $case: "null_value", null_value: nullValueFromJSON(object.null_value) } - : isSet(object.number_value) - ? { $case: "number_value", number_value: Number(object.number_value) } - : isSet(object.string_value) - ? { $case: "string_value", string_value: String(object.string_value) } - : isSet(object.bool_value) - ? { $case: "bool_value", bool_value: Boolean(object.bool_value) } - : isSet(object.struct_value) - ? { $case: "struct_value", struct_value: object.struct_value } - : isSet(object.list_value) - ? { $case: "list_value", list_value: [...object.list_value] } - : undefined, - }; - }, - toJSON(message: Value): unknown { const obj: any = {}; if (message.kind?.$case === "null_value") { @@ -393,6 +375,24 @@ export const Value = { return obj; }, + fromJSON(object: any): Value { + return { + kind: isSet(object.null_value) + ? { $case: "null_value", null_value: nullValueFromJSON(object.null_value) } + : isSet(object.number_value) + ? { $case: "number_value", number_value: Number(object.number_value) } + : isSet(object.string_value) + ? { $case: "string_value", string_value: String(object.string_value) } + : isSet(object.bool_value) + ? { $case: "bool_value", bool_value: Boolean(object.bool_value) } + : isSet(object.struct_value) + ? { $case: "struct_value", struct_value: object.struct_value } + : isSet(object.list_value) + ? { $case: "list_value", list_value: [...object.list_value] } + : undefined, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -512,10 +512,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -524,6 +520,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions-snake/simple.ts b/integration/oneof-unions-snake/simple.ts index 68d930e95..a377e002b 100644 --- a/integration/oneof-unions-snake/simple.ts +++ b/integration/oneof-unions-snake/simple.ts @@ -48,10 +48,6 @@ export const SimpleStruct = { return message; }, - fromJSON(object: any): SimpleStruct { - return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; - }, - toJSON(message: SimpleStruct): unknown { const obj: any = {}; if (message.simple_struct !== undefined) { @@ -60,6 +56,10 @@ export const SimpleStruct = { return obj; }, + fromJSON(object: any): SimpleStruct { + return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; + }, + create, I>>(base?: I): SimpleStruct { return SimpleStruct.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions/google/protobuf/struct.ts b/integration/oneof-unions/google/protobuf/struct.ts index 5c0628529..f54c228a8 100644 --- a/integration/oneof-unions/google/protobuf/struct.ts +++ b/integration/oneof-unions/google/protobuf/struct.ts @@ -126,17 +126,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -151,6 +140,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -235,10 +235,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -250,6 +246,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -349,24 +349,6 @@ export const Value = { return message; }, - fromJSON(object: any): Value { - return { - kind: isSet(object.nullValue) - ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } - : isSet(object.numberValue) - ? { $case: "numberValue", numberValue: Number(object.numberValue) } - : isSet(object.stringValue) - ? { $case: "stringValue", stringValue: String(object.stringValue) } - : isSet(object.boolValue) - ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } - : isSet(object.structValue) - ? { $case: "structValue", structValue: object.structValue } - : isSet(object.listValue) - ? { $case: "listValue", listValue: [...object.listValue] } - : undefined, - }; - }, - toJSON(message: Value): unknown { const obj: any = {}; if (message.kind?.$case === "nullValue") { @@ -390,6 +372,24 @@ export const Value = { return obj; }, + fromJSON(object: any): Value { + return { + kind: isSet(object.nullValue) + ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } + : isSet(object.numberValue) + ? { $case: "numberValue", numberValue: Number(object.numberValue) } + : isSet(object.stringValue) + ? { $case: "stringValue", stringValue: String(object.stringValue) } + : isSet(object.boolValue) + ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } + : isSet(object.structValue) + ? { $case: "structValue", structValue: object.structValue } + : isSet(object.listValue) + ? { $case: "listValue", listValue: [...object.listValue] } + : undefined, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -503,10 +503,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -515,6 +511,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions/oneof.ts b/integration/oneof-unions/oneof.ts index e377b010a..fe3ee5aed 100644 --- a/integration/oneof-unions/oneof.ts +++ b/integration/oneof-unions/oneof.ts @@ -231,35 +231,6 @@ export const PleaseChoose = { return message; }, - fromJSON(object: any): PleaseChoose { - return { - name: isSet(object.name) ? String(object.name) : "", - choice: isSet(object.aNumber) - ? { $case: "aNumber", aNumber: Number(object.aNumber) } - : isSet(object.aString) - ? { $case: "aString", aString: String(object.aString) } - : isSet(object.aMessage) - ? { $case: "aMessage", aMessage: PleaseChoose_Submessage.fromJSON(object.aMessage) } - : isSet(object.aBool) - ? { $case: "aBool", aBool: Boolean(object.aBool) } - : isSet(object.bunchaBytes) - ? { $case: "bunchaBytes", bunchaBytes: bytesFromBase64(object.bunchaBytes) } - : isSet(object.anEnum) - ? { $case: "anEnum", anEnum: pleaseChoose_StateEnumFromJSON(object.anEnum) } - : undefined, - age: isSet(object.age) ? Number(object.age) : 0, - eitherOr: isSet(object.either) - ? { $case: "either", either: String(object.either) } - : isSet(object.or) - ? { $case: "or", or: String(object.or) } - : isSet(object.thirdOption) - ? { $case: "thirdOption", thirdOption: String(object.thirdOption) } - : undefined, - signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(0), - value: isSet(object?.value) ? object.value : undefined, - }; - }, - toJSON(message: PleaseChoose): unknown { const obj: any = {}; if (message.name !== "") { @@ -304,6 +275,35 @@ export const PleaseChoose = { return obj; }, + fromJSON(object: any): PleaseChoose { + return { + name: isSet(object.name) ? String(object.name) : "", + choice: isSet(object.aNumber) + ? { $case: "aNumber", aNumber: Number(object.aNumber) } + : isSet(object.aString) + ? { $case: "aString", aString: String(object.aString) } + : isSet(object.aMessage) + ? { $case: "aMessage", aMessage: PleaseChoose_Submessage.fromJSON(object.aMessage) } + : isSet(object.aBool) + ? { $case: "aBool", aBool: Boolean(object.aBool) } + : isSet(object.bunchaBytes) + ? { $case: "bunchaBytes", bunchaBytes: bytesFromBase64(object.bunchaBytes) } + : isSet(object.anEnum) + ? { $case: "anEnum", anEnum: pleaseChoose_StateEnumFromJSON(object.anEnum) } + : undefined, + age: isSet(object.age) ? Number(object.age) : 0, + eitherOr: isSet(object.either) + ? { $case: "either", either: String(object.either) } + : isSet(object.or) + ? { $case: "or", or: String(object.or) } + : isSet(object.thirdOption) + ? { $case: "thirdOption", thirdOption: String(object.thirdOption) } + : undefined, + signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(0), + value: isSet(object?.value) ? object.value : undefined, + }; + }, + create, I>>(base?: I): PleaseChoose { return PleaseChoose.fromPartial(base ?? {}); }, @@ -392,10 +392,6 @@ export const PleaseChoose_Submessage = { return message; }, - fromJSON(object: any): PleaseChoose_Submessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: PleaseChoose_Submessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -404,6 +400,10 @@ export const PleaseChoose_Submessage = { return obj; }, + fromJSON(object: any): PleaseChoose_Submessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): PleaseChoose_Submessage { return PleaseChoose_Submessage.fromPartial(base ?? {}); }, @@ -460,13 +460,6 @@ export const SimpleButOptional = { return message; }, - fromJSON(object: any): SimpleButOptional { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - }; - }, - toJSON(message: SimpleButOptional): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -478,6 +471,13 @@ export const SimpleButOptional = { return obj; }, + fromJSON(object: any): SimpleButOptional { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + }; + }, + create, I>>(base?: I): SimpleButOptional { return SimpleButOptional.fromPartial(base ?? {}); }, diff --git a/integration/output-decode-only-json/decode-json.ts b/integration/output-decode-only-json/decode-json.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/integration/output-decode-only-json/decode.bin b/integration/output-decode-only-json/decode.bin new file mode 100644 index 0000000000000000000000000000000000000000..eeabdd8b416b820c5d52127609afe4f0f6a73842 GIT binary patch literal 4787 zcmbtY&2rnw5eENcYAmlMXe;H?!JcT7io8WrUU_Rb>pg6NBt*fXNE!g8aC2CJ6&>vP>FNIZ>z?ib+15x5gOR9Sg+Uzb zmCJ?g-6y$y<^8|EU{5DOF!98p+#1Zrhc}^fbtS?m5mp~3`^gOZ`(Ln!jbJwL#F^vG zg!(xvUDM!6j^_??W-{5|XYAMuocI=*{ECd>$KQN?i%cPtfwA6QLd8r7#vt?R=oUq# zOeR%ytI(rN=(lXM76jfcddisy^jLA|`jcCPHZvgrs?B2&-6FG<%GCarW4ps(TK$0D z+N1N7|1QOejQP>amw!wTaKj%~IoCXo%e{z)A`;=X z7*!d+jN_~5_2J=2TnjIdX_vYSZW2EM;suZsh(pG>DMoID2n=Si8~EJuM|>6uz~NCa z3x`6k3|!v{=Mq;`;Wuu4$%9b-AIyMr8jRerJ9J1xg*&0(usn6+Sd2LC!L>WWAii{B z{6pS(UT}ku^I_nRTsjodA?OkDYe1sEFFybl@nD=GqN~TJvnYn=u>+)})foiW0vc1s z825wN9f}Gz-H3bekut`?gdCY7Lf7%4CDk%O*kpV)whO1)0s+KHQtUfZLBu4Li;ajo6JYTGuATF>s77UTPxg`@j&M{D=F{^zc#TNdw_+&JyF z3}}OTQ)}CXZdJI^uD5y(qus1vOzw%ujW*egZXG&1e~R zUm83%>^2!Y?wE{gysMeEQSY@hlXrV&w`1v?JZl(My`>qadZP;au*vl^y=`;rL~FIy z9c8?8-quY*zv?Eh=|HK~S~{76={}U2dfg_6mZLhz1He{=ajUD>4UE8t4jMGGUrCi( z`r96)u*nZgPnR9L;5WgB+S)_JqjX-Kjy-8?huy7fJ8b%_3B z-m`Q7X=t`4O+yFh!af|R^(;dYXS8kIG<#j!=(L|B%I9DPu4_2kkPLU)9qR~mJ7G&BLM$Xl-Ch-gLF5Voz4Vi}^=8Xx>g~Etcsiu!+_3cL2$%tE zP0~p;pKCCRM1f(-NZ>+%xZk){g{S-tv6%6XL?{k_Pu zPDXW@ZVDFRDI^nFka1JTGmpumVmc6`5f$Ktk|--Q z7iqh|^^F5+aGF2Aka}bzkd{4XC{Pe?P(yHqQA0#h1*q6S>&%TVQ5@nMfh$aP#2G}w zM|nhExC5doNUApV(Z4`FdVH=a|`8i`m8V*mnE5}pqdMlQP5%<;JJ1Qpx} zRWsr86CpULjaO6%9Ul0CnwAUYRLGaAsgMd;Sr^ihg>)%7H+0aAy-+x#`G-)!OPS^J zYT--e3608Xp`v`xHd(&>`(&6bzEGaY#b;`PhRI@8IgyJG)dCHZ#Y3ec7jtTXhRNbf zr79Ppo`%WdSIWLzWNLwi$>NcMryi{TPA$-I!tzB$Eq<%K&h7mrOIw6Yrl?H8i;;Zt zUZfG`Z!FwgL{G*d?Q)cB7b{QW3y#(y1^pQ^7)=^~g`xt?-FFzHQ=;^VDcXL919srst`aGdG7U-pkHS`bwdLu=T84epMddz^{0D4NE zf?Dh-=AFqi`$YIFpE`HoF91R(O`Zbbf4fMY#K@Whkbnbk)8xSnr{AW@gBcunnhO_R2t!xH2+{fGU8az;offC*shvX*S@5ssr_R^KLYy1EZf;0{f z2>!c891^)T2Ot3l-lcKC45#0vali}?yi2b^SuNh+TllUTI-rmG`|&To{qKNZ27sIN z8k7nCd~pq=i8b^P0Qz})4KTyud3p^n1N!;)&R|16fL^`-CCAo(?78Rnoqf(Wbf3OZ z)!(oUyelx0Kjmzi>FkY1KM^R(Mvj^%ej!j4m6~S(xbw;Z(n&VYA_-*utyunyJ>I<^KrHZM@s5$=E(m5W5on! literal 0 HcmV?d00001 diff --git a/integration/output-decode-only-json/decode.ts b/integration/output-decode-only-json/decode.ts new file mode 100644 index 000000000..50ab78201 --- /dev/null +++ b/integration/output-decode-only-json/decode.ts @@ -0,0 +1,17 @@ +/* eslint-disable */ + +export const protobufPackage = ""; + +export interface Encode { + encode: string; +} + +export const Encode = { + fromJSON(object: any): Encode { + return { encode: isSet(object.encode) ? String(object.encode) : "" }; + }, +}; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/integration/output-decode-only-json/google/protobuf/wrappers.ts b/integration/output-decode-only-json/google/protobuf/wrappers.ts index 0674c218b..36b083d6a 100644 --- a/integration/output-decode-only-json/google/protobuf/wrappers.ts +++ b/integration/output-decode-only-json/google/protobuf/wrappers.ts @@ -1,6 +1,4 @@ /* eslint-disable */ -import * as _m0 from "protobufjs/minimal"; -import Long = require("long"); export const protobufPackage = "google.protobuf"; @@ -94,264 +92,57 @@ export interface BytesValue { value: Uint8Array; } -function createBaseDoubleValue(): DoubleValue { - return { value: 0 }; -} - export const DoubleValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): DoubleValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 9) { - break; - } - - message.value = reader.double(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; }, }; -function createBaseFloatValue(): FloatValue { - return { value: 0 }; -} - export const FloatValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 13) { - break; - } - - message.value = reader.float(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; }, }; -function createBaseInt64Value(): Int64Value { - return { value: 0 }; -} - export const Int64Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = longToNumber(reader.int64() as Long); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; }, }; -function createBaseUInt64Value(): UInt64Value { - return { value: 0 }; -} - export const UInt64Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = longToNumber(reader.uint64() as Long); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; }, }; -function createBaseInt32Value(): Int32Value { - return { value: 0 }; -} - export const Int32Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = reader.int32(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; }, }; -function createBaseUInt32Value(): UInt32Value { - return { value: 0 }; -} - export const UInt32Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = reader.uint32(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; }, }; -function createBaseBoolValue(): BoolValue { - return { value: false }; -} - export const BoolValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = reader.bool(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; }, }; -function createBaseStringValue(): StringValue { - return { value: "" }; -} - export const StringValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): StringValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 10) { - break; - } - - message.value = reader.string(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; }, }; -function createBaseBytesValue(): BytesValue { - return { value: new Uint8Array(0) }; -} - export const BytesValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 10) { - break; - } - - message.value = reader.bytes(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); - } - return message; + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; }, }; @@ -374,14 +165,19 @@ const tsProtoGlobalThis: any = (() => { throw "Unable to locate global object"; })(); -function longToNumber(long: Long): number { - if (long.gt(Number.MAX_SAFE_INTEGER)) { - throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); +function bytesFromBase64(b64: string): Uint8Array { + if (tsProtoGlobalThis.Buffer) { + return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64")); + } else { + const bin = tsProtoGlobalThis.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; } - return long.toNumber(); } -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/output-decode-only-json/parameters.txt b/integration/output-decode-only-json/parameters.txt index dc1ca49ae..998a9a4ec 100644 --- a/integration/output-decode-only-json/parameters.txt +++ b/integration/output-decode-only-json/parameters.txt @@ -1 +1 @@ -outputJsonMethods=decode-only,outputPartialMethods=false,outputJsonMethods=false,nestJs=false +outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=decode-only,nestJs=false diff --git a/integration/output-encode-only-json/decode-json.ts b/integration/output-encode-only-json/decode-json.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/integration/output-encode-only-json/encode.bin b/integration/output-encode-only-json/encode.bin new file mode 100644 index 0000000000000000000000000000000000000000..b67452113f2b89e5ae7bc4ef70c5def32b5b53e2 GIT binary patch literal 4787 zcmbtY&2rnw5eENcYAmlMXe;H?!JcT7io8WrUU_Rb>pg6NBt*fXNE!g8aC2CJ6&>vP>FNIZ>z?ib*_QB!!AMlE!XOUz z%H_iL?vvcU^8Vjnu&0wCn0Vq)ZVhJR!<*2#x)NcO2&<2i{bYvy{V&+VMlc(A;>_`8 zLj9bTu4(Wj$8!fcGnwq~Gj{9+PJD|@enrOc<8QvcMW&F+z*z4tp<*TkV~}}ubc>== zCX*_^UUdaO8f{mCsto0$**)#kB?ZjsqaWom!RvE5-Xt$sjn z?a_J4f0ts_&HeaQDlrK>$DdS#aI%b5Jiijr;m>|><1gZNHTZ8X_m6y`*{%IE|FkKi zTb0TXz3RE}yg!k=O-JAS@{Db$#RKJij{Rqw<+jwqfubJ$Ym3VR!@%RU*?5d>;4gTh z>JJegIkCfCKNjKe5|9KR2jSF-8LtOd^U$4K#{B5z%RiI{Nw0gWkR zjQc_C4n+lo z2DCxFskLoGw<_Fd*IT`Y(QZ~aH1KxEX1ryb8aCwYPDPsi^*P=-=BK(@KY<#pX0!~u zFAW|WcAJbHcTC1L-qlRosP|f$$-6zX+p%;`o;3`s-qMUyy-|gI*yQ?|-nO}QqP1G< zjxydkZ|f$ZUv-n$bfDB~EuBokbRSAhy>633%TXQV0br}bxYgC`21ejR2MwCpucS&X z{cR6Y*yIiERBP%MKe&$-1g73I^;1F(Dy&}3vJJau>%7_NG$h%UZk`!+-TI!lIz<05 z?^!y4G&Eb2rlA9LVIL0EdX^!HGupOpn!T=VblT4m<#R9t*EO7NNQOIY@|JQ%@0fj3 zOFYO3RQUOcj&%gOov@`5Ar_LOZm){LAaVtPUi!(~db4FT^>$q+JRMSVZdm$r1k3=o zCg~)a&ovlDqQEd^Byb@_G+s$vkc@b8>EwC=T(Bz!j!C;tV3Z zmt>i7mL^dP&@xdMT;YwRa+DcVi?K8FVt!3;AbIPhBiSR0UpnyE56~(cAGY9=Y*$oB zP%1-lB~T7irRXXV0hn_j{+VhIVR1b-o>S2piC7F{00L7Io(~d6F1pps@wo5=72F6_ zGvV?RAvmawS5ycc9{7TqmJ8)n$d{_AkP2B@7t)f2bSXJEbkL2xP&lLchfu*wndS0o z;Y;NSjmm1FqI}ObS-$-HWSA_zP@c)fXKI0l$zoMGk&6%20u7VJL!}}Yb83Nx$>K|; zDi@)ihRNbr%D!A=YJrBy;*o-<9<2XPEzoen@rHM845CD2D|3Ko!42QMyqihEB+V+k_pI3`b<;|Vw z@!I_6>-*6!KNXhf>9L4+b3%R|0GcWKJfSxh=%tA@^bi1gBSnuH4jU2yGWkI$eII?fCF#SK}N>3?;!h8_Yy-%shs42SzE{g?rLKc&B< z7JpI(AEp0O;1m5H$6o@3pHliugx^`C{{sgg0SBCve#~&%N$JN74mhAcK>pwxY@+-% zw>P}~?hf!#dO!P%PuC^+7jZZf7qVGhjPc|aq=kym2B1vJJM1ZL@di2K=6CjXP?U`vHBbCPpeQOe&jN7gl>?-cY@S6D$ogBc{26>> 3) { - case 1: - if (tag !== 9) { - break; - } - - message.value = reader.double(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: DoubleValue): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = message.value; } - return message; + return obj; }, }; -function createBaseFloatValue(): FloatValue { - return { value: 0 }; -} - export const FloatValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 13) { - break; - } - - message.value = reader.float(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: FloatValue): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = message.value; } - return message; + return obj; }, }; -function createBaseInt64Value(): Int64Value { - return { value: 0 }; -} - export const Int64Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = longToNumber(reader.int64() as Long); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: Int64Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); } - return message; + return obj; }, }; -function createBaseUInt64Value(): UInt64Value { - return { value: 0 }; -} - export const UInt64Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = longToNumber(reader.uint64() as Long); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: UInt64Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); } - return message; + return obj; }, }; -function createBaseInt32Value(): Int32Value { - return { value: 0 }; -} - export const Int32Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = reader.int32(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: Int32Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); } - return message; + return obj; }, }; -function createBaseUInt32Value(): UInt32Value { - return { value: 0 }; -} - export const UInt32Value = { - decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = reader.uint32(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: UInt32Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); } - return message; + return obj; }, }; -function createBaseBoolValue(): BoolValue { - return { value: false }; -} - export const BoolValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 8) { - break; - } - - message.value = reader.bool(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: BoolValue): unknown { + const obj: any = {}; + if (message.value === true) { + obj.value = message.value; } - return message; + return obj; }, }; -function createBaseStringValue(): StringValue { - return { value: "" }; -} - export const StringValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): StringValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 10) { - break; - } - - message.value = reader.string(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: StringValue): unknown { + const obj: any = {}; + if (message.value !== "") { + obj.value = message.value; } - return message; + return obj; }, }; -function createBaseBytesValue(): BytesValue { - return { value: new Uint8Array(0) }; -} - export const BytesValue = { - decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue { - const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(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: - if (tag !== 10) { - break; - } - - message.value = reader.bytes(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skipType(tag & 7); + toJSON(message: BytesValue): unknown { + const obj: any = {}; + if (message.value.length !== 0) { + obj.value = base64FromBytes(message.value); } - return message; + return obj; }, }; @@ -374,14 +201,14 @@ const tsProtoGlobalThis: any = (() => { throw "Unable to locate global object"; })(); -function longToNumber(long: Long): number { - if (long.gt(Number.MAX_SAFE_INTEGER)) { - throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); +function base64FromBytes(arr: Uint8Array): string { + if (tsProtoGlobalThis.Buffer) { + return tsProtoGlobalThis.Buffer.from(arr).toString("base64"); + } else { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(String.fromCharCode(byte)); + }); + return tsProtoGlobalThis.btoa(bin.join("")); } - return long.toNumber(); -} - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any; - _m0.configure(); } diff --git a/integration/output-encode-only-json/parameters.txt b/integration/output-encode-only-json/parameters.txt index f125b932b..b99c4e51d 100644 --- a/integration/output-encode-only-json/parameters.txt +++ b/integration/output-encode-only-json/parameters.txt @@ -1 +1 @@ -outputJsonMethods=encode-only,outputPartialMethods=false,outputJsonMethods=false,nestJs=false +outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=encode-only,nestJs=false diff --git a/integration/output-index/a.ts b/integration/output-index/a.ts index 05b9a11b9..24cc1c106 100644 --- a/integration/output-index/a.ts +++ b/integration/output-index/a.ts @@ -40,10 +40,6 @@ export const A = { return message; }, - fromJSON(object: any): A { - return { a: isSet(object.a) ? String(object.a) : "" }; - }, - toJSON(message: A): unknown { const obj: any = {}; if (message.a !== "") { @@ -52,6 +48,10 @@ export const A = { return obj; }, + fromJSON(object: any): A { + return { a: isSet(object.a) ? String(object.a) : "" }; + }, + create, I>>(base?: I): A { return A.fromPartial(base ?? {}); }, diff --git a/integration/point/point.ts b/integration/point/point.ts index b98c2845d..54e52080b 100644 --- a/integration/point/point.ts +++ b/integration/point/point.ts @@ -58,10 +58,6 @@ export const Point = { return message; }, - fromJSON(object: any): Point { - return { lat: isSet(object.lat) ? Number(object.lat) : 0, lng: isSet(object.lng) ? Number(object.lng) : 0 }; - }, - toJSON(message: Point): unknown { const obj: any = {}; if (message.lat !== 0) { @@ -73,6 +69,10 @@ export const Point = { return obj; }, + fromJSON(object: any): Point { + return { lat: isSet(object.lat) ? Number(object.lat) : 0, lng: isSet(object.lng) ? Number(object.lng) : 0 }; + }, + create, I>>(base?: I): Point { return Point.fromPartial(base ?? {}); }, @@ -130,13 +130,6 @@ export const Area = { return message; }, - fromJSON(object: any): Area { - return { - nw: isSet(object.nw) ? Point.fromJSON(object.nw) : undefined, - se: isSet(object.se) ? Point.fromJSON(object.se) : undefined, - }; - }, - toJSON(message: Area): unknown { const obj: any = {}; if (message.nw !== undefined) { @@ -148,6 +141,13 @@ export const Area = { return obj; }, + fromJSON(object: any): Area { + return { + nw: isSet(object.nw) ? Point.fromJSON(object.nw) : undefined, + se: isSet(object.se) ? Point.fromJSON(object.se) : undefined, + }; + }, + create, I>>(base?: I): Area { return Area.fromPartial(base ?? {}); }, diff --git a/integration/reserved-words/reserved-words.ts b/integration/reserved-words/reserved-words.ts index c8e70e8fe..ef1097732 100644 --- a/integration/reserved-words/reserved-words.ts +++ b/integration/reserved-words/reserved-words.ts @@ -31,15 +31,15 @@ export const Record = { return message; }, - fromJSON(_: any): Record { - return {}; - }, - toJSON(_: Record): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Record { + return {}; + }, + create, I>>(base?: I): Record { return Record.fromPartial(base ?? {}); }, diff --git a/integration/return-observable/observable.ts b/integration/return-observable/observable.ts index 1d9048445..7ef1338fb 100644 --- a/integration/return-observable/observable.ts +++ b/integration/return-observable/observable.ts @@ -47,10 +47,6 @@ export const ProduceRequest = { return message; }, - fromJSON(object: any): ProduceRequest { - return { ingredients: isSet(object.ingredients) ? String(object.ingredients) : "" }; - }, - toJSON(message: ProduceRequest): unknown { const obj: any = {}; if (message.ingredients !== "") { @@ -59,6 +55,10 @@ export const ProduceRequest = { return obj; }, + fromJSON(object: any): ProduceRequest { + return { ingredients: isSet(object.ingredients) ? String(object.ingredients) : "" }; + }, + create, I>>(base?: I): ProduceRequest { return ProduceRequest.fromPartial(base ?? {}); }, @@ -105,10 +105,6 @@ export const ProduceReply = { return message; }, - fromJSON(object: any): ProduceReply { - return { result: isSet(object.result) ? String(object.result) : "" }; - }, - toJSON(message: ProduceReply): unknown { const obj: any = {}; if (message.result !== "") { @@ -117,6 +113,10 @@ export const ProduceReply = { return obj; }, + fromJSON(object: any): ProduceReply { + return { result: isSet(object.result) ? String(object.result) : "" }; + }, + create, I>>(base?: I): ProduceReply { return ProduceReply.fromPartial(base ?? {}); }, diff --git a/integration/simple-deprecated-fields/simple.ts b/integration/simple-deprecated-fields/simple.ts index f9a7fb45b..3fc013b1c 100644 --- a/integration/simple-deprecated-fields/simple.ts +++ b/integration/simple-deprecated-fields/simple.ts @@ -108,16 +108,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - testField: isSet(object.testField) ? String(object.testField) : "", - testNotDeprecated: isSet(object.testNotDeprecated) ? String(object.testNotDeprecated) : "", - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -138,6 +128,16 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + testField: isSet(object.testField) ? String(object.testField) : "", + testNotDeprecated: isSet(object.testNotDeprecated) ? String(object.testNotDeprecated) : "", + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -188,10 +188,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -200,6 +196,10 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/simple-esmodule-interop/simple.ts b/integration/simple-esmodule-interop/simple.ts index 797fea600..fd8c9c5d8 100644 --- a/integration/simple-esmodule-interop/simple.ts +++ b/integration/simple-esmodule-interop/simple.ts @@ -69,10 +69,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -84,6 +80,10 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -254,23 +254,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -312,6 +295,23 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-json-name/google/protobuf/timestamp.ts b/integration/simple-json-name/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/simple-json-name/google/protobuf/timestamp.ts +++ b/integration/simple-json-name/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-json-name/simple.ts b/integration/simple-json-name/simple.ts index 37f2a3705..d9a4bb9dd 100644 --- a/integration/simple-json-name/simple.ts +++ b/integration/simple-json-name/simple.ts @@ -129,19 +129,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.other_name) ? String(object.other_name) : "", - age: isSet(object.other_age) ? Number(object.other_age) : undefined, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - hyphen: isSet(object["hyphened-name"]) ? String(object["hyphened-name"]) : "", - spaces: isSet(object["name with spaces"]) ? String(object["name with spaces"]) : "", - dollarStart: isSet(object.$dollar) ? String(object.$dollar) : "", - dollarEnd: isSet(object.dollar$) ? String(object.dollar$) : "", - hyphenList: Array.isArray(object?.["hyphen-list"]) ? object["hyphen-list"].map((e: any) => String(e)) : [], - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -171,6 +158,19 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.other_name) ? String(object.other_name) : "", + age: isSet(object.other_age) ? Number(object.other_age) : undefined, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + hyphen: isSet(object["hyphened-name"]) ? String(object["hyphened-name"]) : "", + spaces: isSet(object["name with spaces"]) ? String(object["name with spaces"]) : "", + dollarStart: isSet(object.$dollar) ? String(object.$dollar) : "", + dollarEnd: isSet(object.dollar$) ? String(object.dollar$) : "", + hyphenList: Array.isArray(object?.["hyphen-list"]) ? object["hyphen-list"].map((e: any) => String(e)) : [], + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-bigint/google/protobuf/timestamp.ts b/integration/simple-long-bigint/google/protobuf/timestamp.ts index dbc000c51..bc7c711e2 100644 --- a/integration/simple-long-bigint/google/protobuf/timestamp.ts +++ b/integration/simple-long-bigint/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { return message; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt("0"), - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== BigInt("0")) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt("0"), + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-bigint/google/protobuf/wrappers.ts b/integration/simple-long-bigint/google/protobuf/wrappers.ts index 6f5ad2a6a..0f30b98a5 100644 --- a/integration/simple-long-bigint/google/protobuf/wrappers.ts +++ b/integration/simple-long-bigint/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== BigInt("0")) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== BigInt("0")) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-bigint/simple.ts b/integration/simple-long-bigint/simple.ts index d773deb76..5a4c53cdb 100644 --- a/integration/simple-long-bigint/simple.ts +++ b/integration/simple-long-bigint/simple.ts @@ -227,26 +227,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? BigInt(object.int64) : BigInt("0"), - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? BigInt(object.uint64) : BigInt("0"), - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? BigInt(object.sint64) : BigInt("0"), - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? BigInt(object.fixed64) : BigInt("0"), - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? BigInt(object.sfixed64) : BigInt("0"), - guint64: isSet(object.guint64) ? BigInt(object.guint64) : undefined, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - uint64s: Array.isArray(object?.uint64s) ? object.uint64s.map((e: any) => BigInt(e)) : [], - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -297,6 +277,26 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? BigInt(object.int64) : BigInt("0"), + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? BigInt(object.uint64) : BigInt("0"), + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? BigInt(object.sint64) : BigInt("0"), + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? BigInt(object.fixed64) : BigInt("0"), + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? BigInt(object.sfixed64) : BigInt("0"), + guint64: isSet(object.guint64) ? BigInt(object.guint64) : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + uint64s: Array.isArray(object?.uint64s) ? object.uint64s.map((e: any) => BigInt(e)) : [], + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-string/google/protobuf/timestamp.ts b/integration/simple-long-string/google/protobuf/timestamp.ts index 7785db1cd..9ff4662e1 100644 --- a/integration/simple-long-string/google/protobuf/timestamp.ts +++ b/integration/simple-long-string/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { return message; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? String(object.seconds) : "0", - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== "0") { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? String(object.seconds) : "0", + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-string/google/protobuf/wrappers.ts b/integration/simple-long-string/google/protobuf/wrappers.ts index aa0588050..2640223a8 100644 --- a/integration/simple-long-string/google/protobuf/wrappers.ts +++ b/integration/simple-long-string/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? String(object.value) : "0" }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== "0") { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? String(object.value) : "0" }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? String(object.value) : "0" }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== "0") { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? String(object.value) : "0" }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-string/simple.ts b/integration/simple-long-string/simple.ts index 1c9f48f3f..56ddb30ce 100644 --- a/integration/simple-long-string/simple.ts +++ b/integration/simple-long-string/simple.ts @@ -203,25 +203,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? String(object.int64) : "0", - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? String(object.uint64) : "0", - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? String(object.sint64) : "0", - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? String(object.fixed64) : "0", - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? String(object.sfixed64) : "0", - guint64: isSet(object.guint64) ? String(object.guint64) : undefined, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -269,6 +250,25 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? String(object.int64) : "0", + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? String(object.uint64) : "0", + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? String(object.sint64) : "0", + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? String(object.fixed64) : "0", + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? String(object.sfixed64) : "0", + guint64: isSet(object.guint64) ? String(object.guint64) : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-long/google/protobuf/wrappers.ts b/integration/simple-long/google/protobuf/wrappers.ts index f0fe7c61c..694569f15 100644 --- a/integration/simple-long/google/protobuf/wrappers.ts +++ b/integration/simple-long/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (!message.value.isZero()) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.UZERO }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (!message.value.isZero()) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.UZERO }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-long/simple.ts b/integration/simple-long/simple.ts index 73815f744..534185cda 100644 --- a/integration/simple-long/simple.ts +++ b/integration/simple-long/simple.ts @@ -138,17 +138,6 @@ export const SimpleWithWrappers = { return message; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - bananas: isSet(object.bananas) ? Long.fromValue(object.bananas) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -172,6 +161,17 @@ export const SimpleWithWrappers = { return obj; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + bananas: isSet(object.bananas) ? Long.fromValue(object.bananas) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -254,29 +254,6 @@ export const SimpleWithMap = { return message; }, - fromJSON(object: any): SimpleWithMap { - return { - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - longLookup: isObject(object.longLookup) - ? Object.entries(object.longLookup).reduce<{ [key: string]: Long }>((acc, [key, value]) => { - acc[key] = Long.fromValue(value as Long | string); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.nameLookup) { @@ -309,6 +286,29 @@ export const SimpleWithMap = { return obj; }, + fromJSON(object: any): SimpleWithMap { + return { + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + longLookup: isObject(object.longLookup) + ? Object.entries(object.longLookup).reduce<{ [key: string]: Long }>((acc, [key, value]) => { + acc[key] = Long.fromValue(value as Long | string); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -391,10 +391,6 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -406,6 +402,10 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -465,10 +465,6 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -480,6 +476,10 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -537,13 +537,6 @@ export const SimpleWithMap_LongLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_LongLookupEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, - }; - }, - toJSON(message: SimpleWithMap_LongLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -555,6 +548,13 @@ export const SimpleWithMap_LongLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_LongLookupEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, + }; + }, + create, I>>(base?: I): SimpleWithMap_LongLookupEntry { return SimpleWithMap_LongLookupEntry.fromPartial(base ?? {}); }, @@ -750,24 +750,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Long.fromValue(object.int64) : Long.ZERO, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Long.fromValue(object.uint64) : Long.UZERO, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Long.fromValue(object.sint64) : Long.ZERO, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Long.fromValue(object.fixed64) : Long.UZERO, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Long.fromValue(object.sfixed64) : Long.ZERO, - manyUint64: Array.isArray(object?.manyUint64) ? object.manyUint64.map((e: any) => Long.fromValue(e)) : [], - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -812,6 +794,24 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Long.fromValue(object.int64) : Long.ZERO, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Long.fromValue(object.uint64) : Long.UZERO, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Long.fromValue(object.sint64) : Long.ZERO, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Long.fromValue(object.fixed64) : Long.UZERO, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Long.fromValue(object.sfixed64) : Long.ZERO, + manyUint64: Array.isArray(object?.manyUint64) ? object.manyUint64.map((e: any) => Long.fromValue(e)) : [], + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/google/protobuf/timestamp.ts b/integration/simple-optionals/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/simple-optionals/google/protobuf/timestamp.ts +++ b/integration/simple-optionals/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/google/protobuf/wrappers.ts b/integration/simple-optionals/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/simple-optionals/google/protobuf/wrappers.ts +++ b/integration/simple-optionals/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/import_dir/thing.ts b/integration/simple-optionals/import_dir/thing.ts index dacd1b268..af3bd826e 100644 --- a/integration/simple-optionals/import_dir/thing.ts +++ b/integration/simple-optionals/import_dir/thing.ts @@ -43,10 +43,6 @@ export const ImportedThing = { return message; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -55,6 +51,10 @@ export const ImportedThing = { return obj; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/simple.ts b/integration/simple-optionals/simple.ts index dbc6a1ee4..f281a7dff 100644 --- a/integration/simple-optionals/simple.ts +++ b/integration/simple-optionals/simple.ts @@ -398,23 +398,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -450,6 +433,23 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -517,13 +517,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -535,6 +528,13 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -602,14 +602,6 @@ export const Nested = { return message; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -624,6 +616,14 @@ export const Nested = { return obj; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -684,13 +684,6 @@ export const Nested_InnerMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -702,6 +695,13 @@ export const Nested_InnerMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -751,10 +751,6 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -763,6 +759,10 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -821,13 +821,6 @@ export const OneOfMessage = { return message; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -839,6 +832,13 @@ export const OneOfMessage = { return obj; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -926,16 +926,6 @@ export const SimpleWithWrappers = { return message; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -956,6 +946,16 @@ export const SimpleWithWrappers = { return obj; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1006,10 +1006,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1018,6 +1014,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1093,29 +1093,6 @@ export const SimpleWithMap = { return message; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1148,6 +1125,29 @@ export const SimpleWithMap = { return obj; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1230,13 +1230,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1248,6 +1241,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1309,10 +1309,6 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1324,6 +1320,10 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1383,10 +1383,6 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1398,6 +1394,10 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1448,17 +1448,6 @@ export const SimpleWithSnakeCaseMap = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1473,6 +1462,17 @@ export const SimpleWithSnakeCaseMap = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -1537,13 +1537,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1555,6 +1548,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -1608,10 +1608,6 @@ export const PingRequest = { return message; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -1620,6 +1616,10 @@ export const PingRequest = { return obj; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -1666,10 +1666,6 @@ export const PingResponse = { return message; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -1678,6 +1674,10 @@ export const PingResponse = { return obj; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -1847,23 +1847,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -1905,6 +1888,23 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/thing.ts b/integration/simple-optionals/thing.ts index f890da70b..694fc72a5 100644 --- a/integration/simple-optionals/thing.ts +++ b/integration/simple-optionals/thing.ts @@ -43,10 +43,6 @@ export const ImportedThing = { return message; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -55,6 +51,10 @@ export const ImportedThing = { return obj; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-proto2/simple.ts b/integration/simple-proto2/simple.ts index 1b086230d..c91d30d3e 100644 --- a/integration/simple-proto2/simple.ts +++ b/integration/simple-proto2/simple.ts @@ -75,10 +75,6 @@ export const Issue56 = { return message; }, - fromJSON(object: any): Issue56 { - return { test: isSet(object.test) ? enumWithoutZeroFromJSON(object.test) : 1 }; - }, - toJSON(message: Issue56): unknown { const obj: any = {}; if (message.test !== 1) { @@ -87,6 +83,10 @@ export const Issue56 = { return obj; }, + fromJSON(object: any): Issue56 { + return { test: isSet(object.test) ? enumWithoutZeroFromJSON(object.test) : 1 }; + }, + create, I>>(base?: I): Issue56 { return Issue56.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/google/protobuf/timestamp.ts b/integration/simple-prototype-defaults/google/protobuf/timestamp.ts index c1279f5f9..34b1d16a9 100644 --- a/integration/simple-prototype-defaults/google/protobuf/timestamp.ts +++ b/integration/simple-prototype-defaults/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts index b8a1a2f92..0567fb42b 100644 --- a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts +++ b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/google/type/date.ts b/integration/simple-prototype-defaults/google/type/date.ts index 2e042add8..d10ac99df 100644 --- a/integration/simple-prototype-defaults/google/type/date.ts +++ b/integration/simple-prototype-defaults/google/type/date.ts @@ -89,14 +89,6 @@ export const DateMessage = { return message; }, - fromJSON(object: any): DateMessage { - return { - year: isSet(object.year) ? Number(object.year) : 0, - month: isSet(object.month) ? Number(object.month) : 0, - day: isSet(object.day) ? Number(object.day) : 0, - }; - }, - toJSON(message: DateMessage): unknown { const obj: any = {}; if (message.year !== 0) { @@ -111,6 +103,14 @@ export const DateMessage = { return obj; }, + fromJSON(object: any): DateMessage { + return { + year: isSet(object.year) ? Number(object.year) : 0, + month: isSet(object.month) ? Number(object.month) : 0, + day: isSet(object.day) ? Number(object.day) : 0, + }; + }, + create, I>>(base?: I): DateMessage { return DateMessage.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/import_dir/thing.ts b/integration/simple-prototype-defaults/import_dir/thing.ts index 9ae339e4a..86de68a07 100644 --- a/integration/simple-prototype-defaults/import_dir/thing.ts +++ b/integration/simple-prototype-defaults/import_dir/thing.ts @@ -43,10 +43,6 @@ export const ImportedThing = { return message; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -55,6 +51,10 @@ export const ImportedThing = { return obj; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/simple.ts b/integration/simple-prototype-defaults/simple.ts index fe9580023..e81dcf868 100644 --- a/integration/simple-prototype-defaults/simple.ts +++ b/integration/simple-prototype-defaults/simple.ts @@ -493,26 +493,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -557,6 +537,26 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -629,13 +629,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -647,6 +640,13 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -714,14 +714,6 @@ export const Nested = { return message; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -736,6 +728,14 @@ export const Nested = { return obj; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -796,13 +796,6 @@ export const Nested_InnerMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -814,6 +807,13 @@ export const Nested_InnerMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -863,10 +863,6 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -875,6 +871,10 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -933,13 +933,6 @@ export const OneOfMessage = { return message; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -951,6 +944,13 @@ export const OneOfMessage = { return obj; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -1048,17 +1048,6 @@ export const SimpleWithWrappers = { return message; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - id: isSet(object.id) ? new Uint8Array(object.id) : undefined, - }; - }, - toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -1082,6 +1071,17 @@ export const SimpleWithWrappers = { return obj; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + id: isSet(object.id) ? new Uint8Array(object.id) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1133,10 +1133,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1145,6 +1141,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1282,56 +1282,6 @@ export const SimpleWithMap = { return message; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { - acc[key] = fromJsonTimestamp(value); - return acc; - }, {}) - : {}, - mapOfBytes: isObject(object.mapOfBytes) - ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { - acc[key] = bytesFromBase64(value as string); - return acc; - }, {}) - : {}, - mapOfStringValues: isObject(object.mapOfStringValues) - ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( - (acc, [key, value]) => { - acc[key] = value as string | undefined; - return acc; - }, - {}, - ) - : {}, - longLookup: isObject(object.longLookup) - ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1400,6 +1350,56 @@ export const SimpleWithMap = { return obj; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { + acc[key] = fromJsonTimestamp(value); + return acc; + }, {}) + : {}, + mapOfBytes: isObject(object.mapOfBytes) + ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { + acc[key] = bytesFromBase64(value as string); + return acc; + }, {}) + : {}, + mapOfStringValues: isObject(object.mapOfStringValues) + ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( + (acc, [key, value]) => { + acc[key] = value as string | undefined; + return acc; + }, + {}, + ) + : {}, + longLookup: isObject(object.longLookup) + ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1517,13 +1517,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1535,6 +1528,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1596,10 +1596,6 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1611,6 +1607,10 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1670,10 +1670,6 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1685,6 +1681,10 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1742,13 +1742,6 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1760,6 +1753,13 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithMap_MapOfTimestampsEntry { @@ -1821,13 +1821,6 @@ export const SimpleWithMap_MapOfBytesEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), - }; - }, - toJSON(message: SimpleWithMap_MapOfBytesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1839,6 +1832,13 @@ export const SimpleWithMap_MapOfBytesEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), + }; + }, + create, I>>(base?: I): SimpleWithMap_MapOfBytesEntry { return SimpleWithMap_MapOfBytesEntry.fromPartial(base ?? {}); }, @@ -1900,13 +1900,6 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_MapOfStringValuesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1918,6 +1911,13 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithMap_MapOfStringValuesEntry { @@ -1981,10 +1981,6 @@ export const SimpleWithMap_LongLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_LongLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_LongLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1996,6 +1992,10 @@ export const SimpleWithMap_LongLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_LongLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_LongLookupEntry { return SimpleWithMap_LongLookupEntry.fromPartial(base ?? {}); }, @@ -2048,17 +2048,6 @@ export const SimpleWithSnakeCaseMap = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -2073,6 +2062,17 @@ export const SimpleWithSnakeCaseMap = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -2139,13 +2139,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2157,6 +2150,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -2215,17 +2215,6 @@ export const SimpleWithMapOfEnums = { return message; }, - fromJSON(object: any): SimpleWithMapOfEnums { - return { - enumsById: isObject(object.enumsById) - ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { - acc[Number(key)] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMapOfEnums): unknown { const obj: any = {}; if (message.enumsById) { @@ -2240,6 +2229,17 @@ export const SimpleWithMapOfEnums = { return obj; }, + fromJSON(object: any): SimpleWithMapOfEnums { + return { + enumsById: isObject(object.enumsById) + ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { + acc[Number(key)] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMapOfEnums { return SimpleWithMapOfEnums.fromPartial(base ?? {}); }, @@ -2306,13 +2306,6 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, - }; - }, - toJSON(message: SimpleWithMapOfEnums_EnumsByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2324,6 +2317,13 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, + }; + }, + create, I>>( base?: I, ): SimpleWithMapOfEnums_EnumsByIdEntry { @@ -2377,10 +2377,6 @@ export const PingRequest = { return message; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -2389,6 +2385,10 @@ export const PingRequest = { return obj; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -2435,10 +2435,6 @@ export const PingResponse = { return message; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -2447,6 +2443,10 @@ export const PingResponse = { return obj; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -2616,23 +2616,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -2674,6 +2657,23 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, @@ -2799,18 +2799,6 @@ export const SimpleButOptional = { return message; }, - fromJSON(object: any): SimpleButOptional { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - }; - }, - toJSON(message: SimpleButOptional): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -2837,6 +2825,18 @@ export const SimpleButOptional = { return obj; }, + fromJSON(object: any): SimpleButOptional { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + }; + }, + create, I>>(base?: I): SimpleButOptional { return SimpleButOptional.fromPartial(base ?? {}); }, @@ -2883,15 +2883,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/google/protobuf/struct.ts b/integration/simple-snake/google/protobuf/struct.ts index cf5700cc5..192a29dda 100644 --- a/integration/simple-snake/google/protobuf/struct.ts +++ b/integration/simple-snake/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -165,6 +154,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,10 +249,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,6 +260,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,17 +368,6 @@ export const Value = { return message; }, - fromJSON(object: any): Value { - return { - null_value: isSet(object.null_value) ? nullValueFromJSON(object.null_value) : undefined, - number_value: isSet(object.number_value) ? Number(object.number_value) : undefined, - string_value: isSet(object.string_value) ? String(object.string_value) : undefined, - bool_value: isSet(object.bool_value) ? Boolean(object.bool_value) : undefined, - struct_value: isObject(object.struct_value) ? object.struct_value : undefined, - list_value: Array.isArray(object.list_value) ? [...object.list_value] : undefined, - }; - }, - toJSON(message: Value): unknown { const obj: any = {}; if (message.null_value !== undefined) { @@ -402,6 +391,17 @@ export const Value = { return obj; }, + fromJSON(object: any): Value { + return { + null_value: isSet(object.null_value) ? nullValueFromJSON(object.null_value) : undefined, + number_value: isSet(object.number_value) ? Number(object.number_value) : undefined, + string_value: isSet(object.string_value) ? String(object.string_value) : undefined, + bool_value: isSet(object.bool_value) ? Boolean(object.bool_value) : undefined, + struct_value: isObject(object.struct_value) ? object.struct_value : undefined, + list_value: Array.isArray(object.list_value) ? [...object.list_value] : undefined, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,10 +490,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -502,6 +498,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/google/protobuf/timestamp.ts b/integration/simple-snake/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/simple-snake/google/protobuf/timestamp.ts +++ b/integration/simple-snake/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/google/protobuf/wrappers.ts b/integration/simple-snake/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/simple-snake/google/protobuf/wrappers.ts +++ b/integration/simple-snake/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/import_dir/thing.ts b/integration/simple-snake/import_dir/thing.ts index ea62d88a7..1cc01b254 100644 --- a/integration/simple-snake/import_dir/thing.ts +++ b/integration/simple-snake/import_dir/thing.ts @@ -43,10 +43,6 @@ export const ImportedThing = { return message; }, - fromJSON(object: any): ImportedThing { - return { created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined }; - }, - toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.created_at !== undefined) { @@ -55,6 +51,10 @@ export const ImportedThing = { return obj; }, + fromJSON(object: any): ImportedThing { + return { created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined }; + }, + create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/simple.ts b/integration/simple-snake/simple.ts index 6c2d143ee..777eaefd8 100644 --- a/integration/simple-snake/simple.ts +++ b/integration/simple-snake/simple.ts @@ -403,23 +403,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grand_children: Array.isArray(object?.grand_children) - ? object.grand_children.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - old_states: Array.isArray(object?.old_states) ? object.old_states.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -455,6 +438,23 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grand_children: Array.isArray(object?.grand_children) + ? object.grand_children.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + old_states: Array.isArray(object?.old_states) ? object.old_states.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -522,13 +522,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -540,6 +533,13 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -607,14 +607,6 @@ export const Nested = { return message; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -629,6 +621,14 @@ export const Nested = { return obj; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -689,13 +689,6 @@ export const Nested_InnerMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -707,6 +700,13 @@ export const Nested_InnerMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -756,10 +756,6 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -768,6 +764,10 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -826,13 +826,6 @@ export const OneOfMessage = { return message; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -844,6 +837,13 @@ export const OneOfMessage = { return obj; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -931,16 +931,6 @@ export const SimpleWithWrappers = { return message; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -961,6 +951,16 @@ export const SimpleWithWrappers = { return obj; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1011,10 +1011,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1023,6 +1019,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1098,29 +1098,6 @@ export const SimpleWithMap = { return message; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1153,6 +1130,29 @@ export const SimpleWithMap = { return obj; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1235,13 +1235,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1253,6 +1246,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1314,10 +1314,6 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1329,6 +1325,10 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1388,10 +1388,6 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1403,6 +1399,10 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1453,17 +1453,6 @@ export const SimpleWithSnakeCaseMap = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entities_by_id: isObject(object.entities_by_id) - ? Object.entries(object.entities_by_id).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entities_by_id) { @@ -1478,6 +1467,17 @@ export const SimpleWithSnakeCaseMap = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entities_by_id: isObject(object.entities_by_id) + ? Object.entries(object.entities_by_id).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -1542,13 +1542,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1560,6 +1553,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -1613,10 +1613,6 @@ export const PingRequest = { return message; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -1625,6 +1621,10 @@ export const PingRequest = { return obj; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -1671,10 +1671,6 @@ export const PingResponse = { return message; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -1683,6 +1679,10 @@ export const PingResponse = { return obj; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -1852,23 +1852,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -1910,6 +1893,23 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, @@ -1967,10 +1967,6 @@ export const SimpleStruct = { return message; }, - fromJSON(object: any): SimpleStruct { - return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; - }, - toJSON(message: SimpleStruct): unknown { const obj: any = {}; if (message.simple_struct !== undefined) { @@ -1979,6 +1975,10 @@ export const SimpleStruct = { return obj; }, + fromJSON(object: any): SimpleStruct { + return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; + }, + create, I>>(base?: I): SimpleStruct { return SimpleStruct.fromPartial(base ?? {}); }, diff --git a/integration/simple-string-enums/google/protobuf/struct.ts b/integration/simple-string-enums/google/protobuf/struct.ts index c0bd44e2d..5bbdfce20 100644 --- a/integration/simple-string-enums/google/protobuf/struct.ts +++ b/integration/simple-string-enums/google/protobuf/struct.ts @@ -150,17 +150,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -175,6 +164,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -259,10 +259,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -274,6 +270,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -378,17 +378,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -412,6 +401,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -500,10 +500,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -512,6 +508,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-string-enums/simple.ts b/integration/simple-string-enums/simple.ts index 05a4259c8..aeb54f093 100644 --- a/integration/simple-string-enums/simple.ts +++ b/integration/simple-string-enums/simple.ts @@ -160,21 +160,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - state: isSet(object.state) ? stateEnumFromJSON(object.state) : StateEnum.UNKNOWN, - states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], - nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : NullValue.NULL_VALUE, - stateMap: isObject(object.stateMap) - ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { - acc[key] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -201,6 +186,21 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + state: isSet(object.state) ? stateEnumFromJSON(object.state) : StateEnum.UNKNOWN, + states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], + nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : NullValue.NULL_VALUE, + stateMap: isObject(object.stateMap) + ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { + acc[key] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -269,13 +269,6 @@ export const Simple_StateMapEntry = { return message; }, - fromJSON(object: any): Simple_StateMapEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? stateEnumFromJSON(object.value) : StateEnum.UNKNOWN, - }; - }, - toJSON(message: Simple_StateMapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -287,6 +280,13 @@ export const Simple_StateMapEntry = { return obj; }, + fromJSON(object: any): Simple_StateMapEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? stateEnumFromJSON(object.value) : StateEnum.UNKNOWN, + }; + }, + create, I>>(base?: I): Simple_StateMapEntry { return Simple_StateMapEntry.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/import_dir/thing.ts b/integration/simple-unrecognized-enum/import_dir/thing.ts index 4fe4bb1a2..279398644 100644 --- a/integration/simple-unrecognized-enum/import_dir/thing.ts +++ b/integration/simple-unrecognized-enum/import_dir/thing.ts @@ -43,10 +43,6 @@ export const ImportedThing = { return message; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -55,6 +51,10 @@ export const ImportedThing = { return obj; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/simple.ts b/integration/simple-unrecognized-enum/simple.ts index e4b7063ff..4d1cedd67 100644 --- a/integration/simple-unrecognized-enum/simple.ts +++ b/integration/simple-unrecognized-enum/simple.ts @@ -386,23 +386,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -438,6 +421,23 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -505,13 +505,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -523,6 +516,13 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -590,14 +590,6 @@ export const Nested = { return message; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -612,6 +604,14 @@ export const Nested = { return obj; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -672,13 +672,6 @@ export const Nested_InnerMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -690,6 +683,13 @@ export const Nested_InnerMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -739,10 +739,6 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -751,6 +747,10 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -809,13 +809,6 @@ export const OneOfMessage = { return message; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -827,6 +820,13 @@ export const OneOfMessage = { return obj; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -914,16 +914,6 @@ export const SimpleWithWrappers = { return message; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -944,6 +934,16 @@ export const SimpleWithWrappers = { return obj; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -994,10 +994,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1006,6 +1002,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1081,29 +1081,6 @@ export const SimpleWithMap = { return message; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1136,6 +1113,29 @@ export const SimpleWithMap = { return obj; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1218,13 +1218,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1236,6 +1229,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1297,10 +1297,6 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1312,6 +1308,10 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1371,10 +1371,6 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1386,6 +1382,10 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1436,17 +1436,6 @@ export const SimpleWithSnakeCaseMap = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1461,6 +1450,17 @@ export const SimpleWithSnakeCaseMap = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -1525,13 +1525,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1543,6 +1536,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -1596,10 +1596,6 @@ export const PingRequest = { return message; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -1608,6 +1604,10 @@ export const PingRequest = { return obj; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -1654,10 +1654,6 @@ export const PingResponse = { return message; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -1666,6 +1662,10 @@ export const PingResponse = { return obj; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -1835,23 +1835,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -1893,6 +1876,23 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple/google/protobuf/timestamp.ts b/integration/simple/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/simple/google/protobuf/timestamp.ts +++ b/integration/simple/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple/google/protobuf/wrappers.ts b/integration/simple/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/simple/google/protobuf/wrappers.ts +++ b/integration/simple/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple/google/type/date.ts b/integration/simple/google/type/date.ts index 055208cca..9d18a2931 100644 --- a/integration/simple/google/type/date.ts +++ b/integration/simple/google/type/date.ts @@ -89,14 +89,6 @@ export const DateMessage = { return message; }, - fromJSON(object: any): DateMessage { - return { - year: isSet(object.year) ? Number(object.year) : 0, - month: isSet(object.month) ? Number(object.month) : 0, - day: isSet(object.day) ? Number(object.day) : 0, - }; - }, - toJSON(message: DateMessage): unknown { const obj: any = {}; if (message.year !== 0) { @@ -111,6 +103,14 @@ export const DateMessage = { return obj; }, + fromJSON(object: any): DateMessage { + return { + year: isSet(object.year) ? Number(object.year) : 0, + month: isSet(object.month) ? Number(object.month) : 0, + day: isSet(object.day) ? Number(object.day) : 0, + }; + }, + create, I>>(base?: I): DateMessage { return DateMessage.fromPartial(base ?? {}); }, diff --git a/integration/simple/import_dir/thing.ts b/integration/simple/import_dir/thing.ts index 4fe4bb1a2..279398644 100644 --- a/integration/simple/import_dir/thing.ts +++ b/integration/simple/import_dir/thing.ts @@ -43,10 +43,6 @@ export const ImportedThing = { return message; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -55,6 +51,10 @@ export const ImportedThing = { return obj; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple/simple.ts b/integration/simple/simple.ts index 4e07b22b8..427df9c53 100644 --- a/integration/simple/simple.ts +++ b/integration/simple/simple.ts @@ -505,27 +505,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), - enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -573,6 +552,27 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), + enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -646,13 +646,6 @@ export const Child = { return message; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -664,6 +657,13 @@ export const Child = { return obj; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -731,14 +731,6 @@ export const Nested = { return message; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -753,6 +745,14 @@ export const Nested = { return obj; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -813,13 +813,6 @@ export const Nested_InnerMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -831,6 +824,13 @@ export const Nested_InnerMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -880,10 +880,6 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -892,6 +888,10 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -950,13 +950,6 @@ export const OneOfMessage = { return message; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -968,6 +961,13 @@ export const OneOfMessage = { return obj; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -1065,17 +1065,6 @@ export const SimpleWithWrappers = { return message; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - id: isSet(object.id) ? new Uint8Array(object.id) : undefined, - }; - }, - toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -1099,6 +1088,17 @@ export const SimpleWithWrappers = { return obj; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + id: isSet(object.id) ? new Uint8Array(object.id) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1150,10 +1150,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1162,6 +1158,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1299,56 +1299,6 @@ export const SimpleWithMap = { return message; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { - acc[key] = fromJsonTimestamp(value); - return acc; - }, {}) - : {}, - mapOfBytes: isObject(object.mapOfBytes) - ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { - acc[key] = bytesFromBase64(value as string); - return acc; - }, {}) - : {}, - mapOfStringValues: isObject(object.mapOfStringValues) - ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( - (acc, [key, value]) => { - acc[key] = value as string | undefined; - return acc; - }, - {}, - ) - : {}, - longLookup: isObject(object.longLookup) - ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1417,6 +1367,56 @@ export const SimpleWithMap = { return obj; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { + acc[key] = fromJsonTimestamp(value); + return acc; + }, {}) + : {}, + mapOfBytes: isObject(object.mapOfBytes) + ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { + acc[key] = bytesFromBase64(value as string); + return acc; + }, {}) + : {}, + mapOfStringValues: isObject(object.mapOfStringValues) + ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( + (acc, [key, value]) => { + acc[key] = value as string | undefined; + return acc; + }, + {}, + ) + : {}, + longLookup: isObject(object.longLookup) + ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1534,13 +1534,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1552,6 +1545,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1613,10 +1613,6 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1628,6 +1624,10 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1687,10 +1687,6 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1702,6 +1698,10 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1759,13 +1759,6 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1777,6 +1770,13 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithMap_MapOfTimestampsEntry { @@ -1838,13 +1838,6 @@ export const SimpleWithMap_MapOfBytesEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), - }; - }, - toJSON(message: SimpleWithMap_MapOfBytesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1856,6 +1849,13 @@ export const SimpleWithMap_MapOfBytesEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), + }; + }, + create, I>>(base?: I): SimpleWithMap_MapOfBytesEntry { return SimpleWithMap_MapOfBytesEntry.fromPartial(base ?? {}); }, @@ -1915,13 +1915,6 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithMap_MapOfStringValuesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1933,6 +1926,13 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithMap_MapOfStringValuesEntry { @@ -1994,10 +1994,6 @@ export const SimpleWithMap_LongLookupEntry = { return message; }, - fromJSON(object: any): SimpleWithMap_LongLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: SimpleWithMap_LongLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2009,6 +2005,10 @@ export const SimpleWithMap_LongLookupEntry = { return obj; }, + fromJSON(object: any): SimpleWithMap_LongLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): SimpleWithMap_LongLookupEntry { return SimpleWithMap_LongLookupEntry.fromPartial(base ?? {}); }, @@ -2061,17 +2061,6 @@ export const SimpleWithSnakeCaseMap = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -2086,6 +2075,17 @@ export const SimpleWithSnakeCaseMap = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -2150,13 +2150,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2168,6 +2161,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -2224,17 +2224,6 @@ export const SimpleWithMapOfEnums = { return message; }, - fromJSON(object: any): SimpleWithMapOfEnums { - return { - enumsById: isObject(object.enumsById) - ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { - acc[Number(key)] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: SimpleWithMapOfEnums): unknown { const obj: any = {}; if (message.enumsById) { @@ -2249,6 +2238,17 @@ export const SimpleWithMapOfEnums = { return obj; }, + fromJSON(object: any): SimpleWithMapOfEnums { + return { + enumsById: isObject(object.enumsById) + ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { + acc[Number(key)] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): SimpleWithMapOfEnums { return SimpleWithMapOfEnums.fromPartial(base ?? {}); }, @@ -2313,13 +2313,6 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return message; }, - fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, - }; - }, - toJSON(message: SimpleWithMapOfEnums_EnumsByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2331,6 +2324,13 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return obj; }, + fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, + }; + }, + create, I>>( base?: I, ): SimpleWithMapOfEnums_EnumsByIdEntry { @@ -2382,10 +2382,6 @@ export const PingRequest = { return message; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -2394,6 +2390,10 @@ export const PingRequest = { return obj; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -2440,10 +2440,6 @@ export const PingResponse = { return message; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -2452,6 +2448,10 @@ export const PingResponse = { return obj; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -2621,23 +2621,6 @@ export const Numbers = { return message; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -2679,6 +2662,23 @@ export const Numbers = { return obj; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, @@ -2804,18 +2804,6 @@ export const SimpleButOptional = { return message; }, - fromJSON(object: any): SimpleButOptional { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - }; - }, - toJSON(message: SimpleButOptional): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -2842,6 +2830,18 @@ export const SimpleButOptional = { return obj; }, + fromJSON(object: any): SimpleButOptional { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + }; + }, + create, I>>(base?: I): SimpleButOptional { return SimpleButOptional.fromPartial(base ?? {}); }, @@ -2888,15 +2888,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/bar/bar.ts b/integration/static-only-type-registry/bar/bar.ts index 7b1a4ac87..db58f3900 100644 --- a/integration/static-only-type-registry/bar/bar.ts +++ b/integration/static-only-type-registry/bar/bar.ts @@ -46,10 +46,6 @@ export const Bar = { return message; }, - fromJSON(object: any): Bar { - return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -58,6 +54,10 @@ export const Bar = { return obj; }, + fromJSON(object: any): Bar { + return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/foo.ts b/integration/static-only-type-registry/foo.ts index bf714ce78..969c892c4 100644 --- a/integration/static-only-type-registry/foo.ts +++ b/integration/static-only-type-registry/foo.ts @@ -55,10 +55,6 @@ export const Foo = { return message; }, - fromJSON(object: any): Foo { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -67,6 +63,10 @@ export const Foo = { return obj; }, + fromJSON(object: any): Foo { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -117,10 +117,6 @@ export const Foo2 = { return message; }, - fromJSON(object: any): Foo2 { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -129,6 +125,10 @@ export const Foo2 = { return obj; }, + fromJSON(object: any): Foo2 { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -179,10 +179,6 @@ export const WithStruct = { return message; }, - fromJSON(object: any): WithStruct { - return { struct: isObject(object.struct) ? object.struct : undefined }; - }, - toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -191,6 +187,10 @@ export const WithStruct = { return obj; }, + fromJSON(object: any): WithStruct { + return { struct: isObject(object.struct) ? object.struct : undefined }; + }, + create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/google/protobuf/struct.ts b/integration/static-only-type-registry/google/protobuf/struct.ts index 239a36208..e7d6dea34 100644 --- a/integration/static-only-type-registry/google/protobuf/struct.ts +++ b/integration/static-only-type-registry/google/protobuf/struct.ts @@ -143,17 +143,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -168,6 +157,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -256,10 +256,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -271,6 +267,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -379,17 +379,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -413,6 +402,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -505,10 +505,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -517,6 +513,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/google/protobuf/timestamp.ts b/integration/static-only-type-registry/google/protobuf/timestamp.ts index 6412e7c48..f1c2d4093 100644 --- a/integration/static-only-type-registry/google/protobuf/timestamp.ts +++ b/integration/static-only-type-registry/google/protobuf/timestamp.ts @@ -159,13 +159,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -177,6 +170,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/static-only/bar/bar.ts b/integration/static-only/bar/bar.ts index 43cb9de82..8b1af666d 100644 --- a/integration/static-only/bar/bar.ts +++ b/integration/static-only/bar/bar.ts @@ -45,10 +45,6 @@ export const Bar = { return message; }, - fromJSON(object: any): Bar { - return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -57,6 +53,10 @@ export const Bar = { return obj; }, + fromJSON(object: any): Bar { + return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/static-only/foo.ts b/integration/static-only/foo.ts index 8055715b9..95410b6e8 100644 --- a/integration/static-only/foo.ts +++ b/integration/static-only/foo.ts @@ -54,10 +54,6 @@ export const Foo = { return message; }, - fromJSON(object: any): Foo { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -66,6 +62,10 @@ export const Foo = { return obj; }, + fromJSON(object: any): Foo { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -114,10 +114,6 @@ export const Foo2 = { return message; }, - fromJSON(object: any): Foo2 { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -126,6 +122,10 @@ export const Foo2 = { return obj; }, + fromJSON(object: any): Foo2 { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -174,10 +174,6 @@ export const WithStruct = { return message; }, - fromJSON(object: any): WithStruct { - return { struct: isObject(object.struct) ? object.struct : undefined }; - }, - toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -186,6 +182,10 @@ export const WithStruct = { return obj; }, + fromJSON(object: any): WithStruct { + return { struct: isObject(object.struct) ? object.struct : undefined }; + }, + create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/static-only/google/protobuf/struct.ts b/integration/static-only/google/protobuf/struct.ts index 64cca73ce..9e68ba01e 100644 --- a/integration/static-only/google/protobuf/struct.ts +++ b/integration/static-only/google/protobuf/struct.ts @@ -142,17 +142,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -167,6 +156,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -253,10 +253,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -268,6 +264,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -374,17 +374,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -408,6 +397,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -498,10 +498,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -510,6 +506,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/static-only/google/protobuf/timestamp.ts b/integration/static-only/google/protobuf/timestamp.ts index 0fb7abe8f..8515e6707 100644 --- a/integration/static-only/google/protobuf/timestamp.ts +++ b/integration/static-only/google/protobuf/timestamp.ts @@ -158,13 +158,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -176,6 +169,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/struct/google/protobuf/struct.ts b/integration/struct/google/protobuf/struct.ts index b2486a866..7c416eb52 100644 --- a/integration/struct/google/protobuf/struct.ts +++ b/integration/struct/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -165,6 +154,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,10 +249,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,6 +260,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,17 +368,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -402,6 +391,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,10 +490,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -502,6 +498,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/struct/struct.ts b/integration/struct/struct.ts index 83bf70017..308b7ef6b 100644 --- a/integration/struct/struct.ts +++ b/integration/struct/struct.ts @@ -43,10 +43,6 @@ export const StructMessage = { return message; }, - fromJSON(object: any): StructMessage { - return { value: isObject(object.value) ? object.value : undefined }; - }, - toJSON(message: StructMessage): unknown { const obj: any = {}; if (message.value !== undefined) { @@ -55,6 +51,10 @@ export const StructMessage = { return obj; }, + fromJSON(object: any): StructMessage { + return { value: isObject(object.value) ? object.value : undefined }; + }, + create, I>>(base?: I): StructMessage { return StructMessage.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/bar/bar.ts b/integration/type-annotations/bar/bar.ts index aef3a1bfb..a8fd72163 100644 --- a/integration/type-annotations/bar/bar.ts +++ b/integration/type-annotations/bar/bar.ts @@ -46,10 +46,6 @@ export const Bar = { return message; }, - fromJSON(object: any): Bar { - return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -58,6 +54,10 @@ export const Bar = { return obj; }, + fromJSON(object: any): Bar { + return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/foo.ts b/integration/type-annotations/foo.ts index 2ae6b7752..439bc6547 100644 --- a/integration/type-annotations/foo.ts +++ b/integration/type-annotations/foo.ts @@ -57,10 +57,6 @@ export const Foo = { return message; }, - fromJSON(object: any): Foo { - return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -69,6 +65,10 @@ export const Foo = { return obj; }, + fromJSON(object: any): Foo { + return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -117,10 +117,6 @@ export const Foo2 = { return message; }, - fromJSON(object: any): Foo2 { - return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -129,6 +125,10 @@ export const Foo2 = { return obj; }, + fromJSON(object: any): Foo2 { + return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -177,10 +177,6 @@ export const WithStruct = { return message; }, - fromJSON(object: any): WithStruct { - return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; - }, - toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -189,6 +185,10 @@ export const WithStruct = { return obj; }, + fromJSON(object: any): WithStruct { + return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; + }, + create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/google/protobuf/struct.ts b/integration/type-annotations/google/protobuf/struct.ts index 6e0125ecc..35b3fac3d 100644 --- a/integration/type-annotations/google/protobuf/struct.ts +++ b/integration/type-annotations/google/protobuf/struct.ts @@ -149,18 +149,6 @@ export const Struct = { return message; }, - fromJSON(object: any): Struct { - return { - $type: Struct.$type, - 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 = {}; if (message.fields) { @@ -175,6 +163,18 @@ export const Struct = { return obj; }, + fromJSON(object: any): Struct { + return { + $type: Struct.$type, + fields: isObject(object.fields) + ? Object.entries(object.fields).reduce<{ [key: string]: any | undefined }>((acc, [key, value]) => { + acc[key] = value as any | undefined; + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -261,14 +261,6 @@ export const Struct_FieldsEntry = { return message; }, - fromJSON(object: any): Struct_FieldsEntry { - return { - $type: Struct_FieldsEntry.$type, - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object?.value) ? object.value : undefined, - }; - }, - toJSON(message: Struct_FieldsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -280,6 +272,14 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { + $type: Struct_FieldsEntry.$type, + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object?.value) ? object.value : undefined, + }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -387,18 +387,6 @@ export const Value = { return message; }, - fromJSON(object: any): Value { - return { - $type: Value.$type, - 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 = {}; if (message.nullValue !== undefined) { @@ -422,6 +410,18 @@ export const Value = { return obj; }, + fromJSON(object: any): Value { + return { + $type: Value.$type, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -512,10 +512,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -524,6 +520,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/google/protobuf/timestamp.ts b/integration/type-annotations/google/protobuf/timestamp.ts index d3a2b6743..34571adcc 100644 --- a/integration/type-annotations/google/protobuf/timestamp.ts +++ b/integration/type-annotations/google/protobuf/timestamp.ts @@ -159,14 +159,6 @@ export const Timestamp = { return message; }, - fromJSON(object: any): Timestamp { - return { - $type: Timestamp.$type, - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== 0) { @@ -178,6 +170,14 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + $type: Timestamp.$type, + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/bar/bar.ts b/integration/type-registry/bar/bar.ts index 2b5060a88..b455a1b11 100644 --- a/integration/type-registry/bar/bar.ts +++ b/integration/type-registry/bar/bar.ts @@ -47,10 +47,6 @@ export const Bar = { return message; }, - fromJSON(object: any): Bar { - return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -59,6 +55,10 @@ export const Bar = { return obj; }, + fromJSON(object: any): Bar { + return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/foo.ts b/integration/type-registry/foo.ts index d8e4e26cc..b4384ed87 100644 --- a/integration/type-registry/foo.ts +++ b/integration/type-registry/foo.ts @@ -58,10 +58,6 @@ export const Foo = { return message; }, - fromJSON(object: any): Foo { - return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -70,6 +66,10 @@ export const Foo = { return obj; }, + fromJSON(object: any): Foo { + return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -120,10 +120,6 @@ export const Foo2 = { return message; }, - fromJSON(object: any): Foo2 { - return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -132,6 +128,10 @@ export const Foo2 = { return obj; }, + fromJSON(object: any): Foo2 { + return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -182,10 +182,6 @@ export const WithStruct = { return message; }, - fromJSON(object: any): WithStruct { - return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; - }, - toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -194,6 +190,10 @@ export const WithStruct = { return obj; }, + fromJSON(object: any): WithStruct { + return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; + }, + create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/google/protobuf/struct.ts b/integration/type-registry/google/protobuf/struct.ts index 451bad188..b3eeb96db 100644 --- a/integration/type-registry/google/protobuf/struct.ts +++ b/integration/type-registry/google/protobuf/struct.ts @@ -150,18 +150,6 @@ export const Struct = { return message; }, - fromJSON(object: any): Struct { - return { - $type: Struct.$type, - 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 = {}; if (message.fields) { @@ -176,6 +164,18 @@ export const Struct = { return obj; }, + fromJSON(object: any): Struct { + return { + $type: Struct.$type, + fields: isObject(object.fields) + ? Object.entries(object.fields).reduce<{ [key: string]: any | undefined }>((acc, [key, value]) => { + acc[key] = value as any | undefined; + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -264,14 +264,6 @@ export const Struct_FieldsEntry = { return message; }, - fromJSON(object: any): Struct_FieldsEntry { - return { - $type: Struct_FieldsEntry.$type, - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object?.value) ? object.value : undefined, - }; - }, - toJSON(message: Struct_FieldsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -283,6 +275,14 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { + $type: Struct_FieldsEntry.$type, + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object?.value) ? object.value : undefined, + }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -392,18 +392,6 @@ export const Value = { return message; }, - fromJSON(object: any): Value { - return { - $type: Value.$type, - 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 = {}; if (message.nullValue !== undefined) { @@ -427,6 +415,18 @@ export const Value = { return obj; }, + fromJSON(object: any): Value { + return { + $type: Value.$type, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -519,10 +519,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -531,6 +527,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/google/protobuf/timestamp.ts b/integration/type-registry/google/protobuf/timestamp.ts index cd8375327..fa1b933a7 100644 --- a/integration/type-registry/google/protobuf/timestamp.ts +++ b/integration/type-registry/google/protobuf/timestamp.ts @@ -160,14 +160,6 @@ export const Timestamp = { return message; }, - fromJSON(object: any): Timestamp { - return { - $type: Timestamp.$type, - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== 0) { @@ -179,6 +171,14 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + $type: Timestamp.$type, + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/types-with-underscores/file.ts b/integration/types-with-underscores/file.ts index 6b174be1f..f15534841 100644 --- a/integration/types-with-underscores/file.ts +++ b/integration/types-with-underscores/file.ts @@ -45,10 +45,6 @@ export const Baz = { return message; }, - fromJSON(object: any): Baz { - return { foo: isSet(object.foo) ? FooBar.fromJSON(object.foo) : undefined }; - }, - toJSON(message: Baz): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -57,6 +53,10 @@ export const Baz = { return obj; }, + fromJSON(object: any): Baz { + return { foo: isSet(object.foo) ? FooBar.fromJSON(object.foo) : undefined }; + }, + create, I>>(base?: I): Baz { return Baz.fromPartial(base ?? {}); }, @@ -93,15 +93,15 @@ export const FooBar = { return message; }, - fromJSON(_: any): FooBar { - return {}; - }, - toJSON(_: FooBar): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): FooBar { + return {}; + }, + create, I>>(base?: I): FooBar { return FooBar.fromPartial(base ?? {}); }, diff --git a/integration/use-date-false/google/protobuf/timestamp.ts b/integration/use-date-false/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/use-date-false/google/protobuf/timestamp.ts +++ b/integration/use-date-false/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-date-false/metadata.ts b/integration/use-date-false/metadata.ts index 097fa6736..281207141 100644 --- a/integration/use-date-false/metadata.ts +++ b/integration/use-date-false/metadata.ts @@ -43,10 +43,6 @@ export const Metadata = { return message; }, - fromJSON(object: any): Metadata { - return { lastEdited: isSet(object.lastEdited) ? fromJsonTimestamp(object.lastEdited) : undefined }; - }, - toJSON(message: Metadata): unknown { const obj: any = {}; if (message.lastEdited !== undefined) { @@ -55,6 +51,10 @@ export const Metadata = { return obj; }, + fromJSON(object: any): Metadata { + return { lastEdited: isSet(object.lastEdited) ? fromJsonTimestamp(object.lastEdited) : undefined }; + }, + create, I>>(base?: I): Metadata { return Metadata.fromPartial(base ?? {}); }, diff --git a/integration/use-date-string/google/protobuf/timestamp.ts b/integration/use-date-string/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/use-date-string/google/protobuf/timestamp.ts +++ b/integration/use-date-string/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-date-string/use-date-string.ts b/integration/use-date-string/use-date-string.ts index e8d32a532..dde255b83 100644 --- a/integration/use-date-string/use-date-string.ts +++ b/integration/use-date-string/use-date-string.ts @@ -95,23 +95,6 @@ export const Todo = { return message; }, - fromJSON(object: any): Todo { - return { - id: isSet(object.id) ? String(object.id) : "", - timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined, - repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) - ? object.repeatedTimestamp.map((e: any) => String(e)) - : [], - optionalTimestamp: isSet(object.optionalTimestamp) ? String(object.optionalTimestamp) : undefined, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: Todo): unknown { const obj: any = {}; if (message.id !== "") { @@ -138,6 +121,23 @@ export const Todo = { return obj; }, + fromJSON(object: any): Todo { + return { + id: isSet(object.id) ? String(object.id) : "", + timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined, + repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) + ? object.repeatedTimestamp.map((e: any) => String(e)) + : [], + optionalTimestamp: isSet(object.optionalTimestamp) ? String(object.optionalTimestamp) : undefined, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Todo { return Todo.fromPartial(base ?? {}); }, @@ -206,13 +206,6 @@ export const Todo_MapOfTimestampsEntry = { return message; }, - fromJSON(object: any): Todo_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - toJSON(message: Todo_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -224,6 +217,13 @@ export const Todo_MapOfTimestampsEntry = { return obj; }, + fromJSON(object: any): Todo_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + create, I>>(base?: I): Todo_MapOfTimestampsEntry { return Todo_MapOfTimestampsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-date-true/google/protobuf/empty.ts b/integration/use-date-true/google/protobuf/empty.ts index 1387d7ce4..d1b8ebf5b 100644 --- a/integration/use-date-true/google/protobuf/empty.ts +++ b/integration/use-date-true/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/use-date-true/google/protobuf/timestamp.ts b/integration/use-date-true/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/use-date-true/google/protobuf/timestamp.ts +++ b/integration/use-date-true/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-date-true/use-date-true.ts b/integration/use-date-true/use-date-true.ts index 0fae63006..8dd52c92f 100644 --- a/integration/use-date-true/use-date-true.ts +++ b/integration/use-date-true/use-date-true.ts @@ -96,23 +96,6 @@ export const Todo = { return message; }, - fromJSON(object: any): Todo { - return { - id: isSet(object.id) ? String(object.id) : "", - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) - ? object.repeatedTimestamp.map((e: any) => fromJsonTimestamp(e)) - : [], - optionalTimestamp: isSet(object.optionalTimestamp) ? fromJsonTimestamp(object.optionalTimestamp) : undefined, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { - acc[key] = fromJsonTimestamp(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: Todo): unknown { const obj: any = {}; if (message.id !== "") { @@ -139,6 +122,23 @@ export const Todo = { return obj; }, + fromJSON(object: any): Todo { + return { + id: isSet(object.id) ? String(object.id) : "", + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) + ? object.repeatedTimestamp.map((e: any) => fromJsonTimestamp(e)) + : [], + optionalTimestamp: isSet(object.optionalTimestamp) ? fromJsonTimestamp(object.optionalTimestamp) : undefined, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { + acc[key] = fromJsonTimestamp(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Todo { return Todo.fromPartial(base ?? {}); }, @@ -207,13 +207,6 @@ export const Todo_MapOfTimestampsEntry = { return message; }, - fromJSON(object: any): Todo_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - toJSON(message: Todo_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -225,6 +218,13 @@ export const Todo_MapOfTimestampsEntry = { return obj; }, + fromJSON(object: any): Todo_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + create, I>>(base?: I): Todo_MapOfTimestampsEntry { return Todo_MapOfTimestampsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-exact-types-false/foo.ts b/integration/use-exact-types-false/foo.ts index fe86b5836..4f6c59079 100644 --- a/integration/use-exact-types-false/foo.ts +++ b/integration/use-exact-types-false/foo.ts @@ -53,10 +53,6 @@ export const Foo = { return message; }, - fromJSON(object: any): Foo { - return { bar: isSet(object.bar) ? String(object.bar) : "", baz: isSet(object.baz) ? String(object.baz) : "" }; - }, - toJSON(message: Foo): unknown { const obj: any = {}; if (message.bar !== "") { @@ -68,6 +64,10 @@ export const Foo = { return obj; }, + fromJSON(object: any): Foo { + return { bar: isSet(object.bar) ? String(object.bar) : "", baz: isSet(object.baz) ? String(object.baz) : "" }; + }, + create(base?: DeepPartial): Foo { return Foo.fromPartial(base ?? {}); }, diff --git a/integration/use-map-type/google/protobuf/struct.ts b/integration/use-map-type/google/protobuf/struct.ts index cb6b8e13d..809890879 100644 --- a/integration/use-map-type/google/protobuf/struct.ts +++ b/integration/use-map-type/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { return message; }, - fromJSON(object: any): Struct { - return { - fields: isObject(object.fields) - ? Object.entries(object.fields).reduce>((acc, [key, value]) => { - acc.set(key, value as any | undefined); - return acc; - }, new Map()) - : new Map(), - }; - }, - toJSON(message: Struct): unknown { const obj: any = {}; if (message.fields?.size) { @@ -162,6 +151,17 @@ export const Struct = { return obj; }, + fromJSON(object: any): Struct { + return { + fields: isObject(object.fields) + ? Object.entries(object.fields).reduce>((acc, [key, value]) => { + acc.set(key, value as any | undefined); + return acc; + }, new Map()) + : new Map(), + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -244,10 +244,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -259,6 +255,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -363,17 +363,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -397,6 +386,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -485,10 +485,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -497,6 +493,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/use-map-type/google/protobuf/timestamp.ts b/integration/use-map-type/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/use-map-type/google/protobuf/timestamp.ts +++ b/integration/use-map-type/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-map-type/use-map-type.ts b/integration/use-map-type/use-map-type.ts index ddb7d7b3a..944eb6b9b 100644 --- a/integration/use-map-type/use-map-type.ts +++ b/integration/use-map-type/use-map-type.ts @@ -79,10 +79,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -91,6 +87,10 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -209,42 +209,6 @@ export const Maps = { return message; }, - fromJSON(object: any): Maps { - return { - strToEntity: isObject(object.strToEntity) - ? Object.entries(object.strToEntity).reduce>((acc, [key, value]) => { - acc.set(key, Entity.fromJSON(value)); - return acc; - }, new Map()) - : new Map(), - int32ToInt32: isObject(object.int32ToInt32) - ? Object.entries(object.int32ToInt32).reduce>((acc, [key, value]) => { - acc.set(Number(key), Number(value)); - return acc; - }, new Map()) - : new Map(), - stringToBytes: isObject(object.stringToBytes) - ? Object.entries(object.stringToBytes).reduce>((acc, [key, value]) => { - acc.set(key, bytesFromBase64(value as string)); - return acc; - }, new Map()) - : new Map(), - int64ToInt64: isObject(object.int64ToInt64) - ? Object.entries(object.int64ToInt64).reduce>((acc, [key, value]) => { - acc.set(Number(key), Number(value)); - return acc; - }, new Map()) - : new Map(), - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce>((acc, [key, value]) => { - acc.set(key, fromJsonTimestamp(value)); - return acc; - }, new Map()) - : new Map(), - struct: isObject(object.struct) ? object.struct : undefined, - }; - }, - toJSON(message: Maps): unknown { const obj: any = {}; if (message.strToEntity?.size) { @@ -283,6 +247,42 @@ export const Maps = { return obj; }, + fromJSON(object: any): Maps { + return { + strToEntity: isObject(object.strToEntity) + ? Object.entries(object.strToEntity).reduce>((acc, [key, value]) => { + acc.set(key, Entity.fromJSON(value)); + return acc; + }, new Map()) + : new Map(), + int32ToInt32: isObject(object.int32ToInt32) + ? Object.entries(object.int32ToInt32).reduce>((acc, [key, value]) => { + acc.set(Number(key), Number(value)); + return acc; + }, new Map()) + : new Map(), + stringToBytes: isObject(object.stringToBytes) + ? Object.entries(object.stringToBytes).reduce>((acc, [key, value]) => { + acc.set(key, bytesFromBase64(value as string)); + return acc; + }, new Map()) + : new Map(), + int64ToInt64: isObject(object.int64ToInt64) + ? Object.entries(object.int64ToInt64).reduce>((acc, [key, value]) => { + acc.set(Number(key), Number(value)); + return acc; + }, new Map()) + : new Map(), + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce>((acc, [key, value]) => { + acc.set(key, fromJsonTimestamp(value)); + return acc; + }, new Map()) + : new Map(), + struct: isObject(object.struct) ? object.struct : undefined, + }; + }, + create, I>>(base?: I): Maps { return Maps.fromPartial(base ?? {}); }, @@ -384,13 +384,6 @@ export const Maps_StrToEntityEntry = { return message; }, - fromJSON(object: any): Maps_StrToEntityEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - toJSON(message: Maps_StrToEntityEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -402,6 +395,13 @@ export const Maps_StrToEntityEntry = { return obj; }, + fromJSON(object: any): Maps_StrToEntityEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + create, I>>(base?: I): Maps_StrToEntityEntry { return Maps_StrToEntityEntry.fromPartial(base ?? {}); }, @@ -461,10 +461,6 @@ export const Maps_Int32ToInt32Entry = { return message; }, - fromJSON(object: any): Maps_Int32ToInt32Entry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Maps_Int32ToInt32Entry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -476,6 +472,10 @@ export const Maps_Int32ToInt32Entry = { return obj; }, + fromJSON(object: any): Maps_Int32ToInt32Entry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Maps_Int32ToInt32Entry { return Maps_Int32ToInt32Entry.fromPartial(base ?? {}); }, @@ -533,13 +533,6 @@ export const Maps_StringToBytesEntry = { return message; }, - fromJSON(object: any): Maps_StringToBytesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), - }; - }, - toJSON(message: Maps_StringToBytesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -551,6 +544,13 @@ export const Maps_StringToBytesEntry = { return obj; }, + fromJSON(object: any): Maps_StringToBytesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), + }; + }, + create, I>>(base?: I): Maps_StringToBytesEntry { return Maps_StringToBytesEntry.fromPartial(base ?? {}); }, @@ -608,10 +608,6 @@ export const Maps_Int64ToInt64Entry = { return message; }, - fromJSON(object: any): Maps_Int64ToInt64Entry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Maps_Int64ToInt64Entry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -623,6 +619,10 @@ export const Maps_Int64ToInt64Entry = { return obj; }, + fromJSON(object: any): Maps_Int64ToInt64Entry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Maps_Int64ToInt64Entry { return Maps_Int64ToInt64Entry.fromPartial(base ?? {}); }, @@ -680,13 +680,6 @@ export const Maps_MapOfTimestampsEntry = { return message; }, - fromJSON(object: any): Maps_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - toJSON(message: Maps_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -698,6 +691,13 @@ export const Maps_MapOfTimestampsEntry = { return obj; }, + fromJSON(object: any): Maps_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + create, I>>(base?: I): Maps_MapOfTimestampsEntry { return Maps_MapOfTimestampsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-numeric-enum-json/google/protobuf/struct.ts b/integration/use-numeric-enum-json/google/protobuf/struct.ts index 41928548c..af01115bf 100644 --- a/integration/use-numeric-enum-json/google/protobuf/struct.ts +++ b/integration/use-numeric-enum-json/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -165,6 +154,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,10 +249,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,6 +260,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,17 +368,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -402,6 +391,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,10 +490,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -502,6 +498,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/use-numeric-enum-json/simple.ts b/integration/use-numeric-enum-json/simple.ts index bec6c5696..be06cd540 100644 --- a/integration/use-numeric-enum-json/simple.ts +++ b/integration/use-numeric-enum-json/simple.ts @@ -146,21 +146,6 @@ export const Simple = { return message; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], - nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : 0, - stateMap: isObject(object.stateMap) - ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { - acc[key] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -187,6 +172,21 @@ export const Simple = { return obj; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], + nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : 0, + stateMap: isObject(object.stateMap) + ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { + acc[key] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -255,13 +255,6 @@ export const Simple_StateMapEntry = { return message; }, - fromJSON(object: any): Simple_StateMapEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, - }; - }, - toJSON(message: Simple_StateMapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -273,6 +266,13 @@ export const Simple_StateMapEntry = { return obj; }, + fromJSON(object: any): Simple_StateMapEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, + }; + }, + create, I>>(base?: I): Simple_StateMapEntry { return Simple_StateMapEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-objectid-true-external-import/objectid/objectid.ts b/integration/use-objectid-true-external-import/objectid/objectid.ts index e61fbb74b..982821c72 100644 --- a/integration/use-objectid-true-external-import/objectid/objectid.ts +++ b/integration/use-objectid-true-external-import/objectid/objectid.ts @@ -42,10 +42,6 @@ export const ObjectId = { return message; }, - fromJSON(object: any): ObjectId { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: ObjectId): unknown { const obj: any = {}; if (message.value !== "") { @@ -54,6 +50,10 @@ export const ObjectId = { return obj; }, + fromJSON(object: any): ObjectId { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): ObjectId { return ObjectId.fromPartial(base ?? {}); }, diff --git a/integration/use-objectid-true-external-import/use-objectid-true.ts b/integration/use-objectid-true-external-import/use-objectid-true.ts index 4d51b266a..cea8b7b4f 100644 --- a/integration/use-objectid-true-external-import/use-objectid-true.ts +++ b/integration/use-objectid-true-external-import/use-objectid-true.ts @@ -96,21 +96,6 @@ export const Todo = { return message; }, - fromJSON(object: any): Todo { - return { - id: isSet(object.id) ? String(object.id) : "", - oid: isSet(object.oid) ? fromJsonObjectId(object.oid) : undefined, - repeatedOid: Array.isArray(object?.repeatedOid) ? object.repeatedOid.map((e: any) => fromJsonObjectId(e)) : [], - optionalOid: isSet(object.optionalOid) ? fromJsonObjectId(object.optionalOid) : undefined, - mapOfOids: isObject(object.mapOfOids) - ? Object.entries(object.mapOfOids).reduce<{ [key: string]: mongodb.ObjectId }>((acc, [key, value]) => { - acc[key] = fromJsonObjectId(value); - return acc; - }, {}) - : {}, - }; - }, - toJSON(message: Todo): unknown { const obj: any = {}; if (message.id !== "") { @@ -137,6 +122,21 @@ export const Todo = { return obj; }, + fromJSON(object: any): Todo { + return { + id: isSet(object.id) ? String(object.id) : "", + oid: isSet(object.oid) ? fromJsonObjectId(object.oid) : undefined, + repeatedOid: Array.isArray(object?.repeatedOid) ? object.repeatedOid.map((e: any) => fromJsonObjectId(e)) : [], + optionalOid: isSet(object.optionalOid) ? fromJsonObjectId(object.optionalOid) : undefined, + mapOfOids: isObject(object.mapOfOids) + ? Object.entries(object.mapOfOids).reduce<{ [key: string]: mongodb.ObjectId }>((acc, [key, value]) => { + acc[key] = fromJsonObjectId(value); + return acc; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Todo { return Todo.fromPartial(base ?? {}); }, @@ -207,13 +207,6 @@ export const Todo_MapOfOidsEntry = { return message; }, - fromJSON(object: any): Todo_MapOfOidsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonObjectId(object.value) : undefined, - }; - }, - toJSON(message: Todo_MapOfOidsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -225,6 +218,13 @@ export const Todo_MapOfOidsEntry = { return obj; }, + fromJSON(object: any): Todo_MapOfOidsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonObjectId(object.value) : undefined, + }; + }, + create, I>>(base?: I): Todo_MapOfOidsEntry { return Todo_MapOfOidsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-optionals-all/google/protobuf/timestamp.ts b/integration/use-optionals-all/google/protobuf/timestamp.ts index 6b1f71f5e..017aabd58 100644 --- a/integration/use-optionals-all/google/protobuf/timestamp.ts +++ b/integration/use-optionals-all/google/protobuf/timestamp.ts @@ -158,13 +158,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== undefined && message.seconds !== 0) { @@ -176,6 +169,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-optionals-all/test.ts b/integration/use-optionals-all/test.ts index 25ca5aa67..cb1d0b264 100644 --- a/integration/use-optionals-all/test.ts +++ b/integration/use-optionals-all/test.ts @@ -422,39 +422,6 @@ export const OptionalsTest = { return message; }, - fromJSON(object: any): OptionalsTest { - return { - id: isSet(object.id) ? Number(object.id) : 0, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - long: isSet(object.long) ? Number(object.long) : 0, - truth: isSet(object.truth) ? Boolean(object.truth) : false, - description: isSet(object.description) ? String(object.description) : "", - data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0), - repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : [], - repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : [], - repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : [], - repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : [], - repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : [], - repDescription: Array.isArray(object?.repDescription) ? object.repDescription.map((e: any) => String(e)) : [], - repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : [], - optId: isSet(object.optId) ? Number(object.optId) : undefined, - optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, - optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, - optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, - optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, - optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, - optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, - translations: isObject(object.translations) - ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - }; - }, - toJSON(message: OptionalsTest): unknown { const obj: any = {}; if (message.id !== undefined && message.id !== 0) { @@ -535,6 +502,39 @@ export const OptionalsTest = { return obj; }, + fromJSON(object: any): OptionalsTest { + return { + id: isSet(object.id) ? Number(object.id) : 0, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + long: isSet(object.long) ? Number(object.long) : 0, + truth: isSet(object.truth) ? Boolean(object.truth) : false, + description: isSet(object.description) ? String(object.description) : "", + data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0), + repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : [], + repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : [], + repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : [], + repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : [], + repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : [], + repDescription: Array.isArray(object?.repDescription) ? object.repDescription.map((e: any) => String(e)) : [], + repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : [], + optId: isSet(object.optId) ? Number(object.optId) : undefined, + optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, + optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, + optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, + optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, + optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, + optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, + translations: isObject(object.translations) + ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + }; + }, + create, I>>(base?: I): OptionalsTest { return OptionalsTest.fromPartial(base ?? {}); }, @@ -623,10 +623,6 @@ export const OptionalsTest_TranslationsEntry = { return message; }, - fromJSON(object: any): OptionalsTest_TranslationsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: OptionalsTest_TranslationsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -638,6 +634,10 @@ export const OptionalsTest_TranslationsEntry = { return obj; }, + fromJSON(object: any): OptionalsTest_TranslationsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): OptionalsTest_TranslationsEntry { return OptionalsTest_TranslationsEntry.fromPartial(base ?? {}); }, @@ -677,15 +677,15 @@ export const Child = { return message; }, - fromJSON(_: any): Child { - return {}; - }, - toJSON(_: Child): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Child { + return {}; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/use-optionals-no-undefined/test.ts b/integration/use-optionals-no-undefined/test.ts index a0ae92741..c9919c30b 100644 --- a/integration/use-optionals-no-undefined/test.ts +++ b/integration/use-optionals-no-undefined/test.ts @@ -422,40 +422,6 @@ export const OptionalsTest = { return message; }, - fromJSON(object: any): OptionalsTest { - return { - id: isSet(object.id) ? Number(object.id) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, - long: isSet(object.long) ? Number(object.long) : undefined, - truth: isSet(object.truth) ? Boolean(object.truth) : undefined, - description: isSet(object.description) ? String(object.description) : undefined, - data: isSet(object.data) ? bytesFromBase64(object.data) : undefined, - repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : undefined, - repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : undefined, - repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : undefined, - repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : undefined, - repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : undefined, - repDescription: Array.isArray(object?.repDescription) - ? object.repDescription.map((e: any) => String(e)) - : undefined, - repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : undefined, - optId: isSet(object.optId) ? Number(object.optId) : undefined, - optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, - optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, - optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, - optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, - optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, - optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, - translations: isObject(object.translations) - ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : undefined, - }; - }, - toJSON(message: OptionalsTest): unknown { const obj: any = {}; if (message.id !== undefined && message.id !== 0) { @@ -533,6 +499,40 @@ export const OptionalsTest = { return obj; }, + fromJSON(object: any): OptionalsTest { + return { + id: isSet(object.id) ? Number(object.id) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, + long: isSet(object.long) ? Number(object.long) : undefined, + truth: isSet(object.truth) ? Boolean(object.truth) : undefined, + description: isSet(object.description) ? String(object.description) : undefined, + data: isSet(object.data) ? bytesFromBase64(object.data) : undefined, + repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : undefined, + repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : undefined, + repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : undefined, + repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : undefined, + repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : undefined, + repDescription: Array.isArray(object?.repDescription) + ? object.repDescription.map((e: any) => String(e)) + : undefined, + repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : undefined, + optId: isSet(object.optId) ? Number(object.optId) : undefined, + optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, + optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, + optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, + optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, + optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, + optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, + translations: isObject(object.translations) + ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : undefined, + }; + }, + create, I>>(base?: I): OptionalsTest { return OptionalsTest.fromPartial(base ?? {}); }, @@ -619,10 +619,6 @@ export const OptionalsTest_TranslationsEntry = { return message; }, - fromJSON(object: any): OptionalsTest_TranslationsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: OptionalsTest_TranslationsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -634,6 +630,10 @@ export const OptionalsTest_TranslationsEntry = { return obj; }, + fromJSON(object: any): OptionalsTest_TranslationsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): OptionalsTest_TranslationsEntry { return OptionalsTest_TranslationsEntry.fromPartial(base ?? {}); }, @@ -673,15 +673,15 @@ export const Child = { return message; }, - fromJSON(_: any): Child { - return {}; - }, - toJSON(_: Child): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Child { + return {}; + }, + create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/use-readonly-types/google/protobuf/field_mask.ts b/integration/use-readonly-types/google/protobuf/field_mask.ts index bb2f0e74f..d0a5cd6e5 100644 --- a/integration/use-readonly-types/google/protobuf/field_mask.ts +++ b/integration/use-readonly-types/google/protobuf/field_mask.ts @@ -243,6 +243,10 @@ export const FieldMask = { return message; }, + toJSON(message: FieldMask): string { + return message.paths.join(","); + }, + fromJSON(object: any): FieldMask { return { paths: typeof (object) === "string" @@ -253,10 +257,6 @@ export const FieldMask = { }; }, - toJSON(message: FieldMask): string { - return message.paths.join(","); - }, - create, I>>(base?: I): FieldMask { return FieldMask.fromPartial(base ?? {}); }, diff --git a/integration/use-readonly-types/google/protobuf/struct.ts b/integration/use-readonly-types/google/protobuf/struct.ts index 9cf68f024..4e2df0254 100644 --- a/integration/use-readonly-types/google/protobuf/struct.ts +++ b/integration/use-readonly-types/google/protobuf/struct.ts @@ -126,17 +126,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -151,6 +140,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -235,10 +235,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -250,6 +246,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -349,24 +349,6 @@ export const Value = { return message; }, - fromJSON(object: any): Value { - return { - kind: isSet(object.nullValue) - ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } - : isSet(object.numberValue) - ? { $case: "numberValue", numberValue: Number(object.numberValue) } - : isSet(object.stringValue) - ? { $case: "stringValue", stringValue: String(object.stringValue) } - : isSet(object.boolValue) - ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } - : isSet(object.structValue) - ? { $case: "structValue", structValue: object.structValue } - : isSet(object.listValue) - ? { $case: "listValue", listValue: [...object.listValue] } - : undefined, - }; - }, - toJSON(message: Value): unknown { const obj: any = {}; if (message.kind?.$case === "nullValue") { @@ -390,6 +372,24 @@ export const Value = { return obj; }, + fromJSON(object: any): Value { + return { + kind: isSet(object.nullValue) + ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } + : isSet(object.numberValue) + ? { $case: "numberValue", numberValue: Number(object.numberValue) } + : isSet(object.stringValue) + ? { $case: "stringValue", stringValue: String(object.stringValue) } + : isSet(object.boolValue) + ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } + : isSet(object.structValue) + ? { $case: "structValue", structValue: object.structValue } + : isSet(object.listValue) + ? { $case: "listValue", listValue: [...object.listValue] } + : undefined, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -503,10 +503,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -515,6 +511,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/use-readonly-types/use-readonly-types.ts b/integration/use-readonly-types/use-readonly-types.ts index c706088eb..3774ccd79 100644 --- a/integration/use-readonly-types/use-readonly-types.ts +++ b/integration/use-readonly-types/use-readonly-types.ts @@ -197,28 +197,6 @@ export const Entity = { return message; }, - fromJSON(object: any): Entity { - return { - intVal: isSet(object.intVal) ? Number(object.intVal) : 0, - stringVal: isSet(object.stringVal) ? String(object.stringVal) : "", - intArray: Array.isArray(object?.intArray) ? object.intArray.map((e: any) => Number(e)) : [], - stringArray: Array.isArray(object?.stringArray) ? object.stringArray.map((e: any) => String(e)) : [], - subEntity: isSet(object.subEntity) ? SubEntity.fromJSON(object.subEntity) : undefined, - subEntityArray: Array.isArray(object?.subEntityArray) - ? object.subEntityArray.map((e: any) => SubEntity.fromJSON(e)) - : [], - optionalIntVal: isSet(object.optionalIntVal) ? Number(object.optionalIntVal) : undefined, - fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined, - listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined, - structValue: isObject(object.structValue) ? object.structValue : undefined, - oneOfValue: isSet(object.theStringValue) - ? { $case: "theStringValue", theStringValue: String(object.theStringValue) } - : isSet(object.theIntValue) - ? { $case: "theIntValue", theIntValue: Number(object.theIntValue) } - : undefined, - }; - }, - toJSON(message: Entity): unknown { const obj: any = {}; if (message.intVal !== 0) { @@ -260,6 +238,28 @@ export const Entity = { return obj; }, + fromJSON(object: any): Entity { + return { + intVal: isSet(object.intVal) ? Number(object.intVal) : 0, + stringVal: isSet(object.stringVal) ? String(object.stringVal) : "", + intArray: Array.isArray(object?.intArray) ? object.intArray.map((e: any) => Number(e)) : [], + stringArray: Array.isArray(object?.stringArray) ? object.stringArray.map((e: any) => String(e)) : [], + subEntity: isSet(object.subEntity) ? SubEntity.fromJSON(object.subEntity) : undefined, + subEntityArray: Array.isArray(object?.subEntityArray) + ? object.subEntityArray.map((e: any) => SubEntity.fromJSON(e)) + : [], + optionalIntVal: isSet(object.optionalIntVal) ? Number(object.optionalIntVal) : undefined, + fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined, + listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined, + structValue: isObject(object.structValue) ? object.structValue : undefined, + oneOfValue: isSet(object.theStringValue) + ? { $case: "theStringValue", theStringValue: String(object.theStringValue) } + : isSet(object.theIntValue) + ? { $case: "theIntValue", theIntValue: Number(object.theIntValue) } + : undefined, + }; + }, + create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -331,10 +331,6 @@ export const SubEntity = { return message; }, - fromJSON(object: any): SubEntity { - return { subVal: isSet(object.subVal) ? Number(object.subVal) : 0 }; - }, - toJSON(message: SubEntity): unknown { const obj: any = {}; if (message.subVal !== 0) { @@ -343,6 +339,10 @@ export const SubEntity = { return obj; }, + fromJSON(object: any): SubEntity { + return { subVal: isSet(object.subVal) ? Number(object.subVal) : 0 }; + }, + create, I>>(base?: I): SubEntity { return SubEntity.fromPartial(base ?? {}); }, diff --git a/integration/value/google/protobuf/struct.ts b/integration/value/google/protobuf/struct.ts index b2486a866..7c416eb52 100644 --- a/integration/value/google/protobuf/struct.ts +++ b/integration/value/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -165,6 +154,17 @@ export const Struct = { return obj; }, + 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; + }, {}) + : {}, + }; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,10 +249,6 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,6 +260,10 @@ export const Struct_FieldsEntry = { return obj; }, + fromJSON(object: any): Struct_FieldsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; + }, + create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,17 +368,6 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -402,6 +391,17 @@ export const Value = { return obj; }, + 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, + }; + }, + create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,10 +490,6 @@ export const ListValue = { return message; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -502,6 +498,10 @@ export const ListValue = { return obj; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/value/google/protobuf/wrappers.ts b/integration/value/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/value/google/protobuf/wrappers.ts +++ b/integration/value/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/value/value.ts b/integration/value/value.ts index a8e9092b0..655130963 100644 --- a/integration/value/value.ts +++ b/integration/value/value.ts @@ -88,16 +88,6 @@ export const ValueMessage = { return message; }, - fromJSON(object: any): ValueMessage { - return { - value: isSet(object?.value) ? object.value : undefined, - anyList: Array.isArray(object.anyList) ? [...object.anyList] : undefined, - repeatedAny: Array.isArray(object?.repeatedAny) ? [...object.repeatedAny] : [], - repeatedStrings: Array.isArray(object?.repeatedStrings) ? object.repeatedStrings.map((e: any) => String(e)) : [], - structValue: isObject(object.structValue) ? object.structValue : undefined, - }; - }, - toJSON(message: ValueMessage): unknown { const obj: any = {}; if (message.value !== undefined) { @@ -118,6 +108,16 @@ export const ValueMessage = { return obj; }, + fromJSON(object: any): ValueMessage { + return { + value: isSet(object?.value) ? object.value : undefined, + anyList: Array.isArray(object.anyList) ? [...object.anyList] : undefined, + repeatedAny: Array.isArray(object?.repeatedAny) ? [...object.repeatedAny] : [], + repeatedStrings: Array.isArray(object?.repeatedStrings) ? object.repeatedStrings.map((e: any) => String(e)) : [], + structValue: isObject(object.structValue) ? object.structValue : undefined, + }; + }, + create, I>>(base?: I): ValueMessage { return ValueMessage.fromPartial(base ?? {}); }, diff --git a/integration/vector-tile/vector_tile.ts b/integration/vector-tile/vector_tile.ts index 7dfda0699..61e684c51 100644 --- a/integration/vector-tile/vector_tile.ts +++ b/integration/vector-tile/vector_tile.ts @@ -114,10 +114,6 @@ export const Tile = { return message; }, - fromJSON(object: any): Tile { - return { layers: Array.isArray(object?.layers) ? object.layers.map((e: any) => Tile_Layer.fromJSON(e)) : [] }; - }, - toJSON(message: Tile): unknown { const obj: any = {}; if (message.layers?.length) { @@ -126,6 +122,10 @@ export const Tile = { return obj; }, + fromJSON(object: any): Tile { + return { layers: Array.isArray(object?.layers) ? object.layers.map((e: any) => Tile_Layer.fromJSON(e)) : [] }; + }, + create, I>>(base?: I): Tile { return Tile.fromPartial(base ?? {}); }, @@ -232,18 +232,6 @@ export const Tile_Value = { return message; }, - fromJSON(object: any): Tile_Value { - return { - stringValue: isSet(object.stringValue) ? String(object.stringValue) : "", - floatValue: isSet(object.floatValue) ? Number(object.floatValue) : 0, - doubleValue: isSet(object.doubleValue) ? Number(object.doubleValue) : 0, - intValue: isSet(object.intValue) ? Number(object.intValue) : 0, - uintValue: isSet(object.uintValue) ? Number(object.uintValue) : 0, - sintValue: isSet(object.sintValue) ? Number(object.sintValue) : 0, - boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : false, - }; - }, - toJSON(message: Tile_Value): unknown { const obj: any = {}; if (message.stringValue !== "") { @@ -270,6 +258,18 @@ export const Tile_Value = { return obj; }, + fromJSON(object: any): Tile_Value { + return { + stringValue: isSet(object.stringValue) ? String(object.stringValue) : "", + floatValue: isSet(object.floatValue) ? Number(object.floatValue) : 0, + doubleValue: isSet(object.doubleValue) ? Number(object.doubleValue) : 0, + intValue: isSet(object.intValue) ? Number(object.intValue) : 0, + uintValue: isSet(object.uintValue) ? Number(object.uintValue) : 0, + sintValue: isSet(object.sintValue) ? Number(object.sintValue) : 0, + boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : false, + }; + }, + create, I>>(base?: I): Tile_Value { return Tile_Value.fromPartial(base ?? {}); }, @@ -376,15 +376,6 @@ export const Tile_Feature = { return message; }, - fromJSON(object: any): Tile_Feature { - return { - id: isSet(object.id) ? Number(object.id) : 0, - tags: Array.isArray(object?.tags) ? object.tags.map((e: any) => Number(e)) : [], - type: isSet(object.type) ? tile_GeomTypeFromJSON(object.type) : 0, - geometry: Array.isArray(object?.geometry) ? object.geometry.map((e: any) => Number(e)) : [], - }; - }, - toJSON(message: Tile_Feature): unknown { const obj: any = {}; if (message.id !== 0) { @@ -402,6 +393,15 @@ export const Tile_Feature = { return obj; }, + fromJSON(object: any): Tile_Feature { + return { + id: isSet(object.id) ? Number(object.id) : 0, + tags: Array.isArray(object?.tags) ? object.tags.map((e: any) => Number(e)) : [], + type: isSet(object.type) ? tile_GeomTypeFromJSON(object.type) : 0, + geometry: Array.isArray(object?.geometry) ? object.geometry.map((e: any) => Number(e)) : [], + }; + }, + create, I>>(base?: I): Tile_Feature { return Tile_Feature.fromPartial(base ?? {}); }, @@ -501,17 +501,6 @@ export const Tile_Layer = { return message; }, - fromJSON(object: any): Tile_Layer { - return { - version: isSet(object.version) ? Number(object.version) : 0, - name: isSet(object.name) ? String(object.name) : "", - features: Array.isArray(object?.features) ? object.features.map((e: any) => Tile_Feature.fromJSON(e)) : [], - keys: Array.isArray(object?.keys) ? object.keys.map((e: any) => String(e)) : [], - values: Array.isArray(object?.values) ? object.values.map((e: any) => Tile_Value.fromJSON(e)) : [], - extent: isSet(object.extent) ? Number(object.extent) : 0, - }; - }, - toJSON(message: Tile_Layer): unknown { const obj: any = {}; if (message.version !== 0) { @@ -535,6 +524,17 @@ export const Tile_Layer = { return obj; }, + fromJSON(object: any): Tile_Layer { + return { + version: isSet(object.version) ? Number(object.version) : 0, + name: isSet(object.name) ? String(object.name) : "", + features: Array.isArray(object?.features) ? object.features.map((e: any) => Tile_Feature.fromJSON(e)) : [], + keys: Array.isArray(object?.keys) ? object.keys.map((e: any) => String(e)) : [], + values: Array.isArray(object?.values) ? object.values.map((e: any) => Tile_Value.fromJSON(e)) : [], + extent: isSet(object.extent) ? Number(object.extent) : 0, + }; + }, + create, I>>(base?: I): Tile_Layer { return Tile_Layer.fromPartial(base ?? {}); }, diff --git a/integration/wrappers-regression/google/protobuf/empty.ts b/integration/wrappers-regression/google/protobuf/empty.ts index 1387d7ce4..d1b8ebf5b 100644 --- a/integration/wrappers-regression/google/protobuf/empty.ts +++ b/integration/wrappers-regression/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, - fromJSON(_: any): Empty { - return {}; - }, - toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, + fromJSON(_: any): Empty { + return {}; + }, + create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/wrappers-regression/google/protobuf/timestamp.ts b/integration/wrappers-regression/google/protobuf/timestamp.ts index 032f4ab29..4947dacaa 100644 --- a/integration/wrappers-regression/google/protobuf/timestamp.ts +++ b/integration/wrappers-regression/google/protobuf/timestamp.ts @@ -156,13 +156,6 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -174,6 +167,13 @@ export const Timestamp = { return obj; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/wrappers-regression/google/protobuf/wrappers.ts b/integration/wrappers-regression/google/protobuf/wrappers.ts index 6637762f8..14888eb05 100644 --- a/integration/wrappers-regression/google/protobuf/wrappers.ts +++ b/integration/wrappers-regression/google/protobuf/wrappers.ts @@ -129,10 +129,6 @@ export const DoubleValue = { return message; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -141,6 +137,10 @@ export const DoubleValue = { return obj; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,10 +187,6 @@ export const FloatValue = { return message; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -199,6 +195,10 @@ export const FloatValue = { return obj; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,10 +245,6 @@ export const Int64Value = { return message; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -257,6 +253,10 @@ export const Int64Value = { return obj; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,10 +303,6 @@ export const UInt64Value = { return message; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -315,6 +311,10 @@ export const UInt64Value = { return obj; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,10 +361,6 @@ export const Int32Value = { return message; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -373,6 +369,10 @@ export const Int32Value = { return obj; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,10 +419,6 @@ export const UInt32Value = { return message; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -431,6 +427,10 @@ export const UInt32Value = { return obj; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,10 +477,6 @@ export const BoolValue = { return message; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -489,6 +485,10 @@ export const BoolValue = { return obj; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,10 +535,6 @@ export const StringValue = { return message; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -547,6 +543,10 @@ export const StringValue = { return obj; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,10 +593,6 @@ export const BytesValue = { return message; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -605,6 +601,10 @@ export const BytesValue = { return obj; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/src/main.ts b/src/main.ts index 4d71cb9b4..dede10b00 100644 --- a/src/main.ts +++ b/src/main.ts @@ -236,14 +236,13 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri } if (options.outputJsonMethods) { if(options.outputJsonMethods === true || - options.outputEncodeMethods === "encode-only" || - options.outputEncodeMethods === "encode-no-creation" + options.outputJsonMethods === "encode-only" ){ - staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); + staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); } - if (options.outputEncodeMethods === true || options.outputEncodeMethods === "decode-only") { - staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); + if (options.outputJsonMethods === true || options.outputJsonMethods === "decode-only") { + staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); } } if (options.outputPartialMethods) { From 36b7d9d4dd032be47058d151dd72b8c24ff4d082 Mon Sep 17 00:00:00 2001 From: Francesco Battista Date: Tue, 18 Jul 2023 17:07:37 -0400 Subject: [PATCH 3/7] feat(ts-proto#859): inverted fromJSON and toJSON methods to avoid changing all tests --- integration/angular/simple-message.ts | 8 +- .../simple.ts | 8 +- integration/async-iterable-services/simple.ts | 8 +- integration/avoid-import-conflicts/simple.ts | 50 +- integration/avoid-import-conflicts/simple2.ts | 8 +- integration/barrel-imports/bar.ts | 8 +- integration/barrel-imports/foo.ts | 14 +- .../batching.ts | 100 ++-- integration/batching-with-context/batching.ts | 100 ++-- integration/batching/batching.ts | 100 ++-- integration/bytes-as-base64/message.ts | 8 +- .../bytes-node/google/protobuf/wrappers.ts | 72 +-- integration/bytes-node/point.ts | 14 +- integration/const-enum/const-enum.ts | 38 +- .../enums-as-literals-with-string-enums.ts | 8 +- .../enums-as-literals/enums-as-literals.ts | 8 +- integration/extensions/test.ts | 30 +- integration/fieldmask/fieldmask.ts | 8 +- .../fieldmask/google/protobuf/field_mask.ts | 8 +- integration/file-suffix/child.pb.ts | 8 +- .../google/protobuf/timestamp.pb.ts | 14 +- integration/file-suffix/parent.pb.ts | 16 +- .../from-partial-no-initialize/test.ts | 62 +-- integration/generic-metadata/hero.ts | 32 +- .../simple.ts | 8 +- .../generic-service-definitions/simple.ts | 8 +- integration/global-this/global-this.ts | 16 +- integration/groups/test.ts | 124 ++--- .../google/protobuf/timestamp.ts | 14 +- .../grpc-js-use-date-false.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../grpc-js-use-date-string.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../grpc-js-use-date-true.ts | 8 +- integration/grpc-js/google/protobuf/empty.ts | 8 +- integration/grpc-js/google/protobuf/struct.ts | 60 +-- .../grpc-js/google/protobuf/timestamp.ts | 14 +- .../grpc-js/google/protobuf/wrappers.ts | 72 +-- integration/grpc-js/simple.ts | 8 +- integration/grpc-web-abort-signal/example.ts | 116 ++--- integration/grpc-web-go-server/example.ts | 116 ++--- .../example.ts | 52 +- integration/grpc-web-no-streaming/example.ts | 52 +- integration/grpc-web/example.ts | 116 ++--- .../google/protobuf/timestamp.ts | 14 +- integration/import-mapping/mapping.ts | 44 +- integration/import-suffix/child.pb.ts | 8 +- .../google/protobuf/timestamp.pb.ts | 14 +- integration/import-suffix/parent.pb.ts | 16 +- integration/lower-case-svc-methods/math.ts | 24 +- integration/map-bigint-optional/test.ts | 36 +- integration/map-long-optional/test.ts | 36 +- integration/map-longstring-optional/test.ts | 36 +- .../nice-grpc/google/protobuf/empty.ts | 8 +- .../nice-grpc/google/protobuf/struct.ts | 60 +-- .../nice-grpc/google/protobuf/timestamp.ts | 14 +- .../nice-grpc/google/protobuf/wrappers.ts | 72 +-- integration/nice-grpc/simple.ts | 8 +- .../no-proto-package/no-proto-package.ts | 16 +- integration/omit-optionals/simple.ts | 14 +- integration/oneof-properties/oneof.ts | 40 +- .../google/protobuf/struct.ts | 74 +-- integration/oneof-unions-snake/simple.ts | 8 +- .../oneof-unions/google/protobuf/struct.ts | 74 +-- integration/oneof-unions/oneof.ts | 80 +-- integration/output-index/a.ts | 8 +- integration/point/point.ts | 22 +- integration/reserved-words/reserved-words.ts | 8 +- integration/return-observable/observable.ts | 16 +- .../simple-deprecated-fields/simple.ts | 28 +- integration/simple-esmodule-interop/simple.ts | 42 +- .../google/protobuf/timestamp.ts | 14 +- integration/simple-json-name/simple.ts | 26 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- integration/simple-long-bigint/simple.ts | 40 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- integration/simple-long-string/simple.ts | 38 +- .../simple-long/google/protobuf/wrappers.ts | 72 +-- integration/simple-long/simple.ts | 134 ++--- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- .../simple-optionals/import_dir/thing.ts | 8 +- integration/simple-optionals/simple.ts | 290 +++++------ integration/simple-optionals/thing.ts | 8 +- integration/simple-proto2/simple.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- .../google/type/date.ts | 16 +- .../import_dir/thing.ts | 8 +- .../simple-prototype-defaults/simple.ts | 470 ++++++++--------- .../simple-snake/google/protobuf/struct.ts | 60 +-- .../simple-snake/google/protobuf/timestamp.ts | 14 +- .../simple-snake/google/protobuf/wrappers.ts | 72 +-- integration/simple-snake/import_dir/thing.ts | 8 +- integration/simple-snake/simple.ts | 298 +++++------ .../google/protobuf/struct.ts | 60 +-- integration/simple-string-enums/simple.ts | 44 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- .../import_dir/thing.ts | 8 +- .../simple-unrecognized-enum/simple.ts | 290 +++++------ .../simple/google/protobuf/timestamp.ts | 14 +- .../simple/google/protobuf/wrappers.ts | 72 +-- integration/simple/google/type/date.ts | 16 +- integration/simple/import_dir/thing.ts | 8 +- integration/simple/simple.ts | 472 +++++++++--------- .../static-only-type-registry/bar/bar.ts | 8 +- integration/static-only-type-registry/foo.ts | 24 +- .../google/protobuf/struct.ts | 60 +-- .../google/protobuf/timestamp.ts | 14 +- integration/static-only/bar/bar.ts | 8 +- integration/static-only/foo.ts | 24 +- .../static-only/google/protobuf/struct.ts | 60 +-- .../static-only/google/protobuf/timestamp.ts | 14 +- integration/struct/google/protobuf/struct.ts | 60 +-- integration/struct/struct.ts | 8 +- integration/type-annotations/bar/bar.ts | 8 +- integration/type-annotations/foo.ts | 24 +- .../google/protobuf/struct.ts | 72 +-- .../google/protobuf/timestamp.ts | 16 +- integration/type-registry/bar/bar.ts | 8 +- integration/type-registry/foo.ts | 24 +- .../type-registry/google/protobuf/struct.ts | 72 +-- .../google/protobuf/timestamp.ts | 16 +- integration/types-with-underscores/file.ts | 16 +- .../google/protobuf/timestamp.ts | 14 +- integration/use-date-false/metadata.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../use-date-string/use-date-string.ts | 48 +- .../use-date-true/google/protobuf/empty.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- integration/use-date-true/use-date-true.ts | 48 +- integration/use-exact-types-false/foo.ts | 8 +- .../use-map-type/google/protobuf/struct.ts | 60 +-- .../use-map-type/google/protobuf/timestamp.ts | 14 +- integration/use-map-type/use-map-type.ts | 138 ++--- .../google/protobuf/struct.ts | 60 +-- integration/use-numeric-enum-json/simple.ts | 44 +- .../objectid/objectid.ts | 8 +- .../use-objectid-true.ts | 44 +- .../google/protobuf/timestamp.ts | 14 +- integration/use-optionals-all/test.ts | 82 +-- .../use-optionals-no-undefined/test.ts | 84 ++-- .../google/protobuf/field_mask.ts | 8 +- .../google/protobuf/struct.ts | 74 +-- .../use-readonly-types/use-readonly-types.ts | 52 +- integration/value/google/protobuf/struct.ts | 60 +-- integration/value/google/protobuf/wrappers.ts | 72 +-- integration/value/value.ts | 20 +- integration/vector-tile/vector_tile.ts | 72 +-- .../google/protobuf/empty.ts | 8 +- .../google/protobuf/timestamp.ts | 14 +- .../google/protobuf/wrappers.ts | 72 +-- src/main.ts | 6 +- 156 files changed, 3544 insertions(+), 3544 deletions(-) diff --git a/integration/angular/simple-message.ts b/integration/angular/simple-message.ts index ffa20dc20..bb230e72b 100644 --- a/integration/angular/simple-message.ts +++ b/integration/angular/simple-message.ts @@ -42,6 +42,10 @@ export const SimpleMessage = { return message; }, + fromJSON(object: any): SimpleMessage { + return { numberField: isSet(object.numberField) ? Number(object.numberField) : 0 }; + }, + toJSON(message: SimpleMessage): unknown { const obj: any = {}; if (message.numberField !== 0) { @@ -50,10 +54,6 @@ export const SimpleMessage = { return obj; }, - fromJSON(object: any): SimpleMessage { - return { numberField: isSet(object.numberField) ? Number(object.numberField) : 0 }; - }, - create, I>>(base?: I): SimpleMessage { return SimpleMessage.fromPartial(base ?? {}); }, diff --git a/integration/async-iterable-services-abort-signal/simple.ts b/integration/async-iterable-services-abort-signal/simple.ts index 8dea5cc48..bcfc7f913 100644 --- a/integration/async-iterable-services-abort-signal/simple.ts +++ b/integration/async-iterable-services-abort-signal/simple.ts @@ -75,6 +75,10 @@ export const EchoMsg = { } }, + fromJSON(object: any): EchoMsg { + return { body: isSet(object.body) ? String(object.body) : "" }; + }, + toJSON(message: EchoMsg): unknown { const obj: any = {}; if (message.body !== "") { @@ -83,10 +87,6 @@ export const EchoMsg = { return obj; }, - fromJSON(object: any): EchoMsg { - return { body: isSet(object.body) ? String(object.body) : "" }; - }, - create, I>>(base?: I): EchoMsg { return EchoMsg.fromPartial(base ?? {}); }, diff --git a/integration/async-iterable-services/simple.ts b/integration/async-iterable-services/simple.ts index 848a65bea..a06a74093 100644 --- a/integration/async-iterable-services/simple.ts +++ b/integration/async-iterable-services/simple.ts @@ -75,6 +75,10 @@ export const EchoMsg = { } }, + fromJSON(object: any): EchoMsg { + return { body: isSet(object.body) ? String(object.body) : "" }; + }, + toJSON(message: EchoMsg): unknown { const obj: any = {}; if (message.body !== "") { @@ -83,10 +87,6 @@ export const EchoMsg = { return obj; }, - fromJSON(object: any): EchoMsg { - return { body: isSet(object.body) ? String(object.body) : "" }; - }, - create, I>>(base?: I): EchoMsg { return EchoMsg.fromPartial(base ?? {}); }, diff --git a/integration/avoid-import-conflicts/simple.ts b/integration/avoid-import-conflicts/simple.ts index bb6172c8a..299bbe76c 100644 --- a/integration/avoid-import-conflicts/simple.ts +++ b/integration/avoid-import-conflicts/simple.ts @@ -6,8 +6,8 @@ import { fooServiceToJSON, Simple as Simple3, SimpleEnum as SimpleEnum1, - simpleEnumFromJSON as simpleEnumFromJSON5, - simpleEnumToJSON as simpleEnumToJSON4, + simpleEnumFromJSON as simpleEnumFromJSON4, + simpleEnumToJSON as simpleEnumToJSON5, } from "./simple2"; export const protobufPackage = "simple"; @@ -114,6 +114,13 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + otherSimple: isSet(object.otherSimple) ? Simple3.fromJSON(object.otherSimple) : undefined, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -125,13 +132,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - otherSimple: isSet(object.otherSimple) ? Simple3.fromJSON(object.otherSimple) : undefined, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -191,24 +191,24 @@ export const SimpleEnums = { return message; }, + fromJSON(object: any): SimpleEnums { + return { + localEnum: isSet(object.localEnum) ? simpleEnumFromJSON(object.localEnum) : 0, + importEnum: isSet(object.importEnum) ? simpleEnumFromJSON4(object.importEnum) : 0, + }; + }, + toJSON(message: SimpleEnums): unknown { const obj: any = {}; if (message.localEnum !== 0) { obj.localEnum = simpleEnumToJSON(message.localEnum); } if (message.importEnum !== 0) { - obj.importEnum = simpleEnumToJSON4(message.importEnum); + obj.importEnum = simpleEnumToJSON5(message.importEnum); } return obj; }, - fromJSON(object: any): SimpleEnums { - return { - localEnum: isSet(object.localEnum) ? simpleEnumFromJSON(object.localEnum) : 0, - importEnum: isSet(object.importEnum) ? simpleEnumFromJSON5(object.importEnum) : 0, - }; - }, - create, I>>(base?: I): SimpleEnums { return SimpleEnums.fromPartial(base ?? {}); }, @@ -256,6 +256,10 @@ export const FooServiceCreateRequest = { return message; }, + fromJSON(object: any): FooServiceCreateRequest { + return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; + }, + toJSON(message: FooServiceCreateRequest): unknown { const obj: any = {}; if (message.kind !== 0) { @@ -264,10 +268,6 @@ export const FooServiceCreateRequest = { return obj; }, - fromJSON(object: any): FooServiceCreateRequest { - return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; - }, - create, I>>(base?: I): FooServiceCreateRequest { return FooServiceCreateRequest.fromPartial(base ?? {}); }, @@ -314,6 +314,10 @@ export const FooServiceCreateResponse = { return message; }, + fromJSON(object: any): FooServiceCreateResponse { + return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; + }, + toJSON(message: FooServiceCreateResponse): unknown { const obj: any = {}; if (message.kind !== 0) { @@ -322,10 +326,6 @@ export const FooServiceCreateResponse = { return obj; }, - fromJSON(object: any): FooServiceCreateResponse { - return { kind: isSet(object.kind) ? fooServiceFromJSON(object.kind) : 0 }; - }, - create, I>>(base?: I): FooServiceCreateResponse { return FooServiceCreateResponse.fromPartial(base ?? {}); }, diff --git a/integration/avoid-import-conflicts/simple2.ts b/integration/avoid-import-conflicts/simple2.ts index ab9c1c448..111f0665e 100644 --- a/integration/avoid-import-conflicts/simple2.ts +++ b/integration/avoid-import-conflicts/simple2.ts @@ -131,6 +131,10 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -142,10 +146,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, diff --git a/integration/barrel-imports/bar.ts b/integration/barrel-imports/bar.ts index 4e98ffb1f..7ea77bd2a 100644 --- a/integration/barrel-imports/bar.ts +++ b/integration/barrel-imports/bar.ts @@ -51,6 +51,10 @@ export const Bar = { return message; }, + fromJSON(object: any): Bar { + return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; + }, + toJSON(message: Bar): unknown { const obj: any = {}; if (message.name !== "") { @@ -62,10 +66,6 @@ export const Bar = { return obj; }, - fromJSON(object: any): Bar { - return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; - }, - create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/barrel-imports/foo.ts b/integration/barrel-imports/foo.ts index c98443de4..e5a81e984 100644 --- a/integration/barrel-imports/foo.ts +++ b/integration/barrel-imports/foo.ts @@ -52,6 +52,13 @@ export const Foo = { return message; }, + fromJSON(object: any): Foo { + return { + name: isSet(object.name) ? String(object.name) : "", + bar: isSet(object.bar) ? Bar.fromJSON(object.bar) : undefined, + }; + }, + toJSON(message: Foo): unknown { const obj: any = {}; if (message.name !== "") { @@ -63,13 +70,6 @@ export const Foo = { return obj; }, - fromJSON(object: any): Foo { - return { - name: isSet(object.name) ? String(object.name) : "", - bar: isSet(object.bar) ? Bar.fromJSON(object.bar) : undefined, - }; - }, - create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, diff --git a/integration/batching-with-context-esModuleInterop/batching.ts b/integration/batching-with-context-esModuleInterop/batching.ts index be79ca4d4..ff89bf541 100644 --- a/integration/batching-with-context-esModuleInterop/batching.ts +++ b/integration/batching-with-context-esModuleInterop/batching.ts @@ -81,6 +81,10 @@ export const BatchQueryRequest = { return message; }, + fromJSON(object: any): BatchQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + toJSON(message: BatchQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -89,10 +93,6 @@ export const BatchQueryRequest = { return obj; }, - fromJSON(object: any): BatchQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - create, I>>(base?: I): BatchQueryRequest { return BatchQueryRequest.fromPartial(base ?? {}); }, @@ -139,6 +139,10 @@ export const BatchQueryResponse = { return message; }, + fromJSON(object: any): BatchQueryResponse { + return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; + }, + toJSON(message: BatchQueryResponse): unknown { const obj: any = {}; if (message.entities?.length) { @@ -147,10 +151,6 @@ export const BatchQueryResponse = { return obj; }, - fromJSON(object: any): BatchQueryResponse { - return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; - }, - create, I>>(base?: I): BatchQueryResponse { return BatchQueryResponse.fromPartial(base ?? {}); }, @@ -197,6 +197,10 @@ export const BatchMapQueryRequest = { return message; }, + fromJSON(object: any): BatchMapQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + toJSON(message: BatchMapQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -205,10 +209,6 @@ export const BatchMapQueryRequest = { return obj; }, - fromJSON(object: any): BatchMapQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - create, I>>(base?: I): BatchMapQueryRequest { return BatchMapQueryRequest.fromPartial(base ?? {}); }, @@ -258,6 +258,17 @@ export const BatchMapQueryResponse = { return message; }, + fromJSON(object: any): BatchMapQueryResponse { + return { + entities: isObject(object.entities) + ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { + acc[key] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: BatchMapQueryResponse): unknown { const obj: any = {}; if (message.entities) { @@ -272,17 +283,6 @@ export const BatchMapQueryResponse = { return obj; }, - fromJSON(object: any): BatchMapQueryResponse { - return { - entities: isObject(object.entities) - ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { - acc[key] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): BatchMapQueryResponse { return BatchMapQueryResponse.fromPartial(base ?? {}); }, @@ -344,6 +344,13 @@ export const BatchMapQueryResponse_EntitiesEntry = { return message; }, + fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: BatchMapQueryResponse_EntitiesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -355,13 +362,6 @@ export const BatchMapQueryResponse_EntitiesEntry = { return obj; }, - fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): BatchMapQueryResponse_EntitiesEntry { @@ -415,6 +415,10 @@ export const GetOnlyMethodRequest = { return message; }, + fromJSON(object: any): GetOnlyMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + toJSON(message: GetOnlyMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -423,10 +427,6 @@ export const GetOnlyMethodRequest = { return obj; }, - fromJSON(object: any): GetOnlyMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - create, I>>(base?: I): GetOnlyMethodRequest { return GetOnlyMethodRequest.fromPartial(base ?? {}); }, @@ -473,6 +473,10 @@ export const GetOnlyMethodResponse = { return message; }, + fromJSON(object: any): GetOnlyMethodResponse { + return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; + }, + toJSON(message: GetOnlyMethodResponse): unknown { const obj: any = {}; if (message.entity !== undefined) { @@ -481,10 +485,6 @@ export const GetOnlyMethodResponse = { return obj; }, - fromJSON(object: any): GetOnlyMethodResponse { - return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; - }, - create, I>>(base?: I): GetOnlyMethodResponse { return GetOnlyMethodResponse.fromPartial(base ?? {}); }, @@ -533,6 +533,10 @@ export const WriteMethodRequest = { return message; }, + fromJSON(object: any): WriteMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + toJSON(message: WriteMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -541,10 +545,6 @@ export const WriteMethodRequest = { return obj; }, - fromJSON(object: any): WriteMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - create, I>>(base?: I): WriteMethodRequest { return WriteMethodRequest.fromPartial(base ?? {}); }, @@ -581,15 +581,15 @@ export const WriteMethodResponse = { return message; }, + fromJSON(_: any): WriteMethodResponse { + return {}; + }, + toJSON(_: WriteMethodResponse): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): WriteMethodResponse { - return {}; - }, - create, I>>(base?: I): WriteMethodResponse { return WriteMethodResponse.fromPartial(base ?? {}); }, @@ -645,6 +645,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== "") { @@ -656,10 +660,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, diff --git a/integration/batching-with-context/batching.ts b/integration/batching-with-context/batching.ts index e81cf661f..77b71e738 100644 --- a/integration/batching-with-context/batching.ts +++ b/integration/batching-with-context/batching.ts @@ -81,6 +81,10 @@ export const BatchQueryRequest = { return message; }, + fromJSON(object: any): BatchQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + toJSON(message: BatchQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -89,10 +93,6 @@ export const BatchQueryRequest = { return obj; }, - fromJSON(object: any): BatchQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - create, I>>(base?: I): BatchQueryRequest { return BatchQueryRequest.fromPartial(base ?? {}); }, @@ -139,6 +139,10 @@ export const BatchQueryResponse = { return message; }, + fromJSON(object: any): BatchQueryResponse { + return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; + }, + toJSON(message: BatchQueryResponse): unknown { const obj: any = {}; if (message.entities?.length) { @@ -147,10 +151,6 @@ export const BatchQueryResponse = { return obj; }, - fromJSON(object: any): BatchQueryResponse { - return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; - }, - create, I>>(base?: I): BatchQueryResponse { return BatchQueryResponse.fromPartial(base ?? {}); }, @@ -197,6 +197,10 @@ export const BatchMapQueryRequest = { return message; }, + fromJSON(object: any): BatchMapQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + toJSON(message: BatchMapQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -205,10 +209,6 @@ export const BatchMapQueryRequest = { return obj; }, - fromJSON(object: any): BatchMapQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - create, I>>(base?: I): BatchMapQueryRequest { return BatchMapQueryRequest.fromPartial(base ?? {}); }, @@ -258,6 +258,17 @@ export const BatchMapQueryResponse = { return message; }, + fromJSON(object: any): BatchMapQueryResponse { + return { + entities: isObject(object.entities) + ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { + acc[key] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: BatchMapQueryResponse): unknown { const obj: any = {}; if (message.entities) { @@ -272,17 +283,6 @@ export const BatchMapQueryResponse = { return obj; }, - fromJSON(object: any): BatchMapQueryResponse { - return { - entities: isObject(object.entities) - ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { - acc[key] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): BatchMapQueryResponse { return BatchMapQueryResponse.fromPartial(base ?? {}); }, @@ -344,6 +344,13 @@ export const BatchMapQueryResponse_EntitiesEntry = { return message; }, + fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: BatchMapQueryResponse_EntitiesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -355,13 +362,6 @@ export const BatchMapQueryResponse_EntitiesEntry = { return obj; }, - fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): BatchMapQueryResponse_EntitiesEntry { @@ -415,6 +415,10 @@ export const GetOnlyMethodRequest = { return message; }, + fromJSON(object: any): GetOnlyMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + toJSON(message: GetOnlyMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -423,10 +427,6 @@ export const GetOnlyMethodRequest = { return obj; }, - fromJSON(object: any): GetOnlyMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - create, I>>(base?: I): GetOnlyMethodRequest { return GetOnlyMethodRequest.fromPartial(base ?? {}); }, @@ -473,6 +473,10 @@ export const GetOnlyMethodResponse = { return message; }, + fromJSON(object: any): GetOnlyMethodResponse { + return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; + }, + toJSON(message: GetOnlyMethodResponse): unknown { const obj: any = {}; if (message.entity !== undefined) { @@ -481,10 +485,6 @@ export const GetOnlyMethodResponse = { return obj; }, - fromJSON(object: any): GetOnlyMethodResponse { - return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; - }, - create, I>>(base?: I): GetOnlyMethodResponse { return GetOnlyMethodResponse.fromPartial(base ?? {}); }, @@ -533,6 +533,10 @@ export const WriteMethodRequest = { return message; }, + fromJSON(object: any): WriteMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + toJSON(message: WriteMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -541,10 +545,6 @@ export const WriteMethodRequest = { return obj; }, - fromJSON(object: any): WriteMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - create, I>>(base?: I): WriteMethodRequest { return WriteMethodRequest.fromPartial(base ?? {}); }, @@ -581,15 +581,15 @@ export const WriteMethodResponse = { return message; }, + fromJSON(_: any): WriteMethodResponse { + return {}; + }, + toJSON(_: WriteMethodResponse): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): WriteMethodResponse { - return {}; - }, - create, I>>(base?: I): WriteMethodResponse { return WriteMethodResponse.fromPartial(base ?? {}); }, @@ -645,6 +645,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== "") { @@ -656,10 +660,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, diff --git a/integration/batching/batching.ts b/integration/batching/batching.ts index a5595363a..ea5e6ddbb 100644 --- a/integration/batching/batching.ts +++ b/integration/batching/batching.ts @@ -79,6 +79,10 @@ export const BatchQueryRequest = { return message; }, + fromJSON(object: any): BatchQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + toJSON(message: BatchQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -87,10 +91,6 @@ export const BatchQueryRequest = { return obj; }, - fromJSON(object: any): BatchQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - create, I>>(base?: I): BatchQueryRequest { return BatchQueryRequest.fromPartial(base ?? {}); }, @@ -137,6 +137,10 @@ export const BatchQueryResponse = { return message; }, + fromJSON(object: any): BatchQueryResponse { + return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; + }, + toJSON(message: BatchQueryResponse): unknown { const obj: any = {}; if (message.entities?.length) { @@ -145,10 +149,6 @@ export const BatchQueryResponse = { return obj; }, - fromJSON(object: any): BatchQueryResponse { - return { entities: Array.isArray(object?.entities) ? object.entities.map((e: any) => Entity.fromJSON(e)) : [] }; - }, - create, I>>(base?: I): BatchQueryResponse { return BatchQueryResponse.fromPartial(base ?? {}); }, @@ -195,6 +195,10 @@ export const BatchMapQueryRequest = { return message; }, + fromJSON(object: any): BatchMapQueryRequest { + return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; + }, + toJSON(message: BatchMapQueryRequest): unknown { const obj: any = {}; if (message.ids?.length) { @@ -203,10 +207,6 @@ export const BatchMapQueryRequest = { return obj; }, - fromJSON(object: any): BatchMapQueryRequest { - return { ids: Array.isArray(object?.ids) ? object.ids.map((e: any) => String(e)) : [] }; - }, - create, I>>(base?: I): BatchMapQueryRequest { return BatchMapQueryRequest.fromPartial(base ?? {}); }, @@ -256,6 +256,17 @@ export const BatchMapQueryResponse = { return message; }, + fromJSON(object: any): BatchMapQueryResponse { + return { + entities: isObject(object.entities) + ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { + acc[key] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: BatchMapQueryResponse): unknown { const obj: any = {}; if (message.entities) { @@ -270,17 +281,6 @@ export const BatchMapQueryResponse = { return obj; }, - fromJSON(object: any): BatchMapQueryResponse { - return { - entities: isObject(object.entities) - ? Object.entries(object.entities).reduce<{ [key: string]: Entity }>((acc, [key, value]) => { - acc[key] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): BatchMapQueryResponse { return BatchMapQueryResponse.fromPartial(base ?? {}); }, @@ -342,6 +342,13 @@ export const BatchMapQueryResponse_EntitiesEntry = { return message; }, + fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: BatchMapQueryResponse_EntitiesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -353,13 +360,6 @@ export const BatchMapQueryResponse_EntitiesEntry = { return obj; }, - fromJSON(object: any): BatchMapQueryResponse_EntitiesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): BatchMapQueryResponse_EntitiesEntry { @@ -413,6 +413,10 @@ export const GetOnlyMethodRequest = { return message; }, + fromJSON(object: any): GetOnlyMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + toJSON(message: GetOnlyMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -421,10 +425,6 @@ export const GetOnlyMethodRequest = { return obj; }, - fromJSON(object: any): GetOnlyMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - create, I>>(base?: I): GetOnlyMethodRequest { return GetOnlyMethodRequest.fromPartial(base ?? {}); }, @@ -471,6 +471,10 @@ export const GetOnlyMethodResponse = { return message; }, + fromJSON(object: any): GetOnlyMethodResponse { + return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; + }, + toJSON(message: GetOnlyMethodResponse): unknown { const obj: any = {}; if (message.entity !== undefined) { @@ -479,10 +483,6 @@ export const GetOnlyMethodResponse = { return obj; }, - fromJSON(object: any): GetOnlyMethodResponse { - return { entity: isSet(object.entity) ? Entity.fromJSON(object.entity) : undefined }; - }, - create, I>>(base?: I): GetOnlyMethodResponse { return GetOnlyMethodResponse.fromPartial(base ?? {}); }, @@ -531,6 +531,10 @@ export const WriteMethodRequest = { return message; }, + fromJSON(object: any): WriteMethodRequest { + return { id: isSet(object.id) ? String(object.id) : "" }; + }, + toJSON(message: WriteMethodRequest): unknown { const obj: any = {}; if (message.id !== "") { @@ -539,10 +543,6 @@ export const WriteMethodRequest = { return obj; }, - fromJSON(object: any): WriteMethodRequest { - return { id: isSet(object.id) ? String(object.id) : "" }; - }, - create, I>>(base?: I): WriteMethodRequest { return WriteMethodRequest.fromPartial(base ?? {}); }, @@ -579,15 +579,15 @@ export const WriteMethodResponse = { return message; }, + fromJSON(_: any): WriteMethodResponse { + return {}; + }, + toJSON(_: WriteMethodResponse): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): WriteMethodResponse { - return {}; - }, - create, I>>(base?: I): WriteMethodResponse { return WriteMethodResponse.fromPartial(base ?? {}); }, @@ -643,6 +643,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== "") { @@ -654,10 +658,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? String(object.id) : "", name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, diff --git a/integration/bytes-as-base64/message.ts b/integration/bytes-as-base64/message.ts index ced9d34b0..9678e3084 100644 --- a/integration/bytes-as-base64/message.ts +++ b/integration/bytes-as-base64/message.ts @@ -11,6 +11,10 @@ function createBaseMessage(): Message { } export const Message = { + fromJSON(object: any): Message { + return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0) }; + }, + toJSON(message: Message): unknown { const obj: any = {}; if (message.data.length !== 0) { @@ -19,10 +23,6 @@ export const Message = { return obj; }, - fromJSON(object: any): Message { - return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0) }; - }, - create, I>>(base?: I): Message { return Message.fromPartial(base ?? {}); }, diff --git a/integration/bytes-node/google/protobuf/wrappers.ts b/integration/bytes-node/google/protobuf/wrappers.ts index 045c1aba7..1bbfbcb1d 100644 --- a/integration/bytes-node/google/protobuf/wrappers.ts +++ b/integration/bytes-node/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? Buffer.from(bytesFromBase64(object.value)) : Buffer.alloc(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? Buffer.from(bytesFromBase64(object.value)) : Buffer.alloc(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/bytes-node/point.ts b/integration/bytes-node/point.ts index 96abb30ef..c9f0a51e0 100644 --- a/integration/bytes-node/point.ts +++ b/integration/bytes-node/point.ts @@ -54,6 +54,13 @@ export const Point = { return message; }, + fromJSON(object: any): Point { + return { + data: isSet(object.data) ? Buffer.from(bytesFromBase64(object.data)) : Buffer.alloc(0), + dataWrapped: isSet(object.dataWrapped) ? new Buffer(object.dataWrapped) : undefined, + }; + }, + toJSON(message: Point): unknown { const obj: any = {}; if (message.data.length !== 0) { @@ -65,13 +72,6 @@ export const Point = { return obj; }, - fromJSON(object: any): Point { - return { - data: isSet(object.data) ? Buffer.from(bytesFromBase64(object.data)) : Buffer.alloc(0), - dataWrapped: isSet(object.dataWrapped) ? new Buffer(object.dataWrapped) : undefined, - }; - }, - create, I>>(base?: I): Point { return Point.fromPartial(base ?? {}); }, diff --git a/integration/const-enum/const-enum.ts b/integration/const-enum/const-enum.ts index de3ee3841..c6140f96d 100644 --- a/integration/const-enum/const-enum.ts +++ b/integration/const-enum/const-enum.ts @@ -122,6 +122,18 @@ export const DividerData = { return message; }, + fromJSON(object: any): DividerData { + return { + type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE, + typeMap: isObject(object.typeMap) + ? Object.entries(object.typeMap).reduce<{ [key: string]: DividerData_DividerType }>((acc, [key, value]) => { + acc[key] = dividerData_DividerTypeFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: DividerData): unknown { const obj: any = {}; if (message.type !== DividerData_DividerType.DOUBLE) { @@ -139,18 +151,6 @@ export const DividerData = { return obj; }, - fromJSON(object: any): DividerData { - return { - type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE, - typeMap: isObject(object.typeMap) - ? Object.entries(object.typeMap).reduce<{ [key: string]: DividerData_DividerType }>((acc, [key, value]) => { - acc[key] = dividerData_DividerTypeFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): DividerData { return DividerData.fromPartial(base ?? {}); }, @@ -216,6 +216,13 @@ export const DividerData_TypeMapEntry = { return message; }, + fromJSON(object: any): DividerData_TypeMapEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? dividerData_DividerTypeFromJSON(object.value) : DividerData_DividerType.DOUBLE, + }; + }, + toJSON(message: DividerData_TypeMapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -227,13 +234,6 @@ export const DividerData_TypeMapEntry = { return obj; }, - fromJSON(object: any): DividerData_TypeMapEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? dividerData_DividerTypeFromJSON(object.value) : DividerData_DividerType.DOUBLE, - }; - }, - create, I>>(base?: I): DividerData_TypeMapEntry { return DividerData_TypeMapEntry.fromPartial(base ?? {}); }, diff --git a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts index 887f71a48..554f21662 100644 --- a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts +++ b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts @@ -105,6 +105,10 @@ export const DividerData = { return message; }, + fromJSON(object: any): DividerData { + return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE }; + }, + toJSON(message: DividerData): unknown { const obj: any = {}; if (message.type !== DividerData_DividerType.DOUBLE) { @@ -113,10 +117,6 @@ export const DividerData = { return obj; }, - fromJSON(object: any): DividerData { - return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : DividerData_DividerType.DOUBLE }; - }, - create, I>>(base?: I): DividerData { return DividerData.fromPartial(base ?? {}); }, diff --git a/integration/enums-as-literals/enums-as-literals.ts b/integration/enums-as-literals/enums-as-literals.ts index 48abc99f4..93d1914a0 100644 --- a/integration/enums-as-literals/enums-as-literals.ts +++ b/integration/enums-as-literals/enums-as-literals.ts @@ -83,6 +83,10 @@ export const DividerData = { return message; }, + fromJSON(object: any): DividerData { + return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : 0 }; + }, + toJSON(message: DividerData): unknown { const obj: any = {}; if (message.type !== 0) { @@ -91,10 +95,6 @@ export const DividerData = { return obj; }, - fromJSON(object: any): DividerData { - return { type: isSet(object.type) ? dividerData_DividerTypeFromJSON(object.type) : 0 }; - }, - create, I>>(base?: I): DividerData { return DividerData.fromPartial(base ?? {}); }, diff --git a/integration/extensions/test.ts b/integration/extensions/test.ts index 00a87945d..e843bccac 100644 --- a/integration/extensions/test.ts +++ b/integration/extensions/test.ts @@ -173,6 +173,10 @@ export const Extendable = { return results; }, + fromJSON(object: any): Extendable { + return { field: isSet(object.field) ? String(object.field) : undefined }; + }, + toJSON(message: Extendable): unknown { const obj: any = {}; if (message.field !== undefined && message.field !== "") { @@ -181,10 +185,6 @@ export const Extendable = { return obj; }, - fromJSON(object: any): Extendable { - return { field: isSet(object.field) ? String(object.field) : undefined }; - }, - create, I>>(base?: I): Extendable { return Extendable.fromPartial(base ?? {}); }, @@ -283,6 +283,10 @@ export const Nested = { return message; }, + fromJSON(object: any): Nested { + return { field: isSet(object.field) ? String(object.field) : undefined }; + }, + toJSON(message: Nested): unknown { const obj: any = {}; if (message.field !== undefined && message.field !== "") { @@ -291,10 +295,6 @@ export const Nested = { return obj; }, - fromJSON(object: any): Nested { - return { field: isSet(object.field) ? String(object.field) : undefined }; - }, - create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -378,6 +378,13 @@ export const Group = { return message; }, + fromJSON(object: any): Group { + return { + name: isSet(object.name) ? String(object.name) : undefined, + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + toJSON(message: Group): unknown { const obj: any = {}; if (message.name !== undefined && message.name !== "") { @@ -389,13 +396,6 @@ export const Group = { return obj; }, - fromJSON(object: any): Group { - return { - name: isSet(object.name) ? String(object.name) : undefined, - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - create, I>>(base?: I): Group { return Group.fromPartial(base ?? {}); }, diff --git a/integration/fieldmask/fieldmask.ts b/integration/fieldmask/fieldmask.ts index 2076e88a4..8b908180b 100644 --- a/integration/fieldmask/fieldmask.ts +++ b/integration/fieldmask/fieldmask.ts @@ -43,6 +43,10 @@ export const FieldMaskMessage = { return message; }, + fromJSON(object: any): FieldMaskMessage { + return { fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined }; + }, + toJSON(message: FieldMaskMessage): unknown { const obj: any = {}; if (message.fieldMask !== undefined) { @@ -51,10 +55,6 @@ export const FieldMaskMessage = { return obj; }, - fromJSON(object: any): FieldMaskMessage { - return { fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined }; - }, - create, I>>(base?: I): FieldMaskMessage { return FieldMaskMessage.fromPartial(base ?? {}); }, diff --git a/integration/fieldmask/google/protobuf/field_mask.ts b/integration/fieldmask/google/protobuf/field_mask.ts index 6c3b36dcc..327bf5421 100644 --- a/integration/fieldmask/google/protobuf/field_mask.ts +++ b/integration/fieldmask/google/protobuf/field_mask.ts @@ -243,10 +243,6 @@ export const FieldMask = { return message; }, - toJSON(message: FieldMask): string { - return message.paths.join(","); - }, - fromJSON(object: any): FieldMask { return { paths: typeof (object) === "string" @@ -257,6 +253,10 @@ export const FieldMask = { }; }, + toJSON(message: FieldMask): string { + return message.paths.join(","); + }, + create, I>>(base?: I): FieldMask { return FieldMask.fromPartial(base ?? {}); }, diff --git a/integration/file-suffix/child.pb.ts b/integration/file-suffix/child.pb.ts index e55d20909..8c91027c8 100644 --- a/integration/file-suffix/child.pb.ts +++ b/integration/file-suffix/child.pb.ts @@ -75,6 +75,10 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -83,10 +87,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/file-suffix/google/protobuf/timestamp.pb.ts b/integration/file-suffix/google/protobuf/timestamp.pb.ts index 4947dacaa..032f4ab29 100644 --- a/integration/file-suffix/google/protobuf/timestamp.pb.ts +++ b/integration/file-suffix/google/protobuf/timestamp.pb.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/file-suffix/parent.pb.ts b/integration/file-suffix/parent.pb.ts index 5ec327104..8cd18e863 100644 --- a/integration/file-suffix/parent.pb.ts +++ b/integration/file-suffix/parent.pb.ts @@ -66,6 +66,14 @@ export const Parent = { return message; }, + fromJSON(object: any): Parent { + return { + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + }; + }, + toJSON(message: Parent): unknown { const obj: any = {}; if (message.child !== undefined) { @@ -80,14 +88,6 @@ export const Parent = { return obj; }, - fromJSON(object: any): Parent { - return { - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - }; - }, - create, I>>(base?: I): Parent { return Parent.fromPartial(base ?? {}); }, diff --git a/integration/from-partial-no-initialize/test.ts b/integration/from-partial-no-initialize/test.ts index 5ed74541a..4dc48cfcb 100644 --- a/integration/from-partial-no-initialize/test.ts +++ b/integration/from-partial-no-initialize/test.ts @@ -57,6 +57,10 @@ export const TPartialMessage = { return message; }, + fromJSON(object: any): TPartialMessage { + return { field: isSet(object.field) ? String(object.field) : undefined }; + }, + toJSON(message: TPartialMessage): unknown { const obj: any = {}; if (message.field !== undefined && message.field !== "") { @@ -65,10 +69,6 @@ export const TPartialMessage = { return obj; }, - fromJSON(object: any): TPartialMessage { - return { field: isSet(object.field) ? String(object.field) : undefined }; - }, - create, I>>(base?: I): TPartialMessage { return TPartialMessage.fromPartial(base ?? {}); }, @@ -211,6 +211,29 @@ export const TPartial = { return message; }, + fromJSON(object: any): TPartial { + return { + number: isSet(object.number) ? Number(object.number) : undefined, + string: isSet(object.string) ? String(object.string) : undefined, + map: isObject(object.map) + ? Object.entries(object.map).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : undefined, + message: isSet(object.message) ? TPartialMessage.fromJSON(object.message) : undefined, + repeatedMessage: Array.isArray(object?.repeatedMessage) + ? object.repeatedMessage.map((e: any) => TPartialMessage.fromJSON(e)) + : undefined, + repeatedString: Array.isArray(object?.repeatedString) + ? object.repeatedString.map((e: any) => String(e)) + : undefined, + repeatedNumber: Array.isArray(object?.repeatedNumber) + ? object.repeatedNumber.map((e: any) => Number(e)) + : undefined, + }; + }, + toJSON(message: TPartial): unknown { const obj: any = {}; if (message.number !== undefined && message.number !== 0) { @@ -243,29 +266,6 @@ export const TPartial = { return obj; }, - fromJSON(object: any): TPartial { - return { - number: isSet(object.number) ? Number(object.number) : undefined, - string: isSet(object.string) ? String(object.string) : undefined, - map: isObject(object.map) - ? Object.entries(object.map).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : undefined, - message: isSet(object.message) ? TPartialMessage.fromJSON(object.message) : undefined, - repeatedMessage: Array.isArray(object?.repeatedMessage) - ? object.repeatedMessage.map((e: any) => TPartialMessage.fromJSON(e)) - : undefined, - repeatedString: Array.isArray(object?.repeatedString) - ? object.repeatedString.map((e: any) => String(e)) - : undefined, - repeatedNumber: Array.isArray(object?.repeatedNumber) - ? object.repeatedNumber.map((e: any) => Number(e)) - : undefined, - }; - }, - create, I>>(base?: I): TPartial { return TPartial.fromPartial(base ?? {}); }, @@ -337,6 +337,10 @@ export const TPartial_MapEntry = { return message; }, + fromJSON(object: any): TPartial_MapEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: TPartial_MapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -348,10 +352,6 @@ export const TPartial_MapEntry = { return obj; }, - fromJSON(object: any): TPartial_MapEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): TPartial_MapEntry { return TPartial_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/generic-metadata/hero.ts b/integration/generic-metadata/hero.ts index a4dc27871..de969f6f1 100644 --- a/integration/generic-metadata/hero.ts +++ b/integration/generic-metadata/hero.ts @@ -59,6 +59,10 @@ export const HeroById = { return message; }, + fromJSON(object: any): HeroById { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: HeroById): unknown { const obj: any = {}; if (message.id !== 0) { @@ -67,10 +71,6 @@ export const HeroById = { return obj; }, - fromJSON(object: any): HeroById { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): HeroById { return HeroById.fromPartial(base ?? {}); }, @@ -117,6 +117,10 @@ export const VillainById = { return message; }, + fromJSON(object: any): VillainById { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: VillainById): unknown { const obj: any = {}; if (message.id !== 0) { @@ -125,10 +129,6 @@ export const VillainById = { return obj; }, - fromJSON(object: any): VillainById { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): VillainById { return VillainById.fromPartial(base ?? {}); }, @@ -185,6 +185,10 @@ export const Hero = { return message; }, + fromJSON(object: any): Hero { + return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Hero): unknown { const obj: any = {}; if (message.id !== 0) { @@ -196,10 +200,6 @@ export const Hero = { return obj; }, - fromJSON(object: any): Hero { - return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Hero { return Hero.fromPartial(base ?? {}); }, @@ -257,6 +257,10 @@ export const Villain = { return message; }, + fromJSON(object: any): Villain { + return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Villain): unknown { const obj: any = {}; if (message.id !== 0) { @@ -268,10 +272,6 @@ export const Villain = { return obj; }, - fromJSON(object: any): Villain { - return { id: isSet(object.id) ? Number(object.id) : 0, name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Villain { return Villain.fromPartial(base ?? {}); }, diff --git a/integration/generic-service-definitions-and-services/simple.ts b/integration/generic-service-definitions-and-services/simple.ts index e7794da2d..09d413f92 100644 --- a/integration/generic-service-definitions-and-services/simple.ts +++ b/integration/generic-service-definitions-and-services/simple.ts @@ -42,6 +42,10 @@ export const TestMessage = { return message; }, + fromJSON(object: any): TestMessage { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.value !== "") { @@ -50,10 +54,6 @@ export const TestMessage = { return obj; }, - fromJSON(object: any): TestMessage { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/generic-service-definitions/simple.ts b/integration/generic-service-definitions/simple.ts index e7794da2d..09d413f92 100644 --- a/integration/generic-service-definitions/simple.ts +++ b/integration/generic-service-definitions/simple.ts @@ -42,6 +42,10 @@ export const TestMessage = { return message; }, + fromJSON(object: any): TestMessage { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.value !== "") { @@ -50,10 +54,6 @@ export const TestMessage = { return obj; }, - fromJSON(object: any): TestMessage { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/global-this/global-this.ts b/integration/global-this/global-this.ts index 02fa32512..216089c26 100644 --- a/integration/global-this/global-this.ts +++ b/integration/global-this/global-this.ts @@ -46,6 +46,10 @@ export const Object = { return message; }, + fromJSON(object: any): Object { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Object): unknown { const obj: any = {}; if (message.name !== "") { @@ -54,10 +58,6 @@ export const Object = { return obj; }, - fromJSON(object: any): Object { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Object { return Object.fromPartial(base ?? {}); }, @@ -104,6 +104,10 @@ export const Error = { return message; }, + fromJSON(object: any): Error { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Error): unknown { const obj: any = {}; if (message.name !== "") { @@ -112,10 +116,6 @@ export const Error = { return obj; }, - fromJSON(object: any): Error { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Error { return Error.fromPartial(base ?? {}); }, diff --git a/integration/groups/test.ts b/integration/groups/test.ts index 8f24e7b2f..038e37513 100644 --- a/integration/groups/test.ts +++ b/integration/groups/test.ts @@ -133,6 +133,14 @@ export const GroupsOptionalTest = { return message; }, + fromJSON(object: any): GroupsOptionalTest { + return { + int1: isSet(object.int1) ? Number(object.int1) : undefined, + group: isSet(object.group) ? GroupsOptionalTest_Group.fromJSON(object.group) : undefined, + int3: isSet(object.int3) ? Number(object.int3) : undefined, + }; + }, + toJSON(message: GroupsOptionalTest): unknown { const obj: any = {}; if (message.int1 !== undefined && message.int1 !== 0) { @@ -147,14 +155,6 @@ export const GroupsOptionalTest = { return obj; }, - fromJSON(object: any): GroupsOptionalTest { - return { - int1: isSet(object.int1) ? Number(object.int1) : undefined, - group: isSet(object.group) ? GroupsOptionalTest_Group.fromJSON(object.group) : undefined, - int3: isSet(object.int3) ? Number(object.int3) : undefined, - }; - }, - create, I>>(base?: I): GroupsOptionalTest { return GroupsOptionalTest.fromPartial(base ?? {}); }, @@ -242,6 +242,13 @@ export const GroupsOptionalTest_Group = { return message; }, + fromJSON(object: any): GroupsOptionalTest_Group { + return { + key: isSet(object.key) ? String(object.key) : undefined, + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + toJSON(message: GroupsOptionalTest_Group): unknown { const obj: any = {}; if (message.key !== undefined && message.key !== "") { @@ -253,13 +260,6 @@ export const GroupsOptionalTest_Group = { return obj; }, - fromJSON(object: any): GroupsOptionalTest_Group { - return { - key: isSet(object.key) ? String(object.key) : undefined, - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - create, I>>(base?: I): GroupsOptionalTest_Group { return GroupsOptionalTest_Group.fromPartial(base ?? {}); }, @@ -399,6 +399,16 @@ export const GroupsRepeatedTest = { return message; }, + fromJSON(object: any): GroupsRepeatedTest { + return { + int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, + group: Array.isArray(object?.group) + ? object.group.map((e: any) => GroupsRepeatedTest_Group.fromJSON(e)) + : undefined, + int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, + }; + }, + toJSON(message: GroupsRepeatedTest): unknown { const obj: any = {}; if (message.int1?.length) { @@ -413,16 +423,6 @@ export const GroupsRepeatedTest = { return obj; }, - fromJSON(object: any): GroupsRepeatedTest { - return { - int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, - group: Array.isArray(object?.group) - ? object.group.map((e: any) => GroupsRepeatedTest_Group.fromJSON(e)) - : undefined, - int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, - }; - }, - create, I>>(base?: I): GroupsRepeatedTest { return GroupsRepeatedTest.fromPartial(base ?? {}); }, @@ -518,6 +518,13 @@ export const GroupsRepeatedTest_Group = { return message; }, + fromJSON(object: any): GroupsRepeatedTest_Group { + return { + key: Array.isArray(object?.key) ? object.key.map((e: any) => String(e)) : undefined, + value: Array.isArray(object?.value) ? object.value.map((e: any) => String(e)) : undefined, + }; + }, + toJSON(message: GroupsRepeatedTest_Group): unknown { const obj: any = {}; if (message.key?.length) { @@ -529,13 +536,6 @@ export const GroupsRepeatedTest_Group = { return obj; }, - fromJSON(object: any): GroupsRepeatedTest_Group { - return { - key: Array.isArray(object?.key) ? object.key.map((e: any) => String(e)) : undefined, - value: Array.isArray(object?.value) ? object.value.map((e: any) => String(e)) : undefined, - }; - }, - create, I>>(base?: I): GroupsRepeatedTest_Group { return GroupsRepeatedTest_Group.fromPartial(base ?? {}); }, @@ -675,6 +675,16 @@ export const GroupsNestedTest = { return message; }, + fromJSON(object: any): GroupsNestedTest { + return { + int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, + group: Array.isArray(object?.group) + ? object.group.map((e: any) => GroupsNestedTest_Group.fromJSON(e)) + : undefined, + int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, + }; + }, + toJSON(message: GroupsNestedTest): unknown { const obj: any = {}; if (message.int1?.length) { @@ -689,16 +699,6 @@ export const GroupsNestedTest = { return obj; }, - fromJSON(object: any): GroupsNestedTest { - return { - int1: Array.isArray(object?.int1) ? object.int1.map((e: any) => Number(e)) : undefined, - group: Array.isArray(object?.group) - ? object.group.map((e: any) => GroupsNestedTest_Group.fromJSON(e)) - : undefined, - int3: Array.isArray(object?.int3) ? object.int3.map((e: any) => Number(e)) : undefined, - }; - }, - create, I>>(base?: I): GroupsNestedTest { return GroupsNestedTest.fromPartial(base ?? {}); }, @@ -779,14 +779,6 @@ export const GroupsNestedTest_Group = { return message; }, - toJSON(message: GroupsNestedTest_Group): unknown { - const obj: any = {}; - if (message.nested?.length) { - obj.nested = message.nested.map((e) => GroupsNestedTest_Group_Nested.toJSON(e)); - } - return obj; - }, - fromJSON(object: any): GroupsNestedTest_Group { return { nested: Array.isArray(object?.nested) @@ -795,6 +787,14 @@ export const GroupsNestedTest_Group = { }; }, + toJSON(message: GroupsNestedTest_Group): unknown { + const obj: any = {}; + if (message.nested?.length) { + obj.nested = message.nested.map((e) => GroupsNestedTest_Group_Nested.toJSON(e)); + } + return obj; + }, + create, I>>(base?: I): GroupsNestedTest_Group { return GroupsNestedTest_Group.fromPartial(base ?? {}); }, @@ -873,14 +873,6 @@ export const GroupsNestedTest_Group_Nested = { return message; }, - toJSON(message: GroupsNestedTest_Group_Nested): unknown { - const obj: any = {}; - if (message.nested2?.length) { - obj.nested2 = message.nested2.map((e) => GroupsNestedTest_Group_Nested_Nested2.toJSON(e)); - } - return obj; - }, - fromJSON(object: any): GroupsNestedTest_Group_Nested { return { nested2: Array.isArray(object?.nested2) @@ -889,6 +881,14 @@ export const GroupsNestedTest_Group_Nested = { }; }, + toJSON(message: GroupsNestedTest_Group_Nested): unknown { + const obj: any = {}; + if (message.nested2?.length) { + obj.nested2 = message.nested2.map((e) => GroupsNestedTest_Group_Nested_Nested2.toJSON(e)); + } + return obj; + }, + create, I>>(base?: I): GroupsNestedTest_Group_Nested { return GroupsNestedTest_Group_Nested.fromPartial(base ?? {}); }, @@ -964,6 +964,10 @@ export const GroupsNestedTest_Group_Nested_Nested2 = { return message; }, + fromJSON(object: any): GroupsNestedTest_Group_Nested_Nested2 { + return { string1: isSet(object.string1) ? String(object.string1) : undefined }; + }, + toJSON(message: GroupsNestedTest_Group_Nested_Nested2): unknown { const obj: any = {}; if (message.string1 !== undefined && message.string1 !== "") { @@ -972,10 +976,6 @@ export const GroupsNestedTest_Group_Nested_Nested2 = { return obj; }, - fromJSON(object: any): GroupsNestedTest_Group_Nested_Nested2 { - return { string1: isSet(object.string1) ? String(object.string1) : undefined }; - }, - create, I>>( base?: I, ): GroupsNestedTest_Group_Nested_Nested2 { diff --git a/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts b/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts index 59c3ee198..511846364 100644 --- a/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts +++ b/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts @@ -55,6 +55,10 @@ export const TimestampMessage = { return message; }, + fromJSON(object: any): TimestampMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: TimestampMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -63,10 +67,6 @@ export const TimestampMessage = { return obj; }, - fromJSON(object: any): TimestampMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): TimestampMessage { return TimestampMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts b/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts index ebce875f3..021ca8402 100644 --- a/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts +++ b/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts @@ -55,6 +55,10 @@ export const TimestampMessage = { return message; }, + fromJSON(object: any): TimestampMessage { + return { timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined }; + }, + toJSON(message: TimestampMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -63,10 +67,6 @@ export const TimestampMessage = { return obj; }, - fromJSON(object: any): TimestampMessage { - return { timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined }; - }, - create, I>>(base?: I): TimestampMessage { return TimestampMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts b/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts index 0d52339db..606cf4504 100644 --- a/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts +++ b/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts @@ -55,6 +55,10 @@ export const TimestampMessage = { return message; }, + fromJSON(object: any): TimestampMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: TimestampMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -63,10 +67,6 @@ export const TimestampMessage = { return obj; }, - fromJSON(object: any): TimestampMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): TimestampMessage { return TimestampMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/empty.ts b/integration/grpc-js/google/protobuf/empty.ts index d1b8ebf5b..1387d7ce4 100644 --- a/integration/grpc-js/google/protobuf/empty.ts +++ b/integration/grpc-js/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/struct.ts b/integration/grpc-js/google/protobuf/struct.ts index 7c416eb52..b2486a866 100644 --- a/integration/grpc-js/google/protobuf/struct.ts +++ b/integration/grpc-js/google/protobuf/struct.ts @@ -140,6 +140,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -154,17 +165,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,6 +249,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -260,10 +264,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,6 +368,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -391,17 +402,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,6 +490,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -498,10 +502,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/timestamp.ts b/integration/grpc-js/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/grpc-js/google/protobuf/timestamp.ts +++ b/integration/grpc-js/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/google/protobuf/wrappers.ts b/integration/grpc-js/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/grpc-js/google/protobuf/wrappers.ts +++ b/integration/grpc-js/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/grpc-js/simple.ts b/integration/grpc-js/simple.ts index 986bbf920..a552d77d9 100644 --- a/integration/grpc-js/simple.ts +++ b/integration/grpc-js/simple.ts @@ -74,6 +74,10 @@ export const TestMessage = { return message; }, + fromJSON(object: any): TestMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -82,10 +86,6 @@ export const TestMessage = { return obj; }, - fromJSON(object: any): TestMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-abort-signal/example.ts b/integration/grpc-web-abort-signal/example.ts index fb1ff3f30..a0f08c644 100644 --- a/integration/grpc-web-abort-signal/example.ts +++ b/integration/grpc-web-abort-signal/example.ts @@ -140,6 +140,13 @@ export const DashFlash = { return message; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -151,13 +158,6 @@ export const DashFlash = { return obj; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -225,6 +225,14 @@ export const DashUserSettingsState = { return message; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -239,14 +247,6 @@ export const DashUserSettingsState = { return obj; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -307,6 +307,13 @@ export const DashUserSettingsState_URLs = { return message; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -318,13 +325,6 @@ export const DashUserSettingsState_URLs = { return obj; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -402,6 +402,15 @@ export const DashCred = { return message; }, + fromJSON(object: any): DashCred { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + token: isSet(object.token) ? String(object.token) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashCred): unknown { const obj: any = {}; if (message.description !== "") { @@ -419,15 +428,6 @@ export const DashCred = { return obj; }, - fromJSON(object: any): DashCred { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - token: isSet(object.token) ? String(object.token) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashCred { return DashCred.fromPartial(base ?? {}); }, @@ -487,6 +487,13 @@ export const DashAPICredsCreateReq = { return message; }, + fromJSON(object: any): DashAPICredsCreateReq { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + }; + }, + toJSON(message: DashAPICredsCreateReq): unknown { const obj: any = {}; if (message.description !== "") { @@ -498,13 +505,6 @@ export const DashAPICredsCreateReq = { return obj; }, - fromJSON(object: any): DashAPICredsCreateReq { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - }; - }, - create, I>>(base?: I): DashAPICredsCreateReq { return DashAPICredsCreateReq.fromPartial(base ?? {}); }, @@ -582,6 +582,15 @@ export const DashAPICredsUpdateReq = { return message; }, + fromJSON(object: any): DashAPICredsUpdateReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashAPICredsUpdateReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -599,15 +608,6 @@ export const DashAPICredsUpdateReq = { return obj; }, - fromJSON(object: any): DashAPICredsUpdateReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashAPICredsUpdateReq { return DashAPICredsUpdateReq.fromPartial(base ?? {}); }, @@ -667,6 +667,13 @@ export const DashAPICredsDeleteReq = { return message; }, + fromJSON(object: any): DashAPICredsDeleteReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashAPICredsDeleteReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -678,13 +685,6 @@ export const DashAPICredsDeleteReq = { return obj; }, - fromJSON(object: any): DashAPICredsDeleteReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashAPICredsDeleteReq { return DashAPICredsDeleteReq.fromPartial(base ?? {}); }, @@ -722,15 +722,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-go-server/example.ts b/integration/grpc-web-go-server/example.ts index c01936c78..d1f2e05e3 100644 --- a/integration/grpc-web-go-server/example.ts +++ b/integration/grpc-web-go-server/example.ts @@ -138,6 +138,13 @@ export const DashFlash = { return message; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -149,13 +156,6 @@ export const DashFlash = { return obj; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -223,6 +223,14 @@ export const DashUserSettingsState = { return message; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -237,14 +245,6 @@ export const DashUserSettingsState = { return obj; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -305,6 +305,13 @@ export const DashUserSettingsState_URLs = { return message; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -316,13 +323,6 @@ export const DashUserSettingsState_URLs = { return obj; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -400,6 +400,15 @@ export const DashCred = { return message; }, + fromJSON(object: any): DashCred { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + token: isSet(object.token) ? String(object.token) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashCred): unknown { const obj: any = {}; if (message.description !== "") { @@ -417,15 +426,6 @@ export const DashCred = { return obj; }, - fromJSON(object: any): DashCred { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - token: isSet(object.token) ? String(object.token) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashCred { return DashCred.fromPartial(base ?? {}); }, @@ -485,6 +485,13 @@ export const DashAPICredsCreateReq = { return message; }, + fromJSON(object: any): DashAPICredsCreateReq { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + }; + }, + toJSON(message: DashAPICredsCreateReq): unknown { const obj: any = {}; if (message.description !== "") { @@ -496,13 +503,6 @@ export const DashAPICredsCreateReq = { return obj; }, - fromJSON(object: any): DashAPICredsCreateReq { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - }; - }, - create, I>>(base?: I): DashAPICredsCreateReq { return DashAPICredsCreateReq.fromPartial(base ?? {}); }, @@ -580,6 +580,15 @@ export const DashAPICredsUpdateReq = { return message; }, + fromJSON(object: any): DashAPICredsUpdateReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashAPICredsUpdateReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -597,15 +606,6 @@ export const DashAPICredsUpdateReq = { return obj; }, - fromJSON(object: any): DashAPICredsUpdateReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashAPICredsUpdateReq { return DashAPICredsUpdateReq.fromPartial(base ?? {}); }, @@ -665,6 +665,13 @@ export const DashAPICredsDeleteReq = { return message; }, + fromJSON(object: any): DashAPICredsDeleteReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashAPICredsDeleteReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -676,13 +683,6 @@ export const DashAPICredsDeleteReq = { return obj; }, - fromJSON(object: any): DashAPICredsDeleteReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashAPICredsDeleteReq { return DashAPICredsDeleteReq.fromPartial(base ?? {}); }, @@ -720,15 +720,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-no-streaming-observable/example.ts b/integration/grpc-web-no-streaming-observable/example.ts index ecf03c576..82366a50c 100644 --- a/integration/grpc-web-no-streaming-observable/example.ts +++ b/integration/grpc-web-no-streaming-observable/example.ts @@ -116,6 +116,13 @@ export const DashFlash = { return message; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -127,13 +134,6 @@ export const DashFlash = { return obj; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -201,6 +201,14 @@ export const DashUserSettingsState = { return message; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -215,14 +223,6 @@ export const DashUserSettingsState = { return obj; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -283,6 +283,13 @@ export const DashUserSettingsState_URLs = { return message; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -294,13 +301,6 @@ export const DashUserSettingsState_URLs = { return obj; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -338,15 +338,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web-no-streaming/example.ts b/integration/grpc-web-no-streaming/example.ts index bc07c7b32..d055a5e0c 100644 --- a/integration/grpc-web-no-streaming/example.ts +++ b/integration/grpc-web-no-streaming/example.ts @@ -114,6 +114,13 @@ export const DashFlash = { return message; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -125,13 +132,6 @@ export const DashFlash = { return obj; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -199,6 +199,14 @@ export const DashUserSettingsState = { return message; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -213,14 +221,6 @@ export const DashUserSettingsState = { return obj; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -281,6 +281,13 @@ export const DashUserSettingsState_URLs = { return message; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -292,13 +299,6 @@ export const DashUserSettingsState_URLs = { return obj; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -336,15 +336,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/grpc-web/example.ts b/integration/grpc-web/example.ts index 9453a7f1b..49e312479 100644 --- a/integration/grpc-web/example.ts +++ b/integration/grpc-web/example.ts @@ -140,6 +140,13 @@ export const DashFlash = { return message; }, + fromJSON(object: any): DashFlash { + return { + msg: isSet(object.msg) ? String(object.msg) : "", + type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: DashFlash): unknown { const obj: any = {}; if (message.msg !== "") { @@ -151,13 +158,6 @@ export const DashFlash = { return obj; }, - fromJSON(object: any): DashFlash { - return { - msg: isSet(object.msg) ? String(object.msg) : "", - type: isSet(object.type) ? dashFlash_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): DashFlash { return DashFlash.fromPartial(base ?? {}); }, @@ -225,6 +225,14 @@ export const DashUserSettingsState = { return message; }, + fromJSON(object: any): DashUserSettingsState { + return { + email: isSet(object.email) ? String(object.email) : "", + urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, + flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], + }; + }, + toJSON(message: DashUserSettingsState): unknown { const obj: any = {}; if (message.email !== "") { @@ -239,14 +247,6 @@ export const DashUserSettingsState = { return obj; }, - fromJSON(object: any): DashUserSettingsState { - return { - email: isSet(object.email) ? String(object.email) : "", - urls: isSet(object.urls) ? DashUserSettingsState_URLs.fromJSON(object.urls) : undefined, - flashes: Array.isArray(object?.flashes) ? object.flashes.map((e: any) => DashFlash.fromJSON(e)) : [], - }; - }, - create, I>>(base?: I): DashUserSettingsState { return DashUserSettingsState.fromPartial(base ?? {}); }, @@ -307,6 +307,13 @@ export const DashUserSettingsState_URLs = { return message; }, + fromJSON(object: any): DashUserSettingsState_URLs { + return { + connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", + connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", + }; + }, + toJSON(message: DashUserSettingsState_URLs): unknown { const obj: any = {}; if (message.connectGoogle !== "") { @@ -318,13 +325,6 @@ export const DashUserSettingsState_URLs = { return obj; }, - fromJSON(object: any): DashUserSettingsState_URLs { - return { - connectGoogle: isSet(object.connectGoogle) ? String(object.connectGoogle) : "", - connectGithub: isSet(object.connectGithub) ? String(object.connectGithub) : "", - }; - }, - create, I>>(base?: I): DashUserSettingsState_URLs { return DashUserSettingsState_URLs.fromPartial(base ?? {}); }, @@ -402,6 +402,15 @@ export const DashCred = { return message; }, + fromJSON(object: any): DashCred { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + token: isSet(object.token) ? String(object.token) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashCred): unknown { const obj: any = {}; if (message.description !== "") { @@ -419,15 +428,6 @@ export const DashCred = { return obj; }, - fromJSON(object: any): DashCred { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - token: isSet(object.token) ? String(object.token) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashCred { return DashCred.fromPartial(base ?? {}); }, @@ -487,6 +487,13 @@ export const DashAPICredsCreateReq = { return message; }, + fromJSON(object: any): DashAPICredsCreateReq { + return { + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + }; + }, + toJSON(message: DashAPICredsCreateReq): unknown { const obj: any = {}; if (message.description !== "") { @@ -498,13 +505,6 @@ export const DashAPICredsCreateReq = { return obj; }, - fromJSON(object: any): DashAPICredsCreateReq { - return { - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - }; - }, - create, I>>(base?: I): DashAPICredsCreateReq { return DashAPICredsCreateReq.fromPartial(base ?? {}); }, @@ -582,6 +582,15 @@ export const DashAPICredsUpdateReq = { return message; }, + fromJSON(object: any): DashAPICredsUpdateReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + description: isSet(object.description) ? String(object.description) : "", + metadata: isSet(object.metadata) ? String(object.metadata) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashAPICredsUpdateReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -599,15 +608,6 @@ export const DashAPICredsUpdateReq = { return obj; }, - fromJSON(object: any): DashAPICredsUpdateReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - description: isSet(object.description) ? String(object.description) : "", - metadata: isSet(object.metadata) ? String(object.metadata) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashAPICredsUpdateReq { return DashAPICredsUpdateReq.fromPartial(base ?? {}); }, @@ -667,6 +667,13 @@ export const DashAPICredsDeleteReq = { return message; }, + fromJSON(object: any): DashAPICredsDeleteReq { + return { + credSid: isSet(object.credSid) ? String(object.credSid) : "", + id: isSet(object.id) ? String(object.id) : "", + }; + }, + toJSON(message: DashAPICredsDeleteReq): unknown { const obj: any = {}; if (message.credSid !== "") { @@ -678,13 +685,6 @@ export const DashAPICredsDeleteReq = { return obj; }, - fromJSON(object: any): DashAPICredsDeleteReq { - return { - credSid: isSet(object.credSid) ? String(object.credSid) : "", - id: isSet(object.id) ? String(object.id) : "", - }; - }, - create, I>>(base?: I): DashAPICredsDeleteReq { return DashAPICredsDeleteReq.fromPartial(base ?? {}); }, @@ -722,15 +722,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/import-mapping/google/protobuf/timestamp.ts b/integration/import-mapping/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/import-mapping/google/protobuf/timestamp.ts +++ b/integration/import-mapping/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/import-mapping/mapping.ts b/integration/import-mapping/mapping.ts index 862a761d1..06fd3c94e 100644 --- a/integration/import-mapping/mapping.ts +++ b/integration/import-mapping/mapping.ts @@ -63,6 +63,10 @@ export const WithEmtpy = { return message; }, + fromJSON(object: any): WithEmtpy { + return { empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined }; + }, + toJSON(message: WithEmtpy): unknown { const obj: any = {}; if (message.empty !== undefined) { @@ -71,10 +75,6 @@ export const WithEmtpy = { return obj; }, - fromJSON(object: any): WithEmtpy { - return { empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined }; - }, - create, I>>(base?: I): WithEmtpy { return WithEmtpy.fromPartial(base ?? {}); }, @@ -121,6 +121,10 @@ export const WithStruct = { return message; }, + fromJSON(object: any): WithStruct { + return { strut: isObject(object.strut) ? object.strut : undefined }; + }, + toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.strut !== undefined) { @@ -129,10 +133,6 @@ export const WithStruct = { return obj; }, - fromJSON(object: any): WithStruct { - return { strut: isObject(object.strut) ? object.strut : undefined }; - }, - create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, @@ -179,6 +179,10 @@ export const WithTimestamp = { return message; }, + fromJSON(object: any): WithTimestamp { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: WithTimestamp): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -187,10 +191,6 @@ export const WithTimestamp = { return obj; }, - fromJSON(object: any): WithTimestamp { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): WithTimestamp { return WithTimestamp.fromPartial(base ?? {}); }, @@ -277,6 +277,16 @@ export const WithAll = { return message; }, + fromJSON(object: any): WithAll { + return { + empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined, + strut: isObject(object.strut) ? object.strut : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + duration: isSet(object.duration) ? Duration.fromJSON(object.duration) : undefined, + veryVerySecret: isSet(object.veryVerySecret) ? VeryVerySecret.fromJSON(object.veryVerySecret) : undefined, + }; + }, + toJSON(message: WithAll): unknown { const obj: any = {}; if (message.empty !== undefined) { @@ -297,16 +307,6 @@ export const WithAll = { return obj; }, - fromJSON(object: any): WithAll { - return { - empty: isSet(object.empty) ? Empty.fromJSON(object.empty) : undefined, - strut: isObject(object.strut) ? object.strut : undefined, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - duration: isSet(object.duration) ? Duration.fromJSON(object.duration) : undefined, - veryVerySecret: isSet(object.veryVerySecret) ? VeryVerySecret.fromJSON(object.veryVerySecret) : undefined, - }; - }, - create, I>>(base?: I): WithAll { return WithAll.fromPartial(base ?? {}); }, diff --git a/integration/import-suffix/child.pb.ts b/integration/import-suffix/child.pb.ts index 4998f6748..95c76a35c 100644 --- a/integration/import-suffix/child.pb.ts +++ b/integration/import-suffix/child.pb.ts @@ -75,6 +75,10 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -83,10 +87,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/import-suffix/google/protobuf/timestamp.pb.ts b/integration/import-suffix/google/protobuf/timestamp.pb.ts index f2a10e03e..de977dc2b 100644 --- a/integration/import-suffix/google/protobuf/timestamp.pb.ts +++ b/integration/import-suffix/google/protobuf/timestamp.pb.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/import-suffix/parent.pb.ts b/integration/import-suffix/parent.pb.ts index a59a95f59..0cd242d71 100644 --- a/integration/import-suffix/parent.pb.ts +++ b/integration/import-suffix/parent.pb.ts @@ -66,6 +66,14 @@ export const Parent = { return message; }, + fromJSON(object: any): Parent { + return { + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + }; + }, + toJSON(message: Parent): unknown { const obj: any = {}; if (message.child !== undefined) { @@ -80,14 +88,6 @@ export const Parent = { return obj; }, - fromJSON(object: any): Parent { - return { - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - childEnum: isSet(object.childEnum) ? childEnumFromJSON(object.childEnum) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - }; - }, - create, I>>(base?: I): Parent { return Parent.fromPartial(base ?? {}); }, diff --git a/integration/lower-case-svc-methods/math.ts b/integration/lower-case-svc-methods/math.ts index 79d70f243..8bb700a08 100644 --- a/integration/lower-case-svc-methods/math.ts +++ b/integration/lower-case-svc-methods/math.ts @@ -63,6 +63,10 @@ export const NumPair = { return message; }, + fromJSON(object: any): NumPair { + return { num1: isSet(object.num1) ? Number(object.num1) : 0, num2: isSet(object.num2) ? Number(object.num2) : 0 }; + }, + toJSON(message: NumPair): unknown { const obj: any = {}; if (message.num1 !== 0) { @@ -74,10 +78,6 @@ export const NumPair = { return obj; }, - fromJSON(object: any): NumPair { - return { num1: isSet(object.num1) ? Number(object.num1) : 0, num2: isSet(object.num2) ? Number(object.num2) : 0 }; - }, - create, I>>(base?: I): NumPair { return NumPair.fromPartial(base ?? {}); }, @@ -125,6 +125,10 @@ export const NumSingle = { return message; }, + fromJSON(object: any): NumSingle { + return { num: isSet(object.num) ? Number(object.num) : 0 }; + }, + toJSON(message: NumSingle): unknown { const obj: any = {}; if (message.num !== 0) { @@ -133,10 +137,6 @@ export const NumSingle = { return obj; }, - fromJSON(object: any): NumSingle { - return { num: isSet(object.num) ? Number(object.num) : 0 }; - }, - create, I>>(base?: I): NumSingle { return NumSingle.fromPartial(base ?? {}); }, @@ -195,6 +195,10 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { num: Array.isArray(object?.num) ? object.num.map((e: any) => Number(e)) : [] }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.num?.length) { @@ -203,10 +207,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { num: Array.isArray(object?.num) ? object.num.map((e: any) => Number(e)) : [] }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/map-bigint-optional/test.ts b/integration/map-bigint-optional/test.ts index 7865885a6..e2edeac10 100644 --- a/integration/map-bigint-optional/test.ts +++ b/integration/map-bigint-optional/test.ts @@ -83,17 +83,6 @@ export const MapBigInt = { return message; }, - toJSON(message: MapBigInt): unknown { - const obj: any = {}; - if (message.map?.size) { - obj.map = {}; - message.map.forEach((v, k) => { - obj.map[k.toString()] = v.toString(); - }); - } - return obj; - }, - fromJSON(object: any): MapBigInt { return { map: isObject(object.map) @@ -105,6 +94,17 @@ export const MapBigInt = { }; }, + toJSON(message: MapBigInt): unknown { + const obj: any = {}; + if (message.map?.size) { + obj.map = {}; + message.map.forEach((v, k) => { + obj.map[k.toString()] = v.toString(); + }); + } + return obj; + }, + create, I>>(base?: I): MapBigInt { return MapBigInt.fromPartial(base ?? {}); }, @@ -196,6 +196,13 @@ export const MapBigInt_MapEntry = { return message; }, + fromJSON(object: any): MapBigInt_MapEntry { + return { + key: isSet(object.key) ? BigInt(object.key) : BigInt("0"), + value: isSet(object.value) ? BigInt(object.value) : BigInt("0"), + }; + }, + toJSON(message: MapBigInt_MapEntry): unknown { const obj: any = {}; if (message.key !== BigInt("0")) { @@ -207,13 +214,6 @@ export const MapBigInt_MapEntry = { return obj; }, - fromJSON(object: any): MapBigInt_MapEntry { - return { - key: isSet(object.key) ? BigInt(object.key) : BigInt("0"), - value: isSet(object.value) ? BigInt(object.value) : BigInt("0"), - }; - }, - create, I>>(base?: I): MapBigInt_MapEntry { return MapBigInt_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/map-long-optional/test.ts b/integration/map-long-optional/test.ts index 0dd4556d3..ac947f4af 100644 --- a/integration/map-long-optional/test.ts +++ b/integration/map-long-optional/test.ts @@ -83,17 +83,6 @@ export const MapBigInt = { return message; }, - toJSON(message: MapBigInt): unknown { - const obj: any = {}; - if (message.map?.size) { - obj.map = {}; - message.map.forEach((v, k) => { - obj.map[longToNumber(k)] = v.toString(); - }); - } - return obj; - }, - fromJSON(object: any): MapBigInt { return { map: isObject(object.map) @@ -105,6 +94,17 @@ export const MapBigInt = { }; }, + toJSON(message: MapBigInt): unknown { + const obj: any = {}; + if (message.map?.size) { + obj.map = {}; + message.map.forEach((v, k) => { + obj.map[longToNumber(k)] = v.toString(); + }); + } + return obj; + }, + create, I>>(base?: I): MapBigInt { return MapBigInt.fromPartial(base ?? {}); }, @@ -196,6 +196,13 @@ export const MapBigInt_MapEntry = { return message; }, + fromJSON(object: any): MapBigInt_MapEntry { + return { + key: isSet(object.key) ? Long.fromValue(object.key) : Long.UZERO, + value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, + }; + }, + toJSON(message: MapBigInt_MapEntry): unknown { const obj: any = {}; if (!message.key.isZero()) { @@ -207,13 +214,6 @@ export const MapBigInt_MapEntry = { return obj; }, - fromJSON(object: any): MapBigInt_MapEntry { - return { - key: isSet(object.key) ? Long.fromValue(object.key) : Long.UZERO, - value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, - }; - }, - create, I>>(base?: I): MapBigInt_MapEntry { return MapBigInt_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/map-longstring-optional/test.ts b/integration/map-longstring-optional/test.ts index 6acce601d..e5fccb66c 100644 --- a/integration/map-longstring-optional/test.ts +++ b/integration/map-longstring-optional/test.ts @@ -83,17 +83,6 @@ export const MapBigInt = { return message; }, - toJSON(message: MapBigInt): unknown { - const obj: any = {}; - if (message.map?.size) { - obj.map = {}; - message.map.forEach((v, k) => { - obj.map[k] = v; - }); - } - return obj; - }, - fromJSON(object: any): MapBigInt { return { map: isObject(object.map) @@ -105,6 +94,17 @@ export const MapBigInt = { }; }, + toJSON(message: MapBigInt): unknown { + const obj: any = {}; + if (message.map?.size) { + obj.map = {}; + message.map.forEach((v, k) => { + obj.map[k] = v; + }); + } + return obj; + }, + create, I>>(base?: I): MapBigInt { return MapBigInt.fromPartial(base ?? {}); }, @@ -196,6 +196,13 @@ export const MapBigInt_MapEntry = { return message; }, + fromJSON(object: any): MapBigInt_MapEntry { + return { + key: isSet(object.key) ? String(object.key) : "0", + value: isSet(object.value) ? String(object.value) : "0", + }; + }, + toJSON(message: MapBigInt_MapEntry): unknown { const obj: any = {}; if (message.key !== "0") { @@ -207,13 +214,6 @@ export const MapBigInt_MapEntry = { return obj; }, - fromJSON(object: any): MapBigInt_MapEntry { - return { - key: isSet(object.key) ? String(object.key) : "0", - value: isSet(object.value) ? String(object.value) : "0", - }; - }, - create, I>>(base?: I): MapBigInt_MapEntry { return MapBigInt_MapEntry.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/empty.ts b/integration/nice-grpc/google/protobuf/empty.ts index 5aadfe4a4..89e044465 100644 --- a/integration/nice-grpc/google/protobuf/empty.ts +++ b/integration/nice-grpc/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create(base?: DeepPartial): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/struct.ts b/integration/nice-grpc/google/protobuf/struct.ts index e9c35b23c..1aa09a906 100644 --- a/integration/nice-grpc/google/protobuf/struct.ts +++ b/integration/nice-grpc/google/protobuf/struct.ts @@ -140,6 +140,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -154,17 +165,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create(base?: DeepPartial): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,6 +249,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -260,10 +264,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create(base?: DeepPartial): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,6 +368,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -391,17 +402,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create(base?: DeepPartial): Value { return Value.fromPartial(base ?? {}); }, @@ -490,6 +490,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -498,10 +502,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create(base?: DeepPartial): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/timestamp.ts b/integration/nice-grpc/google/protobuf/timestamp.ts index 669166a20..a4b4415ac 100644 --- a/integration/nice-grpc/google/protobuf/timestamp.ts +++ b/integration/nice-grpc/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create(base?: DeepPartial): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/google/protobuf/wrappers.ts b/integration/nice-grpc/google/protobuf/wrappers.ts index 79a4e8b32..aabe92a94 100644 --- a/integration/nice-grpc/google/protobuf/wrappers.ts +++ b/integration/nice-grpc/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create(base?: DeepPartial): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create(base?: DeepPartial): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create(base?: DeepPartial): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create(base?: DeepPartial): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create(base?: DeepPartial): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create(base?: DeepPartial): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create(base?: DeepPartial): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create(base?: DeepPartial): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create(base?: DeepPartial): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/nice-grpc/simple.ts b/integration/nice-grpc/simple.ts index d49931be4..109f33346 100644 --- a/integration/nice-grpc/simple.ts +++ b/integration/nice-grpc/simple.ts @@ -57,6 +57,10 @@ export const TestMessage = { return message; }, + fromJSON(object: any): TestMessage { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -65,10 +69,6 @@ export const TestMessage = { return obj; }, - fromJSON(object: any): TestMessage { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create(base?: DeepPartial): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/no-proto-package/no-proto-package.ts b/integration/no-proto-package/no-proto-package.ts index 730a65a2c..6eeed4715 100644 --- a/integration/no-proto-package/no-proto-package.ts +++ b/integration/no-proto-package/no-proto-package.ts @@ -47,6 +47,10 @@ export const User = { return message; }, + fromJSON(object: any): User { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: User): unknown { const obj: any = {}; if (message.name !== "") { @@ -55,10 +59,6 @@ export const User = { return obj; }, - fromJSON(object: any): User { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): User { return User.fromPartial(base ?? {}); }, @@ -95,15 +95,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/omit-optionals/simple.ts b/integration/omit-optionals/simple.ts index 01bbdc1d8..738aa496f 100644 --- a/integration/omit-optionals/simple.ts +++ b/integration/omit-optionals/simple.ts @@ -53,6 +53,13 @@ export const TestMessage = { return message; }, + fromJSON(object: any): TestMessage { + return { + field1: isSet(object.field1) ? Boolean(object.field1) : false, + field2: isSet(object.field2) ? Boolean(object.field2) : undefined, + }; + }, + toJSON(message: TestMessage): unknown { const obj: any = {}; if (message.field1 === true) { @@ -64,13 +71,6 @@ export const TestMessage = { return obj; }, - fromJSON(object: any): TestMessage { - return { - field1: isSet(object.field1) ? Boolean(object.field1) : false, - field2: isSet(object.field2) ? Boolean(object.field2) : undefined, - }; - }, - create, I>>(base?: I): TestMessage { return TestMessage.fromPartial(base ?? {}); }, diff --git a/integration/oneof-properties/oneof.ts b/integration/oneof-properties/oneof.ts index d7d55beb2..4e844786c 100644 --- a/integration/oneof-properties/oneof.ts +++ b/integration/oneof-properties/oneof.ts @@ -223,6 +223,22 @@ export const PleaseChoose = { return message; }, + fromJSON(object: any): PleaseChoose { + return { + name: isSet(object.name) ? String(object.name) : "", + aNumber: isSet(object.aNumber) ? Number(object.aNumber) : undefined, + aString: isSet(object.aString) ? String(object.aString) : undefined, + aMessage: isSet(object.aMessage) ? PleaseChoose_Submessage.fromJSON(object.aMessage) : undefined, + aBool: isSet(object.aBool) ? Boolean(object.aBool) : undefined, + bunchaBytes: isSet(object.bunchaBytes) ? bytesFromBase64(object.bunchaBytes) : undefined, + anEnum: isSet(object.anEnum) ? pleaseChoose_StateEnumFromJSON(object.anEnum) : undefined, + age: isSet(object.age) ? Number(object.age) : 0, + either: isSet(object.either) ? String(object.either) : undefined, + or: isSet(object.or) ? String(object.or) : undefined, + thirdOption: isSet(object.thirdOption) ? String(object.thirdOption) : undefined, + }; + }, + toJSON(message: PleaseChoose): unknown { const obj: any = {}; if (message.name !== "") { @@ -261,22 +277,6 @@ export const PleaseChoose = { return obj; }, - fromJSON(object: any): PleaseChoose { - return { - name: isSet(object.name) ? String(object.name) : "", - aNumber: isSet(object.aNumber) ? Number(object.aNumber) : undefined, - aString: isSet(object.aString) ? String(object.aString) : undefined, - aMessage: isSet(object.aMessage) ? PleaseChoose_Submessage.fromJSON(object.aMessage) : undefined, - aBool: isSet(object.aBool) ? Boolean(object.aBool) : undefined, - bunchaBytes: isSet(object.bunchaBytes) ? bytesFromBase64(object.bunchaBytes) : undefined, - anEnum: isSet(object.anEnum) ? pleaseChoose_StateEnumFromJSON(object.anEnum) : undefined, - age: isSet(object.age) ? Number(object.age) : 0, - either: isSet(object.either) ? String(object.either) : undefined, - or: isSet(object.or) ? String(object.or) : undefined, - thirdOption: isSet(object.thirdOption) ? String(object.thirdOption) : undefined, - }; - }, - create, I>>(base?: I): PleaseChoose { return PleaseChoose.fromPartial(base ?? {}); }, @@ -335,6 +335,10 @@ export const PleaseChoose_Submessage = { return message; }, + fromJSON(object: any): PleaseChoose_Submessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: PleaseChoose_Submessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -343,10 +347,6 @@ export const PleaseChoose_Submessage = { return obj; }, - fromJSON(object: any): PleaseChoose_Submessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): PleaseChoose_Submessage { return PleaseChoose_Submessage.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions-snake/google/protobuf/struct.ts b/integration/oneof-unions-snake/google/protobuf/struct.ts index fc6e51fc5..f21e1fa8b 100644 --- a/integration/oneof-unions-snake/google/protobuf/struct.ts +++ b/integration/oneof-unions-snake/google/protobuf/struct.ts @@ -126,6 +126,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -140,17 +151,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -235,6 +235,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -246,10 +250,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -352,6 +352,24 @@ export const Value = { return message; }, + fromJSON(object: any): Value { + return { + kind: isSet(object.null_value) + ? { $case: "null_value", null_value: nullValueFromJSON(object.null_value) } + : isSet(object.number_value) + ? { $case: "number_value", number_value: Number(object.number_value) } + : isSet(object.string_value) + ? { $case: "string_value", string_value: String(object.string_value) } + : isSet(object.bool_value) + ? { $case: "bool_value", bool_value: Boolean(object.bool_value) } + : isSet(object.struct_value) + ? { $case: "struct_value", struct_value: object.struct_value } + : isSet(object.list_value) + ? { $case: "list_value", list_value: [...object.list_value] } + : undefined, + }; + }, + toJSON(message: Value): unknown { const obj: any = {}; if (message.kind?.$case === "null_value") { @@ -375,24 +393,6 @@ export const Value = { return obj; }, - fromJSON(object: any): Value { - return { - kind: isSet(object.null_value) - ? { $case: "null_value", null_value: nullValueFromJSON(object.null_value) } - : isSet(object.number_value) - ? { $case: "number_value", number_value: Number(object.number_value) } - : isSet(object.string_value) - ? { $case: "string_value", string_value: String(object.string_value) } - : isSet(object.bool_value) - ? { $case: "bool_value", bool_value: Boolean(object.bool_value) } - : isSet(object.struct_value) - ? { $case: "struct_value", struct_value: object.struct_value } - : isSet(object.list_value) - ? { $case: "list_value", list_value: [...object.list_value] } - : undefined, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -512,6 +512,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -520,10 +524,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions-snake/simple.ts b/integration/oneof-unions-snake/simple.ts index a377e002b..68d930e95 100644 --- a/integration/oneof-unions-snake/simple.ts +++ b/integration/oneof-unions-snake/simple.ts @@ -48,6 +48,10 @@ export const SimpleStruct = { return message; }, + fromJSON(object: any): SimpleStruct { + return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; + }, + toJSON(message: SimpleStruct): unknown { const obj: any = {}; if (message.simple_struct !== undefined) { @@ -56,10 +60,6 @@ export const SimpleStruct = { return obj; }, - fromJSON(object: any): SimpleStruct { - return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; - }, - create, I>>(base?: I): SimpleStruct { return SimpleStruct.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions/google/protobuf/struct.ts b/integration/oneof-unions/google/protobuf/struct.ts index f54c228a8..5c0628529 100644 --- a/integration/oneof-unions/google/protobuf/struct.ts +++ b/integration/oneof-unions/google/protobuf/struct.ts @@ -126,6 +126,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -140,17 +151,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -235,6 +235,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -246,10 +250,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -349,6 +349,24 @@ export const Value = { return message; }, + fromJSON(object: any): Value { + return { + kind: isSet(object.nullValue) + ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } + : isSet(object.numberValue) + ? { $case: "numberValue", numberValue: Number(object.numberValue) } + : isSet(object.stringValue) + ? { $case: "stringValue", stringValue: String(object.stringValue) } + : isSet(object.boolValue) + ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } + : isSet(object.structValue) + ? { $case: "structValue", structValue: object.structValue } + : isSet(object.listValue) + ? { $case: "listValue", listValue: [...object.listValue] } + : undefined, + }; + }, + toJSON(message: Value): unknown { const obj: any = {}; if (message.kind?.$case === "nullValue") { @@ -372,24 +390,6 @@ export const Value = { return obj; }, - fromJSON(object: any): Value { - return { - kind: isSet(object.nullValue) - ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } - : isSet(object.numberValue) - ? { $case: "numberValue", numberValue: Number(object.numberValue) } - : isSet(object.stringValue) - ? { $case: "stringValue", stringValue: String(object.stringValue) } - : isSet(object.boolValue) - ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } - : isSet(object.structValue) - ? { $case: "structValue", structValue: object.structValue } - : isSet(object.listValue) - ? { $case: "listValue", listValue: [...object.listValue] } - : undefined, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -503,6 +503,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -511,10 +515,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/oneof-unions/oneof.ts b/integration/oneof-unions/oneof.ts index fe3ee5aed..e377b010a 100644 --- a/integration/oneof-unions/oneof.ts +++ b/integration/oneof-unions/oneof.ts @@ -231,6 +231,35 @@ export const PleaseChoose = { return message; }, + fromJSON(object: any): PleaseChoose { + return { + name: isSet(object.name) ? String(object.name) : "", + choice: isSet(object.aNumber) + ? { $case: "aNumber", aNumber: Number(object.aNumber) } + : isSet(object.aString) + ? { $case: "aString", aString: String(object.aString) } + : isSet(object.aMessage) + ? { $case: "aMessage", aMessage: PleaseChoose_Submessage.fromJSON(object.aMessage) } + : isSet(object.aBool) + ? { $case: "aBool", aBool: Boolean(object.aBool) } + : isSet(object.bunchaBytes) + ? { $case: "bunchaBytes", bunchaBytes: bytesFromBase64(object.bunchaBytes) } + : isSet(object.anEnum) + ? { $case: "anEnum", anEnum: pleaseChoose_StateEnumFromJSON(object.anEnum) } + : undefined, + age: isSet(object.age) ? Number(object.age) : 0, + eitherOr: isSet(object.either) + ? { $case: "either", either: String(object.either) } + : isSet(object.or) + ? { $case: "or", or: String(object.or) } + : isSet(object.thirdOption) + ? { $case: "thirdOption", thirdOption: String(object.thirdOption) } + : undefined, + signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(0), + value: isSet(object?.value) ? object.value : undefined, + }; + }, + toJSON(message: PleaseChoose): unknown { const obj: any = {}; if (message.name !== "") { @@ -275,35 +304,6 @@ export const PleaseChoose = { return obj; }, - fromJSON(object: any): PleaseChoose { - return { - name: isSet(object.name) ? String(object.name) : "", - choice: isSet(object.aNumber) - ? { $case: "aNumber", aNumber: Number(object.aNumber) } - : isSet(object.aString) - ? { $case: "aString", aString: String(object.aString) } - : isSet(object.aMessage) - ? { $case: "aMessage", aMessage: PleaseChoose_Submessage.fromJSON(object.aMessage) } - : isSet(object.aBool) - ? { $case: "aBool", aBool: Boolean(object.aBool) } - : isSet(object.bunchaBytes) - ? { $case: "bunchaBytes", bunchaBytes: bytesFromBase64(object.bunchaBytes) } - : isSet(object.anEnum) - ? { $case: "anEnum", anEnum: pleaseChoose_StateEnumFromJSON(object.anEnum) } - : undefined, - age: isSet(object.age) ? Number(object.age) : 0, - eitherOr: isSet(object.either) - ? { $case: "either", either: String(object.either) } - : isSet(object.or) - ? { $case: "or", or: String(object.or) } - : isSet(object.thirdOption) - ? { $case: "thirdOption", thirdOption: String(object.thirdOption) } - : undefined, - signature: isSet(object.signature) ? bytesFromBase64(object.signature) : new Uint8Array(0), - value: isSet(object?.value) ? object.value : undefined, - }; - }, - create, I>>(base?: I): PleaseChoose { return PleaseChoose.fromPartial(base ?? {}); }, @@ -392,6 +392,10 @@ export const PleaseChoose_Submessage = { return message; }, + fromJSON(object: any): PleaseChoose_Submessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: PleaseChoose_Submessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -400,10 +404,6 @@ export const PleaseChoose_Submessage = { return obj; }, - fromJSON(object: any): PleaseChoose_Submessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): PleaseChoose_Submessage { return PleaseChoose_Submessage.fromPartial(base ?? {}); }, @@ -460,6 +460,13 @@ export const SimpleButOptional = { return message; }, + fromJSON(object: any): SimpleButOptional { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + }; + }, + toJSON(message: SimpleButOptional): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -471,13 +478,6 @@ export const SimpleButOptional = { return obj; }, - fromJSON(object: any): SimpleButOptional { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - }; - }, - create, I>>(base?: I): SimpleButOptional { return SimpleButOptional.fromPartial(base ?? {}); }, diff --git a/integration/output-index/a.ts b/integration/output-index/a.ts index 24cc1c106..05b9a11b9 100644 --- a/integration/output-index/a.ts +++ b/integration/output-index/a.ts @@ -40,6 +40,10 @@ export const A = { return message; }, + fromJSON(object: any): A { + return { a: isSet(object.a) ? String(object.a) : "" }; + }, + toJSON(message: A): unknown { const obj: any = {}; if (message.a !== "") { @@ -48,10 +52,6 @@ export const A = { return obj; }, - fromJSON(object: any): A { - return { a: isSet(object.a) ? String(object.a) : "" }; - }, - create, I>>(base?: I): A { return A.fromPartial(base ?? {}); }, diff --git a/integration/point/point.ts b/integration/point/point.ts index 54e52080b..b98c2845d 100644 --- a/integration/point/point.ts +++ b/integration/point/point.ts @@ -58,6 +58,10 @@ export const Point = { return message; }, + fromJSON(object: any): Point { + return { lat: isSet(object.lat) ? Number(object.lat) : 0, lng: isSet(object.lng) ? Number(object.lng) : 0 }; + }, + toJSON(message: Point): unknown { const obj: any = {}; if (message.lat !== 0) { @@ -69,10 +73,6 @@ export const Point = { return obj; }, - fromJSON(object: any): Point { - return { lat: isSet(object.lat) ? Number(object.lat) : 0, lng: isSet(object.lng) ? Number(object.lng) : 0 }; - }, - create, I>>(base?: I): Point { return Point.fromPartial(base ?? {}); }, @@ -130,6 +130,13 @@ export const Area = { return message; }, + fromJSON(object: any): Area { + return { + nw: isSet(object.nw) ? Point.fromJSON(object.nw) : undefined, + se: isSet(object.se) ? Point.fromJSON(object.se) : undefined, + }; + }, + toJSON(message: Area): unknown { const obj: any = {}; if (message.nw !== undefined) { @@ -141,13 +148,6 @@ export const Area = { return obj; }, - fromJSON(object: any): Area { - return { - nw: isSet(object.nw) ? Point.fromJSON(object.nw) : undefined, - se: isSet(object.se) ? Point.fromJSON(object.se) : undefined, - }; - }, - create, I>>(base?: I): Area { return Area.fromPartial(base ?? {}); }, diff --git a/integration/reserved-words/reserved-words.ts b/integration/reserved-words/reserved-words.ts index ef1097732..c8e70e8fe 100644 --- a/integration/reserved-words/reserved-words.ts +++ b/integration/reserved-words/reserved-words.ts @@ -31,15 +31,15 @@ export const Record = { return message; }, + fromJSON(_: any): Record { + return {}; + }, + toJSON(_: Record): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Record { - return {}; - }, - create, I>>(base?: I): Record { return Record.fromPartial(base ?? {}); }, diff --git a/integration/return-observable/observable.ts b/integration/return-observable/observable.ts index 7ef1338fb..1d9048445 100644 --- a/integration/return-observable/observable.ts +++ b/integration/return-observable/observable.ts @@ -47,6 +47,10 @@ export const ProduceRequest = { return message; }, + fromJSON(object: any): ProduceRequest { + return { ingredients: isSet(object.ingredients) ? String(object.ingredients) : "" }; + }, + toJSON(message: ProduceRequest): unknown { const obj: any = {}; if (message.ingredients !== "") { @@ -55,10 +59,6 @@ export const ProduceRequest = { return obj; }, - fromJSON(object: any): ProduceRequest { - return { ingredients: isSet(object.ingredients) ? String(object.ingredients) : "" }; - }, - create, I>>(base?: I): ProduceRequest { return ProduceRequest.fromPartial(base ?? {}); }, @@ -105,6 +105,10 @@ export const ProduceReply = { return message; }, + fromJSON(object: any): ProduceReply { + return { result: isSet(object.result) ? String(object.result) : "" }; + }, + toJSON(message: ProduceReply): unknown { const obj: any = {}; if (message.result !== "") { @@ -113,10 +117,6 @@ export const ProduceReply = { return obj; }, - fromJSON(object: any): ProduceReply { - return { result: isSet(object.result) ? String(object.result) : "" }; - }, - create, I>>(base?: I): ProduceReply { return ProduceReply.fromPartial(base ?? {}); }, diff --git a/integration/simple-deprecated-fields/simple.ts b/integration/simple-deprecated-fields/simple.ts index 3fc013b1c..f9a7fb45b 100644 --- a/integration/simple-deprecated-fields/simple.ts +++ b/integration/simple-deprecated-fields/simple.ts @@ -108,6 +108,16 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + testField: isSet(object.testField) ? String(object.testField) : "", + testNotDeprecated: isSet(object.testNotDeprecated) ? String(object.testNotDeprecated) : "", + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -128,16 +138,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - testField: isSet(object.testField) ? String(object.testField) : "", - testNotDeprecated: isSet(object.testNotDeprecated) ? String(object.testNotDeprecated) : "", - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -188,6 +188,10 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -196,10 +200,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/simple-esmodule-interop/simple.ts b/integration/simple-esmodule-interop/simple.ts index fd8c9c5d8..797fea600 100644 --- a/integration/simple-esmodule-interop/simple.ts +++ b/integration/simple-esmodule-interop/simple.ts @@ -69,6 +69,10 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -80,10 +84,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { name: isSet(object.name) ? String(object.name) : "", age: isSet(object.age) ? Number(object.age) : 0 }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -254,6 +254,23 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -295,23 +312,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-json-name/google/protobuf/timestamp.ts b/integration/simple-json-name/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/simple-json-name/google/protobuf/timestamp.ts +++ b/integration/simple-json-name/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-json-name/simple.ts b/integration/simple-json-name/simple.ts index d9a4bb9dd..37f2a3705 100644 --- a/integration/simple-json-name/simple.ts +++ b/integration/simple-json-name/simple.ts @@ -129,6 +129,19 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.other_name) ? String(object.other_name) : "", + age: isSet(object.other_age) ? Number(object.other_age) : undefined, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + hyphen: isSet(object["hyphened-name"]) ? String(object["hyphened-name"]) : "", + spaces: isSet(object["name with spaces"]) ? String(object["name with spaces"]) : "", + dollarStart: isSet(object.$dollar) ? String(object.$dollar) : "", + dollarEnd: isSet(object.dollar$) ? String(object.dollar$) : "", + hyphenList: Array.isArray(object?.["hyphen-list"]) ? object["hyphen-list"].map((e: any) => String(e)) : [], + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -158,19 +171,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.other_name) ? String(object.other_name) : "", - age: isSet(object.other_age) ? Number(object.other_age) : undefined, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - hyphen: isSet(object["hyphened-name"]) ? String(object["hyphened-name"]) : "", - spaces: isSet(object["name with spaces"]) ? String(object["name with spaces"]) : "", - dollarStart: isSet(object.$dollar) ? String(object.$dollar) : "", - dollarEnd: isSet(object.dollar$) ? String(object.dollar$) : "", - hyphenList: Array.isArray(object?.["hyphen-list"]) ? object["hyphen-list"].map((e: any) => String(e)) : [], - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-bigint/google/protobuf/timestamp.ts b/integration/simple-long-bigint/google/protobuf/timestamp.ts index bc7c711e2..dbc000c51 100644 --- a/integration/simple-long-bigint/google/protobuf/timestamp.ts +++ b/integration/simple-long-bigint/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { return message; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt("0"), + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== BigInt("0")) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt("0"), - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-bigint/google/protobuf/wrappers.ts b/integration/simple-long-bigint/google/protobuf/wrappers.ts index 0f30b98a5..6f5ad2a6a 100644 --- a/integration/simple-long-bigint/google/protobuf/wrappers.ts +++ b/integration/simple-long-bigint/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== BigInt("0")) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== BigInt("0")) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? BigInt(object.value) : BigInt("0") }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-bigint/simple.ts b/integration/simple-long-bigint/simple.ts index 5a4c53cdb..d773deb76 100644 --- a/integration/simple-long-bigint/simple.ts +++ b/integration/simple-long-bigint/simple.ts @@ -227,6 +227,26 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? BigInt(object.int64) : BigInt("0"), + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? BigInt(object.uint64) : BigInt("0"), + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? BigInt(object.sint64) : BigInt("0"), + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? BigInt(object.fixed64) : BigInt("0"), + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? BigInt(object.sfixed64) : BigInt("0"), + guint64: isSet(object.guint64) ? BigInt(object.guint64) : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + uint64s: Array.isArray(object?.uint64s) ? object.uint64s.map((e: any) => BigInt(e)) : [], + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -277,26 +297,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? BigInt(object.int64) : BigInt("0"), - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? BigInt(object.uint64) : BigInt("0"), - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? BigInt(object.sint64) : BigInt("0"), - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? BigInt(object.fixed64) : BigInt("0"), - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? BigInt(object.sfixed64) : BigInt("0"), - guint64: isSet(object.guint64) ? BigInt(object.guint64) : undefined, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - uint64s: Array.isArray(object?.uint64s) ? object.uint64s.map((e: any) => BigInt(e)) : [], - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-string/google/protobuf/timestamp.ts b/integration/simple-long-string/google/protobuf/timestamp.ts index 9ff4662e1..7785db1cd 100644 --- a/integration/simple-long-string/google/protobuf/timestamp.ts +++ b/integration/simple-long-string/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { return message; }, + fromJSON(object: any): Timestamp { + return { + seconds: isSet(object.seconds) ? String(object.seconds) : "0", + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== "0") { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? String(object.seconds) : "0", - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-string/google/protobuf/wrappers.ts b/integration/simple-long-string/google/protobuf/wrappers.ts index 2640223a8..aa0588050 100644 --- a/integration/simple-long-string/google/protobuf/wrappers.ts +++ b/integration/simple-long-string/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? String(object.value) : "0" }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== "0") { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? String(object.value) : "0" }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? String(object.value) : "0" }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== "0") { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? String(object.value) : "0" }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-long-string/simple.ts b/integration/simple-long-string/simple.ts index 56ddb30ce..1c9f48f3f 100644 --- a/integration/simple-long-string/simple.ts +++ b/integration/simple-long-string/simple.ts @@ -203,6 +203,25 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? String(object.int64) : "0", + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? String(object.uint64) : "0", + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? String(object.sint64) : "0", + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? String(object.fixed64) : "0", + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? String(object.sfixed64) : "0", + guint64: isSet(object.guint64) ? String(object.guint64) : undefined, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -250,25 +269,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? String(object.int64) : "0", - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? String(object.uint64) : "0", - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? String(object.sint64) : "0", - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? String(object.fixed64) : "0", - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? String(object.sfixed64) : "0", - guint64: isSet(object.guint64) ? String(object.guint64) : undefined, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-long/google/protobuf/wrappers.ts b/integration/simple-long/google/protobuf/wrappers.ts index 694569f15..f0fe7c61c 100644 --- a/integration/simple-long/google/protobuf/wrappers.ts +++ b/integration/simple-long/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (!message.value.isZero()) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.UZERO }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (!message.value.isZero()) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Long.fromValue(object.value) : Long.UZERO }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-long/simple.ts b/integration/simple-long/simple.ts index 534185cda..73815f744 100644 --- a/integration/simple-long/simple.ts +++ b/integration/simple-long/simple.ts @@ -138,6 +138,17 @@ export const SimpleWithWrappers = { return message; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + bananas: isSet(object.bananas) ? Long.fromValue(object.bananas) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -161,17 +172,6 @@ export const SimpleWithWrappers = { return obj; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - bananas: isSet(object.bananas) ? Long.fromValue(object.bananas) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -254,6 +254,29 @@ export const SimpleWithMap = { return message; }, + fromJSON(object: any): SimpleWithMap { + return { + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + longLookup: isObject(object.longLookup) + ? Object.entries(object.longLookup).reduce<{ [key: string]: Long }>((acc, [key, value]) => { + acc[key] = Long.fromValue(value as Long | string); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.nameLookup) { @@ -286,29 +309,6 @@ export const SimpleWithMap = { return obj; }, - fromJSON(object: any): SimpleWithMap { - return { - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - longLookup: isObject(object.longLookup) - ? Object.entries(object.longLookup).reduce<{ [key: string]: Long }>((acc, [key, value]) => { - acc[key] = Long.fromValue(value as Long | string); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -391,6 +391,10 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -402,10 +406,6 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -465,6 +465,10 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -476,10 +480,6 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -537,6 +537,13 @@ export const SimpleWithMap_LongLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_LongLookupEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, + }; + }, + toJSON(message: SimpleWithMap_LongLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -548,13 +555,6 @@ export const SimpleWithMap_LongLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_LongLookupEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Long.fromValue(object.value) : Long.ZERO, - }; - }, - create, I>>(base?: I): SimpleWithMap_LongLookupEntry { return SimpleWithMap_LongLookupEntry.fromPartial(base ?? {}); }, @@ -750,6 +750,24 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Long.fromValue(object.int64) : Long.ZERO, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Long.fromValue(object.uint64) : Long.UZERO, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Long.fromValue(object.sint64) : Long.ZERO, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Long.fromValue(object.fixed64) : Long.UZERO, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Long.fromValue(object.sfixed64) : Long.ZERO, + manyUint64: Array.isArray(object?.manyUint64) ? object.manyUint64.map((e: any) => Long.fromValue(e)) : [], + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -794,24 +812,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Long.fromValue(object.int64) : Long.ZERO, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Long.fromValue(object.uint64) : Long.UZERO, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Long.fromValue(object.sint64) : Long.ZERO, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Long.fromValue(object.fixed64) : Long.UZERO, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Long.fromValue(object.sfixed64) : Long.ZERO, - manyUint64: Array.isArray(object?.manyUint64) ? object.manyUint64.map((e: any) => Long.fromValue(e)) : [], - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/google/protobuf/timestamp.ts b/integration/simple-optionals/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/simple-optionals/google/protobuf/timestamp.ts +++ b/integration/simple-optionals/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/google/protobuf/wrappers.ts b/integration/simple-optionals/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/simple-optionals/google/protobuf/wrappers.ts +++ b/integration/simple-optionals/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/import_dir/thing.ts b/integration/simple-optionals/import_dir/thing.ts index af3bd826e..dacd1b268 100644 --- a/integration/simple-optionals/import_dir/thing.ts +++ b/integration/simple-optionals/import_dir/thing.ts @@ -43,6 +43,10 @@ export const ImportedThing = { return message; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -51,10 +55,6 @@ export const ImportedThing = { return obj; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/simple.ts b/integration/simple-optionals/simple.ts index f281a7dff..dbc6a1ee4 100644 --- a/integration/simple-optionals/simple.ts +++ b/integration/simple-optionals/simple.ts @@ -398,6 +398,23 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -433,23 +450,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -517,6 +517,13 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -528,13 +535,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -602,6 +602,14 @@ export const Nested = { return message; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -616,14 +624,6 @@ export const Nested = { return obj; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -684,6 +684,13 @@ export const Nested_InnerMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -695,13 +702,6 @@ export const Nested_InnerMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -751,6 +751,10 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -759,10 +763,6 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -821,6 +821,13 @@ export const OneOfMessage = { return message; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -832,13 +839,6 @@ export const OneOfMessage = { return obj; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -926,6 +926,16 @@ export const SimpleWithWrappers = { return message; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -946,16 +956,6 @@ export const SimpleWithWrappers = { return obj; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1006,6 +1006,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1014,10 +1018,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1093,6 +1093,29 @@ export const SimpleWithMap = { return message; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1125,29 +1148,6 @@ export const SimpleWithMap = { return obj; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1230,6 +1230,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1241,13 +1248,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1309,6 +1309,10 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1320,10 +1324,6 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1383,6 +1383,10 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1394,10 +1398,6 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1448,6 +1448,17 @@ export const SimpleWithSnakeCaseMap = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1462,17 +1473,6 @@ export const SimpleWithSnakeCaseMap = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -1537,6 +1537,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1548,13 +1555,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -1608,6 +1608,10 @@ export const PingRequest = { return message; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -1616,10 +1620,6 @@ export const PingRequest = { return obj; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -1666,6 +1666,10 @@ export const PingResponse = { return message; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -1674,10 +1678,6 @@ export const PingResponse = { return obj; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -1847,6 +1847,23 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -1888,23 +1905,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple-optionals/thing.ts b/integration/simple-optionals/thing.ts index 694fc72a5..f890da70b 100644 --- a/integration/simple-optionals/thing.ts +++ b/integration/simple-optionals/thing.ts @@ -43,6 +43,10 @@ export const ImportedThing = { return message; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -51,10 +55,6 @@ export const ImportedThing = { return obj; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-proto2/simple.ts b/integration/simple-proto2/simple.ts index c91d30d3e..1b086230d 100644 --- a/integration/simple-proto2/simple.ts +++ b/integration/simple-proto2/simple.ts @@ -75,6 +75,10 @@ export const Issue56 = { return message; }, + fromJSON(object: any): Issue56 { + return { test: isSet(object.test) ? enumWithoutZeroFromJSON(object.test) : 1 }; + }, + toJSON(message: Issue56): unknown { const obj: any = {}; if (message.test !== 1) { @@ -83,10 +87,6 @@ export const Issue56 = { return obj; }, - fromJSON(object: any): Issue56 { - return { test: isSet(object.test) ? enumWithoutZeroFromJSON(object.test) : 1 }; - }, - create, I>>(base?: I): Issue56 { return Issue56.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/google/protobuf/timestamp.ts b/integration/simple-prototype-defaults/google/protobuf/timestamp.ts index 34b1d16a9..c1279f5f9 100644 --- a/integration/simple-prototype-defaults/google/protobuf/timestamp.ts +++ b/integration/simple-prototype-defaults/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts index 0567fb42b..b8a1a2f92 100644 --- a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts +++ b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/google/type/date.ts b/integration/simple-prototype-defaults/google/type/date.ts index d10ac99df..2e042add8 100644 --- a/integration/simple-prototype-defaults/google/type/date.ts +++ b/integration/simple-prototype-defaults/google/type/date.ts @@ -89,6 +89,14 @@ export const DateMessage = { return message; }, + fromJSON(object: any): DateMessage { + return { + year: isSet(object.year) ? Number(object.year) : 0, + month: isSet(object.month) ? Number(object.month) : 0, + day: isSet(object.day) ? Number(object.day) : 0, + }; + }, + toJSON(message: DateMessage): unknown { const obj: any = {}; if (message.year !== 0) { @@ -103,14 +111,6 @@ export const DateMessage = { return obj; }, - fromJSON(object: any): DateMessage { - return { - year: isSet(object.year) ? Number(object.year) : 0, - month: isSet(object.month) ? Number(object.month) : 0, - day: isSet(object.day) ? Number(object.day) : 0, - }; - }, - create, I>>(base?: I): DateMessage { return DateMessage.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/import_dir/thing.ts b/integration/simple-prototype-defaults/import_dir/thing.ts index 86de68a07..9ae339e4a 100644 --- a/integration/simple-prototype-defaults/import_dir/thing.ts +++ b/integration/simple-prototype-defaults/import_dir/thing.ts @@ -43,6 +43,10 @@ export const ImportedThing = { return message; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -51,10 +55,6 @@ export const ImportedThing = { return obj; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-prototype-defaults/simple.ts b/integration/simple-prototype-defaults/simple.ts index e81dcf868..fe9580023 100644 --- a/integration/simple-prototype-defaults/simple.ts +++ b/integration/simple-prototype-defaults/simple.ts @@ -493,6 +493,26 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -537,26 +557,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -629,6 +629,13 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -640,13 +647,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -714,6 +714,14 @@ export const Nested = { return message; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -728,14 +736,6 @@ export const Nested = { return obj; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -796,6 +796,13 @@ export const Nested_InnerMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -807,13 +814,6 @@ export const Nested_InnerMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -863,6 +863,10 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -871,10 +875,6 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -933,6 +933,13 @@ export const OneOfMessage = { return message; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -944,13 +951,6 @@ export const OneOfMessage = { return obj; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -1048,6 +1048,17 @@ export const SimpleWithWrappers = { return message; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + id: isSet(object.id) ? new Uint8Array(object.id) : undefined, + }; + }, + toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -1071,17 +1082,6 @@ export const SimpleWithWrappers = { return obj; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - id: isSet(object.id) ? new Uint8Array(object.id) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1133,6 +1133,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1141,10 +1145,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1282,6 +1282,56 @@ export const SimpleWithMap = { return message; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { + acc[key] = fromJsonTimestamp(value); + return acc; + }, {}) + : {}, + mapOfBytes: isObject(object.mapOfBytes) + ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { + acc[key] = bytesFromBase64(value as string); + return acc; + }, {}) + : {}, + mapOfStringValues: isObject(object.mapOfStringValues) + ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( + (acc, [key, value]) => { + acc[key] = value as string | undefined; + return acc; + }, + {}, + ) + : {}, + longLookup: isObject(object.longLookup) + ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1350,56 +1400,6 @@ export const SimpleWithMap = { return obj; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { - acc[key] = fromJsonTimestamp(value); - return acc; - }, {}) - : {}, - mapOfBytes: isObject(object.mapOfBytes) - ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { - acc[key] = bytesFromBase64(value as string); - return acc; - }, {}) - : {}, - mapOfStringValues: isObject(object.mapOfStringValues) - ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( - (acc, [key, value]) => { - acc[key] = value as string | undefined; - return acc; - }, - {}, - ) - : {}, - longLookup: isObject(object.longLookup) - ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1517,6 +1517,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1528,13 +1535,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1596,6 +1596,10 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1607,10 +1611,6 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1670,6 +1670,10 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1681,10 +1685,6 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1742,6 +1742,13 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1753,13 +1760,6 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithMap_MapOfTimestampsEntry { @@ -1821,6 +1821,13 @@ export const SimpleWithMap_MapOfBytesEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), + }; + }, + toJSON(message: SimpleWithMap_MapOfBytesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1832,13 +1839,6 @@ export const SimpleWithMap_MapOfBytesEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), - }; - }, - create, I>>(base?: I): SimpleWithMap_MapOfBytesEntry { return SimpleWithMap_MapOfBytesEntry.fromPartial(base ?? {}); }, @@ -1900,6 +1900,13 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_MapOfStringValuesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1911,13 +1918,6 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithMap_MapOfStringValuesEntry { @@ -1981,6 +1981,10 @@ export const SimpleWithMap_LongLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_LongLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_LongLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1992,10 +1996,6 @@ export const SimpleWithMap_LongLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_LongLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_LongLookupEntry { return SimpleWithMap_LongLookupEntry.fromPartial(base ?? {}); }, @@ -2048,6 +2048,17 @@ export const SimpleWithSnakeCaseMap = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -2062,17 +2073,6 @@ export const SimpleWithSnakeCaseMap = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -2139,6 +2139,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2150,13 +2157,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -2215,6 +2215,17 @@ export const SimpleWithMapOfEnums = { return message; }, + fromJSON(object: any): SimpleWithMapOfEnums { + return { + enumsById: isObject(object.enumsById) + ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { + acc[Number(key)] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMapOfEnums): unknown { const obj: any = {}; if (message.enumsById) { @@ -2229,17 +2240,6 @@ export const SimpleWithMapOfEnums = { return obj; }, - fromJSON(object: any): SimpleWithMapOfEnums { - return { - enumsById: isObject(object.enumsById) - ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { - acc[Number(key)] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMapOfEnums { return SimpleWithMapOfEnums.fromPartial(base ?? {}); }, @@ -2306,6 +2306,13 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, + }; + }, + toJSON(message: SimpleWithMapOfEnums_EnumsByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2317,13 +2324,6 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, - }; - }, - create, I>>( base?: I, ): SimpleWithMapOfEnums_EnumsByIdEntry { @@ -2377,6 +2377,10 @@ export const PingRequest = { return message; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -2385,10 +2389,6 @@ export const PingRequest = { return obj; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -2435,6 +2435,10 @@ export const PingResponse = { return message; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -2443,10 +2447,6 @@ export const PingResponse = { return obj; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -2616,6 +2616,23 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -2657,23 +2674,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, @@ -2799,6 +2799,18 @@ export const SimpleButOptional = { return message; }, + fromJSON(object: any): SimpleButOptional { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + }; + }, + toJSON(message: SimpleButOptional): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -2825,18 +2837,6 @@ export const SimpleButOptional = { return obj; }, - fromJSON(object: any): SimpleButOptional { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - }; - }, - create, I>>(base?: I): SimpleButOptional { return SimpleButOptional.fromPartial(base ?? {}); }, @@ -2883,15 +2883,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/google/protobuf/struct.ts b/integration/simple-snake/google/protobuf/struct.ts index 192a29dda..cf5700cc5 100644 --- a/integration/simple-snake/google/protobuf/struct.ts +++ b/integration/simple-snake/google/protobuf/struct.ts @@ -140,6 +140,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -154,17 +165,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,6 +249,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -260,10 +264,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,6 +368,17 @@ export const Value = { return message; }, + fromJSON(object: any): Value { + return { + null_value: isSet(object.null_value) ? nullValueFromJSON(object.null_value) : undefined, + number_value: isSet(object.number_value) ? Number(object.number_value) : undefined, + string_value: isSet(object.string_value) ? String(object.string_value) : undefined, + bool_value: isSet(object.bool_value) ? Boolean(object.bool_value) : undefined, + struct_value: isObject(object.struct_value) ? object.struct_value : undefined, + list_value: Array.isArray(object.list_value) ? [...object.list_value] : undefined, + }; + }, + toJSON(message: Value): unknown { const obj: any = {}; if (message.null_value !== undefined) { @@ -391,17 +402,6 @@ export const Value = { return obj; }, - fromJSON(object: any): Value { - return { - null_value: isSet(object.null_value) ? nullValueFromJSON(object.null_value) : undefined, - number_value: isSet(object.number_value) ? Number(object.number_value) : undefined, - string_value: isSet(object.string_value) ? String(object.string_value) : undefined, - bool_value: isSet(object.bool_value) ? Boolean(object.bool_value) : undefined, - struct_value: isObject(object.struct_value) ? object.struct_value : undefined, - list_value: Array.isArray(object.list_value) ? [...object.list_value] : undefined, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,6 +490,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -498,10 +502,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/google/protobuf/timestamp.ts b/integration/simple-snake/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/simple-snake/google/protobuf/timestamp.ts +++ b/integration/simple-snake/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/google/protobuf/wrappers.ts b/integration/simple-snake/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/simple-snake/google/protobuf/wrappers.ts +++ b/integration/simple-snake/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/import_dir/thing.ts b/integration/simple-snake/import_dir/thing.ts index 1cc01b254..ea62d88a7 100644 --- a/integration/simple-snake/import_dir/thing.ts +++ b/integration/simple-snake/import_dir/thing.ts @@ -43,6 +43,10 @@ export const ImportedThing = { return message; }, + fromJSON(object: any): ImportedThing { + return { created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined }; + }, + toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.created_at !== undefined) { @@ -51,10 +55,6 @@ export const ImportedThing = { return obj; }, - fromJSON(object: any): ImportedThing { - return { created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined }; - }, - create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-snake/simple.ts b/integration/simple-snake/simple.ts index 777eaefd8..6c2d143ee 100644 --- a/integration/simple-snake/simple.ts +++ b/integration/simple-snake/simple.ts @@ -403,6 +403,23 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grand_children: Array.isArray(object?.grand_children) + ? object.grand_children.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + old_states: Array.isArray(object?.old_states) ? object.old_states.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -438,23 +455,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - created_at: isSet(object.created_at) ? fromJsonTimestamp(object.created_at) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grand_children: Array.isArray(object?.grand_children) - ? object.grand_children.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - old_states: Array.isArray(object?.old_states) ? object.old_states.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -522,6 +522,13 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -533,13 +540,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -607,6 +607,14 @@ export const Nested = { return message; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -621,14 +629,6 @@ export const Nested = { return obj; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -689,6 +689,13 @@ export const Nested_InnerMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -700,13 +707,6 @@ export const Nested_InnerMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -756,6 +756,10 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -764,10 +768,6 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -826,6 +826,13 @@ export const OneOfMessage = { return message; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -837,13 +844,6 @@ export const OneOfMessage = { return obj; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -931,6 +931,16 @@ export const SimpleWithWrappers = { return message; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -951,16 +961,6 @@ export const SimpleWithWrappers = { return obj; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1011,6 +1011,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1019,10 +1023,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1098,6 +1098,29 @@ export const SimpleWithMap = { return message; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1130,29 +1153,6 @@ export const SimpleWithMap = { return obj; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1235,6 +1235,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1246,13 +1253,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1314,6 +1314,10 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1325,10 +1329,6 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1388,6 +1388,10 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1399,10 +1403,6 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1453,6 +1453,17 @@ export const SimpleWithSnakeCaseMap = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entities_by_id: isObject(object.entities_by_id) + ? Object.entries(object.entities_by_id).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entities_by_id) { @@ -1467,17 +1478,6 @@ export const SimpleWithSnakeCaseMap = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entities_by_id: isObject(object.entities_by_id) - ? Object.entries(object.entities_by_id).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -1542,6 +1542,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1553,13 +1560,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -1613,6 +1613,10 @@ export const PingRequest = { return message; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -1621,10 +1625,6 @@ export const PingRequest = { return obj; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -1671,6 +1671,10 @@ export const PingResponse = { return message; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -1679,10 +1683,6 @@ export const PingResponse = { return obj; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -1852,6 +1852,23 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -1893,23 +1910,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, @@ -1967,6 +1967,10 @@ export const SimpleStruct = { return message; }, + fromJSON(object: any): SimpleStruct { + return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; + }, + toJSON(message: SimpleStruct): unknown { const obj: any = {}; if (message.simple_struct !== undefined) { @@ -1975,10 +1979,6 @@ export const SimpleStruct = { return obj; }, - fromJSON(object: any): SimpleStruct { - return { simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined }; - }, - create, I>>(base?: I): SimpleStruct { return SimpleStruct.fromPartial(base ?? {}); }, diff --git a/integration/simple-string-enums/google/protobuf/struct.ts b/integration/simple-string-enums/google/protobuf/struct.ts index 5bbdfce20..c0bd44e2d 100644 --- a/integration/simple-string-enums/google/protobuf/struct.ts +++ b/integration/simple-string-enums/google/protobuf/struct.ts @@ -150,6 +150,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -164,17 +175,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -259,6 +259,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -270,10 +274,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -378,6 +378,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -401,17 +412,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -500,6 +500,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -508,10 +512,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-string-enums/simple.ts b/integration/simple-string-enums/simple.ts index aeb54f093..05a4259c8 100644 --- a/integration/simple-string-enums/simple.ts +++ b/integration/simple-string-enums/simple.ts @@ -160,6 +160,21 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + state: isSet(object.state) ? stateEnumFromJSON(object.state) : StateEnum.UNKNOWN, + states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], + nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : NullValue.NULL_VALUE, + stateMap: isObject(object.stateMap) + ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { + acc[key] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -186,21 +201,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - state: isSet(object.state) ? stateEnumFromJSON(object.state) : StateEnum.UNKNOWN, - states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], - nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : NullValue.NULL_VALUE, - stateMap: isObject(object.stateMap) - ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { - acc[key] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -269,6 +269,13 @@ export const Simple_StateMapEntry = { return message; }, + fromJSON(object: any): Simple_StateMapEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? stateEnumFromJSON(object.value) : StateEnum.UNKNOWN, + }; + }, + toJSON(message: Simple_StateMapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -280,13 +287,6 @@ export const Simple_StateMapEntry = { return obj; }, - fromJSON(object: any): Simple_StateMapEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? stateEnumFromJSON(object.value) : StateEnum.UNKNOWN, - }; - }, - create, I>>(base?: I): Simple_StateMapEntry { return Simple_StateMapEntry.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/import_dir/thing.ts b/integration/simple-unrecognized-enum/import_dir/thing.ts index 279398644..4fe4bb1a2 100644 --- a/integration/simple-unrecognized-enum/import_dir/thing.ts +++ b/integration/simple-unrecognized-enum/import_dir/thing.ts @@ -43,6 +43,10 @@ export const ImportedThing = { return message; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -51,10 +55,6 @@ export const ImportedThing = { return obj; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple-unrecognized-enum/simple.ts b/integration/simple-unrecognized-enum/simple.ts index 4d1cedd67..e4b7063ff 100644 --- a/integration/simple-unrecognized-enum/simple.ts +++ b/integration/simple-unrecognized-enum/simple.ts @@ -386,6 +386,23 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -421,23 +438,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -505,6 +505,13 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -516,13 +523,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -590,6 +590,14 @@ export const Nested = { return message; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -604,14 +612,6 @@ export const Nested = { return obj; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -672,6 +672,13 @@ export const Nested_InnerMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -683,13 +690,6 @@ export const Nested_InnerMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -739,6 +739,10 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -747,10 +751,6 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -809,6 +809,13 @@ export const OneOfMessage = { return message; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -820,13 +827,6 @@ export const OneOfMessage = { return obj; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -914,6 +914,16 @@ export const SimpleWithWrappers = { return message; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + }; + }, + toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -934,16 +944,6 @@ export const SimpleWithWrappers = { return obj; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - }; - }, - create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -994,6 +994,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1002,10 +1006,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1081,6 +1081,29 @@ export const SimpleWithMap = { return message; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1113,29 +1136,6 @@ export const SimpleWithMap = { return obj; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1218,6 +1218,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1229,13 +1236,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1297,6 +1297,10 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1308,10 +1312,6 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1371,6 +1371,10 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1382,10 +1386,6 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1436,6 +1436,17 @@ export const SimpleWithSnakeCaseMap = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1450,17 +1461,6 @@ export const SimpleWithSnakeCaseMap = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -1525,6 +1525,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1536,13 +1543,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -1596,6 +1596,10 @@ export const PingRequest = { return message; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -1604,10 +1608,6 @@ export const PingRequest = { return obj; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -1654,6 +1654,10 @@ export const PingResponse = { return message; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -1662,10 +1666,6 @@ export const PingResponse = { return obj; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -1835,6 +1835,23 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -1876,23 +1893,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, diff --git a/integration/simple/google/protobuf/timestamp.ts b/integration/simple/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/simple/google/protobuf/timestamp.ts +++ b/integration/simple/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/simple/google/protobuf/wrappers.ts b/integration/simple/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/simple/google/protobuf/wrappers.ts +++ b/integration/simple/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/simple/google/type/date.ts b/integration/simple/google/type/date.ts index 9d18a2931..055208cca 100644 --- a/integration/simple/google/type/date.ts +++ b/integration/simple/google/type/date.ts @@ -89,6 +89,14 @@ export const DateMessage = { return message; }, + fromJSON(object: any): DateMessage { + return { + year: isSet(object.year) ? Number(object.year) : 0, + month: isSet(object.month) ? Number(object.month) : 0, + day: isSet(object.day) ? Number(object.day) : 0, + }; + }, + toJSON(message: DateMessage): unknown { const obj: any = {}; if (message.year !== 0) { @@ -103,14 +111,6 @@ export const DateMessage = { return obj; }, - fromJSON(object: any): DateMessage { - return { - year: isSet(object.year) ? Number(object.year) : 0, - month: isSet(object.month) ? Number(object.month) : 0, - day: isSet(object.day) ? Number(object.day) : 0, - }; - }, - create, I>>(base?: I): DateMessage { return DateMessage.fromPartial(base ?? {}); }, diff --git a/integration/simple/import_dir/thing.ts b/integration/simple/import_dir/thing.ts index 279398644..4fe4bb1a2 100644 --- a/integration/simple/import_dir/thing.ts +++ b/integration/simple/import_dir/thing.ts @@ -43,6 +43,10 @@ export const ImportedThing = { return message; }, + fromJSON(object: any): ImportedThing { + return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; + }, + toJSON(message: ImportedThing): unknown { const obj: any = {}; if (message.createdAt !== undefined) { @@ -51,10 +55,6 @@ export const ImportedThing = { return obj; }, - fromJSON(object: any): ImportedThing { - return { createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined }; - }, - create, I>>(base?: I): ImportedThing { return ImportedThing.fromPartial(base ?? {}); }, diff --git a/integration/simple/simple.ts b/integration/simple/simple.ts index 427df9c53..4e07b22b8 100644 --- a/integration/simple/simple.ts +++ b/integration/simple/simple.ts @@ -505,6 +505,27 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + age: isSet(object.age) ? Number(object.age) : 0, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + grandChildren: Array.isArray(object?.grandChildren) + ? object.grandChildren.map((e: any) => Child.fromJSON(e)) + : [], + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), + enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -552,27 +573,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - age: isSet(object.age) ? Number(object.age) : 0, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - grandChildren: Array.isArray(object?.grandChildren) - ? object.grandChildren.map((e: any) => Child.fromJSON(e)) - : [], - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - oldStates: Array.isArray(object?.oldStates) ? object.oldStates.map((e: any) => stateEnumFromJSON(e)) : [], - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - blobs: Array.isArray(object?.blobs) ? object.blobs.map((e: any) => bytesFromBase64(e)) : [], - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - blob: isSet(object.blob) ? bytesFromBase64(object.blob) : new Uint8Array(0), - enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -646,6 +646,13 @@ export const Child = { return message; }, + fromJSON(object: any): Child { + return { + name: isSet(object.name) ? String(object.name) : "", + type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, + }; + }, + toJSON(message: Child): unknown { const obj: any = {}; if (message.name !== "") { @@ -657,13 +664,6 @@ export const Child = { return obj; }, - fromJSON(object: any): Child { - return { - name: isSet(object.name) ? String(object.name) : "", - type: isSet(object.type) ? child_TypeFromJSON(object.type) : 0, - }; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, @@ -731,6 +731,14 @@ export const Nested = { return message; }, + fromJSON(object: any): Nested { + return { + name: isSet(object.name) ? String(object.name) : "", + message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, + state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, + }; + }, + toJSON(message: Nested): unknown { const obj: any = {}; if (message.name !== "") { @@ -745,14 +753,6 @@ export const Nested = { return obj; }, - fromJSON(object: any): Nested { - return { - name: isSet(object.name) ? String(object.name) : "", - message: isSet(object.message) ? Nested_InnerMessage.fromJSON(object.message) : undefined, - state: isSet(object.state) ? nested_InnerEnumFromJSON(object.state) : 0, - }; - }, - create, I>>(base?: I): Nested { return Nested.fromPartial(base ?? {}); }, @@ -813,6 +813,13 @@ export const Nested_InnerMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage { + return { + name: isSet(object.name) ? String(object.name) : "", + deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, + }; + }, + toJSON(message: Nested_InnerMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -824,13 +831,6 @@ export const Nested_InnerMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage { - return { - name: isSet(object.name) ? String(object.name) : "", - deep: isSet(object.deep) ? Nested_InnerMessage_DeepMessage.fromJSON(object.deep) : undefined, - }; - }, - create, I>>(base?: I): Nested_InnerMessage { return Nested_InnerMessage.fromPartial(base ?? {}); }, @@ -880,6 +880,10 @@ export const Nested_InnerMessage_DeepMessage = { return message; }, + fromJSON(object: any): Nested_InnerMessage_DeepMessage { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + toJSON(message: Nested_InnerMessage_DeepMessage): unknown { const obj: any = {}; if (message.name !== "") { @@ -888,10 +892,6 @@ export const Nested_InnerMessage_DeepMessage = { return obj; }, - fromJSON(object: any): Nested_InnerMessage_DeepMessage { - return { name: isSet(object.name) ? String(object.name) : "" }; - }, - create, I>>(base?: I): Nested_InnerMessage_DeepMessage { return Nested_InnerMessage_DeepMessage.fromPartial(base ?? {}); }, @@ -950,6 +950,13 @@ export const OneOfMessage = { return message; }, + fromJSON(object: any): OneOfMessage { + return { + first: isSet(object.first) ? String(object.first) : undefined, + last: isSet(object.last) ? String(object.last) : undefined, + }; + }, + toJSON(message: OneOfMessage): unknown { const obj: any = {}; if (message.first !== undefined) { @@ -961,13 +968,6 @@ export const OneOfMessage = { return obj; }, - fromJSON(object: any): OneOfMessage { - return { - first: isSet(object.first) ? String(object.first) : undefined, - last: isSet(object.last) ? String(object.last) : undefined, - }; - }, - create, I>>(base?: I): OneOfMessage { return OneOfMessage.fromPartial(base ?? {}); }, @@ -1065,6 +1065,17 @@ export const SimpleWithWrappers = { return message; }, + fromJSON(object: any): SimpleWithWrappers { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, + coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], + snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], + id: isSet(object.id) ? new Uint8Array(object.id) : undefined, + }; + }, + toJSON(message: SimpleWithWrappers): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -1088,17 +1099,6 @@ export const SimpleWithWrappers = { return obj; }, - fromJSON(object: any): SimpleWithWrappers { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - enabled: isSet(object.enabled) ? Boolean(object.enabled) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Number(e)) : [], - snacks: Array.isArray(object?.snacks) ? object.snacks.map((e: any) => String(e)) : [], - id: isSet(object.id) ? new Uint8Array(object.id) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithWrappers { return SimpleWithWrappers.fromPartial(base ?? {}); }, @@ -1150,6 +1150,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -1158,10 +1162,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -1299,6 +1299,56 @@ export const SimpleWithMap = { return message; }, + fromJSON(object: any): SimpleWithMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + nameLookup: isObject(object.nameLookup) + ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + intLookup: isObject(object.intLookup) + ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { + acc[key] = fromJsonTimestamp(value); + return acc; + }, {}) + : {}, + mapOfBytes: isObject(object.mapOfBytes) + ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { + acc[key] = bytesFromBase64(value as string); + return acc; + }, {}) + : {}, + mapOfStringValues: isObject(object.mapOfStringValues) + ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( + (acc, [key, value]) => { + acc[key] = value as string | undefined; + return acc; + }, + {}, + ) + : {}, + longLookup: isObject(object.longLookup) + ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -1367,56 +1417,6 @@ export const SimpleWithMap = { return obj; }, - fromJSON(object: any): SimpleWithMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - nameLookup: isObject(object.nameLookup) - ? Object.entries(object.nameLookup).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - intLookup: isObject(object.intLookup) - ? Object.entries(object.intLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { - acc[key] = fromJsonTimestamp(value); - return acc; - }, {}) - : {}, - mapOfBytes: isObject(object.mapOfBytes) - ? Object.entries(object.mapOfBytes).reduce<{ [key: string]: Uint8Array }>((acc, [key, value]) => { - acc[key] = bytesFromBase64(value as string); - return acc; - }, {}) - : {}, - mapOfStringValues: isObject(object.mapOfStringValues) - ? Object.entries(object.mapOfStringValues).reduce<{ [key: string]: string | undefined }>( - (acc, [key, value]) => { - acc[key] = value as string | undefined; - return acc; - }, - {}, - ) - : {}, - longLookup: isObject(object.longLookup) - ? Object.entries(object.longLookup).reduce<{ [key: number]: number }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMap { return SimpleWithMap.fromPartial(base ?? {}); }, @@ -1534,6 +1534,13 @@ export const SimpleWithMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1545,13 +1552,6 @@ export const SimpleWithMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>(base?: I): SimpleWithMap_EntitiesByIdEntry { return SimpleWithMap_EntitiesByIdEntry.fromPartial(base ?? {}); }, @@ -1613,6 +1613,10 @@ export const SimpleWithMap_NameLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_NameLookupEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: SimpleWithMap_NameLookupEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1624,10 +1628,6 @@ export const SimpleWithMap_NameLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_NameLookupEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): SimpleWithMap_NameLookupEntry { return SimpleWithMap_NameLookupEntry.fromPartial(base ?? {}); }, @@ -1687,6 +1687,10 @@ export const SimpleWithMap_IntLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_IntLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_IntLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -1698,10 +1702,6 @@ export const SimpleWithMap_IntLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_IntLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_IntLookupEntry { return SimpleWithMap_IntLookupEntry.fromPartial(base ?? {}); }, @@ -1759,6 +1759,13 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1770,13 +1777,6 @@ export const SimpleWithMap_MapOfTimestampsEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithMap_MapOfTimestampsEntry { @@ -1838,6 +1838,13 @@ export const SimpleWithMap_MapOfBytesEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), + }; + }, + toJSON(message: SimpleWithMap_MapOfBytesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1849,13 +1856,6 @@ export const SimpleWithMap_MapOfBytesEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_MapOfBytesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), - }; - }, - create, I>>(base?: I): SimpleWithMap_MapOfBytesEntry { return SimpleWithMap_MapOfBytesEntry.fromPartial(base ?? {}); }, @@ -1915,6 +1915,13 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithMap_MapOfStringValuesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -1926,13 +1933,6 @@ export const SimpleWithMap_MapOfStringValuesEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_MapOfStringValuesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithMap_MapOfStringValuesEntry { @@ -1994,6 +1994,10 @@ export const SimpleWithMap_LongLookupEntry = { return message; }, + fromJSON(object: any): SimpleWithMap_LongLookupEntry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: SimpleWithMap_LongLookupEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2005,10 +2009,6 @@ export const SimpleWithMap_LongLookupEntry = { return obj; }, - fromJSON(object: any): SimpleWithMap_LongLookupEntry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): SimpleWithMap_LongLookupEntry { return SimpleWithMap_LongLookupEntry.fromPartial(base ?? {}); }, @@ -2061,6 +2061,17 @@ export const SimpleWithSnakeCaseMap = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap { + return { + entitiesById: isObject(object.entitiesById) + ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { + acc[Number(key)] = Entity.fromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap): unknown { const obj: any = {}; if (message.entitiesById) { @@ -2075,17 +2086,6 @@ export const SimpleWithSnakeCaseMap = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap { - return { - entitiesById: isObject(object.entitiesById) - ? Object.entries(object.entitiesById).reduce<{ [key: number]: Entity }>((acc, [key, value]) => { - acc[Number(key)] = Entity.fromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithSnakeCaseMap { return SimpleWithSnakeCaseMap.fromPartial(base ?? {}); }, @@ -2150,6 +2150,13 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2161,13 +2168,6 @@ export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithSnakeCaseMap_EntitiesByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>( base?: I, ): SimpleWithSnakeCaseMap_EntitiesByIdEntry { @@ -2224,6 +2224,17 @@ export const SimpleWithMapOfEnums = { return message; }, + fromJSON(object: any): SimpleWithMapOfEnums { + return { + enumsById: isObject(object.enumsById) + ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { + acc[Number(key)] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: SimpleWithMapOfEnums): unknown { const obj: any = {}; if (message.enumsById) { @@ -2238,17 +2249,6 @@ export const SimpleWithMapOfEnums = { return obj; }, - fromJSON(object: any): SimpleWithMapOfEnums { - return { - enumsById: isObject(object.enumsById) - ? Object.entries(object.enumsById).reduce<{ [key: number]: StateEnum }>((acc, [key, value]) => { - acc[Number(key)] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): SimpleWithMapOfEnums { return SimpleWithMapOfEnums.fromPartial(base ?? {}); }, @@ -2313,6 +2313,13 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return message; }, + fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { + return { + key: isSet(object.key) ? Number(object.key) : 0, + value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, + }; + }, + toJSON(message: SimpleWithMapOfEnums_EnumsByIdEntry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -2324,13 +2331,6 @@ export const SimpleWithMapOfEnums_EnumsByIdEntry = { return obj; }, - fromJSON(object: any): SimpleWithMapOfEnums_EnumsByIdEntry { - return { - key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, - }; - }, - create, I>>( base?: I, ): SimpleWithMapOfEnums_EnumsByIdEntry { @@ -2382,6 +2382,10 @@ export const PingRequest = { return message; }, + fromJSON(object: any): PingRequest { + return { input: isSet(object.input) ? String(object.input) : "" }; + }, + toJSON(message: PingRequest): unknown { const obj: any = {}; if (message.input !== "") { @@ -2390,10 +2394,6 @@ export const PingRequest = { return obj; }, - fromJSON(object: any): PingRequest { - return { input: isSet(object.input) ? String(object.input) : "" }; - }, - create, I>>(base?: I): PingRequest { return PingRequest.fromPartial(base ?? {}); }, @@ -2440,6 +2440,10 @@ export const PingResponse = { return message; }, + fromJSON(object: any): PingResponse { + return { output: isSet(object.output) ? String(object.output) : "" }; + }, + toJSON(message: PingResponse): unknown { const obj: any = {}; if (message.output !== "") { @@ -2448,10 +2452,6 @@ export const PingResponse = { return obj; }, - fromJSON(object: any): PingResponse { - return { output: isSet(object.output) ? String(object.output) : "" }; - }, - create, I>>(base?: I): PingResponse { return PingResponse.fromPartial(base ?? {}); }, @@ -2621,6 +2621,23 @@ export const Numbers = { return message; }, + fromJSON(object: any): Numbers { + return { + double: isSet(object.double) ? Number(object.double) : 0, + float: isSet(object.float) ? Number(object.float) : 0, + int32: isSet(object.int32) ? Number(object.int32) : 0, + int64: isSet(object.int64) ? Number(object.int64) : 0, + uint32: isSet(object.uint32) ? Number(object.uint32) : 0, + uint64: isSet(object.uint64) ? Number(object.uint64) : 0, + sint32: isSet(object.sint32) ? Number(object.sint32) : 0, + sint64: isSet(object.sint64) ? Number(object.sint64) : 0, + fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, + fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, + sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, + sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, + }; + }, + toJSON(message: Numbers): unknown { const obj: any = {}; if (message.double !== 0) { @@ -2662,23 +2679,6 @@ export const Numbers = { return obj; }, - fromJSON(object: any): Numbers { - return { - double: isSet(object.double) ? Number(object.double) : 0, - float: isSet(object.float) ? Number(object.float) : 0, - int32: isSet(object.int32) ? Number(object.int32) : 0, - int64: isSet(object.int64) ? Number(object.int64) : 0, - uint32: isSet(object.uint32) ? Number(object.uint32) : 0, - uint64: isSet(object.uint64) ? Number(object.uint64) : 0, - sint32: isSet(object.sint32) ? Number(object.sint32) : 0, - sint64: isSet(object.sint64) ? Number(object.sint64) : 0, - fixed32: isSet(object.fixed32) ? Number(object.fixed32) : 0, - fixed64: isSet(object.fixed64) ? Number(object.fixed64) : 0, - sfixed32: isSet(object.sfixed32) ? Number(object.sfixed32) : 0, - sfixed64: isSet(object.sfixed64) ? Number(object.sfixed64) : 0, - }; - }, - create, I>>(base?: I): Numbers { return Numbers.fromPartial(base ?? {}); }, @@ -2804,6 +2804,18 @@ export const SimpleButOptional = { return message; }, + fromJSON(object: any): SimpleButOptional { + return { + name: isSet(object.name) ? String(object.name) : undefined, + age: isSet(object.age) ? Number(object.age) : undefined, + createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, + thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, + birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, + }; + }, + toJSON(message: SimpleButOptional): unknown { const obj: any = {}; if (message.name !== undefined) { @@ -2830,18 +2842,6 @@ export const SimpleButOptional = { return obj; }, - fromJSON(object: any): SimpleButOptional { - return { - name: isSet(object.name) ? String(object.name) : undefined, - age: isSet(object.age) ? Number(object.age) : undefined, - createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, - thing: isSet(object.thing) ? ImportedThing.fromJSON(object.thing) : undefined, - birthday: isSet(object.birthday) ? DateMessage.fromJSON(object.birthday) : undefined, - }; - }, - create, I>>(base?: I): SimpleButOptional { return SimpleButOptional.fromPartial(base ?? {}); }, @@ -2888,15 +2888,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/bar/bar.ts b/integration/static-only-type-registry/bar/bar.ts index db58f3900..7b1a4ac87 100644 --- a/integration/static-only-type-registry/bar/bar.ts +++ b/integration/static-only-type-registry/bar/bar.ts @@ -46,6 +46,10 @@ export const Bar = { return message; }, + fromJSON(object: any): Bar { + return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -54,10 +58,6 @@ export const Bar = { return obj; }, - fromJSON(object: any): Bar { - return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/foo.ts b/integration/static-only-type-registry/foo.ts index 969c892c4..bf714ce78 100644 --- a/integration/static-only-type-registry/foo.ts +++ b/integration/static-only-type-registry/foo.ts @@ -55,6 +55,10 @@ export const Foo = { return message; }, + fromJSON(object: any): Foo { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -63,10 +67,6 @@ export const Foo = { return obj; }, - fromJSON(object: any): Foo { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -117,6 +117,10 @@ export const Foo2 = { return message; }, + fromJSON(object: any): Foo2 { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -125,10 +129,6 @@ export const Foo2 = { return obj; }, - fromJSON(object: any): Foo2 { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -179,6 +179,10 @@ export const WithStruct = { return message; }, + fromJSON(object: any): WithStruct { + return { struct: isObject(object.struct) ? object.struct : undefined }; + }, + toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -187,10 +191,6 @@ export const WithStruct = { return obj; }, - fromJSON(object: any): WithStruct { - return { struct: isObject(object.struct) ? object.struct : undefined }; - }, - create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/google/protobuf/struct.ts b/integration/static-only-type-registry/google/protobuf/struct.ts index e7d6dea34..239a36208 100644 --- a/integration/static-only-type-registry/google/protobuf/struct.ts +++ b/integration/static-only-type-registry/google/protobuf/struct.ts @@ -143,6 +143,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -157,17 +168,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -256,6 +256,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -267,10 +271,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -379,6 +379,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -402,17 +413,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -505,6 +505,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -513,10 +517,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/static-only-type-registry/google/protobuf/timestamp.ts b/integration/static-only-type-registry/google/protobuf/timestamp.ts index f1c2d4093..6412e7c48 100644 --- a/integration/static-only-type-registry/google/protobuf/timestamp.ts +++ b/integration/static-only-type-registry/google/protobuf/timestamp.ts @@ -159,6 +159,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -170,13 +177,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/static-only/bar/bar.ts b/integration/static-only/bar/bar.ts index 8b1af666d..43cb9de82 100644 --- a/integration/static-only/bar/bar.ts +++ b/integration/static-only/bar/bar.ts @@ -45,6 +45,10 @@ export const Bar = { return message; }, + fromJSON(object: any): Bar { + return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -53,10 +57,6 @@ export const Bar = { return obj; }, - fromJSON(object: any): Bar { - return { foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/static-only/foo.ts b/integration/static-only/foo.ts index 95410b6e8..8055715b9 100644 --- a/integration/static-only/foo.ts +++ b/integration/static-only/foo.ts @@ -54,6 +54,10 @@ export const Foo = { return message; }, + fromJSON(object: any): Foo { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -62,10 +66,6 @@ export const Foo = { return obj; }, - fromJSON(object: any): Foo { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -114,6 +114,10 @@ export const Foo2 = { return message; }, + fromJSON(object: any): Foo2 { + return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -122,10 +126,6 @@ export const Foo2 = { return obj; }, - fromJSON(object: any): Foo2 { - return { timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -174,6 +174,10 @@ export const WithStruct = { return message; }, + fromJSON(object: any): WithStruct { + return { struct: isObject(object.struct) ? object.struct : undefined }; + }, + toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -182,10 +186,6 @@ export const WithStruct = { return obj; }, - fromJSON(object: any): WithStruct { - return { struct: isObject(object.struct) ? object.struct : undefined }; - }, - create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/static-only/google/protobuf/struct.ts b/integration/static-only/google/protobuf/struct.ts index 9e68ba01e..64cca73ce 100644 --- a/integration/static-only/google/protobuf/struct.ts +++ b/integration/static-only/google/protobuf/struct.ts @@ -142,6 +142,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -156,17 +167,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -253,6 +253,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -264,10 +268,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -374,6 +374,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -397,17 +408,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -498,6 +498,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -506,10 +510,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/static-only/google/protobuf/timestamp.ts b/integration/static-only/google/protobuf/timestamp.ts index 8515e6707..0fb7abe8f 100644 --- a/integration/static-only/google/protobuf/timestamp.ts +++ b/integration/static-only/google/protobuf/timestamp.ts @@ -158,6 +158,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -169,13 +176,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/struct/google/protobuf/struct.ts b/integration/struct/google/protobuf/struct.ts index 7c416eb52..b2486a866 100644 --- a/integration/struct/google/protobuf/struct.ts +++ b/integration/struct/google/protobuf/struct.ts @@ -140,6 +140,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -154,17 +165,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,6 +249,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -260,10 +264,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,6 +368,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -391,17 +402,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,6 +490,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -498,10 +502,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/struct/struct.ts b/integration/struct/struct.ts index 308b7ef6b..83bf70017 100644 --- a/integration/struct/struct.ts +++ b/integration/struct/struct.ts @@ -43,6 +43,10 @@ export const StructMessage = { return message; }, + fromJSON(object: any): StructMessage { + return { value: isObject(object.value) ? object.value : undefined }; + }, + toJSON(message: StructMessage): unknown { const obj: any = {}; if (message.value !== undefined) { @@ -51,10 +55,6 @@ export const StructMessage = { return obj; }, - fromJSON(object: any): StructMessage { - return { value: isObject(object.value) ? object.value : undefined }; - }, - create, I>>(base?: I): StructMessage { return StructMessage.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/bar/bar.ts b/integration/type-annotations/bar/bar.ts index a8fd72163..aef3a1bfb 100644 --- a/integration/type-annotations/bar/bar.ts +++ b/integration/type-annotations/bar/bar.ts @@ -46,6 +46,10 @@ export const Bar = { return message; }, + fromJSON(object: any): Bar { + return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -54,10 +58,6 @@ export const Bar = { return obj; }, - fromJSON(object: any): Bar { - return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/foo.ts b/integration/type-annotations/foo.ts index 439bc6547..2ae6b7752 100644 --- a/integration/type-annotations/foo.ts +++ b/integration/type-annotations/foo.ts @@ -57,6 +57,10 @@ export const Foo = { return message; }, + fromJSON(object: any): Foo { + return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -65,10 +69,6 @@ export const Foo = { return obj; }, - fromJSON(object: any): Foo { - return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -117,6 +117,10 @@ export const Foo2 = { return message; }, + fromJSON(object: any): Foo2 { + return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -125,10 +129,6 @@ export const Foo2 = { return obj; }, - fromJSON(object: any): Foo2 { - return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -177,6 +177,10 @@ export const WithStruct = { return message; }, + fromJSON(object: any): WithStruct { + return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; + }, + toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -185,10 +189,6 @@ export const WithStruct = { return obj; }, - fromJSON(object: any): WithStruct { - return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; - }, - create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/google/protobuf/struct.ts b/integration/type-annotations/google/protobuf/struct.ts index 35b3fac3d..6e0125ecc 100644 --- a/integration/type-annotations/google/protobuf/struct.ts +++ b/integration/type-annotations/google/protobuf/struct.ts @@ -149,6 +149,18 @@ export const Struct = { return message; }, + fromJSON(object: any): Struct { + return { + $type: Struct.$type, + 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 = {}; if (message.fields) { @@ -163,18 +175,6 @@ export const Struct = { return obj; }, - fromJSON(object: any): Struct { - return { - $type: Struct.$type, - fields: isObject(object.fields) - ? Object.entries(object.fields).reduce<{ [key: string]: any | undefined }>((acc, [key, value]) => { - acc[key] = value as any | undefined; - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -261,6 +261,14 @@ export const Struct_FieldsEntry = { return message; }, + fromJSON(object: any): Struct_FieldsEntry { + return { + $type: Struct_FieldsEntry.$type, + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object?.value) ? object.value : undefined, + }; + }, + toJSON(message: Struct_FieldsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -272,14 +280,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { - $type: Struct_FieldsEntry.$type, - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object?.value) ? object.value : undefined, - }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -387,6 +387,18 @@ export const Value = { return message; }, + fromJSON(object: any): Value { + return { + $type: Value.$type, + 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 = {}; if (message.nullValue !== undefined) { @@ -410,18 +422,6 @@ export const Value = { return obj; }, - fromJSON(object: any): Value { - return { - $type: Value.$type, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -512,6 +512,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -520,10 +524,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/type-annotations/google/protobuf/timestamp.ts b/integration/type-annotations/google/protobuf/timestamp.ts index 34571adcc..d3a2b6743 100644 --- a/integration/type-annotations/google/protobuf/timestamp.ts +++ b/integration/type-annotations/google/protobuf/timestamp.ts @@ -159,6 +159,14 @@ export const Timestamp = { return message; }, + fromJSON(object: any): Timestamp { + return { + $type: Timestamp.$type, + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== 0) { @@ -170,14 +178,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - $type: Timestamp.$type, - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/bar/bar.ts b/integration/type-registry/bar/bar.ts index b455a1b11..2b5060a88 100644 --- a/integration/type-registry/bar/bar.ts +++ b/integration/type-registry/bar/bar.ts @@ -47,6 +47,10 @@ export const Bar = { return message; }, + fromJSON(object: any): Bar { + return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; + }, + toJSON(message: Bar): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -55,10 +59,6 @@ export const Bar = { return obj; }, - fromJSON(object: any): Bar { - return { $type: Bar.$type, foo: isSet(object.foo) ? Foo.fromJSON(object.foo) : undefined }; - }, - create, I>>(base?: I): Bar { return Bar.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/foo.ts b/integration/type-registry/foo.ts index b4384ed87..d8e4e26cc 100644 --- a/integration/type-registry/foo.ts +++ b/integration/type-registry/foo.ts @@ -58,6 +58,10 @@ export const Foo = { return message; }, + fromJSON(object: any): Foo { + return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -66,10 +70,6 @@ export const Foo = { return obj; }, - fromJSON(object: any): Foo { - return { $type: Foo.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo { return Foo.fromPartial(base ?? {}); }, @@ -120,6 +120,10 @@ export const Foo2 = { return message; }, + fromJSON(object: any): Foo2 { + return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; + }, + toJSON(message: Foo2): unknown { const obj: any = {}; if (message.timestamp !== undefined) { @@ -128,10 +132,6 @@ export const Foo2 = { return obj; }, - fromJSON(object: any): Foo2 { - return { $type: Foo2.$type, timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined }; - }, - create, I>>(base?: I): Foo2 { return Foo2.fromPartial(base ?? {}); }, @@ -182,6 +182,10 @@ export const WithStruct = { return message; }, + fromJSON(object: any): WithStruct { + return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; + }, + toJSON(message: WithStruct): unknown { const obj: any = {}; if (message.struct !== undefined) { @@ -190,10 +194,6 @@ export const WithStruct = { return obj; }, - fromJSON(object: any): WithStruct { - return { $type: WithStruct.$type, struct: isObject(object.struct) ? object.struct : undefined }; - }, - create, I>>(base?: I): WithStruct { return WithStruct.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/google/protobuf/struct.ts b/integration/type-registry/google/protobuf/struct.ts index b3eeb96db..451bad188 100644 --- a/integration/type-registry/google/protobuf/struct.ts +++ b/integration/type-registry/google/protobuf/struct.ts @@ -150,6 +150,18 @@ export const Struct = { return message; }, + fromJSON(object: any): Struct { + return { + $type: Struct.$type, + 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 = {}; if (message.fields) { @@ -164,18 +176,6 @@ export const Struct = { return obj; }, - fromJSON(object: any): Struct { - return { - $type: Struct.$type, - fields: isObject(object.fields) - ? Object.entries(object.fields).reduce<{ [key: string]: any | undefined }>((acc, [key, value]) => { - acc[key] = value as any | undefined; - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -264,6 +264,14 @@ export const Struct_FieldsEntry = { return message; }, + fromJSON(object: any): Struct_FieldsEntry { + return { + $type: Struct_FieldsEntry.$type, + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object?.value) ? object.value : undefined, + }; + }, + toJSON(message: Struct_FieldsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -275,14 +283,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { - $type: Struct_FieldsEntry.$type, - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object?.value) ? object.value : undefined, - }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -392,6 +392,18 @@ export const Value = { return message; }, + fromJSON(object: any): Value { + return { + $type: Value.$type, + 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 = {}; if (message.nullValue !== undefined) { @@ -415,18 +427,6 @@ export const Value = { return obj; }, - fromJSON(object: any): Value { - return { - $type: Value.$type, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -519,6 +519,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -527,10 +531,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { $type: ListValue.$type, values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/type-registry/google/protobuf/timestamp.ts b/integration/type-registry/google/protobuf/timestamp.ts index fa1b933a7..cd8375327 100644 --- a/integration/type-registry/google/protobuf/timestamp.ts +++ b/integration/type-registry/google/protobuf/timestamp.ts @@ -160,6 +160,14 @@ export const Timestamp = { return message; }, + fromJSON(object: any): Timestamp { + return { + $type: Timestamp.$type, + seconds: isSet(object.seconds) ? Number(object.seconds) : 0, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; + }, + toJSON(message: Timestamp): unknown { const obj: any = {}; if (message.seconds !== 0) { @@ -171,14 +179,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - $type: Timestamp.$type, - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/types-with-underscores/file.ts b/integration/types-with-underscores/file.ts index f15534841..6b174be1f 100644 --- a/integration/types-with-underscores/file.ts +++ b/integration/types-with-underscores/file.ts @@ -45,6 +45,10 @@ export const Baz = { return message; }, + fromJSON(object: any): Baz { + return { foo: isSet(object.foo) ? FooBar.fromJSON(object.foo) : undefined }; + }, + toJSON(message: Baz): unknown { const obj: any = {}; if (message.foo !== undefined) { @@ -53,10 +57,6 @@ export const Baz = { return obj; }, - fromJSON(object: any): Baz { - return { foo: isSet(object.foo) ? FooBar.fromJSON(object.foo) : undefined }; - }, - create, I>>(base?: I): Baz { return Baz.fromPartial(base ?? {}); }, @@ -93,15 +93,15 @@ export const FooBar = { return message; }, + fromJSON(_: any): FooBar { + return {}; + }, + toJSON(_: FooBar): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): FooBar { - return {}; - }, - create, I>>(base?: I): FooBar { return FooBar.fromPartial(base ?? {}); }, diff --git a/integration/use-date-false/google/protobuf/timestamp.ts b/integration/use-date-false/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/use-date-false/google/protobuf/timestamp.ts +++ b/integration/use-date-false/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-date-false/metadata.ts b/integration/use-date-false/metadata.ts index 281207141..097fa6736 100644 --- a/integration/use-date-false/metadata.ts +++ b/integration/use-date-false/metadata.ts @@ -43,6 +43,10 @@ export const Metadata = { return message; }, + fromJSON(object: any): Metadata { + return { lastEdited: isSet(object.lastEdited) ? fromJsonTimestamp(object.lastEdited) : undefined }; + }, + toJSON(message: Metadata): unknown { const obj: any = {}; if (message.lastEdited !== undefined) { @@ -51,10 +55,6 @@ export const Metadata = { return obj; }, - fromJSON(object: any): Metadata { - return { lastEdited: isSet(object.lastEdited) ? fromJsonTimestamp(object.lastEdited) : undefined }; - }, - create, I>>(base?: I): Metadata { return Metadata.fromPartial(base ?? {}); }, diff --git a/integration/use-date-string/google/protobuf/timestamp.ts b/integration/use-date-string/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/use-date-string/google/protobuf/timestamp.ts +++ b/integration/use-date-string/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-date-string/use-date-string.ts b/integration/use-date-string/use-date-string.ts index dde255b83..e8d32a532 100644 --- a/integration/use-date-string/use-date-string.ts +++ b/integration/use-date-string/use-date-string.ts @@ -95,6 +95,23 @@ export const Todo = { return message; }, + fromJSON(object: any): Todo { + return { + id: isSet(object.id) ? String(object.id) : "", + timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined, + repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) + ? object.repeatedTimestamp.map((e: any) => String(e)) + : [], + optionalTimestamp: isSet(object.optionalTimestamp) ? String(object.optionalTimestamp) : undefined, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: Todo): unknown { const obj: any = {}; if (message.id !== "") { @@ -121,23 +138,6 @@ export const Todo = { return obj; }, - fromJSON(object: any): Todo { - return { - id: isSet(object.id) ? String(object.id) : "", - timestamp: isSet(object.timestamp) ? String(object.timestamp) : undefined, - repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) - ? object.repeatedTimestamp.map((e: any) => String(e)) - : [], - optionalTimestamp: isSet(object.optionalTimestamp) ? String(object.optionalTimestamp) : undefined, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Todo { return Todo.fromPartial(base ?? {}); }, @@ -206,6 +206,13 @@ export const Todo_MapOfTimestampsEntry = { return message; }, + fromJSON(object: any): Todo_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? String(object.value) : undefined, + }; + }, + toJSON(message: Todo_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -217,13 +224,6 @@ export const Todo_MapOfTimestampsEntry = { return obj; }, - fromJSON(object: any): Todo_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? String(object.value) : undefined, - }; - }, - create, I>>(base?: I): Todo_MapOfTimestampsEntry { return Todo_MapOfTimestampsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-date-true/google/protobuf/empty.ts b/integration/use-date-true/google/protobuf/empty.ts index d1b8ebf5b..1387d7ce4 100644 --- a/integration/use-date-true/google/protobuf/empty.ts +++ b/integration/use-date-true/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/use-date-true/google/protobuf/timestamp.ts b/integration/use-date-true/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/use-date-true/google/protobuf/timestamp.ts +++ b/integration/use-date-true/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-date-true/use-date-true.ts b/integration/use-date-true/use-date-true.ts index 8dd52c92f..0fae63006 100644 --- a/integration/use-date-true/use-date-true.ts +++ b/integration/use-date-true/use-date-true.ts @@ -96,6 +96,23 @@ export const Todo = { return message; }, + fromJSON(object: any): Todo { + return { + id: isSet(object.id) ? String(object.id) : "", + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) + ? object.repeatedTimestamp.map((e: any) => fromJsonTimestamp(e)) + : [], + optionalTimestamp: isSet(object.optionalTimestamp) ? fromJsonTimestamp(object.optionalTimestamp) : undefined, + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { + acc[key] = fromJsonTimestamp(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: Todo): unknown { const obj: any = {}; if (message.id !== "") { @@ -122,23 +139,6 @@ export const Todo = { return obj; }, - fromJSON(object: any): Todo { - return { - id: isSet(object.id) ? String(object.id) : "", - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - repeatedTimestamp: Array.isArray(object?.repeatedTimestamp) - ? object.repeatedTimestamp.map((e: any) => fromJsonTimestamp(e)) - : [], - optionalTimestamp: isSet(object.optionalTimestamp) ? fromJsonTimestamp(object.optionalTimestamp) : undefined, - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce<{ [key: string]: Date }>((acc, [key, value]) => { - acc[key] = fromJsonTimestamp(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Todo { return Todo.fromPartial(base ?? {}); }, @@ -207,6 +207,13 @@ export const Todo_MapOfTimestampsEntry = { return message; }, + fromJSON(object: any): Todo_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + toJSON(message: Todo_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -218,13 +225,6 @@ export const Todo_MapOfTimestampsEntry = { return obj; }, - fromJSON(object: any): Todo_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - create, I>>(base?: I): Todo_MapOfTimestampsEntry { return Todo_MapOfTimestampsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-exact-types-false/foo.ts b/integration/use-exact-types-false/foo.ts index 4f6c59079..fe86b5836 100644 --- a/integration/use-exact-types-false/foo.ts +++ b/integration/use-exact-types-false/foo.ts @@ -53,6 +53,10 @@ export const Foo = { return message; }, + fromJSON(object: any): Foo { + return { bar: isSet(object.bar) ? String(object.bar) : "", baz: isSet(object.baz) ? String(object.baz) : "" }; + }, + toJSON(message: Foo): unknown { const obj: any = {}; if (message.bar !== "") { @@ -64,10 +68,6 @@ export const Foo = { return obj; }, - fromJSON(object: any): Foo { - return { bar: isSet(object.bar) ? String(object.bar) : "", baz: isSet(object.baz) ? String(object.baz) : "" }; - }, - create(base?: DeepPartial): Foo { return Foo.fromPartial(base ?? {}); }, diff --git a/integration/use-map-type/google/protobuf/struct.ts b/integration/use-map-type/google/protobuf/struct.ts index 809890879..cb6b8e13d 100644 --- a/integration/use-map-type/google/protobuf/struct.ts +++ b/integration/use-map-type/google/protobuf/struct.ts @@ -140,17 +140,6 @@ export const Struct = { return message; }, - toJSON(message: Struct): unknown { - const obj: any = {}; - if (message.fields?.size) { - obj.fields = {}; - message.fields.forEach((v, k) => { - obj.fields[k] = v; - }); - } - return obj; - }, - fromJSON(object: any): Struct { return { fields: isObject(object.fields) @@ -162,6 +151,17 @@ export const Struct = { }; }, + toJSON(message: Struct): unknown { + const obj: any = {}; + if (message.fields?.size) { + obj.fields = {}; + message.fields.forEach((v, k) => { + obj.fields[k] = v; + }); + } + return obj; + }, + create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -244,6 +244,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -255,10 +259,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -363,6 +363,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -386,17 +397,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -485,6 +485,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -493,10 +497,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/use-map-type/google/protobuf/timestamp.ts b/integration/use-map-type/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/use-map-type/google/protobuf/timestamp.ts +++ b/integration/use-map-type/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-map-type/use-map-type.ts b/integration/use-map-type/use-map-type.ts index 944eb6b9b..ddb7d7b3a 100644 --- a/integration/use-map-type/use-map-type.ts +++ b/integration/use-map-type/use-map-type.ts @@ -79,6 +79,10 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { id: isSet(object.id) ? Number(object.id) : 0 }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.id !== 0) { @@ -87,10 +91,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { id: isSet(object.id) ? Number(object.id) : 0 }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -209,6 +209,42 @@ export const Maps = { return message; }, + fromJSON(object: any): Maps { + return { + strToEntity: isObject(object.strToEntity) + ? Object.entries(object.strToEntity).reduce>((acc, [key, value]) => { + acc.set(key, Entity.fromJSON(value)); + return acc; + }, new Map()) + : new Map(), + int32ToInt32: isObject(object.int32ToInt32) + ? Object.entries(object.int32ToInt32).reduce>((acc, [key, value]) => { + acc.set(Number(key), Number(value)); + return acc; + }, new Map()) + : new Map(), + stringToBytes: isObject(object.stringToBytes) + ? Object.entries(object.stringToBytes).reduce>((acc, [key, value]) => { + acc.set(key, bytesFromBase64(value as string)); + return acc; + }, new Map()) + : new Map(), + int64ToInt64: isObject(object.int64ToInt64) + ? Object.entries(object.int64ToInt64).reduce>((acc, [key, value]) => { + acc.set(Number(key), Number(value)); + return acc; + }, new Map()) + : new Map(), + mapOfTimestamps: isObject(object.mapOfTimestamps) + ? Object.entries(object.mapOfTimestamps).reduce>((acc, [key, value]) => { + acc.set(key, fromJsonTimestamp(value)); + return acc; + }, new Map()) + : new Map(), + struct: isObject(object.struct) ? object.struct : undefined, + }; + }, + toJSON(message: Maps): unknown { const obj: any = {}; if (message.strToEntity?.size) { @@ -247,42 +283,6 @@ export const Maps = { return obj; }, - fromJSON(object: any): Maps { - return { - strToEntity: isObject(object.strToEntity) - ? Object.entries(object.strToEntity).reduce>((acc, [key, value]) => { - acc.set(key, Entity.fromJSON(value)); - return acc; - }, new Map()) - : new Map(), - int32ToInt32: isObject(object.int32ToInt32) - ? Object.entries(object.int32ToInt32).reduce>((acc, [key, value]) => { - acc.set(Number(key), Number(value)); - return acc; - }, new Map()) - : new Map(), - stringToBytes: isObject(object.stringToBytes) - ? Object.entries(object.stringToBytes).reduce>((acc, [key, value]) => { - acc.set(key, bytesFromBase64(value as string)); - return acc; - }, new Map()) - : new Map(), - int64ToInt64: isObject(object.int64ToInt64) - ? Object.entries(object.int64ToInt64).reduce>((acc, [key, value]) => { - acc.set(Number(key), Number(value)); - return acc; - }, new Map()) - : new Map(), - mapOfTimestamps: isObject(object.mapOfTimestamps) - ? Object.entries(object.mapOfTimestamps).reduce>((acc, [key, value]) => { - acc.set(key, fromJsonTimestamp(value)); - return acc; - }, new Map()) - : new Map(), - struct: isObject(object.struct) ? object.struct : undefined, - }; - }, - create, I>>(base?: I): Maps { return Maps.fromPartial(base ?? {}); }, @@ -384,6 +384,13 @@ export const Maps_StrToEntityEntry = { return message; }, + fromJSON(object: any): Maps_StrToEntityEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, + }; + }, + toJSON(message: Maps_StrToEntityEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -395,13 +402,6 @@ export const Maps_StrToEntityEntry = { return obj; }, - fromJSON(object: any): Maps_StrToEntityEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? Entity.fromJSON(object.value) : undefined, - }; - }, - create, I>>(base?: I): Maps_StrToEntityEntry { return Maps_StrToEntityEntry.fromPartial(base ?? {}); }, @@ -461,6 +461,10 @@ export const Maps_Int32ToInt32Entry = { return message; }, + fromJSON(object: any): Maps_Int32ToInt32Entry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Maps_Int32ToInt32Entry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -472,10 +476,6 @@ export const Maps_Int32ToInt32Entry = { return obj; }, - fromJSON(object: any): Maps_Int32ToInt32Entry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Maps_Int32ToInt32Entry { return Maps_Int32ToInt32Entry.fromPartial(base ?? {}); }, @@ -533,6 +533,13 @@ export const Maps_StringToBytesEntry = { return message; }, + fromJSON(object: any): Maps_StringToBytesEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), + }; + }, + toJSON(message: Maps_StringToBytesEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -544,13 +551,6 @@ export const Maps_StringToBytesEntry = { return obj; }, - fromJSON(object: any): Maps_StringToBytesEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0), - }; - }, - create, I>>(base?: I): Maps_StringToBytesEntry { return Maps_StringToBytesEntry.fromPartial(base ?? {}); }, @@ -608,6 +608,10 @@ export const Maps_Int64ToInt64Entry = { return message; }, + fromJSON(object: any): Maps_Int64ToInt64Entry { + return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Maps_Int64ToInt64Entry): unknown { const obj: any = {}; if (message.key !== 0) { @@ -619,10 +623,6 @@ export const Maps_Int64ToInt64Entry = { return obj; }, - fromJSON(object: any): Maps_Int64ToInt64Entry { - return { key: isSet(object.key) ? Number(object.key) : 0, value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Maps_Int64ToInt64Entry { return Maps_Int64ToInt64Entry.fromPartial(base ?? {}); }, @@ -680,6 +680,13 @@ export const Maps_MapOfTimestampsEntry = { return message; }, + fromJSON(object: any): Maps_MapOfTimestampsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, + }; + }, + toJSON(message: Maps_MapOfTimestampsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -691,13 +698,6 @@ export const Maps_MapOfTimestampsEntry = { return obj; }, - fromJSON(object: any): Maps_MapOfTimestampsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonTimestamp(object.value) : undefined, - }; - }, - create, I>>(base?: I): Maps_MapOfTimestampsEntry { return Maps_MapOfTimestampsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-numeric-enum-json/google/protobuf/struct.ts b/integration/use-numeric-enum-json/google/protobuf/struct.ts index af01115bf..41928548c 100644 --- a/integration/use-numeric-enum-json/google/protobuf/struct.ts +++ b/integration/use-numeric-enum-json/google/protobuf/struct.ts @@ -140,6 +140,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -154,17 +165,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,6 +249,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -260,10 +264,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,6 +368,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -391,17 +402,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,6 +490,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -498,10 +502,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/use-numeric-enum-json/simple.ts b/integration/use-numeric-enum-json/simple.ts index be06cd540..bec6c5696 100644 --- a/integration/use-numeric-enum-json/simple.ts +++ b/integration/use-numeric-enum-json/simple.ts @@ -146,6 +146,21 @@ export const Simple = { return message; }, + fromJSON(object: any): Simple { + return { + name: isSet(object.name) ? String(object.name) : "", + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], + nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : 0, + stateMap: isObject(object.stateMap) + ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { + acc[key] = stateEnumFromJSON(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: Simple): unknown { const obj: any = {}; if (message.name !== "") { @@ -172,21 +187,6 @@ export const Simple = { return obj; }, - fromJSON(object: any): Simple { - return { - name: isSet(object.name) ? String(object.name) : "", - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - states: Array.isArray(object?.states) ? object.states.map((e: any) => stateEnumFromJSON(e)) : [], - nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : 0, - stateMap: isObject(object.stateMap) - ? Object.entries(object.stateMap).reduce<{ [key: string]: StateEnum }>((acc, [key, value]) => { - acc[key] = stateEnumFromJSON(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Simple { return Simple.fromPartial(base ?? {}); }, @@ -255,6 +255,13 @@ export const Simple_StateMapEntry = { return message; }, + fromJSON(object: any): Simple_StateMapEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, + }; + }, + toJSON(message: Simple_StateMapEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -266,13 +273,6 @@ export const Simple_StateMapEntry = { return obj; }, - fromJSON(object: any): Simple_StateMapEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? stateEnumFromJSON(object.value) : 0, - }; - }, - create, I>>(base?: I): Simple_StateMapEntry { return Simple_StateMapEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-objectid-true-external-import/objectid/objectid.ts b/integration/use-objectid-true-external-import/objectid/objectid.ts index 982821c72..e61fbb74b 100644 --- a/integration/use-objectid-true-external-import/objectid/objectid.ts +++ b/integration/use-objectid-true-external-import/objectid/objectid.ts @@ -42,6 +42,10 @@ export const ObjectId = { return message; }, + fromJSON(object: any): ObjectId { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: ObjectId): unknown { const obj: any = {}; if (message.value !== "") { @@ -50,10 +54,6 @@ export const ObjectId = { return obj; }, - fromJSON(object: any): ObjectId { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): ObjectId { return ObjectId.fromPartial(base ?? {}); }, diff --git a/integration/use-objectid-true-external-import/use-objectid-true.ts b/integration/use-objectid-true-external-import/use-objectid-true.ts index cea8b7b4f..4d51b266a 100644 --- a/integration/use-objectid-true-external-import/use-objectid-true.ts +++ b/integration/use-objectid-true-external-import/use-objectid-true.ts @@ -96,6 +96,21 @@ export const Todo = { return message; }, + fromJSON(object: any): Todo { + return { + id: isSet(object.id) ? String(object.id) : "", + oid: isSet(object.oid) ? fromJsonObjectId(object.oid) : undefined, + repeatedOid: Array.isArray(object?.repeatedOid) ? object.repeatedOid.map((e: any) => fromJsonObjectId(e)) : [], + optionalOid: isSet(object.optionalOid) ? fromJsonObjectId(object.optionalOid) : undefined, + mapOfOids: isObject(object.mapOfOids) + ? Object.entries(object.mapOfOids).reduce<{ [key: string]: mongodb.ObjectId }>((acc, [key, value]) => { + acc[key] = fromJsonObjectId(value); + return acc; + }, {}) + : {}, + }; + }, + toJSON(message: Todo): unknown { const obj: any = {}; if (message.id !== "") { @@ -122,21 +137,6 @@ export const Todo = { return obj; }, - fromJSON(object: any): Todo { - return { - id: isSet(object.id) ? String(object.id) : "", - oid: isSet(object.oid) ? fromJsonObjectId(object.oid) : undefined, - repeatedOid: Array.isArray(object?.repeatedOid) ? object.repeatedOid.map((e: any) => fromJsonObjectId(e)) : [], - optionalOid: isSet(object.optionalOid) ? fromJsonObjectId(object.optionalOid) : undefined, - mapOfOids: isObject(object.mapOfOids) - ? Object.entries(object.mapOfOids).reduce<{ [key: string]: mongodb.ObjectId }>((acc, [key, value]) => { - acc[key] = fromJsonObjectId(value); - return acc; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Todo { return Todo.fromPartial(base ?? {}); }, @@ -207,6 +207,13 @@ export const Todo_MapOfOidsEntry = { return message; }, + fromJSON(object: any): Todo_MapOfOidsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? fromJsonObjectId(object.value) : undefined, + }; + }, + toJSON(message: Todo_MapOfOidsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -218,13 +225,6 @@ export const Todo_MapOfOidsEntry = { return obj; }, - fromJSON(object: any): Todo_MapOfOidsEntry { - return { - key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? fromJsonObjectId(object.value) : undefined, - }; - }, - create, I>>(base?: I): Todo_MapOfOidsEntry { return Todo_MapOfOidsEntry.fromPartial(base ?? {}); }, diff --git a/integration/use-optionals-all/google/protobuf/timestamp.ts b/integration/use-optionals-all/google/protobuf/timestamp.ts index 017aabd58..6b1f71f5e 100644 --- a/integration/use-optionals-all/google/protobuf/timestamp.ts +++ b/integration/use-optionals-all/google/protobuf/timestamp.ts @@ -158,6 +158,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== undefined && message.seconds !== 0) { @@ -169,13 +176,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/use-optionals-all/test.ts b/integration/use-optionals-all/test.ts index cb1d0b264..25ca5aa67 100644 --- a/integration/use-optionals-all/test.ts +++ b/integration/use-optionals-all/test.ts @@ -422,6 +422,39 @@ export const OptionalsTest = { return message; }, + fromJSON(object: any): OptionalsTest { + return { + id: isSet(object.id) ? Number(object.id) : 0, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, + long: isSet(object.long) ? Number(object.long) : 0, + truth: isSet(object.truth) ? Boolean(object.truth) : false, + description: isSet(object.description) ? String(object.description) : "", + data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0), + repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : [], + repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : [], + repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : [], + repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : [], + repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : [], + repDescription: Array.isArray(object?.repDescription) ? object.repDescription.map((e: any) => String(e)) : [], + repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : [], + optId: isSet(object.optId) ? Number(object.optId) : undefined, + optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, + optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, + optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, + optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, + optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, + optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, + translations: isObject(object.translations) + ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : {}, + timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, + }; + }, + toJSON(message: OptionalsTest): unknown { const obj: any = {}; if (message.id !== undefined && message.id !== 0) { @@ -502,39 +535,6 @@ export const OptionalsTest = { return obj; }, - fromJSON(object: any): OptionalsTest { - return { - id: isSet(object.id) ? Number(object.id) : 0, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : 0, - long: isSet(object.long) ? Number(object.long) : 0, - truth: isSet(object.truth) ? Boolean(object.truth) : false, - description: isSet(object.description) ? String(object.description) : "", - data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0), - repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : [], - repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : [], - repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : [], - repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : [], - repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : [], - repDescription: Array.isArray(object?.repDescription) ? object.repDescription.map((e: any) => String(e)) : [], - repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : [], - optId: isSet(object.optId) ? Number(object.optId) : undefined, - optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, - optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, - optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, - optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, - optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, - optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, - translations: isObject(object.translations) - ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : {}, - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - }; - }, - create, I>>(base?: I): OptionalsTest { return OptionalsTest.fromPartial(base ?? {}); }, @@ -623,6 +623,10 @@ export const OptionalsTest_TranslationsEntry = { return message; }, + fromJSON(object: any): OptionalsTest_TranslationsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: OptionalsTest_TranslationsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -634,10 +638,6 @@ export const OptionalsTest_TranslationsEntry = { return obj; }, - fromJSON(object: any): OptionalsTest_TranslationsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): OptionalsTest_TranslationsEntry { return OptionalsTest_TranslationsEntry.fromPartial(base ?? {}); }, @@ -677,15 +677,15 @@ export const Child = { return message; }, + fromJSON(_: any): Child { + return {}; + }, + toJSON(_: Child): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Child { - return {}; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/use-optionals-no-undefined/test.ts b/integration/use-optionals-no-undefined/test.ts index c9919c30b..a0ae92741 100644 --- a/integration/use-optionals-no-undefined/test.ts +++ b/integration/use-optionals-no-undefined/test.ts @@ -422,6 +422,40 @@ export const OptionalsTest = { return message; }, + fromJSON(object: any): OptionalsTest { + return { + id: isSet(object.id) ? Number(object.id) : undefined, + child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, + state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, + long: isSet(object.long) ? Number(object.long) : undefined, + truth: isSet(object.truth) ? Boolean(object.truth) : undefined, + description: isSet(object.description) ? String(object.description) : undefined, + data: isSet(object.data) ? bytesFromBase64(object.data) : undefined, + repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : undefined, + repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : undefined, + repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : undefined, + repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : undefined, + repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : undefined, + repDescription: Array.isArray(object?.repDescription) + ? object.repDescription.map((e: any) => String(e)) + : undefined, + repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : undefined, + optId: isSet(object.optId) ? Number(object.optId) : undefined, + optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, + optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, + optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, + optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, + optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, + optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, + translations: isObject(object.translations) + ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}) + : undefined, + }; + }, + toJSON(message: OptionalsTest): unknown { const obj: any = {}; if (message.id !== undefined && message.id !== 0) { @@ -499,40 +533,6 @@ export const OptionalsTest = { return obj; }, - fromJSON(object: any): OptionalsTest { - return { - id: isSet(object.id) ? Number(object.id) : undefined, - child: isSet(object.child) ? Child.fromJSON(object.child) : undefined, - state: isSet(object.state) ? stateEnumFromJSON(object.state) : undefined, - long: isSet(object.long) ? Number(object.long) : undefined, - truth: isSet(object.truth) ? Boolean(object.truth) : undefined, - description: isSet(object.description) ? String(object.description) : undefined, - data: isSet(object.data) ? bytesFromBase64(object.data) : undefined, - repId: Array.isArray(object?.repId) ? object.repId.map((e: any) => Number(e)) : undefined, - repChild: Array.isArray(object?.repChild) ? object.repChild.map((e: any) => Child.fromJSON(e)) : undefined, - repState: Array.isArray(object?.repState) ? object.repState.map((e: any) => stateEnumFromJSON(e)) : undefined, - repLong: Array.isArray(object?.repLong) ? object.repLong.map((e: any) => Number(e)) : undefined, - repTruth: Array.isArray(object?.repTruth) ? object.repTruth.map((e: any) => Boolean(e)) : undefined, - repDescription: Array.isArray(object?.repDescription) - ? object.repDescription.map((e: any) => String(e)) - : undefined, - repData: Array.isArray(object?.repData) ? object.repData.map((e: any) => bytesFromBase64(e)) : undefined, - optId: isSet(object.optId) ? Number(object.optId) : undefined, - optChild: isSet(object.optChild) ? Child.fromJSON(object.optChild) : undefined, - optState: isSet(object.optState) ? stateEnumFromJSON(object.optState) : undefined, - optLong: isSet(object.optLong) ? Number(object.optLong) : undefined, - optTruth: isSet(object.optTruth) ? Boolean(object.optTruth) : undefined, - optDescription: isSet(object.optDescription) ? String(object.optDescription) : undefined, - optData: isSet(object.optData) ? bytesFromBase64(object.optData) : undefined, - translations: isObject(object.translations) - ? Object.entries(object.translations).reduce<{ [key: string]: string }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) - : undefined, - }; - }, - create, I>>(base?: I): OptionalsTest { return OptionalsTest.fromPartial(base ?? {}); }, @@ -619,6 +619,10 @@ export const OptionalsTest_TranslationsEntry = { return message; }, + fromJSON(object: any): OptionalsTest_TranslationsEntry { + return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: OptionalsTest_TranslationsEntry): unknown { const obj: any = {}; if (message.key !== "") { @@ -630,10 +634,6 @@ export const OptionalsTest_TranslationsEntry = { return obj; }, - fromJSON(object: any): OptionalsTest_TranslationsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): OptionalsTest_TranslationsEntry { return OptionalsTest_TranslationsEntry.fromPartial(base ?? {}); }, @@ -673,15 +673,15 @@ export const Child = { return message; }, + fromJSON(_: any): Child { + return {}; + }, + toJSON(_: Child): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Child { - return {}; - }, - create, I>>(base?: I): Child { return Child.fromPartial(base ?? {}); }, diff --git a/integration/use-readonly-types/google/protobuf/field_mask.ts b/integration/use-readonly-types/google/protobuf/field_mask.ts index d0a5cd6e5..bb2f0e74f 100644 --- a/integration/use-readonly-types/google/protobuf/field_mask.ts +++ b/integration/use-readonly-types/google/protobuf/field_mask.ts @@ -243,10 +243,6 @@ export const FieldMask = { return message; }, - toJSON(message: FieldMask): string { - return message.paths.join(","); - }, - fromJSON(object: any): FieldMask { return { paths: typeof (object) === "string" @@ -257,6 +253,10 @@ export const FieldMask = { }; }, + toJSON(message: FieldMask): string { + return message.paths.join(","); + }, + create, I>>(base?: I): FieldMask { return FieldMask.fromPartial(base ?? {}); }, diff --git a/integration/use-readonly-types/google/protobuf/struct.ts b/integration/use-readonly-types/google/protobuf/struct.ts index 4e2df0254..9cf68f024 100644 --- a/integration/use-readonly-types/google/protobuf/struct.ts +++ b/integration/use-readonly-types/google/protobuf/struct.ts @@ -126,6 +126,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -140,17 +151,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -235,6 +235,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -246,10 +250,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -349,6 +349,24 @@ export const Value = { return message; }, + fromJSON(object: any): Value { + return { + kind: isSet(object.nullValue) + ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } + : isSet(object.numberValue) + ? { $case: "numberValue", numberValue: Number(object.numberValue) } + : isSet(object.stringValue) + ? { $case: "stringValue", stringValue: String(object.stringValue) } + : isSet(object.boolValue) + ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } + : isSet(object.structValue) + ? { $case: "structValue", structValue: object.structValue } + : isSet(object.listValue) + ? { $case: "listValue", listValue: [...object.listValue] } + : undefined, + }; + }, + toJSON(message: Value): unknown { const obj: any = {}; if (message.kind?.$case === "nullValue") { @@ -372,24 +390,6 @@ export const Value = { return obj; }, - fromJSON(object: any): Value { - return { - kind: isSet(object.nullValue) - ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) } - : isSet(object.numberValue) - ? { $case: "numberValue", numberValue: Number(object.numberValue) } - : isSet(object.stringValue) - ? { $case: "stringValue", stringValue: String(object.stringValue) } - : isSet(object.boolValue) - ? { $case: "boolValue", boolValue: Boolean(object.boolValue) } - : isSet(object.structValue) - ? { $case: "structValue", structValue: object.structValue } - : isSet(object.listValue) - ? { $case: "listValue", listValue: [...object.listValue] } - : undefined, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -503,6 +503,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -511,10 +515,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/use-readonly-types/use-readonly-types.ts b/integration/use-readonly-types/use-readonly-types.ts index 3774ccd79..c706088eb 100644 --- a/integration/use-readonly-types/use-readonly-types.ts +++ b/integration/use-readonly-types/use-readonly-types.ts @@ -197,6 +197,28 @@ export const Entity = { return message; }, + fromJSON(object: any): Entity { + return { + intVal: isSet(object.intVal) ? Number(object.intVal) : 0, + stringVal: isSet(object.stringVal) ? String(object.stringVal) : "", + intArray: Array.isArray(object?.intArray) ? object.intArray.map((e: any) => Number(e)) : [], + stringArray: Array.isArray(object?.stringArray) ? object.stringArray.map((e: any) => String(e)) : [], + subEntity: isSet(object.subEntity) ? SubEntity.fromJSON(object.subEntity) : undefined, + subEntityArray: Array.isArray(object?.subEntityArray) + ? object.subEntityArray.map((e: any) => SubEntity.fromJSON(e)) + : [], + optionalIntVal: isSet(object.optionalIntVal) ? Number(object.optionalIntVal) : undefined, + fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined, + listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined, + structValue: isObject(object.structValue) ? object.structValue : undefined, + oneOfValue: isSet(object.theStringValue) + ? { $case: "theStringValue", theStringValue: String(object.theStringValue) } + : isSet(object.theIntValue) + ? { $case: "theIntValue", theIntValue: Number(object.theIntValue) } + : undefined, + }; + }, + toJSON(message: Entity): unknown { const obj: any = {}; if (message.intVal !== 0) { @@ -238,28 +260,6 @@ export const Entity = { return obj; }, - fromJSON(object: any): Entity { - return { - intVal: isSet(object.intVal) ? Number(object.intVal) : 0, - stringVal: isSet(object.stringVal) ? String(object.stringVal) : "", - intArray: Array.isArray(object?.intArray) ? object.intArray.map((e: any) => Number(e)) : [], - stringArray: Array.isArray(object?.stringArray) ? object.stringArray.map((e: any) => String(e)) : [], - subEntity: isSet(object.subEntity) ? SubEntity.fromJSON(object.subEntity) : undefined, - subEntityArray: Array.isArray(object?.subEntityArray) - ? object.subEntityArray.map((e: any) => SubEntity.fromJSON(e)) - : [], - optionalIntVal: isSet(object.optionalIntVal) ? Number(object.optionalIntVal) : undefined, - fieldMask: isSet(object.fieldMask) ? FieldMask.unwrap(FieldMask.fromJSON(object.fieldMask)) : undefined, - listValue: Array.isArray(object.listValue) ? [...object.listValue] : undefined, - structValue: isObject(object.structValue) ? object.structValue : undefined, - oneOfValue: isSet(object.theStringValue) - ? { $case: "theStringValue", theStringValue: String(object.theStringValue) } - : isSet(object.theIntValue) - ? { $case: "theIntValue", theIntValue: Number(object.theIntValue) } - : undefined, - }; - }, - create, I>>(base?: I): Entity { return Entity.fromPartial(base ?? {}); }, @@ -331,6 +331,10 @@ export const SubEntity = { return message; }, + fromJSON(object: any): SubEntity { + return { subVal: isSet(object.subVal) ? Number(object.subVal) : 0 }; + }, + toJSON(message: SubEntity): unknown { const obj: any = {}; if (message.subVal !== 0) { @@ -339,10 +343,6 @@ export const SubEntity = { return obj; }, - fromJSON(object: any): SubEntity { - return { subVal: isSet(object.subVal) ? Number(object.subVal) : 0 }; - }, - create, I>>(base?: I): SubEntity { return SubEntity.fromPartial(base ?? {}); }, diff --git a/integration/value/google/protobuf/struct.ts b/integration/value/google/protobuf/struct.ts index 7c416eb52..b2486a866 100644 --- a/integration/value/google/protobuf/struct.ts +++ b/integration/value/google/protobuf/struct.ts @@ -140,6 +140,17 @@ export const Struct = { 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 = {}; if (message.fields) { @@ -154,17 +165,6 @@ export const Struct = { return obj; }, - 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; - }, {}) - : {}, - }; - }, - create, I>>(base?: I): Struct { return Struct.fromPartial(base ?? {}); }, @@ -249,6 +249,10 @@ export const Struct_FieldsEntry = { 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 = {}; if (message.key !== "") { @@ -260,10 +264,6 @@ export const Struct_FieldsEntry = { return obj; }, - fromJSON(object: any): Struct_FieldsEntry { - return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined }; - }, - create, I>>(base?: I): Struct_FieldsEntry { return Struct_FieldsEntry.fromPartial(base ?? {}); }, @@ -368,6 +368,17 @@ export const Value = { 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 = {}; if (message.nullValue !== undefined) { @@ -391,17 +402,6 @@ export const Value = { return obj; }, - 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, - }; - }, - create, I>>(base?: I): Value { return Value.fromPartial(base ?? {}); }, @@ -490,6 +490,10 @@ export const ListValue = { return message; }, + fromJSON(object: any): ListValue { + return { values: Array.isArray(object?.values) ? [...object.values] : [] }; + }, + toJSON(message: ListValue): unknown { const obj: any = {}; if (message.values?.length) { @@ -498,10 +502,6 @@ export const ListValue = { return obj; }, - fromJSON(object: any): ListValue { - return { values: Array.isArray(object?.values) ? [...object.values] : [] }; - }, - create, I>>(base?: I): ListValue { return ListValue.fromPartial(base ?? {}); }, diff --git a/integration/value/google/protobuf/wrappers.ts b/integration/value/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/value/google/protobuf/wrappers.ts +++ b/integration/value/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/integration/value/value.ts b/integration/value/value.ts index 655130963..a8e9092b0 100644 --- a/integration/value/value.ts +++ b/integration/value/value.ts @@ -88,6 +88,16 @@ export const ValueMessage = { return message; }, + fromJSON(object: any): ValueMessage { + return { + value: isSet(object?.value) ? object.value : undefined, + anyList: Array.isArray(object.anyList) ? [...object.anyList] : undefined, + repeatedAny: Array.isArray(object?.repeatedAny) ? [...object.repeatedAny] : [], + repeatedStrings: Array.isArray(object?.repeatedStrings) ? object.repeatedStrings.map((e: any) => String(e)) : [], + structValue: isObject(object.structValue) ? object.structValue : undefined, + }; + }, + toJSON(message: ValueMessage): unknown { const obj: any = {}; if (message.value !== undefined) { @@ -108,16 +118,6 @@ export const ValueMessage = { return obj; }, - fromJSON(object: any): ValueMessage { - return { - value: isSet(object?.value) ? object.value : undefined, - anyList: Array.isArray(object.anyList) ? [...object.anyList] : undefined, - repeatedAny: Array.isArray(object?.repeatedAny) ? [...object.repeatedAny] : [], - repeatedStrings: Array.isArray(object?.repeatedStrings) ? object.repeatedStrings.map((e: any) => String(e)) : [], - structValue: isObject(object.structValue) ? object.structValue : undefined, - }; - }, - create, I>>(base?: I): ValueMessage { return ValueMessage.fromPartial(base ?? {}); }, diff --git a/integration/vector-tile/vector_tile.ts b/integration/vector-tile/vector_tile.ts index 61e684c51..7dfda0699 100644 --- a/integration/vector-tile/vector_tile.ts +++ b/integration/vector-tile/vector_tile.ts @@ -114,6 +114,10 @@ export const Tile = { return message; }, + fromJSON(object: any): Tile { + return { layers: Array.isArray(object?.layers) ? object.layers.map((e: any) => Tile_Layer.fromJSON(e)) : [] }; + }, + toJSON(message: Tile): unknown { const obj: any = {}; if (message.layers?.length) { @@ -122,10 +126,6 @@ export const Tile = { return obj; }, - fromJSON(object: any): Tile { - return { layers: Array.isArray(object?.layers) ? object.layers.map((e: any) => Tile_Layer.fromJSON(e)) : [] }; - }, - create, I>>(base?: I): Tile { return Tile.fromPartial(base ?? {}); }, @@ -232,6 +232,18 @@ export const Tile_Value = { return message; }, + fromJSON(object: any): Tile_Value { + return { + stringValue: isSet(object.stringValue) ? String(object.stringValue) : "", + floatValue: isSet(object.floatValue) ? Number(object.floatValue) : 0, + doubleValue: isSet(object.doubleValue) ? Number(object.doubleValue) : 0, + intValue: isSet(object.intValue) ? Number(object.intValue) : 0, + uintValue: isSet(object.uintValue) ? Number(object.uintValue) : 0, + sintValue: isSet(object.sintValue) ? Number(object.sintValue) : 0, + boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : false, + }; + }, + toJSON(message: Tile_Value): unknown { const obj: any = {}; if (message.stringValue !== "") { @@ -258,18 +270,6 @@ export const Tile_Value = { return obj; }, - fromJSON(object: any): Tile_Value { - return { - stringValue: isSet(object.stringValue) ? String(object.stringValue) : "", - floatValue: isSet(object.floatValue) ? Number(object.floatValue) : 0, - doubleValue: isSet(object.doubleValue) ? Number(object.doubleValue) : 0, - intValue: isSet(object.intValue) ? Number(object.intValue) : 0, - uintValue: isSet(object.uintValue) ? Number(object.uintValue) : 0, - sintValue: isSet(object.sintValue) ? Number(object.sintValue) : 0, - boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : false, - }; - }, - create, I>>(base?: I): Tile_Value { return Tile_Value.fromPartial(base ?? {}); }, @@ -376,6 +376,15 @@ export const Tile_Feature = { return message; }, + fromJSON(object: any): Tile_Feature { + return { + id: isSet(object.id) ? Number(object.id) : 0, + tags: Array.isArray(object?.tags) ? object.tags.map((e: any) => Number(e)) : [], + type: isSet(object.type) ? tile_GeomTypeFromJSON(object.type) : 0, + geometry: Array.isArray(object?.geometry) ? object.geometry.map((e: any) => Number(e)) : [], + }; + }, + toJSON(message: Tile_Feature): unknown { const obj: any = {}; if (message.id !== 0) { @@ -393,15 +402,6 @@ export const Tile_Feature = { return obj; }, - fromJSON(object: any): Tile_Feature { - return { - id: isSet(object.id) ? Number(object.id) : 0, - tags: Array.isArray(object?.tags) ? object.tags.map((e: any) => Number(e)) : [], - type: isSet(object.type) ? tile_GeomTypeFromJSON(object.type) : 0, - geometry: Array.isArray(object?.geometry) ? object.geometry.map((e: any) => Number(e)) : [], - }; - }, - create, I>>(base?: I): Tile_Feature { return Tile_Feature.fromPartial(base ?? {}); }, @@ -501,6 +501,17 @@ export const Tile_Layer = { return message; }, + fromJSON(object: any): Tile_Layer { + return { + version: isSet(object.version) ? Number(object.version) : 0, + name: isSet(object.name) ? String(object.name) : "", + features: Array.isArray(object?.features) ? object.features.map((e: any) => Tile_Feature.fromJSON(e)) : [], + keys: Array.isArray(object?.keys) ? object.keys.map((e: any) => String(e)) : [], + values: Array.isArray(object?.values) ? object.values.map((e: any) => Tile_Value.fromJSON(e)) : [], + extent: isSet(object.extent) ? Number(object.extent) : 0, + }; + }, + toJSON(message: Tile_Layer): unknown { const obj: any = {}; if (message.version !== 0) { @@ -524,17 +535,6 @@ export const Tile_Layer = { return obj; }, - fromJSON(object: any): Tile_Layer { - return { - version: isSet(object.version) ? Number(object.version) : 0, - name: isSet(object.name) ? String(object.name) : "", - features: Array.isArray(object?.features) ? object.features.map((e: any) => Tile_Feature.fromJSON(e)) : [], - keys: Array.isArray(object?.keys) ? object.keys.map((e: any) => String(e)) : [], - values: Array.isArray(object?.values) ? object.values.map((e: any) => Tile_Value.fromJSON(e)) : [], - extent: isSet(object.extent) ? Number(object.extent) : 0, - }; - }, - create, I>>(base?: I): Tile_Layer { return Tile_Layer.fromPartial(base ?? {}); }, diff --git a/integration/wrappers-regression/google/protobuf/empty.ts b/integration/wrappers-regression/google/protobuf/empty.ts index d1b8ebf5b..1387d7ce4 100644 --- a/integration/wrappers-regression/google/protobuf/empty.ts +++ b/integration/wrappers-regression/google/protobuf/empty.ts @@ -42,15 +42,15 @@ export const Empty = { return message; }, + fromJSON(_: any): Empty { + return {}; + }, + toJSON(_: Empty): unknown { const obj: any = {}; return obj; }, - fromJSON(_: any): Empty { - return {}; - }, - create, I>>(base?: I): Empty { return Empty.fromPartial(base ?? {}); }, diff --git a/integration/wrappers-regression/google/protobuf/timestamp.ts b/integration/wrappers-regression/google/protobuf/timestamp.ts index 4947dacaa..032f4ab29 100644 --- a/integration/wrappers-regression/google/protobuf/timestamp.ts +++ b/integration/wrappers-regression/google/protobuf/timestamp.ts @@ -156,6 +156,13 @@ export const Timestamp = { 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 = {}; if (message.seconds !== 0) { @@ -167,13 +174,6 @@ export const Timestamp = { return obj; }, - fromJSON(object: any): Timestamp { - return { - seconds: isSet(object.seconds) ? Number(object.seconds) : 0, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; - }, - create, I>>(base?: I): Timestamp { return Timestamp.fromPartial(base ?? {}); }, diff --git a/integration/wrappers-regression/google/protobuf/wrappers.ts b/integration/wrappers-regression/google/protobuf/wrappers.ts index 14888eb05..6637762f8 100644 --- a/integration/wrappers-regression/google/protobuf/wrappers.ts +++ b/integration/wrappers-regression/google/protobuf/wrappers.ts @@ -129,6 +129,10 @@ export const DoubleValue = { return message; }, + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -137,10 +141,6 @@ export const DoubleValue = { return obj; }, - fromJSON(object: any): DoubleValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): DoubleValue { return DoubleValue.fromPartial(base ?? {}); }, @@ -187,6 +187,10 @@ export const FloatValue = { return message; }, + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -195,10 +199,6 @@ export const FloatValue = { return obj; }, - fromJSON(object: any): FloatValue { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): FloatValue { return FloatValue.fromPartial(base ?? {}); }, @@ -245,6 +245,10 @@ export const Int64Value = { return message; }, + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -253,10 +257,6 @@ export const Int64Value = { return obj; }, - fromJSON(object: any): Int64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int64Value { return Int64Value.fromPartial(base ?? {}); }, @@ -303,6 +303,10 @@ export const UInt64Value = { return message; }, + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -311,10 +315,6 @@ export const UInt64Value = { return obj; }, - fromJSON(object: any): UInt64Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt64Value { return UInt64Value.fromPartial(base ?? {}); }, @@ -361,6 +361,10 @@ export const Int32Value = { return message; }, + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -369,10 +373,6 @@ export const Int32Value = { return obj; }, - fromJSON(object: any): Int32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): Int32Value { return Int32Value.fromPartial(base ?? {}); }, @@ -419,6 +419,10 @@ export const UInt32Value = { return message; }, + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? Number(object.value) : 0 }; + }, + toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -427,10 +431,6 @@ export const UInt32Value = { return obj; }, - fromJSON(object: any): UInt32Value { - return { value: isSet(object.value) ? Number(object.value) : 0 }; - }, - create, I>>(base?: I): UInt32Value { return UInt32Value.fromPartial(base ?? {}); }, @@ -477,6 +477,10 @@ export const BoolValue = { return message; }, + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? Boolean(object.value) : false }; + }, + toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value === true) { @@ -485,10 +489,6 @@ export const BoolValue = { return obj; }, - fromJSON(object: any): BoolValue { - return { value: isSet(object.value) ? Boolean(object.value) : false }; - }, - create, I>>(base?: I): BoolValue { return BoolValue.fromPartial(base ?? {}); }, @@ -535,6 +535,10 @@ export const StringValue = { return message; }, + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? String(object.value) : "" }; + }, + toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -543,10 +547,6 @@ export const StringValue = { return obj; }, - fromJSON(object: any): StringValue { - return { value: isSet(object.value) ? String(object.value) : "" }; - }, - create, I>>(base?: I): StringValue { return StringValue.fromPartial(base ?? {}); }, @@ -593,6 +593,10 @@ export const BytesValue = { return message; }, + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -601,10 +605,6 @@ export const BytesValue = { return obj; }, - fromJSON(object: any): BytesValue { - return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; - }, - create, I>>(base?: I): BytesValue { return BytesValue.fromPartial(base ?? {}); }, diff --git a/src/main.ts b/src/main.ts index dede10b00..1966e1a49 100644 --- a/src/main.ts +++ b/src/main.ts @@ -235,15 +235,15 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri staticMembers.push(generateDecodeTransform(fullName)); } if (options.outputJsonMethods) { + if (options.outputJsonMethods === true || options.outputJsonMethods === "decode-only") { + staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); + } if(options.outputJsonMethods === true || options.outputJsonMethods === "encode-only" ){ staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); } - if (options.outputJsonMethods === true || options.outputJsonMethods === "decode-only") { - staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); - } } if (options.outputPartialMethods) { staticMembers.push(generateFromPartial(ctx, fullName, message)); From 088ffd737b01cd22b777b4a3cd6fea57de1714e0 Mon Sep 17 00:00:00 2001 From: Francesco Battista Date: Tue, 18 Jul 2023 17:10:35 -0400 Subject: [PATCH 4/7] feat(ts-proto#859): ran yarn format --- src/main.ts | 5 +---- src/options.ts | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1966e1a49..2d2afe130 100644 --- a/src/main.ts +++ b/src/main.ts @@ -238,12 +238,9 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri if (options.outputJsonMethods === true || options.outputJsonMethods === "decode-only") { staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); } - if(options.outputJsonMethods === true || - options.outputJsonMethods === "encode-only" - ){ + if (options.outputJsonMethods === true || options.outputJsonMethods === "encode-only") { staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); } - } if (options.outputPartialMethods) { staticMembers.push(generateFromPartial(ctx, fullName, message)); diff --git a/src/options.ts b/src/options.ts index 24d042d54..81612da00 100644 --- a/src/options.ts +++ b/src/options.ts @@ -46,7 +46,7 @@ export type Options = { fileSuffix: string; importSuffix: string; outputEncodeMethods: true | false | "encode-only" | "decode-only" | "encode-no-creation"; - outputJsonMethods: true | false | "encode-only" | "decode-only" ; + outputJsonMethods: true | false | "encode-only" | "decode-only"; outputPartialMethods: boolean; outputTypeAnnotations: boolean | "static-only"; outputTypeRegistry: boolean; From 8f9d490c5b6e79f66f9ca21ba3ec0ee0162ca2ca Mon Sep 17 00:00:00 2001 From: Francesco Battista Date: Wed, 19 Jul 2023 09:26:48 -0400 Subject: [PATCH 5/7] feat(ts-proto-#859): updated docs and renamed methods to toOnly and fromOnly --- README.markdown | 4 ++++ .../decode.bin | Bin .../decode.proto | 0 .../decode.ts | 0 .../google/protobuf/wrappers.ts | 0 .../parameters.txt | 2 +- .../encode.bin | Bin .../encode.proto | 0 .../encode.ts | 0 .../google/protobuf/wrappers.ts | 0 .../parameters.txt | 2 +- src/main.ts | 4 ++-- src/options.ts | 2 +- 13 files changed, 9 insertions(+), 5 deletions(-) rename integration/{output-decode-only-json => output-fromJSON-only}/decode.bin (100%) rename integration/{output-decode-only-json => output-fromJSON-only}/decode.proto (100%) rename integration/{output-decode-only-json => output-fromJSON-only}/decode.ts (100%) rename integration/{output-decode-only-json => output-fromJSON-only}/google/protobuf/wrappers.ts (100%) rename integration/{output-decode-only-json => output-fromJSON-only}/parameters.txt (66%) rename integration/{output-encode-only-json => output-toJSON-only}/encode.bin (100%) rename integration/{output-encode-only-json => output-toJSON-only}/encode.proto (100%) rename integration/{output-encode-only-json => output-toJSON-only}/encode.ts (100%) rename integration/{output-encode-only-json => output-toJSON-only}/google/protobuf/wrappers.ts (100%) rename integration/{output-encode-only-json => output-toJSON-only}/parameters.txt (66%) diff --git a/README.markdown b/README.markdown index 9a875797a..a872f5304 100644 --- a/README.markdown +++ b/README.markdown @@ -376,6 +376,10 @@ Generated code will be placed in the Gradle build directory. This is also useful if you want "only types". +- With `--ts_proto_opt=outputJsonMethods=to-only` and `--ts_proto_opt=outputJsonMethods=from-only` you will be able to export only one between the `Message.toJSON` and `Message.fromJSON` methods. + + This is useful if you're using ts-proto just to `encode` or `decode` and not for both. + - With `--ts_proto_opt=outputPartialMethods=false`, the `Message.fromPartial` and `Message.create` methods for accepting partially-formed objects/object literals will not be output. - With `--ts_proto_opt=stringEnums=true`, the generated enum types will be string-based instead of int-based. diff --git a/integration/output-decode-only-json/decode.bin b/integration/output-fromJSON-only/decode.bin similarity index 100% rename from integration/output-decode-only-json/decode.bin rename to integration/output-fromJSON-only/decode.bin diff --git a/integration/output-decode-only-json/decode.proto b/integration/output-fromJSON-only/decode.proto similarity index 100% rename from integration/output-decode-only-json/decode.proto rename to integration/output-fromJSON-only/decode.proto diff --git a/integration/output-decode-only-json/decode.ts b/integration/output-fromJSON-only/decode.ts similarity index 100% rename from integration/output-decode-only-json/decode.ts rename to integration/output-fromJSON-only/decode.ts diff --git a/integration/output-decode-only-json/google/protobuf/wrappers.ts b/integration/output-fromJSON-only/google/protobuf/wrappers.ts similarity index 100% rename from integration/output-decode-only-json/google/protobuf/wrappers.ts rename to integration/output-fromJSON-only/google/protobuf/wrappers.ts diff --git a/integration/output-decode-only-json/parameters.txt b/integration/output-fromJSON-only/parameters.txt similarity index 66% rename from integration/output-decode-only-json/parameters.txt rename to integration/output-fromJSON-only/parameters.txt index 998a9a4ec..b93cead45 100644 --- a/integration/output-decode-only-json/parameters.txt +++ b/integration/output-fromJSON-only/parameters.txt @@ -1 +1 @@ -outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=decode-only,nestJs=false +outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=from-only,nestJs=false diff --git a/integration/output-encode-only-json/encode.bin b/integration/output-toJSON-only/encode.bin similarity index 100% rename from integration/output-encode-only-json/encode.bin rename to integration/output-toJSON-only/encode.bin diff --git a/integration/output-encode-only-json/encode.proto b/integration/output-toJSON-only/encode.proto similarity index 100% rename from integration/output-encode-only-json/encode.proto rename to integration/output-toJSON-only/encode.proto diff --git a/integration/output-encode-only-json/encode.ts b/integration/output-toJSON-only/encode.ts similarity index 100% rename from integration/output-encode-only-json/encode.ts rename to integration/output-toJSON-only/encode.ts diff --git a/integration/output-encode-only-json/google/protobuf/wrappers.ts b/integration/output-toJSON-only/google/protobuf/wrappers.ts similarity index 100% rename from integration/output-encode-only-json/google/protobuf/wrappers.ts rename to integration/output-toJSON-only/google/protobuf/wrappers.ts diff --git a/integration/output-encode-only-json/parameters.txt b/integration/output-toJSON-only/parameters.txt similarity index 66% rename from integration/output-encode-only-json/parameters.txt rename to integration/output-toJSON-only/parameters.txt index b99c4e51d..5e25f3ce6 100644 --- a/integration/output-encode-only-json/parameters.txt +++ b/integration/output-toJSON-only/parameters.txt @@ -1 +1 @@ -outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=encode-only,nestJs=false +outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=to-only,nestJs=false diff --git a/src/main.ts b/src/main.ts index 2d2afe130..bbfaedbad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -235,10 +235,10 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri staticMembers.push(generateDecodeTransform(fullName)); } if (options.outputJsonMethods) { - if (options.outputJsonMethods === true || options.outputJsonMethods === "decode-only") { + if (options.outputJsonMethods === true || options.outputJsonMethods === "from-only") { staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message)); } - if (options.outputJsonMethods === true || options.outputJsonMethods === "encode-only") { + if (options.outputJsonMethods === true || options.outputJsonMethods === "to-only") { staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message)); } } diff --git a/src/options.ts b/src/options.ts index 81612da00..dcf515ad9 100644 --- a/src/options.ts +++ b/src/options.ts @@ -46,7 +46,7 @@ export type Options = { fileSuffix: string; importSuffix: string; outputEncodeMethods: true | false | "encode-only" | "decode-only" | "encode-no-creation"; - outputJsonMethods: true | false | "encode-only" | "decode-only"; + outputJsonMethods: true | false | "to-only" | "from-only"; outputPartialMethods: boolean; outputTypeAnnotations: boolean | "static-only"; outputTypeRegistry: boolean; From cdb2adc091188477fc2b2b7b732cd5d8c3b14769 Mon Sep 17 00:00:00 2001 From: Francesco Battista Date: Wed, 23 Aug 2023 14:47:58 +0200 Subject: [PATCH 6/7] feat: removed toJson/fromJSON enums when not used --- integration/fromJson-enums/from-json.bin | Bin 0 -> 411 bytes integration/fromJson-enums/from-json.proto | 9 +++++ integration/fromJson-enums/from-json.ts | 37 +++++++++++++++++++++ integration/fromJson-enums/parameters.txt | 1 + src/enums.ts | 4 +-- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 integration/fromJson-enums/from-json.bin create mode 100644 integration/fromJson-enums/from-json.proto create mode 100644 integration/fromJson-enums/from-json.ts create mode 100644 integration/fromJson-enums/parameters.txt diff --git a/integration/fromJson-enums/from-json.bin b/integration/fromJson-enums/from-json.bin new file mode 100644 index 0000000000000000000000000000000000000000..774a6ce65903747a744511a6d254b321b3abcc13 GIT binary patch literal 411 zcmZ9E!Ab)$5I~d6>^2P5joGftO4t& Date: Wed, 23 Aug 2023 19:06:23 +0200 Subject: [PATCH 7/7] feat(#909): ran format --- src/enums.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/enums.ts b/src/enums.ts index 7c063c36c..042ded819 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -52,11 +52,15 @@ export function generateEnum( chunks.push(code`}`); } - if (options.outputJsonMethods === true || options.outputJsonMethods === 'from-only' || (options.stringEnums && options.outputEncodeMethods)) { + if ( + options.outputJsonMethods === true || + options.outputJsonMethods === "from-only" || + (options.stringEnums && options.outputEncodeMethods) + ) { chunks.push(code`\n`); chunks.push(generateEnumFromJson(ctx, fullName, enumDesc)); } - if (options.outputJsonMethods === true || options.outputJsonMethods === 'to-only') { + if (options.outputJsonMethods === true || options.outputJsonMethods === "to-only") { chunks.push(code`\n`); chunks.push(generateEnumToJson(ctx, fullName, enumDesc)); }