Skip to content

Commit

Permalink
Merge pull request #620 from cosmology-tech/json-safe
Browse files Browse the repository at this point in the history
Json safe
  • Loading branch information
pyramation authored May 25, 2024
2 parents 05c6463 + 851db7b commit fba9188
Show file tree
Hide file tree
Showing 688 changed files with 4,570 additions and 3,838 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ See [RPC Clients](#rpc-clients) for more info.
| `prototypes.typingsFormat.useTelescopeGeneratedType` | Discard GeneratedType from cosmjs, use TelescopeGeneratedType instead inside *.registry.ts files | `false` |
| `prototypes.typingsFormat.useDeepPartial` | defaults to true, but if disabled uses the `Partial` TS type | `false` |
| `prototypes.typingsFormat.useExact` | defaults to false, but if enabled uses the `Exact` TS type | `false` |
| `prototypes.typingsFormat.toJsonUnknown` | defaults to true, but if disabled uses the `JsonSafe` for `toJSON` methods | `true` |
| `prototypes.typingsFormat.timestamp` | use either `date` or `timestamp` for `Timestamp` proto type | "date" |
| `prototypes.typingsFormat.duration` | use either `duration` or `string` for `Duration` proto type | "duration"|
| `prototypes.typingsFormat.setDefaultEnumToUnrecognized` | false: enum empty value would be 0, true: -1(value for enum unrecognized) |true|
Expand Down
17 changes: 9 additions & 8 deletions __fixtures__/v-next/outputv3/akash/audit/v1beta1/audit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Attribute, AttributeAmino, AttributeSDKType } from "../../base/v1beta1/attribute";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.audit.v1beta1";
/** Provider stores owner auditor and attributes details */
export interface Provider {
Expand Down Expand Up @@ -196,7 +197,7 @@ export const Provider = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: Provider): unknown {
toJSON(message: Provider): JsonSafe<Provider> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -318,7 +319,7 @@ export const AuditedAttributes = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: AuditedAttributes): unknown {
toJSON(message: AuditedAttributes): JsonSafe<AuditedAttributes> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -424,7 +425,7 @@ export const AttributesResponse = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => AuditedAttributes.fromJSON(e));
return obj;
},
toJSON(message: AttributesResponse): unknown {
toJSON(message: AttributesResponse): JsonSafe<AttributesResponse> {
const obj: any = {};
if (message.attributes) {
obj.attributes = message.attributes.map(e => e ? AuditedAttributes.toJSON(e) : undefined);
Expand Down Expand Up @@ -522,7 +523,7 @@ export const AttributesFilters = {
if (Array.isArray(object?.owners)) obj.owners = object.owners.map((e: any) => String(e));
return obj;
},
toJSON(message: AttributesFilters): unknown {
toJSON(message: AttributesFilters): JsonSafe<AttributesFilters> {
const obj: any = {};
if (message.auditors) {
obj.auditors = message.auditors.map(e => e);
Expand Down Expand Up @@ -646,7 +647,7 @@ export const MsgSignProviderAttributes = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: MsgSignProviderAttributes): unknown {
toJSON(message: MsgSignProviderAttributes): JsonSafe<MsgSignProviderAttributes> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -743,7 +744,7 @@ export const MsgSignProviderAttributesResponse = {
const obj = createBaseMsgSignProviderAttributesResponse();
return obj;
},
toJSON(_: MsgSignProviderAttributesResponse): unknown {
toJSON(_: MsgSignProviderAttributesResponse): JsonSafe<MsgSignProviderAttributesResponse> {
const obj: any = {};
return obj;
},
Expand Down Expand Up @@ -830,7 +831,7 @@ export const MsgDeleteProviderAttributes = {
if (Array.isArray(object?.keys)) obj.keys = object.keys.map((e: any) => String(e));
return obj;
},
toJSON(message: MsgDeleteProviderAttributes): unknown {
toJSON(message: MsgDeleteProviderAttributes): JsonSafe<MsgDeleteProviderAttributes> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -927,7 +928,7 @@ export const MsgDeleteProviderAttributesResponse = {
const obj = createBaseMsgDeleteProviderAttributesResponse();
return obj;
},
toJSON(_: MsgDeleteProviderAttributesResponse): unknown {
toJSON(_: MsgDeleteProviderAttributesResponse): JsonSafe<MsgDeleteProviderAttributesResponse> {
const obj: any = {};
return obj;
},
Expand Down
17 changes: 9 additions & 8 deletions __fixtures__/v-next/outputv3/akash/audit/v1beta2/audit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Attribute, AttributeAmino, AttributeSDKType } from "../../base/v1beta2/attribute";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.audit.v1beta2";
/** Provider stores owner auditor and attributes details */
export interface Provider {
Expand Down Expand Up @@ -196,7 +197,7 @@ export const Provider = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: Provider): unknown {
toJSON(message: Provider): JsonSafe<Provider> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -318,7 +319,7 @@ export const AuditedAttributes = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: AuditedAttributes): unknown {
toJSON(message: AuditedAttributes): JsonSafe<AuditedAttributes> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -424,7 +425,7 @@ export const AttributesResponse = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => AuditedAttributes.fromJSON(e));
return obj;
},
toJSON(message: AttributesResponse): unknown {
toJSON(message: AttributesResponse): JsonSafe<AttributesResponse> {
const obj: any = {};
if (message.attributes) {
obj.attributes = message.attributes.map(e => e ? AuditedAttributes.toJSON(e) : undefined);
Expand Down Expand Up @@ -522,7 +523,7 @@ export const AttributesFilters = {
if (Array.isArray(object?.owners)) obj.owners = object.owners.map((e: any) => String(e));
return obj;
},
toJSON(message: AttributesFilters): unknown {
toJSON(message: AttributesFilters): JsonSafe<AttributesFilters> {
const obj: any = {};
if (message.auditors) {
obj.auditors = message.auditors.map(e => e);
Expand Down Expand Up @@ -646,7 +647,7 @@ export const MsgSignProviderAttributes = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: MsgSignProviderAttributes): unknown {
toJSON(message: MsgSignProviderAttributes): JsonSafe<MsgSignProviderAttributes> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -743,7 +744,7 @@ export const MsgSignProviderAttributesResponse = {
const obj = createBaseMsgSignProviderAttributesResponse();
return obj;
},
toJSON(_: MsgSignProviderAttributesResponse): unknown {
toJSON(_: MsgSignProviderAttributesResponse): JsonSafe<MsgSignProviderAttributesResponse> {
const obj: any = {};
return obj;
},
Expand Down Expand Up @@ -830,7 +831,7 @@ export const MsgDeleteProviderAttributes = {
if (Array.isArray(object?.keys)) obj.keys = object.keys.map((e: any) => String(e));
return obj;
},
toJSON(message: MsgDeleteProviderAttributes): unknown {
toJSON(message: MsgDeleteProviderAttributes): JsonSafe<MsgDeleteProviderAttributes> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.auditor !== undefined && (obj.auditor = message.auditor);
Expand Down Expand Up @@ -927,7 +928,7 @@ export const MsgDeleteProviderAttributesResponse = {
const obj = createBaseMsgDeleteProviderAttributesResponse();
return obj;
},
toJSON(_: MsgDeleteProviderAttributesResponse): unknown {
toJSON(_: MsgDeleteProviderAttributesResponse): JsonSafe<MsgDeleteProviderAttributesResponse> {
const obj: any = {};
return obj;
},
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/v-next/outputv3/akash/audit/v1beta2/genesis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AuditedAttributes, AuditedAttributesAmino, AuditedAttributesSDKType } from "./audit";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { JsonSafe } from "../../../json-safe";
import { DeepPartial } from "../../../helpers";
export const protobufPackage = "akash.audit.v1beta2";
/** GenesisState defines the basic genesis state used by audit module */
Expand Down Expand Up @@ -53,7 +54,7 @@ export const GenesisState = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => AuditedAttributes.fromJSON(e));
return obj;
},
toJSON(message: GenesisState): unknown {
toJSON(message: GenesisState): JsonSafe<GenesisState> {
const obj: any = {};
if (message.attributes) {
obj.attributes = message.attributes.map(e => e ? AuditedAttributes.toJSON(e) : undefined);
Expand Down
13 changes: 7 additions & 6 deletions __fixtures__/v-next/outputv3/akash/audit/v1beta2/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PageRequest, PageRequestAmino, PageRequestSDKType, PageResponse, PageRe
import { Provider, ProviderAmino, ProviderSDKType } from "./audit";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.audit.v1beta2";
/** QueryProvidersResponse is response type for the Query/Providers RPC method */
export interface QueryProvidersResponse {
Expand Down Expand Up @@ -157,7 +158,7 @@ export const QueryProvidersResponse = {
if (isSet(object.pagination)) obj.pagination = PageResponse.fromJSON(object.pagination);
return obj;
},
toJSON(message: QueryProvidersResponse): unknown {
toJSON(message: QueryProvidersResponse): JsonSafe<QueryProvidersResponse> {
const obj: any = {};
if (message.providers) {
obj.providers = message.providers.map(e => e ? Provider.toJSON(e) : undefined);
Expand Down Expand Up @@ -265,7 +266,7 @@ export const QueryProviderRequest = {
if (isSet(object.owner)) obj.owner = String(object.owner);
return obj;
},
toJSON(message: QueryProviderRequest): unknown {
toJSON(message: QueryProviderRequest): JsonSafe<QueryProviderRequest> {
const obj: any = {};
message.auditor !== undefined && (obj.auditor = message.auditor);
message.owner !== undefined && (obj.owner = message.owner);
Expand Down Expand Up @@ -353,7 +354,7 @@ export const QueryAllProvidersAttributesRequest = {
if (isSet(object.pagination)) obj.pagination = PageRequest.fromJSON(object.pagination);
return obj;
},
toJSON(message: QueryAllProvidersAttributesRequest): unknown {
toJSON(message: QueryAllProvidersAttributesRequest): JsonSafe<QueryAllProvidersAttributesRequest> {
const obj: any = {};
message.pagination !== undefined && (obj.pagination = message.pagination ? PageRequest.toJSON(message.pagination) : undefined);
return obj;
Expand Down Expand Up @@ -443,7 +444,7 @@ export const QueryProviderAttributesRequest = {
if (isSet(object.pagination)) obj.pagination = PageRequest.fromJSON(object.pagination);
return obj;
},
toJSON(message: QueryProviderAttributesRequest): unknown {
toJSON(message: QueryProviderAttributesRequest): JsonSafe<QueryProviderAttributesRequest> {
const obj: any = {};
message.owner !== undefined && (obj.owner = message.owner);
message.pagination !== undefined && (obj.pagination = message.pagination ? PageRequest.toJSON(message.pagination) : undefined);
Expand Down Expand Up @@ -541,7 +542,7 @@ export const QueryProviderAuditorRequest = {
if (isSet(object.owner)) obj.owner = String(object.owner);
return obj;
},
toJSON(message: QueryProviderAuditorRequest): unknown {
toJSON(message: QueryProviderAuditorRequest): JsonSafe<QueryProviderAuditorRequest> {
const obj: any = {};
message.auditor !== undefined && (obj.auditor = message.auditor);
message.owner !== undefined && (obj.owner = message.owner);
Expand Down Expand Up @@ -637,7 +638,7 @@ export const QueryAuditorAttributesRequest = {
if (isSet(object.pagination)) obj.pagination = PageRequest.fromJSON(object.pagination);
return obj;
},
toJSON(message: QueryAuditorAttributesRequest): unknown {
toJSON(message: QueryAuditorAttributesRequest): JsonSafe<QueryAuditorAttributesRequest> {
const obj: any = {};
message.auditor !== undefined && (obj.auditor = message.auditor);
message.pagination !== undefined && (obj.pagination = message.pagination ? PageRequest.toJSON(message.pagination) : undefined);
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv3/akash/base/v1beta1/attribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.base.v1beta1";
/** Attribute represents key value pair */
export interface Attribute {
Expand Down Expand Up @@ -124,7 +125,7 @@ export const Attribute = {
if (isSet(object.value)) obj.value = String(object.value);
return obj;
},
toJSON(message: Attribute): unknown {
toJSON(message: Attribute): JsonSafe<Attribute> {
const obj: any = {};
message.key !== undefined && (obj.key = message.key);
message.value !== undefined && (obj.value = message.value);
Expand Down Expand Up @@ -220,7 +221,7 @@ export const SignedBy = {
if (Array.isArray(object?.anyOf)) obj.anyOf = object.anyOf.map((e: any) => String(e));
return obj;
},
toJSON(message: SignedBy): unknown {
toJSON(message: SignedBy): JsonSafe<SignedBy> {
const obj: any = {};
if (message.allOf) {
obj.allOf = message.allOf.map(e => e);
Expand Down Expand Up @@ -336,7 +337,7 @@ export const PlacementRequirements = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: PlacementRequirements): unknown {
toJSON(message: PlacementRequirements): JsonSafe<PlacementRequirements> {
const obj: any = {};
message.signedBy !== undefined && (obj.signedBy = message.signedBy ? SignedBy.toJSON(message.signedBy) : undefined);
if (message.attributes) {
Expand Down
3 changes: 2 additions & 1 deletion __fixtures__/v-next/outputv3/akash/base/v1beta1/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.base.v1beta1";
/** This describes how the endpoint is implemented when the lease is deployed */
export enum Endpoint_Kind {
Expand Down Expand Up @@ -87,7 +88,7 @@ export const Endpoint = {
if (isSet(object.kind)) obj.kind = endpoint_KindFromJSON(object.kind);
return obj;
},
toJSON(message: Endpoint): unknown {
toJSON(message: Endpoint): JsonSafe<Endpoint> {
const obj: any = {};
message.kind !== undefined && (obj.kind = endpoint_KindToJSON(message.kind));
return obj;
Expand Down
9 changes: 5 additions & 4 deletions __fixtures__/v-next/outputv3/akash/base/v1beta1/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Attribute, AttributeAmino, AttributeSDKType } from "./attribute";
import { Endpoint, EndpointAmino, EndpointSDKType } from "./endpoint";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.base.v1beta1";
/** CPU stores resource units and cpu config attributes */
export interface CPU {
Expand Down Expand Up @@ -138,7 +139,7 @@ export const CPU = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: CPU): unknown {
toJSON(message: CPU): JsonSafe<CPU> {
const obj: any = {};
message.units !== undefined && (obj.units = message.units ? ResourceValue.toJSON(message.units) : undefined);
if (message.attributes) {
Expand Down Expand Up @@ -246,7 +247,7 @@ export const Memory = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: Memory): unknown {
toJSON(message: Memory): JsonSafe<Memory> {
const obj: any = {};
message.quantity !== undefined && (obj.quantity = message.quantity ? ResourceValue.toJSON(message.quantity) : undefined);
if (message.attributes) {
Expand Down Expand Up @@ -354,7 +355,7 @@ export const Storage = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: Storage): unknown {
toJSON(message: Storage): JsonSafe<Storage> {
const obj: any = {};
message.quantity !== undefined && (obj.quantity = message.quantity ? ResourceValue.toJSON(message.quantity) : undefined);
if (message.attributes) {
Expand Down Expand Up @@ -478,7 +479,7 @@ export const ResourceUnits = {
if (Array.isArray(object?.endpoints)) obj.endpoints = object.endpoints.map((e: any) => Endpoint.fromJSON(e));
return obj;
},
toJSON(message: ResourceUnits): unknown {
toJSON(message: ResourceUnits): JsonSafe<ResourceUnits> {
const obj: any = {};
message.cpu !== undefined && (obj.cpu = message.cpu ? CPU.toJSON(message.cpu) : undefined);
message.memory !== undefined && (obj.memory = message.memory ? Memory.toJSON(message.memory) : undefined);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, bytesFromBase64, base64FromBytes, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.base.v1beta1";
/** Unit stores cpu, memory and storage metrics */
export interface ResourceValue {
Expand Down Expand Up @@ -52,7 +53,7 @@ export const ResourceValue = {
if (isSet(object.val)) obj.val = bytesFromBase64(object.val);
return obj;
},
toJSON(message: ResourceValue): unknown {
toJSON(message: ResourceValue): JsonSafe<ResourceValue> {
const obj: any = {};
message.val !== undefined && (obj.val = base64FromBytes(message.val !== undefined ? message.val : new Uint8Array()));
return obj;
Expand Down
7 changes: 4 additions & 3 deletions __fixtures__/v-next/outputv3/akash/base/v1beta2/attribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { JsonSafe } from "../../../json-safe";
export const protobufPackage = "akash.base.v1beta2";
/** Attribute represents key value pair */
export interface Attribute {
Expand Down Expand Up @@ -124,7 +125,7 @@ export const Attribute = {
if (isSet(object.value)) obj.value = String(object.value);
return obj;
},
toJSON(message: Attribute): unknown {
toJSON(message: Attribute): JsonSafe<Attribute> {
const obj: any = {};
message.key !== undefined && (obj.key = message.key);
message.value !== undefined && (obj.value = message.value);
Expand Down Expand Up @@ -220,7 +221,7 @@ export const SignedBy = {
if (Array.isArray(object?.anyOf)) obj.anyOf = object.anyOf.map((e: any) => String(e));
return obj;
},
toJSON(message: SignedBy): unknown {
toJSON(message: SignedBy): JsonSafe<SignedBy> {
const obj: any = {};
if (message.allOf) {
obj.allOf = message.allOf.map(e => e);
Expand Down Expand Up @@ -336,7 +337,7 @@ export const PlacementRequirements = {
if (Array.isArray(object?.attributes)) obj.attributes = object.attributes.map((e: any) => Attribute.fromJSON(e));
return obj;
},
toJSON(message: PlacementRequirements): unknown {
toJSON(message: PlacementRequirements): JsonSafe<PlacementRequirements> {
const obj: any = {};
message.signedBy !== undefined && (obj.signedBy = message.signedBy ? SignedBy.toJSON(message.signedBy) : undefined);
if (message.attributes) {
Expand Down
Loading

0 comments on commit fba9188

Please sign in to comment.