diff --git a/packages/ast/src/encoding/__snapshots__/object.spec.ts.snap b/packages/ast/src/encoding/__snapshots__/object.spec.ts.snap index 0ec1188c9c..b4a59ef0d3 100644 --- a/packages/ast/src/encoding/__snapshots__/object.spec.ts.snap +++ b/packages/ast/src/encoding/__snapshots__/object.spec.ts.snap @@ -38,11 +38,11 @@ exports[`cosmos/staking/v1beta1 Delegation 1`] = ` return message; }, fromJSON(object: any): Delegation { - return { - delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", - validatorAddress: isSet(object.validatorAddress) ? String(object.validatorAddress) : "", - shares: isSet(object.shares) ? String(object.shares) : "" - }; + const obj = createBaseDelegation(); + if (isSet(object.delegatorAddress)) obj.delegatorAddress = String(object.delegatorAddress); + if (isSet(object.validatorAddress)) obj.validatorAddress = String(object.validatorAddress); + if (isSet(object.shares)) obj.shares = String(object.shares); + return obj; }, toJSON(message: Delegation): unknown { const obj: any = {}; @@ -113,11 +113,11 @@ exports[`cosmos/tx/signing/v1beta1/signing SignatureDescriptor 1`] = ` return message; }, fromJSON(object: any): SignatureDescriptor { - return { - publicKey: isSet(object.publicKey) ? Any.fromJSON(object.publicKey) : undefined, - data: isSet(object.data) ? SignatureDescriptor_Data.fromJSON(object.data) : undefined, - sequence: isSet(object.sequence) ? Long.fromValue(object.sequence) : Long.UZERO - }; + const obj = createBaseSignatureDescriptor(); + if (isSet(object.publicKey)) obj.publicKey = Any.fromJSON(object.publicKey); + if (isSet(object.data)) obj.data = SignatureDescriptor_Data.fromJSON(object.data); + if (isSet(object.sequence)) obj.sequence = Long.fromValue(object.sequence); + return obj; }, toJSON(message: SignatureDescriptor): unknown { const obj: any = {}; @@ -128,8 +128,8 @@ exports[`cosmos/tx/signing/v1beta1/signing SignatureDescriptor 1`] = ` }, fromPartial(object: DeepPartial): SignatureDescriptor { const message = createBaseSignatureDescriptor(); - message.publicKey = object.publicKey !== undefined && object.publicKey !== null ? Any.fromPartial(object.publicKey) : undefined; - message.data = object.data !== undefined && object.data !== null ? SignatureDescriptor_Data.fromPartial(object.data) : undefined; + message.publicKey = object.publicKey !== undefined && object.publicKey !== null ? Any.fromPartial(object.publicKey) : Any.fromPartial({}); + message.data = object.data !== undefined && object.data !== null ? SignatureDescriptor_Data.fromPartial(object.data) : SignatureDescriptor_Data.fromPartial({}); message.sequence = object.sequence !== undefined && object.sequence !== null ? Long.fromValue(object.sequence) : Long.UZERO; return message; }, @@ -176,9 +176,9 @@ exports[`cosmos/tx/signing/v1beta1/signing SignatureDescriptors 1`] = ` return message; }, fromJSON(object: any): SignatureDescriptors { - return { - signatures: Array.isArray(object?.signatures) ? object.signatures.map((e: any) => SignatureDescriptor.fromJSON(e)) : [] - }; + const obj = createBaseSignatureDescriptors(); + if (Array.isArray(object?.signatures)) object.signatures.map((e: any) => SignatureDescriptor.fromJSON(e)); + return obj; }, toJSON(message: SignatureDescriptors): unknown { const obj: any = {}; @@ -255,12 +255,12 @@ exports[`cosmos/tx/v1beta1/tx AuxSignerData 1`] = ` return message; }, fromJSON(object: any): AuxSignerData { - return { - address: isSet(object.address) ? String(object.address) : "", - signDoc: isSet(object.signDoc) ? SignDocDirectAux.fromJSON(object.signDoc) : undefined, - mode: isSet(object.mode) ? signModeFromJSON(object.mode) : 0, - sig: isSet(object.sig) ? bytesFromBase64(object.sig) : new Uint8Array() - }; + const obj = createBaseAuxSignerData(); + if (isSet(object.address)) obj.address = String(object.address); + if (isSet(object.signDoc)) obj.signDoc = SignDocDirectAux.fromJSON(object.signDoc); + if (isSet(object.mode)) obj.mode = signModeFromJSON(object.mode); + if (isSet(object.sig)) obj.sig = bytesFromBase64(object.sig); + return obj; }, toJSON(message: AuxSignerData): unknown { const obj: any = {}; @@ -273,7 +273,7 @@ exports[`cosmos/tx/v1beta1/tx AuxSignerData 1`] = ` fromPartial(object: DeepPartial): AuxSignerData { const message = createBaseAuxSignerData(); message.address = object.address ?? ""; - message.signDoc = object.signDoc !== undefined && object.signDoc !== null ? SignDocDirectAux.fromPartial(object.signDoc) : undefined; + message.signDoc = object.signDoc !== undefined && object.signDoc !== null ? SignDocDirectAux.fromPartial(object.signDoc) : SignDocDirectAux.fromPartial({}); message.mode = object.mode ?? 0; message.sig = object.sig ?? new Uint8Array(); return message; @@ -329,10 +329,10 @@ exports[`cosmos/tx/v1beta1/tx ModeInfo_Multi 1`] = ` return message; }, fromJSON(object: any): ModeInfo_Multi { - return { - single: isSet(object.single) ? ModeInfo_Single.fromJSON(object.single) : undefined, - multi: isSet(object.multi) ? ModeInfo_Multi.fromJSON(object.multi) : undefined - }; + const obj = createBaseModeInfo_Multi(); + if (isSet(object.single)) obj.single = ModeInfo_Single.fromJSON(object.single); + if (isSet(object.multi)) obj.multi = ModeInfo_Multi.fromJSON(object.multi); + return obj; }, toJSON(message: ModeInfo_Multi): unknown { const obj: any = {}; @@ -342,8 +342,8 @@ exports[`cosmos/tx/v1beta1/tx ModeInfo_Multi 1`] = ` }, fromPartial(object: DeepPartial): ModeInfo_Multi { const message = createBaseModeInfo_Multi(); - message.single = object.single !== undefined && object.single !== null ? ModeInfo_Single.fromPartial(object.single) : undefined; - message.multi = object.multi !== undefined && object.multi !== null ? ModeInfo_Multi.fromPartial(object.multi) : undefined; + message.single = object.single !== undefined && object.single !== null ? ModeInfo_Single.fromPartial(object.single) : ModeInfo_Single.fromPartial({}); + message.multi = object.multi !== undefined && object.multi !== null ? ModeInfo_Multi.fromPartial(object.multi) : ModeInfo_Multi.fromPartial({}); return message; }, fromSDK(object: ModeInfo_MultiSDKType): ModeInfo_Multi { @@ -408,11 +408,11 @@ exports[`cosmwasm/wasm/v1/proposal 1`] = ` return message; }, fromJSON(object: any): PinCodesProposal { - return { - title: isSet(object.title) ? String(object.title) : "", - description: isSet(object.description) ? String(object.description) : "", - codeIds: Array.isArray(object?.codeIds) ? object.codeIds.map((e: any) => Long.fromValue(e)) : [] - }; + const obj = createBasePinCodesProposal(); + if (isSet(object.title)) obj.title = String(object.title); + if (isSet(object.description)) obj.description = String(object.description); + if (Array.isArray(object?.codeIds)) object.codeIds.map((e: any) => Long.fromValue(e)); + return obj; }, toJSON(message: PinCodesProposal): unknown { const obj: any = {}; @@ -500,11 +500,11 @@ exports[`cosmwasm/wasm/v1/proposal 2`] = ` return message; }, fromJSON(object: any): UnpinCodesProposal { - return { - title: isSet(object.title) ? String(object.title) : "", - description: isSet(object.description) ? String(object.description) : "", - codeIds: Array.isArray(object?.codeIds) ? object.codeIds.map((e: any) => Long.fromValue(e)) : [] - }; + const obj = createBaseUnpinCodesProposal(); + if (isSet(object.title)) obj.title = String(object.title); + if (isSet(object.description)) obj.description = String(object.description); + if (Array.isArray(object?.codeIds)) object.codeIds.map((e: any) => Long.fromValue(e)); + return obj; }, toJSON(message: UnpinCodesProposal): unknown { const obj: any = {}; @@ -577,10 +577,10 @@ exports[`cosmwasm/wasm/v1/query 1`] = ` return message; }, fromJSON(object: any): QueryRawContractStateRequest { - return { - address: isSet(object.address) ? String(object.address) : "", - queryData: isSet(object.queryData) ? bytesFromBase64(object.queryData) : new Uint8Array() - }; + const obj = createBaseQueryRawContractStateRequest(); + if (isSet(object.address)) obj.address = String(object.address); + if (isSet(object.queryData)) obj.queryData = bytesFromBase64(object.queryData); + return obj; }, toJSON(message: QueryRawContractStateRequest): unknown { const obj: any = {}; @@ -662,12 +662,12 @@ exports[`evmos/fees/v1/tx 1`] = ` return message; }, fromJSON(object: any): MsgRegisterDevFeeInfo { - return { - contractAddress: isSet(object.contractAddress) ? String(object.contractAddress) : "", - deployerAddress: isSet(object.deployerAddress) ? String(object.deployerAddress) : "", - withdrawAddress: isSet(object.withdrawAddress) ? String(object.withdrawAddress) : "", - nonces: Array.isArray(object?.nonces) ? object.nonces.map((e: any) => Long.fromValue(e)) : [] - }; + const obj = createBaseMsgRegisterDevFeeInfo(); + if (isSet(object.contractAddress)) obj.contractAddress = String(object.contractAddress); + if (isSet(object.deployerAddress)) obj.deployerAddress = String(object.deployerAddress); + if (isSet(object.withdrawAddress)) obj.withdrawAddress = String(object.withdrawAddress); + if (Array.isArray(object?.nonces)) object.nonces.map((e: any) => Long.fromValue(e)); + return obj; }, toJSON(message: MsgRegisterDevFeeInfo): unknown { const obj: any = {}; @@ -756,12 +756,12 @@ exports[`google/api/expr/conformance/v1alpha1/conformance_service ParseRequest 1 return message; }, fromJSON(object: any): ParseRequest { - return { - celSource: isSet(object.celSource) ? String(object.celSource) : "", - syntaxVersion: isSet(object.syntaxVersion) ? String(object.syntaxVersion) : "", - sourceLocation: isSet(object.sourceLocation) ? String(object.sourceLocation) : "", - disableMacros: isSet(object.disableMacros) ? Boolean(object.disableMacros) : false - }; + const obj = createBaseParseRequest(); + if (isSet(object.celSource)) obj.celSource = String(object.celSource); + if (isSet(object.syntaxVersion)) obj.syntaxVersion = String(object.syntaxVersion); + if (isSet(object.sourceLocation)) obj.sourceLocation = String(object.sourceLocation); + if (isSet(object.disableMacros)) obj.disableMacros = Boolean(object.disableMacros); + return obj; }, toJSON(message: ParseRequest): unknown { const obj: any = {}; @@ -854,14 +854,14 @@ exports[`google/api/expr/v1alpha1/checked Decl_FunctionDecl_Overload MapType 1`] return message; }, fromJSON(object: any): Decl_FunctionDecl_Overload { - return { - overloadId: isSet(object.overloadId) ? String(object.overloadId) : "", - params: Array.isArray(object?.params) ? object.params.map((e: any) => Type.fromJSON(e)) : [], - typeParams: Array.isArray(object?.typeParams) ? object.typeParams.map((e: any) => String(e)) : [], - resultType: isSet(object.resultType) ? Type.fromJSON(object.resultType) : undefined, - isInstanceFunction: isSet(object.isInstanceFunction) ? Boolean(object.isInstanceFunction) : false, - doc: isSet(object.doc) ? String(object.doc) : "" - }; + const obj = createBaseDecl_FunctionDecl_Overload(); + if (isSet(object.overloadId)) obj.overloadId = String(object.overloadId); + if (Array.isArray(object?.params)) object.params.map((e: any) => Type.fromJSON(e)); + if (Array.isArray(object?.typeParams)) object.typeParams.map((e: any) => String(e)); + if (isSet(object.resultType)) obj.resultType = Type.fromJSON(object.resultType); + if (isSet(object.isInstanceFunction)) obj.isInstanceFunction = Boolean(object.isInstanceFunction); + if (isSet(object.doc)) obj.doc = String(object.doc); + return obj; }, toJSON(message: Decl_FunctionDecl_Overload): unknown { const obj: any = {}; @@ -886,7 +886,7 @@ exports[`google/api/expr/v1alpha1/checked Decl_FunctionDecl_Overload MapType 1`] message.overloadId = object.overloadId ?? ""; message.params = object.params?.map(e => Type.fromPartial(e)) || []; message.typeParams = object.typeParams?.map(e => e) || []; - message.resultType = object.resultType !== undefined && object.resultType !== null ? Type.fromPartial(object.resultType) : undefined; + message.resultType = object.resultType !== undefined && object.resultType !== null ? Type.fromPartial(object.resultType) : Type.fromPartial({}); message.isInstanceFunction = object.isInstanceFunction ?? false; message.doc = object.doc ?? ""; return message; @@ -1020,21 +1020,21 @@ exports[`google/api/expr/v1alpha1/checked Type 1`] = ` return message; }, fromJSON(object: any): Type { - return { - dyn: isSet(object.dyn) ? Empty.fromJSON(object.dyn) : undefined, - null: isSet(object.null) ? nullValueFromJSON(object.null) : undefined, - primitive: isSet(object.primitive) ? type_PrimitiveTypeFromJSON(object.primitive) : undefined, - wrapper: isSet(object.wrapper) ? type_PrimitiveTypeFromJSON(object.wrapper) : undefined, - wellKnown: isSet(object.wellKnown) ? type_WellKnownTypeFromJSON(object.wellKnown) : undefined, - listType: isSet(object.listType) ? Type_ListType.fromJSON(object.listType) : undefined, - mapType: isSet(object.mapType) ? Type_MapType.fromJSON(object.mapType) : undefined, - function: isSet(object.function) ? Type_FunctionType.fromJSON(object.function) : undefined, - messageType: isSet(object.messageType) ? String(object.messageType) : undefined, - typeParam: isSet(object.typeParam) ? String(object.typeParam) : undefined, - type: isSet(object.type) ? Type.fromJSON(object.type) : undefined, - error: isSet(object.error) ? Empty.fromJSON(object.error) : undefined, - abstractType: isSet(object.abstractType) ? Type_AbstractType.fromJSON(object.abstractType) : undefined - }; + const obj = createBaseType(); + if (isSet(object.dyn)) obj.dyn = Empty.fromJSON(object.dyn); + if (isSet(object.null)) obj.null = nullValueFromJSON(object.null); + if (isSet(object.primitive)) obj.primitive = type_PrimitiveTypeFromJSON(object.primitive); + if (isSet(object.wrapper)) obj.wrapper = type_PrimitiveTypeFromJSON(object.wrapper); + if (isSet(object.wellKnown)) obj.wellKnown = type_WellKnownTypeFromJSON(object.wellKnown); + if (isSet(object.listType)) obj.listType = Type_ListType.fromJSON(object.listType); + if (isSet(object.mapType)) obj.mapType = Type_MapType.fromJSON(object.mapType); + if (isSet(object.function)) obj.function = Type_FunctionType.fromJSON(object.function); + if (isSet(object.messageType)) obj.messageType = String(object.messageType); + if (isSet(object.typeParam)) obj.typeParam = String(object.typeParam); + if (isSet(object.type)) obj.type = Type.fromJSON(object.type); + if (isSet(object.error)) obj.error = Empty.fromJSON(object.error); + if (isSet(object.abstractType)) obj.abstractType = Type_AbstractType.fromJSON(object.abstractType); + return obj; }, toJSON(message: Type): unknown { const obj: any = {}; @@ -1055,19 +1055,19 @@ exports[`google/api/expr/v1alpha1/checked Type 1`] = ` }, fromPartial(object: DeepPartial): Type { const message = createBaseType(); - message.dyn = object.dyn !== undefined && object.dyn !== null ? Empty.fromPartial(object.dyn) : undefined; + message.dyn = object.dyn !== undefined && object.dyn !== null ? Empty.fromPartial(object.dyn) : Empty.fromPartial({}); message.null = object.null ?? undefined; message.primitive = object.primitive ?? undefined; message.wrapper = object.wrapper ?? undefined; message.wellKnown = object.wellKnown ?? undefined; - message.listType = object.listType !== undefined && object.listType !== null ? Type_ListType.fromPartial(object.listType) : undefined; - message.mapType = object.mapType !== undefined && object.mapType !== null ? Type_MapType.fromPartial(object.mapType) : undefined; - message.function = object.function !== undefined && object.function !== null ? Type_FunctionType.fromPartial(object.function) : undefined; + message.listType = object.listType !== undefined && object.listType !== null ? Type_ListType.fromPartial(object.listType) : Type_ListType.fromPartial({}); + message.mapType = object.mapType !== undefined && object.mapType !== null ? Type_MapType.fromPartial(object.mapType) : Type_MapType.fromPartial({}); + message.function = object.function !== undefined && object.function !== null ? Type_FunctionType.fromPartial(object.function) : Type_FunctionType.fromPartial({}); message.messageType = object.messageType ?? undefined; message.typeParam = object.typeParam ?? undefined; - message.type = object.type !== undefined && object.type !== null ? Type.fromPartial(object.type) : undefined; - message.error = object.error !== undefined && object.error !== null ? Empty.fromPartial(object.error) : undefined; - message.abstractType = object.abstractType !== undefined && object.abstractType !== null ? Type_AbstractType.fromPartial(object.abstractType) : undefined; + message.type = object.type !== undefined && object.type !== null ? Type.fromPartial(object.type) : Type.fromPartial({}); + message.error = object.error !== undefined && object.error !== null ? Empty.fromPartial(object.error) : Empty.fromPartial({}); + message.abstractType = object.abstractType !== undefined && object.abstractType !== null ? Type_AbstractType.fromPartial(object.abstractType) : Type_AbstractType.fromPartial({}); return message; }, fromSDK(object: TypeSDKType): Type { @@ -1139,10 +1139,10 @@ exports[`google/api/expr/v1alpha1/checked nested MapType 1`] = ` return message; }, fromJSON(object: any): Type_MapType { - return { - keyType: isSet(object.keyType) ? Type.fromJSON(object.keyType) : undefined, - valueType: isSet(object.valueType) ? Type.fromJSON(object.valueType) : undefined - }; + const obj = createBaseType_MapType(); + if (isSet(object.keyType)) obj.keyType = Type.fromJSON(object.keyType); + if (isSet(object.valueType)) obj.valueType = Type.fromJSON(object.valueType); + return obj; }, toJSON(message: Type_MapType): unknown { const obj: any = {}; @@ -1152,8 +1152,8 @@ exports[`google/api/expr/v1alpha1/checked nested MapType 1`] = ` }, fromPartial(object: DeepPartial): Type_MapType { const message = createBaseType_MapType(); - message.keyType = object.keyType !== undefined && object.keyType !== null ? Type.fromPartial(object.keyType) : undefined; - message.valueType = object.valueType !== undefined && object.valueType !== null ? Type.fromPartial(object.valueType) : undefined; + message.keyType = object.keyType !== undefined && object.keyType !== null ? Type.fromPartial(object.keyType) : Type.fromPartial({}); + message.valueType = object.valueType !== undefined && object.valueType !== null ? Type.fromPartial(object.valueType) : Type.fromPartial({}); return message; }, fromSDK(object: Type_MapTypeSDKType): Type_MapType { @@ -1233,23 +1233,23 @@ exports[`google/api/expr/v1alpha1/checked typeHash (Long) CheckedExpr 1`] = ` return message; }, fromJSON(object: any): CheckedExpr { - return { - referenceMap: isObject(object.referenceMap) ? Object.entries(object.referenceMap).reduce<{ - [key: Long]: Reference; - }>((acc, [key, value]) => { - acc[Number(key)] = Reference.fromJSON(value); - return acc; - }, {}) : {}, - typeMap: isObject(object.typeMap) ? Object.entries(object.typeMap).reduce<{ - [key: Long]: Type; - }>((acc, [key, value]) => { - acc[Number(key)] = Type.fromJSON(value); - return acc; - }, {}) : {}, - sourceInfo: isSet(object.sourceInfo) ? SourceInfo.fromJSON(object.sourceInfo) : undefined, - exprVersion: isSet(object.exprVersion) ? String(object.exprVersion) : "", - expr: isSet(object.expr) ? Expr.fromJSON(object.expr) : undefined - }; + const obj = createBaseCheckedExpr(); + if (isObject(object.referenceMap)) obj.referenceMap = Object.entries(object.referenceMap).reduce<{ + [key: Long]: Reference; + }>((acc, [key, value]) => { + acc[Number(key)] = Reference.fromJSON(value); + return acc; + }, {}); + if (isObject(object.typeMap)) obj.typeMap = Object.entries(object.typeMap).reduce<{ + [key: Long]: Type; + }>((acc, [key, value]) => { + acc[Number(key)] = Type.fromJSON(value); + return acc; + }, {}); + if (isSet(object.sourceInfo)) obj.sourceInfo = SourceInfo.fromJSON(object.sourceInfo); + if (isSet(object.exprVersion)) obj.exprVersion = String(object.exprVersion); + if (isSet(object.expr)) obj.expr = Expr.fromJSON(object.expr); + return obj; }, toJSON(message: CheckedExpr): unknown { const obj: any = {}; @@ -1288,9 +1288,9 @@ exports[`google/api/expr/v1alpha1/checked typeHash (Long) CheckedExpr 1`] = ` } return acc; }, {}); - message.sourceInfo = object.sourceInfo !== undefined && object.sourceInfo !== null ? SourceInfo.fromPartial(object.sourceInfo) : undefined; + message.sourceInfo = object.sourceInfo !== undefined && object.sourceInfo !== null ? SourceInfo.fromPartial(object.sourceInfo) : SourceInfo.fromPartial({}); message.exprVersion = object.exprVersion ?? ""; - message.expr = object.expr !== undefined && object.expr !== null ? Expr.fromPartial(object.expr) : undefined; + message.expr = object.expr !== undefined && object.expr !== null ? Expr.fromPartial(object.expr) : Expr.fromPartial({}); return message; }, fromSDK(object: CheckedExprSDKType): CheckedExpr { @@ -1408,17 +1408,17 @@ exports[`google/api/expr/v1alpha1/syntax Constant 1`] = ` return message; }, fromJSON(object: any): Constant { - return { - nullValue: isSet(object.nullValue) ? nullValueFromJSON(object.nullValue) : undefined, - boolValue: isSet(object.boolValue) ? Boolean(object.boolValue) : undefined, - int64Value: isSet(object.int64Value) ? Long.fromValue(object.int64Value) : undefined, - uint64Value: isSet(object.uint64Value) ? Long.fromValue(object.uint64Value) : undefined, - doubleValue: isSet(object.doubleValue) ? Number(object.doubleValue) : undefined, - stringValue: isSet(object.stringValue) ? String(object.stringValue) : undefined, - bytesValue: isSet(object.bytesValue) ? bytesFromBase64(object.bytesValue) : undefined, - durationValue: isSet(object.durationValue) ? Duration.fromJSON(object.durationValue) : undefined, - timestampValue: isSet(object.timestampValue) ? fromJsonTimestamp(object.timestampValue) : undefined - }; + const obj = createBaseConstant(); + if (isSet(object.nullValue)) obj.nullValue = nullValueFromJSON(object.nullValue); + if (isSet(object.boolValue)) obj.boolValue = Boolean(object.boolValue); + if (isSet(object.int64Value)) obj.int64Value = Long.fromValue(object.int64Value); + if (isSet(object.uint64Value)) obj.uint64Value = Long.fromValue(object.uint64Value); + if (isSet(object.doubleValue)) obj.doubleValue = Number(object.doubleValue); + if (isSet(object.stringValue)) obj.stringValue = String(object.stringValue); + if (isSet(object.bytesValue)) obj.bytesValue = bytesFromBase64(object.bytesValue); + if (isSet(object.durationValue)) obj.durationValue = Duration.fromJSON(object.durationValue); + if (isSet(object.timestampValue)) obj.timestampValue = fromJsonTimestamp(object.timestampValue); + return obj; }, toJSON(message: Constant): unknown { const obj: any = {}; @@ -1442,7 +1442,7 @@ exports[`google/api/expr/v1alpha1/syntax Constant 1`] = ` message.doubleValue = object.doubleValue ?? undefined; message.stringValue = object.stringValue ?? undefined; message.bytesValue = object.bytesValue ?? undefined; - message.durationValue = object.durationValue !== undefined && object.durationValue !== null ? Duration.fromPartial(object.durationValue) : undefined; + message.durationValue = object.durationValue !== undefined && object.durationValue !== null ? Duration.fromPartial(object.durationValue) : Duration.fromPartial({}); message.timestampValue = object.timestampValue ?? undefined; return message; }, @@ -1507,10 +1507,10 @@ exports[`google/api/expr/v1alpha1/value Entry 1`] = ` return message; }, fromJSON(object: any): Entry { - return { - key: isSet(object.key) ? Value.fromJSON(object.key) : undefined, - value: isSet(object.value) ? Value.fromJSON(object.value) : undefined - }; + const obj = createBaseEntry(); + if (isSet(object.key)) obj.key = Value.fromJSON(object.key); + if (isSet(object.value)) obj.value = Value.fromJSON(object.value); + return obj; }, toJSON(message: Entry): unknown { const obj: any = {}; @@ -1520,8 +1520,8 @@ exports[`google/api/expr/v1alpha1/value Entry 1`] = ` }, fromPartial(object: DeepPartial): Entry { const message = createBaseEntry(); - message.key = object.key !== undefined && object.key !== null ? Value.fromPartial(object.key) : undefined; - message.value = object.value !== undefined && object.value !== null ? Value.fromPartial(object.value) : undefined; + message.key = object.key !== undefined && object.key !== null ? Value.fromPartial(object.key) : Value.fromPartial({}); + message.value = object.value !== undefined && object.value !== null ? Value.fromPartial(object.value) : Value.fromPartial({}); return message; }, fromSDK(object: EntrySDKType): Entry { @@ -1567,9 +1567,9 @@ exports[`google/api/expr/v1alpha1/value MapValue 1`] = ` return message; }, fromJSON(object: any): MapValue { - return { - entries: Array.isArray(object?.entries) ? object.entries.map((e: any) => MapValue_Entry.fromJSON(e)) : [] - }; + const obj = createBaseMapValue(); + if (Array.isArray(object?.entries)) object.entries.map((e: any) => MapValue_Entry.fromJSON(e)); + return obj; }, toJSON(message: MapValue): unknown { const obj: any = {}; @@ -1657,16 +1657,16 @@ exports[`google/api/expr/v1beta1/source 1`] = ` return message; }, fromJSON(object: any): SourceInfo { - return { - location: isSet(object.location) ? String(object.location) : "", - lineOffsets: Array.isArray(object?.lineOffsets) ? object.lineOffsets.map((e: any) => Number(e)) : [], - positions: isObject(object.positions) ? Object.entries(object.positions).reduce<{ - [key: number]: number; - }>((acc, [key, value]) => { - acc[Number(key)] = Number(value); - return acc; - }, {}) : {} - }; + const obj = createBaseSourceInfo(); + if (isSet(object.location)) obj.location = String(object.location); + if (Array.isArray(object?.lineOffsets)) object.lineOffsets.map((e: any) => Number(e)); + if (isObject(object.positions)) obj.positions = Object.entries(object.positions).reduce<{ + [key: number]: number; + }>((acc, [key, value]) => { + acc[Number(key)] = Number(value); + return acc; + }, {}); + return obj; }, toJSON(message: SourceInfo): unknown { const obj: any = {}; @@ -1767,15 +1767,15 @@ exports[`google/api/quota keyType 1`] = ` return message; }, fromJSON(object: any): MetricRule { - return { - selector: isSet(object.selector) ? String(object.selector) : "", - metricCosts: isObject(object.metricCosts) ? Object.entries(object.metricCosts).reduce<{ - [key: string]: Long; - }>((acc, [key, value]) => { - acc[key] = Long.fromValue((value as Long | string)); - return acc; - }, {}) : {} - }; + const obj = createBaseMetricRule(); + if (isSet(object.selector)) obj.selector = String(object.selector); + if (isObject(object.metricCosts)) obj.metricCosts = Object.entries(object.metricCosts).reduce<{ + [key: string]: Long; + }>((acc, [key, value]) => { + acc[key] = Long.fromValue((value as Long | string)); + return acc; + }, {}); + return obj; }, toJSON(message: MetricRule): unknown { const obj: any = {}; @@ -1926,25 +1926,25 @@ exports[`google/api/servicecontrol/v1/log_entry LogEntry 1`] = ` return message; }, fromJSON(object: any): LogEntry { - return { - name: isSet(object.name) ? String(object.name) : "", - timestamp: isSet(object.timestamp) ? fromJsonTimestamp(object.timestamp) : undefined, - severity: isSet(object.severity) ? logSeverityFromJSON(object.severity) : 0, - httpRequest: isSet(object.httpRequest) ? HttpRequest.fromJSON(object.httpRequest) : undefined, - trace: isSet(object.trace) ? String(object.trace) : "", - insertId: isSet(object.insertId) ? String(object.insertId) : "", - labels: isObject(object.labels) ? Object.entries(object.labels).reduce<{ - [key: string]: string; - }>((acc, [key, value]) => { - acc[key] = String(value); - return acc; - }, {}) : {}, - protoPayload: isSet(object.protoPayload) ? Any.fromJSON(object.protoPayload) : undefined, - textPayload: isSet(object.textPayload) ? String(object.textPayload) : undefined, - structPayload: isSet(object.structPayload) ? Struct.fromJSON(object.structPayload) : undefined, - operation: isSet(object.operation) ? LogEntryOperation.fromJSON(object.operation) : undefined, - sourceLocation: isSet(object.sourceLocation) ? LogEntrySourceLocation.fromJSON(object.sourceLocation) : undefined - }; + const obj = createBaseLogEntry(); + if (isSet(object.name)) obj.name = String(object.name); + if (isSet(object.timestamp)) obj.timestamp = fromJsonTimestamp(object.timestamp); + if (isSet(object.severity)) obj.severity = logSeverityFromJSON(object.severity); + if (isSet(object.httpRequest)) obj.httpRequest = HttpRequest.fromJSON(object.httpRequest); + if (isSet(object.trace)) obj.trace = String(object.trace); + if (isSet(object.insertId)) obj.insertId = String(object.insertId); + if (isObject(object.labels)) obj.labels = Object.entries(object.labels).reduce<{ + [key: string]: string; + }>((acc, [key, value]) => { + acc[key] = String(value); + return acc; + }, {}); + if (isSet(object.protoPayload)) obj.protoPayload = Any.fromJSON(object.protoPayload); + if (isSet(object.textPayload)) obj.textPayload = String(object.textPayload); + if (isSet(object.structPayload)) obj.structPayload = Struct.fromJSON(object.structPayload); + if (isSet(object.operation)) obj.operation = LogEntryOperation.fromJSON(object.operation); + if (isSet(object.sourceLocation)) obj.sourceLocation = LogEntrySourceLocation.fromJSON(object.sourceLocation); + return obj; }, toJSON(message: LogEntry): unknown { const obj: any = {}; @@ -1972,7 +1972,7 @@ exports[`google/api/servicecontrol/v1/log_entry LogEntry 1`] = ` message.name = object.name ?? ""; message.timestamp = object.timestamp ?? undefined; message.severity = object.severity ?? 0; - message.httpRequest = object.httpRequest !== undefined && object.httpRequest !== null ? HttpRequest.fromPartial(object.httpRequest) : undefined; + message.httpRequest = object.httpRequest !== undefined && object.httpRequest !== null ? HttpRequest.fromPartial(object.httpRequest) : HttpRequest.fromPartial({}); message.trace = object.trace ?? ""; message.insertId = object.insertId ?? ""; message.labels = Object.entries(object.labels ?? {}).reduce<{ @@ -1983,11 +1983,11 @@ exports[`google/api/servicecontrol/v1/log_entry LogEntry 1`] = ` } return acc; }, {}); - message.protoPayload = object.protoPayload !== undefined && object.protoPayload !== null ? Any.fromPartial(object.protoPayload) : undefined; + message.protoPayload = object.protoPayload !== undefined && object.protoPayload !== null ? Any.fromPartial(object.protoPayload) : Any.fromPartial({}); message.textPayload = object.textPayload ?? undefined; - message.structPayload = object.structPayload !== undefined && object.structPayload !== null ? Struct.fromPartial(object.structPayload) : undefined; - message.operation = object.operation !== undefined && object.operation !== null ? LogEntryOperation.fromPartial(object.operation) : undefined; - message.sourceLocation = object.sourceLocation !== undefined && object.sourceLocation !== null ? LogEntrySourceLocation.fromPartial(object.sourceLocation) : undefined; + message.structPayload = object.structPayload !== undefined && object.structPayload !== null ? Struct.fromPartial(object.structPayload) : Struct.fromPartial({}); + message.operation = object.operation !== undefined && object.operation !== null ? LogEntryOperation.fromPartial(object.operation) : LogEntryOperation.fromPartial({}); + message.sourceLocation = object.sourceLocation !== undefined && object.sourceLocation !== null ? LogEntrySourceLocation.fromPartial(object.sourceLocation) : LogEntrySourceLocation.fromPartial({}); return message; }, fromSDK(object: LogEntrySDKType): LogEntry { @@ -2075,9 +2075,9 @@ exports[`google/rpc/error_details name collisions 2`] = ` return message; }, fromJSON(object: any): PreconditionFailure { - return { - violations: Array.isArray(object?.violations) ? object.violations.map((e: any) => PreconditionFailure_Violation.fromJSON(e)) : [] - }; + const obj = createBasePreconditionFailure(); + if (Array.isArray(object?.violations)) object.violations.map((e: any) => PreconditionFailure_Violation.fromJSON(e)); + return obj; }, toJSON(message: PreconditionFailure): unknown { const obj: any = {}; @@ -2160,13 +2160,13 @@ exports[`ibc/core/port/v1/query 1`] = ` return message; }, fromJSON(object: any): QueryAppVersionRequest { - return { - portId: isSet(object.portId) ? String(object.portId) : "", - connectionId: isSet(object.connectionId) ? String(object.connectionId) : "", - ordering: isSet(object.ordering) ? orderFromJSON(object.ordering) : 0, - counterparty: isSet(object.counterparty) ? Counterparty.fromJSON(object.counterparty) : undefined, - proposedVersion: isSet(object.proposedVersion) ? String(object.proposedVersion) : "" - }; + const obj = createBaseQueryAppVersionRequest(); + if (isSet(object.portId)) obj.portId = String(object.portId); + if (isSet(object.connectionId)) obj.connectionId = String(object.connectionId); + if (isSet(object.ordering)) obj.ordering = orderFromJSON(object.ordering); + if (isSet(object.counterparty)) obj.counterparty = Counterparty.fromJSON(object.counterparty); + if (isSet(object.proposedVersion)) obj.proposedVersion = String(object.proposedVersion); + return obj; }, toJSON(message: QueryAppVersionRequest): unknown { const obj: any = {}; @@ -2182,7 +2182,7 @@ exports[`ibc/core/port/v1/query 1`] = ` message.portId = object.portId ?? ""; message.connectionId = object.connectionId ?? ""; message.ordering = object.ordering ?? 0; - message.counterparty = object.counterparty !== undefined && object.counterparty !== null ? Counterparty.fromPartial(object.counterparty) : undefined; + message.counterparty = object.counterparty !== undefined && object.counterparty !== null ? Counterparty.fromPartial(object.counterparty) : Counterparty.fromPartial({}); message.proposedVersion = object.proposedVersion ?? ""; return message; }, @@ -2324,11 +2324,11 @@ exports[`ibc/core/types/v1/genesis name collisions 2`] = ` return message; }, fromJSON(object: any): GenesisState { - return { - clientGenesis: isSet(object.clientGenesis) ? GenesisState1.fromJSON(object.clientGenesis) : undefined, - connectionGenesis: isSet(object.connectionGenesis) ? GenesisState2.fromJSON(object.connectionGenesis) : undefined, - channelGenesis: isSet(object.channelGenesis) ? GenesisState3.fromJSON(object.channelGenesis) : undefined - }; + const obj = createBaseGenesisState(); + if (isSet(object.clientGenesis)) obj.clientGenesis = GenesisState1.fromJSON(object.clientGenesis); + if (isSet(object.connectionGenesis)) obj.connectionGenesis = GenesisState2.fromJSON(object.connectionGenesis); + if (isSet(object.channelGenesis)) obj.channelGenesis = GenesisState3.fromJSON(object.channelGenesis); + return obj; }, toJSON(message: GenesisState): unknown { const obj: any = {}; @@ -2339,9 +2339,9 @@ exports[`ibc/core/types/v1/genesis name collisions 2`] = ` }, fromPartial(object: DeepPartial): GenesisState { const message = createBaseGenesisState(); - message.clientGenesis = object.clientGenesis !== undefined && object.clientGenesis !== null ? GenesisState1.fromPartial(object.clientGenesis) : undefined; - message.connectionGenesis = object.connectionGenesis !== undefined && object.connectionGenesis !== null ? GenesisState2.fromPartial(object.connectionGenesis) : undefined; - message.channelGenesis = object.channelGenesis !== undefined && object.channelGenesis !== null ? GenesisState3.fromPartial(object.channelGenesis) : undefined; + message.clientGenesis = object.clientGenesis !== undefined && object.clientGenesis !== null ? GenesisState1.fromPartial(object.clientGenesis) : GenesisState1.fromPartial({}); + message.connectionGenesis = object.connectionGenesis !== undefined && object.connectionGenesis !== null ? GenesisState2.fromPartial(object.connectionGenesis) : GenesisState2.fromPartial({}); + message.channelGenesis = object.channelGenesis !== undefined && object.channelGenesis !== null ? GenesisState3.fromPartial(object.channelGenesis) : GenesisState3.fromPartial({}); return message; }, fromSDK(object: GenesisStateSDKType): GenesisState { @@ -2542,10 +2542,10 @@ exports[`osmosis/gamm/v1beta1/query 1`] = ` return message; }, fromJSON(object: any): QueryPoolsResponse { - return { - pools: Array.isArray(object?.pools) ? object.pools.map((e: any) => Any.fromJSON(e)) : [], - pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined - }; + const obj = createBaseQueryPoolsResponse(); + if (Array.isArray(object?.pools)) object.pools.map((e: any) => Any.fromJSON(e)); + if (isSet(object.pagination)) obj.pagination = PageResponse.fromJSON(object.pagination); + return obj; }, toJSON(message: QueryPoolsResponse): unknown { const obj: any = {}; @@ -2560,7 +2560,7 @@ exports[`osmosis/gamm/v1beta1/query 1`] = ` fromPartial(object: DeepPartial): QueryPoolsResponse { const message = createBaseQueryPoolsResponse(); message.pools = object.pools?.map(e => Any.fromPartial(e)) || []; - message.pagination = object.pagination !== undefined && object.pagination !== null ? PageResponse.fromPartial(object.pagination) : undefined; + message.pagination = object.pagination !== undefined && object.pagination !== null ? PageResponse.fromPartial(object.pagination) : PageResponse.fromPartial({}); return message; }, fromSDK(object: QueryPoolsResponseSDKType): QueryPoolsResponse { @@ -2626,12 +2626,12 @@ exports[`osmosis/gamm/v1beta1/tx MsgJoinPool 1`] = ` return message; }, fromJSON(object: any): MsgJoinPool { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, - shareOutAmount: isSet(object.shareOutAmount) ? String(object.shareOutAmount) : "", - tokenInMaxs: Array.isArray(object?.tokenInMaxs) ? object.tokenInMaxs.map((e: any) => Coin.fromJSON(e)) : [] - }; + const obj = createBaseMsgJoinPool(); + if (isSet(object.sender)) obj.sender = String(object.sender); + if (isSet(object.poolId)) obj.poolId = Long.fromValue(object.poolId); + if (isSet(object.shareOutAmount)) obj.shareOutAmount = String(object.shareOutAmount); + if (Array.isArray(object?.tokenInMaxs)) object.tokenInMaxs.map((e: any) => Coin.fromJSON(e)); + return obj; }, toJSON(message: MsgJoinPool): unknown { const obj: any = {}; @@ -2720,12 +2720,12 @@ exports[`osmosis/gamm/v1beta1/tx MsgSwapExactAmountIn 1`] = ` return message; }, fromJSON(object: any): MsgSwapExactAmountIn { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - routes: Array.isArray(object?.routes) ? object.routes.map((e: any) => SwapAmountInRoute.fromJSON(e)) : [], - tokenIn: isSet(object.tokenIn) ? Coin.fromJSON(object.tokenIn) : undefined, - tokenOutMinAmount: isSet(object.tokenOutMinAmount) ? String(object.tokenOutMinAmount) : "" - }; + const obj = createBaseMsgSwapExactAmountIn(); + if (isSet(object.sender)) obj.sender = String(object.sender); + if (Array.isArray(object?.routes)) object.routes.map((e: any) => SwapAmountInRoute.fromJSON(e)); + if (isSet(object.tokenIn)) obj.tokenIn = Coin.fromJSON(object.tokenIn); + if (isSet(object.tokenOutMinAmount)) obj.tokenOutMinAmount = String(object.tokenOutMinAmount); + return obj; }, toJSON(message: MsgSwapExactAmountIn): unknown { const obj: any = {}; @@ -2743,7 +2743,7 @@ exports[`osmosis/gamm/v1beta1/tx MsgSwapExactAmountIn 1`] = ` const message = createBaseMsgSwapExactAmountIn(); message.sender = object.sender ?? ""; message.routes = object.routes?.map(e => SwapAmountInRoute.fromPartial(e)) || []; - message.tokenIn = object.tokenIn !== undefined && object.tokenIn !== null ? Coin.fromPartial(object.tokenIn) : undefined; + message.tokenIn = object.tokenIn !== undefined && object.tokenIn !== null ? Coin.fromPartial(object.tokenIn) : Coin.fromPartial({}); message.tokenOutMinAmount = object.tokenOutMinAmount ?? ""; return message; }, @@ -2814,12 +2814,12 @@ exports[`osmosis/gamm/v1beta1/tx MsgSwapExactAmountOut 1`] = ` return message; }, fromJSON(object: any): MsgSwapExactAmountOut { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - routes: Array.isArray(object?.routes) ? object.routes.map((e: any) => SwapAmountOutRoute.fromJSON(e)) : [], - tokenInMaxAmount: isSet(object.tokenInMaxAmount) ? String(object.tokenInMaxAmount) : "", - tokenOut: isSet(object.tokenOut) ? Coin.fromJSON(object.tokenOut) : undefined - }; + const obj = createBaseMsgSwapExactAmountOut(); + if (isSet(object.sender)) obj.sender = String(object.sender); + if (Array.isArray(object?.routes)) object.routes.map((e: any) => SwapAmountOutRoute.fromJSON(e)); + if (isSet(object.tokenInMaxAmount)) obj.tokenInMaxAmount = String(object.tokenInMaxAmount); + if (isSet(object.tokenOut)) obj.tokenOut = Coin.fromJSON(object.tokenOut); + return obj; }, toJSON(message: MsgSwapExactAmountOut): unknown { const obj: any = {}; @@ -2838,7 +2838,7 @@ exports[`osmosis/gamm/v1beta1/tx MsgSwapExactAmountOut 1`] = ` message.sender = object.sender ?? ""; message.routes = object.routes?.map(e => SwapAmountOutRoute.fromPartial(e)) || []; message.tokenInMaxAmount = object.tokenInMaxAmount ?? ""; - message.tokenOut = object.tokenOut !== undefined && object.tokenOut !== null ? Coin.fromPartial(object.tokenOut) : undefined; + message.tokenOut = object.tokenOut !== undefined && object.tokenOut !== null ? Coin.fromPartial(object.tokenOut) : Coin.fromPartial({}); return message; }, fromSDK(object: MsgSwapExactAmountOutSDKType): MsgSwapExactAmountOut { diff --git a/packages/ast/src/encoding/__tests__/__snapshots__/authz.timestamp.test.ts.snap b/packages/ast/src/encoding/__tests__/__snapshots__/authz.timestamp.test.ts.snap index 5c4a059df2..344d1e5154 100644 --- a/packages/ast/src/encoding/__tests__/__snapshots__/authz.timestamp.test.ts.snap +++ b/packages/ast/src/encoding/__tests__/__snapshots__/authz.timestamp.test.ts.snap @@ -48,10 +48,10 @@ exports[`cosmos/authz/v1beta1/authz date 2`] = ` return message; }, fromJSON(object: any): Grant { - return { - authorization: isSet(object.authorization) ? Any.fromJSON(object.authorization) : undefined, - expiration: isSet(object.expiration) ? new Date(object.expiration) : undefined - }; + const obj = createBaseGrant(); + if (isSet(object.authorization)) obj.authorization = Any.fromJSON(object.authorization); + if (isSet(object.expiration)) obj.expiration = new Date(object.expiration); + return obj; }, toJSON(message: Grant): unknown { const obj: any = {}; @@ -61,7 +61,7 @@ exports[`cosmos/authz/v1beta1/authz date 2`] = ` }, fromPartial(object: DeepPartial): Grant { const message = createBaseGrant(); - message.authorization = object.authorization !== undefined && object.authorization !== null ? Any.fromPartial(object.authorization) : undefined; + message.authorization = object.authorization !== undefined && object.authorization !== null ? Any.fromPartial(object.authorization) : Any.fromPartial({}); message.expiration = object.expiration ?? undefined; return message; }, @@ -176,10 +176,10 @@ exports[`cosmos/authz/v1beta1/authz timestamp 2`] = ` return message; }, fromJSON(object: any): Grant { - return { - authorization: isSet(object.authorization) ? Any.fromJSON(object.authorization) : undefined, - expiration: isSet(object.expiration) ? fromJsonTimestamp(object.expiration) : undefined - }; + const obj = createBaseGrant(); + if (isSet(object.authorization)) obj.authorization = Any.fromJSON(object.authorization); + if (isSet(object.expiration)) obj.expiration = fromJsonTimestamp(object.expiration); + return obj; }, toJSON(message: Grant): unknown { const obj: any = {}; @@ -189,8 +189,8 @@ exports[`cosmos/authz/v1beta1/authz timestamp 2`] = ` }, fromPartial(object: DeepPartial): Grant { const message = createBaseGrant(); - message.authorization = object.authorization !== undefined && object.authorization !== null ? Any.fromPartial(object.authorization) : undefined; - message.expiration = object.expiration !== undefined && object.expiration !== null ? Timestamp.fromPartial(object.expiration) : undefined; + message.authorization = object.authorization !== undefined && object.authorization !== null ? Any.fromPartial(object.authorization) : Any.fromPartial({}); + message.expiration = object.expiration !== undefined && object.expiration !== null ? Timestamp.fromPartial(object.expiration) : Timestamp.fromPartial({}); return message; }, fromSDK(object: GrantSDKType): Grant { diff --git a/packages/ast/src/encoding/__tests__/__snapshots__/lockup.test.ts.snap b/packages/ast/src/encoding/__tests__/__snapshots__/lockup.test.ts.snap index 6e10500c86..1e1088e34c 100644 --- a/packages/ast/src/encoding/__tests__/__snapshots__/lockup.test.ts.snap +++ b/packages/ast/src/encoding/__tests__/__snapshots__/lockup.test.ts.snap @@ -46,11 +46,11 @@ exports[`osmosis/lockup/tx duration 2`] = ` return message; }, fromJSON(object: any): MsgLockTokens { - return { - owner: isSet(object.owner) ? String(object.owner) : "", - duration: isSet(object.duration) ? Duration.fromJSON(object.duration) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Coin.fromJSON(e)) : [] - }; + const obj = createBaseMsgLockTokens(); + if (isSet(object.owner)) obj.owner = String(object.owner); + if (isSet(object.duration)) obj.duration = Duration.fromJSON(object.duration); + if (Array.isArray(object?.coins)) object.coins.map((e: any) => Coin.fromJSON(e)); + return obj; }, toJSON(message: MsgLockTokens): unknown { const obj: any = {}; @@ -66,7 +66,7 @@ exports[`osmosis/lockup/tx duration 2`] = ` fromPartial(object: DeepPartial): MsgLockTokens { const message = createBaseMsgLockTokens(); message.owner = object.owner ?? ""; - message.duration = object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : undefined; + message.duration = object.duration !== undefined && object.duration !== null ? Duration.fromPartial(object.duration) : Duration.fromPartial({}); message.coins = object.coins?.map(e => Coin.fromPartial(e)) || []; return message; }, @@ -193,11 +193,11 @@ exports[`osmosis/lockup/tx string 2`] = ` return message; }, fromJSON(object: any): MsgLockTokens { - return { - owner: isSet(object.owner) ? String(object.owner) : "", - duration: isSet(object.duration) ? String(object.duration) : undefined, - coins: Array.isArray(object?.coins) ? object.coins.map((e: any) => Coin.fromJSON(e)) : [] - }; + const obj = createBaseMsgLockTokens(); + if (isSet(object.owner)) obj.owner = String(object.owner); + if (isSet(object.duration)) obj.duration = String(object.duration); + if (Array.isArray(object?.coins)) object.coins.map((e: any) => Coin.fromJSON(e)); + return obj; }, toJSON(message: MsgLockTokens): unknown { const obj: any = {}; diff --git a/packages/ast/src/encoding/__tests__/__snapshots__/tendermint.test.ts.snap b/packages/ast/src/encoding/__tests__/__snapshots__/tendermint.test.ts.snap index 00a24c2cb5..1bd4f2c1fc 100644 --- a/packages/ast/src/encoding/__tests__/__snapshots__/tendermint.test.ts.snap +++ b/packages/ast/src/encoding/__tests__/__snapshots__/tendermint.test.ts.snap @@ -132,19 +132,19 @@ exports[`ibc/lightclients/tendermint/v1/tendermint duration 2`] = ` return message; }, fromJSON(object: any): ClientState { - return { - chainId: isSet(object.chainId) ? String(object.chainId) : "", - trustLevel: isSet(object.trustLevel) ? Fraction.fromJSON(object.trustLevel) : undefined, - trustingPeriod: isSet(object.trustingPeriod) ? Duration.fromJSON(object.trustingPeriod) : undefined, - unbondingPeriod: isSet(object.unbondingPeriod) ? Duration.fromJSON(object.unbondingPeriod) : undefined, - maxClockDrift: isSet(object.maxClockDrift) ? Duration.fromJSON(object.maxClockDrift) : undefined, - frozenHeight: isSet(object.frozenHeight) ? Height.fromJSON(object.frozenHeight) : undefined, - latestHeight: isSet(object.latestHeight) ? Height.fromJSON(object.latestHeight) : undefined, - proofSpecs: Array.isArray(object?.proofSpecs) ? object.proofSpecs.map((e: any) => ProofSpec.fromJSON(e)) : [], - upgradePath: Array.isArray(object?.upgradePath) ? object.upgradePath.map((e: any) => String(e)) : [], - allowUpdateAfterExpiry: isSet(object.allowUpdateAfterExpiry) ? Boolean(object.allowUpdateAfterExpiry) : false, - allowUpdateAfterMisbehaviour: isSet(object.allowUpdateAfterMisbehaviour) ? Boolean(object.allowUpdateAfterMisbehaviour) : false - }; + const obj = createBaseClientState(); + if (isSet(object.chainId)) obj.chainId = String(object.chainId); + if (isSet(object.trustLevel)) obj.trustLevel = Fraction.fromJSON(object.trustLevel); + if (isSet(object.trustingPeriod)) obj.trustingPeriod = Duration.fromJSON(object.trustingPeriod); + if (isSet(object.unbondingPeriod)) obj.unbondingPeriod = Duration.fromJSON(object.unbondingPeriod); + if (isSet(object.maxClockDrift)) obj.maxClockDrift = Duration.fromJSON(object.maxClockDrift); + if (isSet(object.frozenHeight)) obj.frozenHeight = Height.fromJSON(object.frozenHeight); + if (isSet(object.latestHeight)) obj.latestHeight = Height.fromJSON(object.latestHeight); + if (Array.isArray(object?.proofSpecs)) object.proofSpecs.map((e: any) => ProofSpec.fromJSON(e)); + if (Array.isArray(object?.upgradePath)) object.upgradePath.map((e: any) => String(e)); + if (isSet(object.allowUpdateAfterExpiry)) obj.allowUpdateAfterExpiry = Boolean(object.allowUpdateAfterExpiry); + if (isSet(object.allowUpdateAfterMisbehaviour)) obj.allowUpdateAfterMisbehaviour = Boolean(object.allowUpdateAfterMisbehaviour); + return obj; }, toJSON(message: ClientState): unknown { const obj: any = {}; @@ -172,12 +172,12 @@ exports[`ibc/lightclients/tendermint/v1/tendermint duration 2`] = ` fromPartial(object: DeepPartial): ClientState { const message = createBaseClientState(); message.chainId = object.chainId ?? ""; - message.trustLevel = object.trustLevel !== undefined && object.trustLevel !== null ? Fraction.fromPartial(object.trustLevel) : undefined; - message.trustingPeriod = object.trustingPeriod !== undefined && object.trustingPeriod !== null ? Duration.fromPartial(object.trustingPeriod) : undefined; - message.unbondingPeriod = object.unbondingPeriod !== undefined && object.unbondingPeriod !== null ? Duration.fromPartial(object.unbondingPeriod) : undefined; - message.maxClockDrift = object.maxClockDrift !== undefined && object.maxClockDrift !== null ? Duration.fromPartial(object.maxClockDrift) : undefined; - message.frozenHeight = object.frozenHeight !== undefined && object.frozenHeight !== null ? Height.fromPartial(object.frozenHeight) : undefined; - message.latestHeight = object.latestHeight !== undefined && object.latestHeight !== null ? Height.fromPartial(object.latestHeight) : undefined; + message.trustLevel = object.trustLevel !== undefined && object.trustLevel !== null ? Fraction.fromPartial(object.trustLevel) : Fraction.fromPartial({}); + message.trustingPeriod = object.trustingPeriod !== undefined && object.trustingPeriod !== null ? Duration.fromPartial(object.trustingPeriod) : Duration.fromPartial({}); + message.unbondingPeriod = object.unbondingPeriod !== undefined && object.unbondingPeriod !== null ? Duration.fromPartial(object.unbondingPeriod) : Duration.fromPartial({}); + message.maxClockDrift = object.maxClockDrift !== undefined && object.maxClockDrift !== null ? Duration.fromPartial(object.maxClockDrift) : Duration.fromPartial({}); + message.frozenHeight = object.frozenHeight !== undefined && object.frozenHeight !== null ? Height.fromPartial(object.frozenHeight) : Height.fromPartial({}); + message.latestHeight = object.latestHeight !== undefined && object.latestHeight !== null ? Height.fromPartial(object.latestHeight) : Height.fromPartial({}); message.proofSpecs = object.proofSpecs?.map(e => ProofSpec.fromPartial(e)) || []; message.upgradePath = object.upgradePath?.map(e => e) || []; message.allowUpdateAfterExpiry = object.allowUpdateAfterExpiry ?? false; @@ -531,19 +531,19 @@ exports[`ibc/lightclients/tendermint/v1/tendermint string 2`] = ` return message; }, fromJSON(object: any): ClientState { - return { - chainId: isSet(object.chainId) ? String(object.chainId) : "", - trustLevel: isSet(object.trustLevel) ? Fraction.fromJSON(object.trustLevel) : undefined, - trustingPeriod: isSet(object.trustingPeriod) ? String(object.trustingPeriod) : undefined, - unbondingPeriod: isSet(object.unbondingPeriod) ? String(object.unbondingPeriod) : undefined, - maxClockDrift: isSet(object.maxClockDrift) ? String(object.maxClockDrift) : undefined, - frozenHeight: isSet(object.frozenHeight) ? Height.fromJSON(object.frozenHeight) : undefined, - latestHeight: isSet(object.latestHeight) ? Height.fromJSON(object.latestHeight) : undefined, - proofSpecs: Array.isArray(object?.proofSpecs) ? object.proofSpecs.map((e: any) => ProofSpec.fromJSON(e)) : [], - upgradePath: Array.isArray(object?.upgradePath) ? object.upgradePath.map((e: any) => String(e)) : [], - allowUpdateAfterExpiry: isSet(object.allowUpdateAfterExpiry) ? Boolean(object.allowUpdateAfterExpiry) : false, - allowUpdateAfterMisbehaviour: isSet(object.allowUpdateAfterMisbehaviour) ? Boolean(object.allowUpdateAfterMisbehaviour) : false - }; + const obj = createBaseClientState(); + if (isSet(object.chainId)) obj.chainId = String(object.chainId); + if (isSet(object.trustLevel)) obj.trustLevel = Fraction.fromJSON(object.trustLevel); + if (isSet(object.trustingPeriod)) obj.trustingPeriod = String(object.trustingPeriod); + if (isSet(object.unbondingPeriod)) obj.unbondingPeriod = String(object.unbondingPeriod); + if (isSet(object.maxClockDrift)) obj.maxClockDrift = String(object.maxClockDrift); + if (isSet(object.frozenHeight)) obj.frozenHeight = Height.fromJSON(object.frozenHeight); + if (isSet(object.latestHeight)) obj.latestHeight = Height.fromJSON(object.latestHeight); + if (Array.isArray(object?.proofSpecs)) object.proofSpecs.map((e: any) => ProofSpec.fromJSON(e)); + if (Array.isArray(object?.upgradePath)) object.upgradePath.map((e: any) => String(e)); + if (isSet(object.allowUpdateAfterExpiry)) obj.allowUpdateAfterExpiry = Boolean(object.allowUpdateAfterExpiry); + if (isSet(object.allowUpdateAfterMisbehaviour)) obj.allowUpdateAfterMisbehaviour = Boolean(object.allowUpdateAfterMisbehaviour); + return obj; }, toJSON(message: ClientState): unknown { const obj: any = {}; @@ -571,12 +571,12 @@ exports[`ibc/lightclients/tendermint/v1/tendermint string 2`] = ` fromPartial(object: DeepPartial): ClientState { const message = createBaseClientState(); message.chainId = object.chainId ?? ""; - message.trustLevel = object.trustLevel !== undefined && object.trustLevel !== null ? Fraction.fromPartial(object.trustLevel) : undefined; + message.trustLevel = object.trustLevel !== undefined && object.trustLevel !== null ? Fraction.fromPartial(object.trustLevel) : Fraction.fromPartial({}); message.trustingPeriod = object.trustingPeriod ?? undefined; message.unbondingPeriod = object.unbondingPeriod ?? undefined; message.maxClockDrift = object.maxClockDrift ?? undefined; - message.frozenHeight = object.frozenHeight !== undefined && object.frozenHeight !== null ? Height.fromPartial(object.frozenHeight) : undefined; - message.latestHeight = object.latestHeight !== undefined && object.latestHeight !== null ? Height.fromPartial(object.latestHeight) : undefined; + message.frozenHeight = object.frozenHeight !== undefined && object.frozenHeight !== null ? Height.fromPartial(object.frozenHeight) : Height.fromPartial({}); + message.latestHeight = object.latestHeight !== undefined && object.latestHeight !== null ? Height.fromPartial(object.latestHeight) : Height.fromPartial({}); message.proofSpecs = object.proofSpecs?.map(e => ProofSpec.fromPartial(e)) || []; message.upgradePath = object.upgradePath?.map(e => e) || []; message.allowUpdateAfterExpiry = object.allowUpdateAfterExpiry ?? false; diff --git a/packages/ast/src/encoding/proto/__snapshots__/interfaces-amino.test.ts.snap b/packages/ast/src/encoding/proto/__snapshots__/interfaces-amino.test.ts.snap index 64808cfa86..4ed016cb4c 100644 --- a/packages/ast/src/encoding/proto/__snapshots__/interfaces-amino.test.ts.snap +++ b/packages/ast/src/encoding/proto/__snapshots__/interfaces-amino.test.ts.snap @@ -32,10 +32,10 @@ exports[`Duration 1`] = ` return message; }, fromJSON(object: any): Duration { - return { - seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0 - }; + const obj = createBaseDuration(); + if (isSet(object.seconds)) obj.seconds = Long.fromValue(object.seconds); + if (isSet(object.nanos)) obj.nanos = Number(object.nanos); + return obj; }, toJSON(message: Duration): unknown { const obj: any = {}; @@ -121,10 +121,10 @@ exports[`Height 1`] = ` return message; }, fromJSON(object: any): Height { - return { - revisionNumber: isSet(object.revisionNumber) ? Long.fromValue(object.revisionNumber) : Long.UZERO, - revisionHeight: isSet(object.revisionHeight) ? Long.fromValue(object.revisionHeight) : Long.UZERO - }; + const obj = createBaseHeight(); + if (isSet(object.revisionNumber)) obj.revisionNumber = Long.fromValue(object.revisionNumber); + if (isSet(object.revisionHeight)) obj.revisionHeight = Long.fromValue(object.revisionHeight); + return obj; }, toJSON(message: Height): unknown { const obj: any = {}; @@ -248,15 +248,15 @@ exports[`MsgCreateValidator 1`] = ` return message; }, fromJSON(object: any): MsgCreateValidator { - return { - description: isSet(object.description) ? Description.fromJSON(object.description) : undefined, - commission: isSet(object.commission) ? CommissionRates.fromJSON(object.commission) : undefined, - minSelfDelegation: isSet(object.minSelfDelegation) ? String(object.minSelfDelegation) : "", - delegatorAddress: isSet(object.delegatorAddress) ? String(object.delegatorAddress) : "", - validatorAddress: isSet(object.validatorAddress) ? String(object.validatorAddress) : "", - pubkey: isSet(object.pubkey) ? Any.fromJSON(object.pubkey) : undefined, - value: isSet(object.value) ? Coin.fromJSON(object.value) : undefined - }; + const obj = createBaseMsgCreateValidator(); + if (isSet(object.description)) obj.description = Description.fromJSON(object.description); + if (isSet(object.commission)) obj.commission = CommissionRates.fromJSON(object.commission); + if (isSet(object.minSelfDelegation)) obj.minSelfDelegation = String(object.minSelfDelegation); + if (isSet(object.delegatorAddress)) obj.delegatorAddress = String(object.delegatorAddress); + if (isSet(object.validatorAddress)) obj.validatorAddress = String(object.validatorAddress); + if (isSet(object.pubkey)) obj.pubkey = Any.fromJSON(object.pubkey); + if (isSet(object.value)) obj.value = Coin.fromJSON(object.value); + return obj; }, toJSON(message: MsgCreateValidator): unknown { const obj: any = {}; @@ -271,13 +271,13 @@ exports[`MsgCreateValidator 1`] = ` }, fromPartial(object: DeepPartial): MsgCreateValidator { const message = createBaseMsgCreateValidator(); - message.description = object.description !== undefined && object.description !== null ? Description.fromPartial(object.description) : undefined; - message.commission = object.commission !== undefined && object.commission !== null ? CommissionRates.fromPartial(object.commission) : undefined; + message.description = object.description !== undefined && object.description !== null ? Description.fromPartial(object.description) : Description.fromPartial({}); + message.commission = object.commission !== undefined && object.commission !== null ? CommissionRates.fromPartial(object.commission) : CommissionRates.fromPartial({}); message.minSelfDelegation = object.minSelfDelegation ?? ""; message.delegatorAddress = object.delegatorAddress ?? ""; message.validatorAddress = object.validatorAddress ?? ""; - message.pubkey = object.pubkey !== undefined && object.pubkey !== null ? Any.fromPartial(object.pubkey) : undefined; - message.value = object.value !== undefined && object.value !== null ? Coin.fromPartial(object.value) : undefined; + message.pubkey = object.pubkey !== undefined && object.pubkey !== null ? Any.fromPartial(object.pubkey) : Any.fromPartial({}); + message.value = object.value !== undefined && object.value !== null ? Coin.fromPartial(object.value) : Coin.fromPartial({}); return message; }, fromSDK(object: MsgCreateValidatorSDKType): MsgCreateValidator { @@ -392,11 +392,11 @@ exports[`MsgStoreCode 1`] = ` return message; }, fromJSON(object: any): MsgStoreCode { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - wasmByteCode: isSet(object.wasmByteCode) ? bytesFromBase64(object.wasmByteCode) : new Uint8Array(), - instantiatePermission: isSet(object.instantiatePermission) ? AccessConfig.fromJSON(object.instantiatePermission) : undefined - }; + const obj = createBaseMsgStoreCode(); + if (isSet(object.sender)) obj.sender = String(object.sender); + if (isSet(object.wasmByteCode)) obj.wasmByteCode = bytesFromBase64(object.wasmByteCode); + if (isSet(object.instantiatePermission)) obj.instantiatePermission = AccessConfig.fromJSON(object.instantiatePermission); + return obj; }, toJSON(message: MsgStoreCode): unknown { const obj: any = {}; @@ -409,7 +409,7 @@ exports[`MsgStoreCode 1`] = ` const message = createBaseMsgStoreCode(); message.sender = object.sender ?? ""; message.wasmByteCode = object.wasmByteCode ?? new Uint8Array(); - message.instantiatePermission = object.instantiatePermission !== undefined && object.instantiatePermission !== null ? AccessConfig.fromPartial(object.instantiatePermission) : undefined; + message.instantiatePermission = object.instantiatePermission !== undefined && object.instantiatePermission !== null ? AccessConfig.fromPartial(object.instantiatePermission) : AccessConfig.fromPartial({}); return message; }, fromSDK(object: MsgStoreCodeSDKType): MsgStoreCode { @@ -502,11 +502,11 @@ exports[`MsgSubmitProposal 1`] = ` return message; }, fromJSON(object: any): MsgSubmitProposal { - return { - content: isSet(object.content) ? Any.fromJSON(object.content) : undefined, - initialDeposit: Array.isArray(object?.initialDeposit) ? object.initialDeposit.map((e: any) => Coin.fromJSON(e)) : [], - proposer: isSet(object.proposer) ? String(object.proposer) : "" - }; + const obj = createBaseMsgSubmitProposal(); + if (isSet(object.content)) obj.content = Any.fromJSON(object.content); + if (Array.isArray(object?.initialDeposit)) object.initialDeposit.map((e: any) => Coin.fromJSON(e)); + if (isSet(object.proposer)) obj.proposer = String(object.proposer); + return obj; }, toJSON(message: MsgSubmitProposal): unknown { const obj: any = {}; @@ -521,7 +521,7 @@ exports[`MsgSubmitProposal 1`] = ` }, fromPartial(object: DeepPartial): MsgSubmitProposal { const message = createBaseMsgSubmitProposal(); - message.content = object.content !== undefined && object.content !== null ? Any.fromPartial(object.content) : undefined; + message.content = object.content !== undefined && object.content !== null ? Any.fromPartial(object.content) : Any.fromPartial({}); message.initialDeposit = object.initialDeposit?.map(e => Coin.fromPartial(e)) || []; message.proposer = object.proposer ?? ""; return message; @@ -648,15 +648,15 @@ exports[`MsgTransfer 1`] = ` return message; }, fromJSON(object: any): MsgTransfer { - return { - sourcePort: isSet(object.sourcePort) ? String(object.sourcePort) : "", - sourceChannel: isSet(object.sourceChannel) ? String(object.sourceChannel) : "", - token: isSet(object.token) ? Coin.fromJSON(object.token) : undefined, - sender: isSet(object.sender) ? String(object.sender) : "", - receiver: isSet(object.receiver) ? String(object.receiver) : "", - timeoutHeight: isSet(object.timeoutHeight) ? Height.fromJSON(object.timeoutHeight) : undefined, - timeoutTimestamp: isSet(object.timeoutTimestamp) ? Long.fromValue(object.timeoutTimestamp) : Long.UZERO - }; + const obj = createBaseMsgTransfer(); + if (isSet(object.sourcePort)) obj.sourcePort = String(object.sourcePort); + if (isSet(object.sourceChannel)) obj.sourceChannel = String(object.sourceChannel); + if (isSet(object.token)) obj.token = Coin.fromJSON(object.token); + if (isSet(object.sender)) obj.sender = String(object.sender); + if (isSet(object.receiver)) obj.receiver = String(object.receiver); + if (isSet(object.timeoutHeight)) obj.timeoutHeight = Height.fromJSON(object.timeoutHeight); + if (isSet(object.timeoutTimestamp)) obj.timeoutTimestamp = Long.fromValue(object.timeoutTimestamp); + return obj; }, toJSON(message: MsgTransfer): unknown { const obj: any = {}; @@ -673,10 +673,10 @@ exports[`MsgTransfer 1`] = ` const message = createBaseMsgTransfer(); message.sourcePort = object.sourcePort ?? ""; message.sourceChannel = object.sourceChannel ?? ""; - message.token = object.token !== undefined && object.token !== null ? Coin.fromPartial(object.token) : undefined; + message.token = object.token !== undefined && object.token !== null ? Coin.fromPartial(object.token) : Coin.fromPartial({}); message.sender = object.sender ?? ""; message.receiver = object.receiver ?? ""; - message.timeoutHeight = object.timeoutHeight !== undefined && object.timeoutHeight !== null ? Height.fromPartial(object.timeoutHeight) : undefined; + message.timeoutHeight = object.timeoutHeight !== undefined && object.timeoutHeight !== null ? Height.fromPartial(object.timeoutHeight) : Height.fromPartial({}); message.timeoutTimestamp = object.timeoutTimestamp !== undefined && object.timeoutTimestamp !== null ? Long.fromValue(object.timeoutTimestamp) : Long.UZERO; return message; }, diff --git a/packages/ast/src/encoding/proto/__tests__/__snapshots__/contracts.test.ts.snap b/packages/ast/src/encoding/proto/__tests__/__snapshots__/contracts.test.ts.snap index 8cb29cdebd..bb5b0c3b82 100644 --- a/packages/ast/src/encoding/proto/__tests__/__snapshots__/contracts.test.ts.snap +++ b/packages/ast/src/encoding/proto/__tests__/__snapshots__/contracts.test.ts.snap @@ -58,12 +58,12 @@ exports[`MsgExecuteContract interface 2`] = ` return message; }, fromJSON(object: any): MsgExecuteContract { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - contract: isSet(object.contract) ? String(object.contract) : "", - msg: isSet(object.msg) ? bytesFromBase64(object.msg) : new Uint8Array(), - funds: Array.isArray(object?.funds) ? object.funds.map((e: any) => Coin.fromJSON(e)) : [] - }; + const obj = createBaseMsgExecuteContract(); + if (isSet(object.sender)) obj.sender = String(object.sender); + if (isSet(object.contract)) obj.contract = String(object.contract); + if (isSet(object.msg)) obj.msg = bytesFromBase64(object.msg); + if (Array.isArray(object?.funds)) object.funds.map((e: any) => Coin.fromJSON(e)); + return obj; }, toJSON(message: MsgExecuteContract): unknown { const obj: any = {}; diff --git a/packages/ast/src/encoding/proto/from-json/index.ts b/packages/ast/src/encoding/proto/from-json/index.ts index d9dff247b5..cf8e21056f 100644 --- a/packages/ast/src/encoding/proto/from-json/index.ts +++ b/packages/ast/src/encoding/proto/from-json/index.ts @@ -15,7 +15,7 @@ export interface FromJSONMethod { isOptional: boolean; } -export const _fromJSONMethodFields = (context: ProtoParseContext, name: string, proto: ProtoType) => { +export const fromJSONMethodFields = (context: ProtoParseContext, name: string, proto: ProtoType) => { const oneOfs = getOneOfs(proto); const fields = Object.keys(proto.fields ?? {}).map(fieldName => { const field = { @@ -145,41 +145,6 @@ export const _fromJSONMethodFields = (context: ProtoParseContext, name: string, return fields; }; -export const fromJSONMethodFields = (context: ProtoParseContext, name: string, proto: ProtoType) => { - // const oneOfs = getOneOfs(proto); - let fields: t.IfStatement[]; - fields = Object.keys(proto.fields ?? {}).map(fieldName => - t.ifStatement( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(fieldName) - ) - ] - ), - t.expressionStatement( - t.assignmentExpression( - '=', - t.memberExpression( - t.identifier('obj'), - t.identifier(fieldName) - ), - t.callExpression( - t.identifier('fromJSON'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(fieldName) - ) - ], - - ))), - )); - - return fields; -} export const fromJSONMethod = (context: ProtoParseContext, name: string, proto: ProtoType) => { const fields = fromJSONMethodFields(context, name, proto); @@ -201,15 +166,11 @@ export const fromJSONMethod = (context: ProtoParseContext, name: string, proto: ) ) ] - ), - // fields, - // t.returnStatement( - // t.identifier('obj') - // ) + ) ] for (let i = 0; i < fields.length; i++) { - statements.push(fields[i]); + statements.push(fields[i] as t.Statement); } statements.push( @@ -227,27 +188,8 @@ export const fromJSONMethod = (context: ProtoParseContext, name: string, proto: ), false ) - ], t.blockStatement( - // [ - // t.variableDeclaration( - // 'const', - // [ - // t.variableDeclarator( - // t.identifier('obj'), - // t.callExpression( - // t.identifier('createBase' + name), - // [] - // ) - // ) - // ] - // ), - // fields, - // t.returnStatement( - // t.identifier('obj') - // ) - // ] statements ), false, diff --git a/packages/ast/src/encoding/proto/from-json/utils.ts b/packages/ast/src/encoding/proto/from-json/utils.ts index 81ba4f78c7..ce90e809b1 100644 --- a/packages/ast/src/encoding/proto/from-json/utils.ts +++ b/packages/ast/src/encoding/proto/from-json/utils.ts @@ -15,33 +15,39 @@ const getPropNames = (field: ProtoField) => { export const fromJSON = { - // sender: isSet(object.sender) ? String(object.sender) : "" + // OLD: sender: isSet(object.sender) ? String(object.sender) : "" + // NEW: if (isSet(object.sender)) { obj.sender = String(object.sender) } string(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( - t.identifier('String'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - getDefaultTSTypeFromProtoType(args.context, args.field, args.isOneOf) + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier('String'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) ) }, @@ -50,28 +56,33 @@ export const fromJSON = { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( - t.identifier('Number'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - getDefaultTSTypeFromProtoType(args.context, args.field, args.isOneOf) + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier('Number'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) ) }, @@ -98,71 +109,84 @@ export const fromJSON = { return fromJSON.number(args); }, - // disableMacros: isSet(object.disableMacros) ? Boolean(object.disableMacros) : false + // OLD disableMacros: isSet(object.disableMacros) ? Boolean(object.disableMacros) : false + // NEW if (isSet(object.disableMacros)) { obj.disableMacros = Boolean(object.disableMacros) } bool(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( - t.identifier('Boolean'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - getDefaultTSTypeFromProtoType(args.context, args.field, args.isOneOf) + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier('Boolean'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) ) }, - // int64Value: isSet(object.int64Value) ? Long.fromValue(object.int64Value) : Long.UZERO, + // OLD int64Value: isSet(object.int64Value) ? Long.fromValue(object.int64Value) : Long.UZERO, + // NEW if (isSet(object.int64Value)) { obj.int64Value = Long.fromValue(object.int64Value) } long(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); TypeLong.addUtil(args.context); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - TypeLong.getFromValueWithArgs(args.context, + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + TypeLong.getFromValueWithArgs(args.context, t.memberExpression( t.identifier('object'), t.identifier(objProp) ) - ), - getDefaultTSTypeFromProtoType(args.context, args.field, args.isOneOf) + ) + ) ) - ); + ) }, int64(args: FromJSONMethod) { return fromJSON.long(args); }, - // uint64Value: isSet(object.uint64Value) ? Long.fromString(object.uint64Value) : Long.ZERO, + // OLD uint64Value: isSet(object.uint64Value) ? Long.fromString(object.uint64Value) : Long.ZERO, + // NEW if (isSet(object.uint64Value)) { obj.uint64Value = Long.fromString(object.uint64Value) } uint64(args: FromJSONMethod) { return fromJSON.long(args); }, @@ -183,97 +207,115 @@ export const fromJSON = { const name = args.context.getTypeName(args.field); args.context.addUtil('isSet'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ t.memberExpression( - t.identifier(name), - t.identifier('fromJSON') + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) ), - [ + t.callExpression( t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.identifier('undefined') + t.identifier(name), + t.identifier('fromJSON') + ), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) - ); + ) }, - // mode: isSet(object.mode) ? signModeFromJSON(object.mode) : 0, + // OLD mode: isSet(object.mode) ? signModeFromJSON(object.mode) : 0, + // NEW if (isSet(object.mode)) { obj.mode = signModeFromJSON(object.mode) } enum(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); const fromJSONFuncName = args.context.getFromEnum(args.field); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( - t.identifier(fromJSONFuncName), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - args.isOptional ? t.identifier('undefined') : t.numericLiteral(0) + + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier(fromJSONFuncName), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) - ); + ) }, - // queryData: isSet(object.queryData) ? bytesFromBase64(object.queryData) : new Uint8Array() + // OLD queryData: isSet(object.queryData) ? bytesFromBase64(object.queryData) : new Uint8Array() + // NEW if (isSet(object.queryData)) { obj.queryData = bytesFromBase64(object.queryData) } bytes(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); args.context.addUtil('bytesFromBase64'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( - t.identifier('bytesFromBase64'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - getDefaultTSTypeFromProtoType(args.context, args.field, args.isOneOf) + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier('bytesFromBase64'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) - ); + ) }, @@ -290,35 +332,41 @@ export const fromJSON = { } }, - // period: isSet(object.period) ? String(object.period) : undefined, - + // OLD period: isSet(object.period) ? String(object.period) : undefined, + // NEW if (isSet(object.period)) { obj.period = String(object.period) } durationString(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isSet'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.callExpression( - t.identifier('String'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.identifier('undefined') + + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier('String'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) ) - ); + ) }, // periodReset: isSet(object.periodReset) ? fromJsonTimestamp(object.periodReset) : undefined @@ -348,36 +396,70 @@ export const fromJSON = { args.context.addUtil('isSet'); args.context.addUtil('fromJsonTimestamp'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression(t.identifier('isSet'), [ - t.memberExpression(t.identifier('object'), t.identifier(objProp)) - ]), - t.callExpression(t.identifier('fromJsonTimestamp'), [ - t.memberExpression(t.identifier('object'), t.identifier(objProp)) - ]), - t.identifier('undefined') + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.callExpression( + t.identifier('fromJsonTimestamp'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) + ) ) - ); }, timestampDate(args: FromJSONMethod) { const { messageProp, objProp } = getPropNames(args.field); args.context.addUtil('isSet'); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression(t.identifier('isSet'), [ - t.memberExpression(t.identifier('object'), t.identifier(objProp)) - ]), - t.newExpression(t.identifier('Date'), [ - t.memberExpression(t.identifier('object'), t.identifier(objProp)) - ]), - t.identifier('undefined') + return t.ifStatement( + t.callExpression( + t.identifier('isSet'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) + ), + t.newExpression( + t.identifier('Date'), + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ) + ) + ) ) - ); }, // labels: isObject(object.labels) ? Object.entries(object.labels).reduce<{ @@ -496,100 +578,104 @@ export const fromJSON = { throw new Error('keyHash requires new type. Ask maintainers.'); } - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( - t.identifier('isObject'), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - callExpression( + return t.ifStatement( + t.callExpression( + t.identifier('isObject'), + [ t.memberExpression( - t.callExpression( - t.memberExpression( - t.identifier('Object'), - t.identifier('entries') - ), - [ - t.memberExpression( - t.identifier('object'), - t.identifier(objProp) - ) - ] - ), - t.identifier('reduce') + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier(messageProp) ), - [ - t.arrowFunctionExpression( - [ - t.identifier('acc'), - t.arrayPattern( - [ - t.identifier('key'), - t.identifier('value') - ] - ) - ], - t.blockStatement([ - t.expressionStatement( - t.assignmentExpression( - '=', - t.memberExpression( - t.identifier('acc'), - wrapKey(t.identifier('key')), - true - ), - fromJSON - ) + callExpression( + t.memberExpression( + t.callExpression( + t.memberExpression( + t.identifier('Object'), + t.identifier('entries') ), - t.returnStatement( - t.identifier('acc') - ) - ]) + [ + t.memberExpression( + t.identifier('object'), + t.identifier(objProp) + ) + ] + ), + t.identifier('reduce') ), - t.objectExpression( - [] - ) - ], - t.tsTypeParameterInstantiation( [ - t.tsTypeLiteral( + t.arrowFunctionExpression( [ - t.tsIndexSignature( + t.identifier('acc'), + t.arrayPattern( [ - identifier('key', t.tsTypeAnnotation( - keyTypeType - )) - ], - t.tsTypeAnnotation( - t.tsTypeReference( - t.identifier(valueTypeType) - ) + t.identifier('key'), + t.identifier('value') + ] + ) + ], + t.blockStatement([ + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('acc'), + wrapKey(t.identifier('key')), + true + ), + fromJSON ) + ), + t.returnStatement( + t.identifier('acc') ) - ] + ]) + ), + t.objectExpression( + [] ) - ] + ], + t.tsTypeParameterInstantiation( + [ + t.tsTypeLiteral( + [ + t.tsIndexSignature( + [ + identifier('key', t.tsTypeAnnotation( + keyTypeType + )) + ], + t.tsTypeAnnotation( + t.tsTypeReference( + t.identifier(valueTypeType) + ) + ) + ) + ] + ) + ] + ) ) - ), - t.objectExpression([]) + ) ) ) }, - // codeIds: Array.isArray(object?.codeIds) ? object.codeIds.map((e: any) => Long.fromString(e)) : [], + //OLD: codeIds: Array.isArray(object?.codeIds) ? object.codeIds.map((e: any) => Long.fromString(e)) : [], + //NEW: if (Array.isArray(object?.codeIds)) { object.codeIds.map((e: any) => Long.fromString(e)) } array(args: FromJSONMethod, expr: t.Expression) { const { messageProp, objProp } = getPropNames(args.field); - return t.objectProperty( - t.identifier(messageProp), - t.conditionalExpression( - t.callExpression( + return t.ifStatement( + t.callExpression( t.memberExpression( t.identifier('Array'), t.identifier('isArray') @@ -602,7 +688,8 @@ export const fromJSON = { true ) ] - ), + ), + t.expressionStatement( t.callExpression( t.memberExpression( t.memberExpression( @@ -622,8 +709,7 @@ export const fromJSON = { false ) ] - ), - t.arrayExpression([]) + ) ) ) } diff --git a/packages/ast/src/encoding/proto/implements/__tests__/__snapshots__/interface-decoder.test.ts.snap b/packages/ast/src/encoding/proto/implements/__tests__/__snapshots__/interface-decoder.test.ts.snap index f6d7e6fb5e..43c702205a 100644 --- a/packages/ast/src/encoding/proto/implements/__tests__/__snapshots__/interface-decoder.test.ts.snap +++ b/packages/ast/src/encoding/proto/implements/__tests__/__snapshots__/interface-decoder.test.ts.snap @@ -62,10 +62,10 @@ exports[`PoolI objects 1`] = ` return message; }, fromJSON(object: any): QueryPoolsResponse { - return { - pools: Array.isArray(object?.pools) ? object.pools.map((e: any) => Any.fromJSON(e)) : [], - pagination: isSet(object.pagination) ? PageResponse.fromJSON(object.pagination) : undefined - }; + const obj = createBaseQueryPoolsResponse(); + if (Array.isArray(object?.pools)) object.pools.map((e: any) => Any.fromJSON(e)); + if (isSet(object.pagination)) obj.pagination = PageResponse.fromJSON(object.pagination); + return obj; }, toJSON(message: QueryPoolsResponse): unknown { const obj: any = {}; @@ -80,7 +80,7 @@ exports[`PoolI objects 1`] = ` fromPartial(object: DeepPartial): QueryPoolsResponse { const message = createBaseQueryPoolsResponse(); message.pools = object.pools?.map(e => Any.fromPartial(e)) || []; - message.pagination = object.pagination !== undefined && object.pagination !== null ? PageResponse.fromPartial(object.pagination) : undefined; + message.pagination = object.pagination !== undefined && object.pagination !== null ? PageResponse.fromPartial(object.pagination) : PageResponse.fromPartial({}); return message; }, fromSDK(object: QueryPoolsResponseSDKType): QueryPoolsResponse { diff --git a/packages/ast/types/src/encoding/proto/from-json/index.d.ts b/packages/ast/types/src/encoding/proto/from-json/index.d.ts index 40abe4975b..9e027ded80 100644 --- a/packages/ast/types/src/encoding/proto/from-json/index.d.ts +++ b/packages/ast/types/src/encoding/proto/from-json/index.d.ts @@ -7,5 +7,5 @@ export interface FromJSONMethod { isOneOf: boolean; isOptional: boolean; } -export declare const fromJSONMethodFields: (context: ProtoParseContext, name: string, proto: ProtoType) => t.ObjectProperty[]; +export declare const fromJSONMethodFields: (context: ProtoParseContext, name: string, proto: ProtoType) => t.IfStatement[]; export declare const fromJSONMethod: (context: ProtoParseContext, name: string, proto: ProtoType) => t.ObjectMethod; diff --git a/packages/ast/types/src/encoding/proto/from-json/utils.d.ts b/packages/ast/types/src/encoding/proto/from-json/utils.d.ts index 0657dd6b34..3f265da0ef 100644 --- a/packages/ast/types/src/encoding/proto/from-json/utils.d.ts +++ b/packages/ast/types/src/encoding/proto/from-json/utils.d.ts @@ -1,32 +1,32 @@ import * as t from '@babel/types'; import { FromJSONMethod } from './index'; export declare const fromJSON: { - string(args: FromJSONMethod): t.ObjectProperty; - number(args: FromJSONMethod): t.ObjectProperty; - double(args: FromJSONMethod): t.ObjectProperty; - float(args: FromJSONMethod): t.ObjectProperty; - int32(args: FromJSONMethod): t.ObjectProperty; - sint32(args: FromJSONMethod): t.ObjectProperty; - uint32(args: FromJSONMethod): t.ObjectProperty; - fixed32(args: FromJSONMethod): t.ObjectProperty; - sfixed32(args: FromJSONMethod): t.ObjectProperty; - bool(args: FromJSONMethod): t.ObjectProperty; - long(args: FromJSONMethod): t.ObjectProperty; - int64(args: FromJSONMethod): t.ObjectProperty; - uint64(args: FromJSONMethod): t.ObjectProperty; - sint64(args: FromJSONMethod): t.ObjectProperty; - fixed64(args: FromJSONMethod): t.ObjectProperty; - sfixed64(args: FromJSONMethod): t.ObjectProperty; - type(args: FromJSONMethod): t.ObjectProperty; - enum(args: FromJSONMethod): t.ObjectProperty; - bytes(args: FromJSONMethod): t.ObjectProperty; - duration(args: FromJSONMethod): t.ObjectProperty; - durationString(args: FromJSONMethod): t.ObjectProperty; - timestamp(args: FromJSONMethod): t.ObjectProperty; - timestampTimestamp(args: FromJSONMethod): t.ObjectProperty; - timestampDate(args: FromJSONMethod): t.ObjectProperty; - keyHash(args: FromJSONMethod): t.ObjectProperty; - array(args: FromJSONMethod, expr: t.Expression): t.ObjectProperty; + string(args: FromJSONMethod): t.IfStatement; + number(args: FromJSONMethod): t.IfStatement; + double(args: FromJSONMethod): t.IfStatement; + float(args: FromJSONMethod): t.IfStatement; + int32(args: FromJSONMethod): t.IfStatement; + sint32(args: FromJSONMethod): t.IfStatement; + uint32(args: FromJSONMethod): t.IfStatement; + fixed32(args: FromJSONMethod): t.IfStatement; + sfixed32(args: FromJSONMethod): t.IfStatement; + bool(args: FromJSONMethod): t.IfStatement; + long(args: FromJSONMethod): t.IfStatement; + int64(args: FromJSONMethod): t.IfStatement; + uint64(args: FromJSONMethod): t.IfStatement; + sint64(args: FromJSONMethod): t.IfStatement; + fixed64(args: FromJSONMethod): t.IfStatement; + sfixed64(args: FromJSONMethod): t.IfStatement; + type(args: FromJSONMethod): t.IfStatement; + enum(args: FromJSONMethod): t.IfStatement; + bytes(args: FromJSONMethod): t.IfStatement; + duration(args: FromJSONMethod): t.IfStatement; + durationString(args: FromJSONMethod): t.IfStatement; + timestamp(args: FromJSONMethod): t.IfStatement; + timestampTimestamp(args: FromJSONMethod): t.IfStatement; + timestampDate(args: FromJSONMethod): t.IfStatement; + keyHash(args: FromJSONMethod): t.IfStatement; + array(args: FromJSONMethod, expr: t.Expression): t.IfStatement; }; export declare const arrayTypes: { string(): t.CallExpression;