diff --git a/__fixtures__/misc/output/binary.ts b/__fixtures__/misc/output/binary.ts new file mode 100644 index 0000000000..f8751d571c --- /dev/null +++ b/__fixtures__/misc/output/binary.ts @@ -0,0 +1,472 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +// Copyright (c) 2016, Daniel Wirtz All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: + +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of its author, nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- + +// Code generated by the command line utilities is owned by the owner +// of the input file used when generating it. This code is not +// standalone and requires a support library to be linked with it. This +// support library is itself covered by the above license. + +import { utf8Length, utf8Read, utf8Write } from "./utf8"; +import { + int64ToString, + readInt32, + readUInt32, + uInt64ToString, + varint32read, + varint64read, + writeVarint32, + writeVarint64, + int64FromString, + int64Length, + writeFixed32, + writeByte, + zzDecode, + zzEncode, +} from "./varint"; + +export enum WireType { + Varint = 0, + + Fixed64 = 1, + + Bytes = 2, + + Fixed32 = 5, +} + +// Reader + +export class BinaryReader { + buf: Uint8Array; + pos: number; + type: number; + len: number; + + protected assertBounds(): void { + if (this.pos > this.len) throw new RangeError("premature EOF"); + } + + constructor(buf?: ArrayLike) { + this.buf = buf ? new Uint8Array(buf) : new Uint8Array(0); + this.pos = 0; + this.type = 0; + this.len = this.buf.length; + } + + tag(): [number, WireType, number] { + const tag = this.uint32(), + fieldNo = tag >>> 3, + wireType = tag & 7; + if (fieldNo <= 0 || wireType < 0 || wireType > 5) + throw new Error( + "illegal tag: field no " + fieldNo + " wire type " + wireType + ); + return [fieldNo, wireType, tag]; + } + + skip(length?: number) { + if (typeof length === "number") { + if (this.pos + length > this.len) throw indexOutOfRange(this, length); + this.pos += length; + } else { + do { + if (this.pos >= this.len) throw indexOutOfRange(this); + } while (this.buf[this.pos++] & 128); + } + return this; + } + + skipType(wireType: number) { + switch (wireType) { + case WireType.Varint: + this.skip(); + break; + case WireType.Fixed64: + this.skip(8); + break; + case WireType.Bytes: + this.skip(this.uint32()); + break; + case 3: + while ((wireType = this.uint32() & 7) !== 4) { + this.skipType(wireType); + } + break; + case WireType.Fixed32: + this.skip(4); + break; + + /* istanbul ignore next */ + default: + throw Error("invalid wire type " + wireType + " at offset " + this.pos); + } + return this; + } + + uint32(): number { + return varint32read.bind(this)(); + } + + int32(): number { + return this.uint32() | 0; + } + + sint32(): number { + const num = this.uint32(); + return num % 2 === 1 ? (num + 1) / -2 : num / 2; // zigzag encoding + } + + fixed32(): number { + const val = readUInt32(this.buf, this.pos); + this.pos += 4; + return val; + } + + sfixed32(): number { + const val = readInt32(this.buf, this.pos); + this.pos += 4; + return val; + } + + int64(): bigint { + const [lo, hi] = varint64read.bind(this)(); + return BigInt(int64ToString(lo, hi)); + } + + uint64(): bigint { + const [lo, hi] = varint64read.bind(this)(); + return BigInt(uInt64ToString(lo, hi)); + } + + sint64(): bigint { + let [lo, hi] = varint64read.bind(this)(); + // zig zag + [lo, hi] = zzDecode(lo, hi); + return BigInt(int64ToString(lo, hi)); + } + + fixed64(): bigint { + const lo = this.sfixed32(); + const hi = this.sfixed32(); + return BigInt(uInt64ToString(lo, hi)); + } + sfixed64(): bigint { + const lo = this.sfixed32(); + const hi = this.sfixed32(); + return BigInt(int64ToString(lo, hi)); + } + + float(): number { + throw new Error("float not supported"); + } + + double(): number { + throw new Error("double not supported"); + } + + bool(): boolean { + const [lo, hi] = varint64read.bind(this)(); + return lo !== 0 || hi !== 0; + } + + bytes(): Uint8Array { + const len = this.uint32(), + start = this.pos; + this.pos += len; + this.assertBounds(); + return this.buf.subarray(start, start + len); + } + + string(): string { + const bytes = this.bytes(); + return utf8Read(bytes, 0, bytes.length); + } +} + +// Writer + +type OpVal = string | number | object | Uint8Array; + +class Op { + fn?: (val: OpVal, buf: Uint8Array | number[], pos: number) => void; + len: number; + val: OpVal; + next?: Op; + + constructor( + fn: ( + val: OpVal, + buf: Uint8Array | number[], + pos: number + ) => void | undefined, + len: number, + val: OpVal + ) { + this.fn = fn; + this.len = len; + this.val = val; + } +} + +class State { + head: Op; + tail: Op; + len: number; + next: State; + + constructor(writer: BinaryWriter) { + this.head = writer.head; + this.tail = writer.tail; + this.len = writer.len; + this.next = writer.states; + } +} + +export class BinaryWriter { + len = 0; + head: Op; + tail: Op; + states: State; + + constructor() { + this.head = new Op(null, 0, 0); + this.tail = this.head; + this.states = null; + } + + static create() { + return new BinaryWriter(); + } + + static alloc(size: number): Uint8Array | number[] { + if (typeof Uint8Array !== "undefined") { + return pool( + (size) => new Uint8Array(size), + Uint8Array.prototype.subarray + )(size); + } else { + return new Array(size); + } + } + + private _push( + fn: (val: OpVal, buf: Uint8Array | number[], pos: number) => void, + len: number, + val: OpVal + ) { + this.tail = this.tail.next = new Op(fn, len, val); + this.len += len; + return this; + } + + finish(): Uint8Array { + let head = this.head.next, + pos = 0; + const buf = BinaryWriter.alloc(this.len); + while (head) { + head.fn(head.val, buf, pos); + pos += head.len; + head = head.next; + } + return buf as Uint8Array; + } + + fork(): BinaryWriter { + this.states = new State(this); + this.head = this.tail = new Op(null, 0, 0); + this.len = 0; + return this; + } + + reset(): BinaryWriter { + if (this.states) { + this.head = this.states.head; + this.tail = this.states.tail; + this.len = this.states.len; + this.states = this.states.next; + } else { + this.head = this.tail = new Op(null, 0, 0); + this.len = 0; + } + return this; + } + + ldelim(): BinaryWriter { + const head = this.head, + tail = this.tail, + len = this.len; + this.reset().uint32(len); + if (len) { + this.tail.next = head.next; // skip noop + this.tail = tail; + this.len += len; + } + return this; + } + + tag(fieldNo: number, type: WireType): BinaryWriter { + return this.uint32(((fieldNo << 3) | type) >>> 0); + } + + uint32(value: number): BinaryWriter { + this.len += (this.tail = this.tail.next = + new Op( + writeVarint32, + (value = value >>> 0) < 128 + ? 1 + : value < 16384 + ? 2 + : value < 2097152 + ? 3 + : value < 268435456 + ? 4 + : 5, + value + )).len; + return this; + } + + int32(value: number): BinaryWriter { + return value < 0 + ? this._push(writeVarint64, 10, int64FromString(value.toString())) // 10 bytes per spec + : this.uint32(value); + } + + sint32(value: number): BinaryWriter { + return this.uint32(((value << 1) ^ (value >> 31)) >>> 0); + } + + int64(value: string | number | bigint): BinaryWriter { + const { lo, hi } = int64FromString(value.toString()); + return this._push(writeVarint64, int64Length(lo, hi), { lo, hi }); + } + + // uint64 is the same with int64 + uint64 = BinaryWriter.prototype.int64; + + sint64(value: string | number | bigint): BinaryWriter { + let { lo, hi } = int64FromString(value.toString()); + // zig zag + [lo, hi] = zzEncode(lo, hi); + return this._push(writeVarint64, int64Length(lo, hi), { lo, hi }); + } + + fixed64(value: string | number | bigint): BinaryWriter { + const { lo, hi } = int64FromString(value.toString()); + return this._push(writeFixed32, 4, lo)._push(writeFixed32, 4, hi); + } + + // sfixed64 is the same with fixed64 + sfixed64 = BinaryWriter.prototype.fixed64; + + bool(value: boolean): BinaryWriter { + return this._push(writeByte, 1, value ? 1 : 0); + } + + fixed32(value: number): BinaryWriter { + return this._push(writeFixed32, 4, value >>> 0); + } + + // sfixed32 is the same with fixed32 + sfixed32 = BinaryWriter.prototype.fixed32; + + float(value: number): BinaryWriter { + throw new Error("float not supported" + value); + } + + double(value: number): BinaryWriter { + throw new Error("double not supported" + value); + } + + bytes(value: Uint8Array): BinaryWriter { + const len = value.length >>> 0; + if (!len) return this._push(writeByte, 1, 0); + return this.uint32(len)._push(writeBytes, len, value); + } + + string(value: string): BinaryWriter { + const len = utf8Length(value); + return len + ? this.uint32(len)._push(utf8Write, len, value) + : this._push(writeByte, 1, 0); + } +} + +function writeBytes( + val: Uint8Array | number[], + buf: Uint8Array | number[], + pos: number +) { + if (typeof Uint8Array !== "undefined") { + (buf as Uint8Array).set(val, pos); + } else { + for (let i = 0; i < val.length; ++i) buf[pos + i] = val[i]; + } +} + +function pool( + alloc: (size: number) => Uint8Array, + slice: (begin?: number, end?: number) => Uint8Array, + size?: number +): (size: number) => Uint8Array { + const SIZE = size || 8192; + const MAX = SIZE >>> 1; + let slab = null; + let offset = SIZE; + return function pool_alloc(size): Uint8Array { + if (size < 1 || size > MAX) return alloc(size); + if (offset + size > SIZE) { + slab = alloc(SIZE); + offset = 0; + } + const buf: Uint8Array = slice.call(slab, offset, (offset += size)); + if (offset & 7) + // align to 32 bit + offset = (offset | 7) + 1; + return buf; + }; +} + +function indexOutOfRange(reader: BinaryReader, writeLength?: number) { + return RangeError( + "index out of range: " + + reader.pos + + " + " + + (writeLength || 1) + + " > " + + reader.len + ); +} diff --git a/__fixtures__/misc/output/extern.ts b/__fixtures__/misc/output/extern.ts new file mode 100644 index 0000000000..ee864605e6 --- /dev/null +++ b/__fixtures__/misc/output/extern.ts @@ -0,0 +1,33 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + +import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate' +import { Tendermint34Client, HttpEndpoint } from "@cosmjs/tendermint-rpc"; + +const _rpcClients: Record = {}; + +export const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => { + if (typeof rpcEndpoint === 'string') { + return rpcEndpoint; + } else if (!!rpcEndpoint) { + //@ts-ignore + return rpcEndpoint.url; + } +} + +export const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => { + const key = getRpcEndpointKey(rpcEndpoint); + if (!key) return; + if (_rpcClients.hasOwnProperty(key)) { + return _rpcClients[key]; + } + const tmClient = await Tendermint34Client.connect(rpcEndpoint); + //@ts-ignore + const client = new QueryClient(tmClient); + const rpc = createProtobufRpcClient(client); + _rpcClients[key] = rpc; + return rpc; +} diff --git a/__fixtures__/misc/output/google/api/expr/v1alpha1/eval.ts b/__fixtures__/misc/output/google/api/expr/v1alpha1/eval.ts new file mode 100644 index 0000000000..4f4969cdd4 --- /dev/null +++ b/__fixtures__/misc/output/google/api/expr/v1alpha1/eval.ts @@ -0,0 +1,223 @@ +import { BinaryReader, BinaryWriter } from "../../../../binary"; +import { DeepPartial, isSet } from "../../../../helpers"; +export const protobufPackage = "google.api.expr.v1alpha1"; +export interface ExprValue { + /** The ids of the expressions with unknown values. */ + exprs: IdRef[]; +} +export interface ExprValueProtoMsg { + typeUrl: "/google.api.expr.v1alpha1.ExprValue"; + value: Uint8Array; +} +export interface ExprValueAmino { + /** The ids of the expressions with unknown values. */ + exprs: IdRefAmino[]; +} +export interface ExprValueAminoMsg { + type: "/google.api.expr.v1alpha1.ExprValue"; + value: ExprValueAmino; +} +export interface ExprValueSDKType { + exprs: IdRefSDKType[]; +} +export interface IdRef { + /** The expression id. */ + id: number; +} +export interface IdRefProtoMsg { + typeUrl: "/google.api.expr.v1alpha1.IdRef"; + value: Uint8Array; +} +export interface IdRefAmino { + /** The expression id. */ + id: number; +} +export interface IdRefAminoMsg { + type: "/google.api.expr.v1alpha1.IdRef"; + value: IdRefAmino; +} +export interface IdRefSDKType { + id: number; +} +function createBaseExprValue(): ExprValue { + return { + exprs: [] + }; +} +export const ExprValue = { + encode(message: ExprValue, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + for (const v of message.exprs) { + IdRef.encode(v!, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): ExprValue { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseExprValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.exprs.push(IdRef.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromJSON(object: any): ExprValue { + return { + exprs: Array.isArray(object?.exprs) ? object.exprs.map((e: any) => IdRef.fromJSON(e)) : [] + }; + }, + toJSON(message: ExprValue): unknown { + const obj: any = {}; + if (message.exprs) { + obj.exprs = message.exprs.map(e => e ? IdRef.toJSON(e) : undefined); + } else { + obj.exprs = []; + } + return obj; + }, + fromPartial(object: DeepPartial): ExprValue { + const message = createBaseExprValue(); + message.exprs = object.exprs?.map(e => IdRef.fromPartial(e)) || []; + return message; + }, + fromSDK(object: ExprValueSDKType): ExprValue { + return { + exprs: Array.isArray(object?.exprs) ? object.exprs.map((e: any) => IdRef.fromSDK(e)) : [] + }; + }, + fromSDKJSON(object: any): ExprValueSDKType { + return { + exprs: Array.isArray(object?.exprs) ? object.exprs.map((e: any) => IdRef.fromSDKJSON(e)) : [] + }; + }, + toSDK(message: ExprValue): ExprValueSDKType { + const obj: any = {}; + if (message.exprs) { + obj.exprs = message.exprs.map(e => e ? IdRef.toSDK(e) : undefined); + } else { + obj.exprs = []; + } + return obj; + }, + fromAmino(object: ExprValueAmino): ExprValue { + return { + exprs: Array.isArray(object?.exprs) ? object.exprs.map((e: any) => IdRef.fromAmino(e)) : [] + }; + }, + toAmino(message: ExprValue): ExprValueAmino { + const obj: any = {}; + if (message.exprs) { + obj.exprs = message.exprs.map(e => e ? IdRef.toAmino(e) : undefined); + } else { + obj.exprs = []; + } + return obj; + }, + fromAminoMsg(object: ExprValueAminoMsg): ExprValue { + return ExprValue.fromAmino(object.value); + }, + fromProtoMsg(message: ExprValueProtoMsg): ExprValue { + return ExprValue.decode(message.value); + }, + toProto(message: ExprValue): Uint8Array { + return ExprValue.encode(message).finish(); + }, + toProtoMsg(message: ExprValue): ExprValueProtoMsg { + return { + typeUrl: "/google.api.expr.v1alpha1.ExprValue", + value: ExprValue.encode(message).finish() + }; + } +}; +function createBaseIdRef(): IdRef { + return { + id: 0 + }; +} +export const IdRef = { + encode(message: IdRef, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.id !== 0) { + writer.uint32(8).int32(message.id); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): IdRef { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseIdRef(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.id = reader.int32(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromJSON(object: any): IdRef { + return { + id: isSet(object.id) ? Number(object.id) : 0 + }; + }, + toJSON(message: IdRef): unknown { + const obj: any = {}; + message.id !== undefined && (obj.id = Math.round(message.id)); + return obj; + }, + fromPartial(object: DeepPartial): IdRef { + const message = createBaseIdRef(); + message.id = object.id ?? 0; + return message; + }, + fromSDK(object: IdRefSDKType): IdRef { + return { + id: object?.id + }; + }, + fromSDKJSON(object: any): IdRefSDKType { + return { + id: isSet(object.id) ? Number(object.id) : 0 + }; + }, + toSDK(message: IdRef): IdRefSDKType { + const obj: any = {}; + obj.id = message.id; + return obj; + }, + fromAmino(object: IdRefAmino): IdRef { + return { + id: object.id + }; + }, + toAmino(message: IdRef): IdRefAmino { + const obj: any = {}; + obj.id = message.id; + return obj; + }, + fromAminoMsg(object: IdRefAminoMsg): IdRef { + return IdRef.fromAmino(object.value); + }, + fromProtoMsg(message: IdRefProtoMsg): IdRef { + return IdRef.decode(message.value); + }, + toProto(message: IdRef): Uint8Array { + return IdRef.encode(message).finish(); + }, + toProtoMsg(message: IdRef): IdRefProtoMsg { + return { + typeUrl: "/google.api.expr.v1alpha1.IdRef", + value: IdRef.encode(message).finish() + }; + } +}; \ No newline at end of file diff --git a/__fixtures__/misc/output/google/bundle.ts b/__fixtures__/misc/output/google/bundle.ts new file mode 100644 index 0000000000..73d63e7270 --- /dev/null +++ b/__fixtures__/misc/output/google/bundle.ts @@ -0,0 +1,10 @@ +import * as _0 from "./api/expr/v1alpha1/eval"; +export namespace google { + export namespace api { + export namespace expr { + export const v1alpha1 = { + ..._0 + }; + } + } +} \ No newline at end of file diff --git a/__fixtures__/misc/output/helpers.ts b/__fixtures__/misc/output/helpers.ts new file mode 100644 index 0000000000..f92d2b935a --- /dev/null +++ b/__fixtures__/misc/output/helpers.ts @@ -0,0 +1,257 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +declare var self: any | undefined; +declare var window: any | undefined; +declare var global: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== 'undefined') return globalThis; + if (typeof self !== 'undefined') return self; + if (typeof window !== 'undefined') return window; + if (typeof global !== 'undefined') return global; + throw 'Unable to locate global object'; +})(); + +const atob: (b64: string) => string = + globalThis.atob || + ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); + +export function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || + ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); + +export function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(String.fromCharCode(byte)); + }); + return btoa(bin.join('')); +} + +export interface AminoHeight { + readonly revision_number?: string; + readonly revision_height?: string; +} + +export function omitDefault( + input: T +): T | undefined { + if (typeof input === 'string') { + return input === '' ? undefined : input; + } + + if (typeof input === 'number') { + return input === 0 ? undefined : input; + } + + if (typeof input === 'bigint') { + return input === BigInt(0) ? undefined : input; + } + + throw new Error(`Got unsupported type ${typeof input}`); +} + +interface Duration { + /** + * Signed seconds of the span of time. Must be from -315,576,000,000 + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + */ + seconds: bigint; + /** + * Signed fractions of a second at nanosecond resolution of the span + * of time. Durations less than one second are represented with a 0 + * `seconds` field and a positive or negative `nanos` field. For durations + * of one second or more, a non-zero value for the `nanos` field must be + * of the same sign as the `seconds` field. Must be from -999,999,999 + * to +999,999,999 inclusive. + */ + + nanos: number; +} + +export function toDuration(duration: string): Duration { + return { + seconds: BigInt(Math.floor(parseInt(duration) / 1000000000)), + nanos: parseInt(duration) % 1000000000 + }; +} + +export function fromDuration(duration: Duration): string { + return ( + parseInt(duration.seconds.toString()) * 1000000000 + + duration.nanos + ).toString(); +} + +export function isSet(value: any): boolean { + return value !== null && value !== undefined; +} + +export function isObject(value: any): boolean { + return typeof value === 'object' && value !== null; +} + +export interface PageRequest { + key: Uint8Array; + offset: bigint; + limit: bigint; + countTotal: boolean; + reverse: boolean; +} + +export interface PageRequestParams { + 'pagination.key'?: string; + 'pagination.offset'?: string; + 'pagination.limit'?: string; + 'pagination.count_total'?: boolean; + 'pagination.reverse'?: boolean; +} + +export interface Params { + params: PageRequestParams; +} + +export const setPaginationParams = ( + options: Params, + pagination?: PageRequest +) => { + if (!pagination) { + return options; + } + + if (typeof pagination?.countTotal !== 'undefined') { + options.params['pagination.count_total'] = pagination.countTotal; + } + if (typeof pagination?.key !== 'undefined') { + // String to Uint8Array + // let uint8arr = new Uint8Array(Buffer.from(data,'base64')); + + // Uint8Array to String + options.params['pagination.key'] = Buffer.from(pagination.key).toString( + 'base64' + ); + } + if (typeof pagination?.limit !== 'undefined') { + options.params['pagination.limit'] = pagination.limit.toString(); + } + if (typeof pagination?.offset !== 'undefined') { + options.params['pagination.offset'] = pagination.offset.toString(); + } + if (typeof pagination?.reverse !== 'undefined') { + options.params['pagination.reverse'] = pagination.reverse; + } + + return options; +}; + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | bigint + | boolean + | undefined; + +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record< + Exclude>, + never + >; + +export interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise; +} + +interface Timestamp { + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + */ + seconds: bigint; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + */ + + nanos: number; +} + +export function toTimestamp(date: Date): Timestamp { + const seconds = numberToLong(date.getTime() / 1_000); + const nanos = (date.getTime() % 1000) * 1000000; + return { + seconds, + nanos + }; +} + +export function fromTimestamp(t: Timestamp): Date { + let millis = Number(t.seconds) * 1000; + millis += t.nanos / 1000000; + return new Date(millis); +} + +const fromJSON = (object: any): Timestamp => { + return { + seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt(0), + nanos: isSet(object.nanos) ? Number(object.nanos) : 0 + }; +}; + +const timestampFromJSON = (object: any): Timestamp => { + return { + seconds: isSet(object.seconds) + ? BigInt(object.seconds.toString()) + : BigInt(0), + nanos: isSet(object.nanos) ? Number(object.nanos) : 0 + }; +}; + +export function fromJsonTimestamp(o: any): Timestamp { + if (o instanceof Date) { + return toTimestamp(o); + } else if (typeof o === 'string') { + return toTimestamp(new Date(o)); + } else { + return timestampFromJSON(o); + } +} + +function numberToLong(number: number) { + return BigInt(number); +} diff --git a/__fixtures__/misc/output/index.ts b/__fixtures__/misc/output/index.ts new file mode 100644 index 0000000000..33e57b8d5d --- /dev/null +++ b/__fixtures__/misc/output/index.ts @@ -0,0 +1,15 @@ +/** + * This file and any referenced files were automatically generated by @cosmology/telescope@latest + * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain + * and run the transpile command or yarn proto command to regenerate this bundle. + */ + +export * from "./google/bundle"; +export * from "./misc/bundle"; +export * from "./extern"; +export * from "./react-query"; +export * from "./mobx"; +export * from "./pinia-endpoint"; +export * from "./varint"; +export * from "./utf8"; +export * from "./binary"; \ No newline at end of file diff --git a/__fixtures__/misc/output/misc/bundle.ts b/__fixtures__/misc/output/misc/bundle.ts new file mode 100644 index 0000000000..7b026b05a8 --- /dev/null +++ b/__fixtures__/misc/output/misc/bundle.ts @@ -0,0 +1,4 @@ +import * as _1 from "./eval_request"; +export const misc = { + ..._1 +}; \ No newline at end of file diff --git a/__fixtures__/misc/output/misc/eval_request.ts b/__fixtures__/misc/output/misc/eval_request.ts new file mode 100644 index 0000000000..c93abfdfb5 --- /dev/null +++ b/__fixtures__/misc/output/misc/eval_request.ts @@ -0,0 +1,468 @@ +import { ExprValue, ExprValueAmino, ExprValueSDKType, IdRef, IdRefAmino, IdRefSDKType } from "../google/api/expr/v1alpha1/eval"; +import { BinaryReader, BinaryWriter } from "../binary"; +import { isSet, DeepPartial, isObject } from "../helpers"; +export const protobufPackage = "misc"; +export interface EvalRequest_BindingsEntry { + key: string; + value: ExprValue; +} +export interface EvalRequest_BindingsEntryProtoMsg { + typeUrl: string; + value: Uint8Array; +} +export interface EvalRequest_BindingsEntryAmino { + key: string; + value?: ExprValueAmino; +} +export interface EvalRequest_BindingsEntryAminoMsg { + type: string; + value: EvalRequest_BindingsEntryAmino; +} +export interface EvalRequest_BindingsEntrySDKType { + key: string; + value: ExprValueSDKType; +} +export interface EvalRequest_RefsEntry { + key: string; + value: IdRef; +} +export interface EvalRequest_RefsEntryProtoMsg { + typeUrl: string; + value: Uint8Array; +} +export interface EvalRequest_RefsEntryAmino { + key: string; + value?: IdRefAmino; +} +export interface EvalRequest_RefsEntryAminoMsg { + type: string; + value: EvalRequest_RefsEntryAmino; +} +export interface EvalRequest_RefsEntrySDKType { + key: string; + value: IdRefSDKType; +} +export interface EvalRequest { + /** + * Bindings for the external variables. The types SHOULD be compatible + * with the type environment in [CheckRequest][google.api.expr.conformance.v1alpha1.CheckRequest], if checked. + */ + bindings: { + [key: string]: ExprValue; + }; + refs: { + [key: string]: IdRef; + }; +} +export interface EvalRequestProtoMsg { + typeUrl: "/misc.EvalRequest"; + value: Uint8Array; +} +export interface EvalRequestAmino { + /** + * Bindings for the external variables. The types SHOULD be compatible + * with the type environment in [CheckRequest][google.api.expr.conformance.v1alpha1.CheckRequest], if checked. + */ + bindings?: { + [key: string]: ExprValueAmino; + }; + refs?: { + [key: string]: IdRefAmino; + }; +} +export interface EvalRequestAminoMsg { + type: "/misc.EvalRequest"; + value: EvalRequestAmino; +} +export interface EvalRequestSDKType { + bindings: { + [key: string]: ExprValueSDKType; + }; + refs: { + [key: string]: IdRefSDKType; + }; +} +function createBaseEvalRequest_BindingsEntry(): EvalRequest_BindingsEntry { + return { + key: "", + value: ExprValue.fromPartial({}) + }; +} +export const EvalRequest_BindingsEntry = { + encode(message: EvalRequest_BindingsEntry, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.key !== "") { + writer.uint32(10).string(message.key); + } + if (message.value !== undefined) { + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): EvalRequest_BindingsEntry { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseEvalRequest_BindingsEntry(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.string(); + break; + case 2: + message.value = ExprValue.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromJSON(object: any): EvalRequest_BindingsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined + }; + }, + toJSON(message: EvalRequest_BindingsEntry): unknown { + const obj: any = {}; + message.key !== undefined && (obj.key = message.key); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); + return obj; + }, + fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { + const message = createBaseEvalRequest_BindingsEntry(); + message.key = object.key ?? ""; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; + return message; + }, + fromSDK(object: EvalRequest_BindingsEntrySDKType): EvalRequest_BindingsEntry { + return { + key: object?.key, + value: object.value ? ExprValue.fromSDK(object.value) : undefined + }; + }, + fromSDKJSON(object: any): EvalRequest_BindingsEntrySDKType { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? ExprValue.fromSDKJSON(object.value) : undefined + }; + }, + toSDK(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntrySDKType { + const obj: any = {}; + obj.key = message.key; + message.value !== undefined && (obj.value = message.value ? ExprValue.toSDK(message.value) : undefined); + return obj; + }, + fromAmino(object: EvalRequest_BindingsEntryAmino): EvalRequest_BindingsEntry { + return { + key: object.key, + value: object?.value ? ExprValue.fromAmino(object.value) : undefined + }; + }, + toAmino(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntryAmino { + const obj: any = {}; + obj.key = message.key; + obj.value = message.value ? ExprValue.toAmino(message.value) : undefined; + return obj; + }, + fromAminoMsg(object: EvalRequest_BindingsEntryAminoMsg): EvalRequest_BindingsEntry { + return EvalRequest_BindingsEntry.fromAmino(object.value); + }, + fromProtoMsg(message: EvalRequest_BindingsEntryProtoMsg): EvalRequest_BindingsEntry { + return EvalRequest_BindingsEntry.decode(message.value); + }, + toProto(message: EvalRequest_BindingsEntry): Uint8Array { + return EvalRequest_BindingsEntry.encode(message).finish(); + } +}; +function createBaseEvalRequest_RefsEntry(): EvalRequest_RefsEntry { + return { + key: "", + value: IdRef.fromPartial({}) + }; +} +export const EvalRequest_RefsEntry = { + encode(message: EvalRequest_RefsEntry, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + if (message.key !== "") { + writer.uint32(10).string(message.key); + } + if (message.value !== undefined) { + IdRef.encode(message.value, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): EvalRequest_RefsEntry { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseEvalRequest_RefsEntry(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.string(); + break; + case 2: + message.value = IdRef.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromJSON(object: any): EvalRequest_RefsEntry { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? IdRef.fromJSON(object.value) : undefined + }; + }, + toJSON(message: EvalRequest_RefsEntry): unknown { + const obj: any = {}; + message.key !== undefined && (obj.key = message.key); + message.value !== undefined && (obj.value = message.value ? IdRef.toJSON(message.value) : undefined); + return obj; + }, + fromPartial(object: DeepPartial): EvalRequest_RefsEntry { + const message = createBaseEvalRequest_RefsEntry(); + message.key = object.key ?? ""; + message.value = object.value !== undefined && object.value !== null ? IdRef.fromPartial(object.value) : undefined; + return message; + }, + fromSDK(object: EvalRequest_RefsEntrySDKType): EvalRequest_RefsEntry { + return { + key: object?.key, + value: object.value ? IdRef.fromSDK(object.value) : undefined + }; + }, + fromSDKJSON(object: any): EvalRequest_RefsEntrySDKType { + return { + key: isSet(object.key) ? String(object.key) : "", + value: isSet(object.value) ? IdRef.fromSDKJSON(object.value) : undefined + }; + }, + toSDK(message: EvalRequest_RefsEntry): EvalRequest_RefsEntrySDKType { + const obj: any = {}; + obj.key = message.key; + message.value !== undefined && (obj.value = message.value ? IdRef.toSDK(message.value) : undefined); + return obj; + }, + fromAmino(object: EvalRequest_RefsEntryAmino): EvalRequest_RefsEntry { + return { + key: object.key, + value: object?.value ? IdRef.fromAmino(object.value) : undefined + }; + }, + toAmino(message: EvalRequest_RefsEntry): EvalRequest_RefsEntryAmino { + const obj: any = {}; + obj.key = message.key; + obj.value = message.value ? IdRef.toAmino(message.value) : undefined; + return obj; + }, + fromAminoMsg(object: EvalRequest_RefsEntryAminoMsg): EvalRequest_RefsEntry { + return EvalRequest_RefsEntry.fromAmino(object.value); + }, + fromProtoMsg(message: EvalRequest_RefsEntryProtoMsg): EvalRequest_RefsEntry { + return EvalRequest_RefsEntry.decode(message.value); + }, + toProto(message: EvalRequest_RefsEntry): Uint8Array { + return EvalRequest_RefsEntry.encode(message).finish(); + } +}; +function createBaseEvalRequest(): EvalRequest { + return { + bindings: {}, + refs: {} + }; +} +export const EvalRequest = { + encode(message: EvalRequest, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { + Object.entries(message.bindings).forEach(([key, value]) => { + EvalRequest_BindingsEntry.encode({ + key: (key as any), + value + }, writer.uint32(10).fork()).ldelim(); + }); + Object.entries(message.refs).forEach(([key, value]) => { + EvalRequest_RefsEntry.encode({ + key: (key as any), + value + }, writer.uint32(18).fork()).ldelim(); + }); + return writer; + }, + decode(input: BinaryReader | Uint8Array, length?: number): EvalRequest { + const reader = input instanceof BinaryReader ? input : new BinaryReader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseEvalRequest(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + const entry1 = EvalRequest_BindingsEntry.decode(reader, reader.uint32()); + if (entry1.value !== undefined) { + message.bindings[entry1.key] = entry1.value; + } + break; + case 2: + const entry2 = EvalRequest_RefsEntry.decode(reader, reader.uint32()); + if (entry2.value !== undefined) { + message.refs[entry2.key] = entry2.value; + } + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + fromJSON(object: any): EvalRequest { + return { + bindings: isObject(object.bindings) ? Object.entries(object.bindings).reduce<{ + [key: string]: ExprValue; + }>((acc, [key, value]) => { + acc[key] = ExprValue.fromJSON(value); + return acc; + }, {}) : {}, + refs: isObject(object.refs) ? Object.entries(object.refs).reduce<{ + [key: string]: IdRef; + }>((acc, [key, value]) => { + acc[key] = IdRef.fromJSON(value); + return acc; + }, {}) : {} + }; + }, + toJSON(message: EvalRequest): unknown { + const obj: any = {}; + obj.bindings = {}; + if (message.bindings) { + Object.entries(message.bindings).forEach(([k, v]) => { + obj.bindings[k] = ExprValue.toJSON(v); + }); + } + obj.refs = {}; + if (message.refs) { + Object.entries(message.refs).forEach(([k, v]) => { + obj.refs[k] = IdRef.toJSON(v); + }); + } + return obj; + }, + fromPartial(object: DeepPartial): EvalRequest { + const message = createBaseEvalRequest(); + message.bindings = Object.entries(object.bindings ?? {}).reduce<{ + [key: string]: ExprValue; + }>((acc, [key, value]) => { + if (value !== undefined) { + acc[key] = ExprValue.fromPartial(value); + } + return acc; + }, {}); + message.refs = Object.entries(object.refs ?? {}).reduce<{ + [key: string]: IdRef; + }>((acc, [key, value]) => { + if (value !== undefined) { + acc[key] = IdRef.fromPartial(value); + } + return acc; + }, {}); + return message; + }, + fromSDK(object: EvalRequestSDKType): EvalRequest { + return { + bindings: isObject(object.bindings) ? Object.entries(object.bindings).reduce<{ + [key: string]: ExprValue; + }>((acc, [key, value]) => { + acc[key] = ExprValue.fromSDK(value); + return acc; + }, {}) : {}, + refs: isObject(object.refs) ? Object.entries(object.refs).reduce<{ + [key: string]: IdRef; + }>((acc, [key, value]) => { + acc[key] = IdRef.fromSDK(value); + return acc; + }, {}) : {} + }; + }, + fromSDKJSON(object: any): EvalRequestSDKType { + return { + bindings: isObject(object.bindings) ? Object.entries(object.bindings).reduce<{ + [key: string]: ExprValue; + }>((acc, [key, value]) => { + acc[key] = ExprValue.fromSDKJSON(value); + return acc; + }, {}) : {}, + refs: isObject(object.refs) ? Object.entries(object.refs).reduce<{ + [key: string]: IdRef; + }>((acc, [key, value]) => { + acc[key] = IdRef.fromSDKJSON(value); + return acc; + }, {}) : {} + }; + }, + toSDK(message: EvalRequest): EvalRequestSDKType { + const obj: any = {}; + obj.bindings = {}; + if (message.bindings) { + Object.entries(message.bindings).forEach(([k, v]) => { + obj.bindings[k] = ExprValue.toSDK(v); + }); + } + obj.refs = {}; + if (message.refs) { + Object.entries(message.refs).forEach(([k, v]) => { + obj.refs[k] = IdRef.toSDK(v); + }); + } + return obj; + }, + fromAmino(object: EvalRequestAmino): EvalRequest { + return { + bindings: isObject(object.bindings) ? Object.entries(object.bindings).reduce<{ + [key: string]: ExprValue; + }>((acc, [key, value]) => { + acc[key] = ExprValue.fromAmino(value); + return acc; + }, {}) : {}, + refs: isObject(object.refs) ? Object.entries(object.refs).reduce<{ + [key: string]: IdRef; + }>((acc, [key, value]) => { + acc[key] = IdRef.fromAmino(value); + return acc; + }, {}) : {} + }; + }, + toAmino(message: EvalRequest): EvalRequestAmino { + const obj: any = {}; + obj.bindings = {}; + if (message.bindings) { + Object.entries(message.bindings).forEach(([k, v]) => { + obj.bindings[k] = ExprValue.toAmino(v); + }); + } + obj.refs = {}; + if (message.refs) { + Object.entries(message.refs).forEach(([k, v]) => { + obj.refs[k] = IdRef.toAmino(v); + }); + } + return obj; + }, + fromAminoMsg(object: EvalRequestAminoMsg): EvalRequest { + return EvalRequest.fromAmino(object.value); + }, + fromProtoMsg(message: EvalRequestProtoMsg): EvalRequest { + return EvalRequest.decode(message.value); + }, + toProto(message: EvalRequest): Uint8Array { + return EvalRequest.encode(message).finish(); + }, + toProtoMsg(message: EvalRequest): EvalRequestProtoMsg { + return { + typeUrl: "/misc.EvalRequest", + value: EvalRequest.encode(message).finish() + }; + } +}; \ No newline at end of file diff --git a/__fixtures__/misc/output/mobx.ts b/__fixtures__/misc/output/mobx.ts new file mode 100644 index 0000000000..9e66db0620 --- /dev/null +++ b/__fixtures__/misc/output/mobx.ts @@ -0,0 +1,82 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +import { + makeAutoObservable, + runInAction +} from 'mobx'; + +import { QueryStatus } from '@tanstack/react-query'; + +export interface MobxResponse { + data: T | undefined; + isSuccess: boolean; + isLoading: boolean; + refetch: () => Promise; +} + +export class QueryStore { + state?: QueryStatus; + request?: Request; + response?: Response; + fetchFunc?: (request: Request) => Promise; + + constructor(fetchFunc?: (request: Request) => Promise) { + this.fetchFunc = fetchFunc; + makeAutoObservable(this) + } + + get isLoading() { + return this.state === 'loading'; + } + + get isSuccess() { + return this.state === 'success'; + } + + refetch = async (): Promise => { + runInAction(() => { + this.response = void 0; + this.state = 'loading'; + }); + try { + if (!this.fetchFunc) + throw new Error( + 'Query Service not initialized or request function not implemented' + ); + if (!this.request) throw new Error('Request not provided'); + const response = await this.fetchFunc(this.request); + runInAction(() => { + this.response = response; + this.state = 'success'; + }); + console.log( + '%cquery.rpc.Query.ts line:572 this.state', + 'color: #007acc;', + this.state, + this.response + ); + } catch (e) { + console.error(e); + runInAction(() => { + this.state = 'error'; + }); + } + } + + getData(request?: Request): MobxResponse { + runInAction(() => { + this.request = request; + }); + return { + data: this.response, + isSuccess: this.isSuccess, + isLoading: this.isLoading, + refetch: this.refetch, + }; + } +} diff --git a/__fixtures__/misc/output/pinia-endpoint.ts b/__fixtures__/misc/output/pinia-endpoint.ts new file mode 100644 index 0000000000..94788f3e3d --- /dev/null +++ b/__fixtures__/misc/output/pinia-endpoint.ts @@ -0,0 +1,22 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +import { defineStore } from "pinia"; +import type { LCDClient } from '@cosmology/lcd'; + +export const useEndpoint = defineStore('pinia.endpoint', { + state: () => { + return { + restClient: {} as LCDClient, + } + }, + actions: { + setRestClient(client: LCDClient) { + this.restClient = client + } + } +}) diff --git a/__fixtures__/misc/output/react-query.ts b/__fixtures__/misc/output/react-query.ts new file mode 100644 index 0000000000..6f5178b23b --- /dev/null +++ b/__fixtures__/misc/output/react-query.ts @@ -0,0 +1,71 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + +import { getRpcClient } from './extern' +import { + useQuery, + UseQueryOptions, +} from '@tanstack/react-query'; + +import { HttpEndpoint, ProtobufRpcClient } from '@cosmjs/stargate'; +import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; + +export interface ReactQueryParams { + options?: UseQueryOptions; +} + +export interface UseRpcClientQuery extends ReactQueryParams { + rpcEndpoint: string | HttpEndpoint; +} + +export interface UseRpcEndpointQuery extends ReactQueryParams { + getter: () => Promise; + extraKey?: string +} + +export const useRpcEndpoint = ({ + getter, + options, + extraKey +}: UseRpcEndpointQuery) => { + return useQuery(['rpcEndpoint', extraKey], async () => { + return await getter(); + }, options); +}; + +export const useRpcClient = ({ + rpcEndpoint, + options, +}: UseRpcClientQuery) => { + return useQuery(['rpcClient', rpcEndpoint], async () => { + return await getRpcClient(rpcEndpoint); + }, options); +}; + +interface UseTendermintClient extends ReactQueryParams { + rpcEndpoint: string | HttpEndpoint; +} + +/** + * Hook that uses react-query to cache a connected tendermint client. + */ +export const useTendermintClient = ({ + rpcEndpoint, + options, +}: UseTendermintClient) => { + const { data: client } = useQuery( + ['client', 'tendermint', rpcEndpoint], + () => Tendermint34Client.connect(rpcEndpoint), + { + // allow overriding + onError: (e) => { + throw new Error(`Failed to connect to ${rpcEndpoint}` + '\n' + e) + }, + ...options, + } + ) + return { client } +}; diff --git a/__fixtures__/misc/output/utf8.ts b/__fixtures__/misc/output/utf8.ts new file mode 100644 index 0000000000..f149e7aa04 --- /dev/null +++ b/__fixtures__/misc/output/utf8.ts @@ -0,0 +1,148 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +// Copyright (c) 2016, Daniel Wirtz All rights reserved. + +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: + +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of its author, nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"use strict"; + +/** + * Calculates the UTF8 byte length of a string. + * @param {string} string String + * @returns {number} Byte length + */ +export function utf8Length(str: string) { + let len = 0, + c = 0; + for (let i = 0; i < str.length; ++i) { + c = str.charCodeAt(i); + if (c < 128) len += 1; + else if (c < 2048) len += 2; + else if ( + (c & 0xfc00) === 0xd800 && + (str.charCodeAt(i + 1) & 0xfc00) === 0xdc00 + ) { + ++i; + len += 4; + } else len += 3; + } + return len; +} + +/** + * Reads UTF8 bytes as a string. + * @param {Uint8Array} buffer Source buffer + * @param {number} start Source start + * @param {number} end Source end + * @returns {string} String read + */ +export function utf8Read( + buffer: ArrayLike, + start: number, + end: number +) { + const len = end - start; + if (len < 1) return ""; + const chunk = []; + let parts = null, + i = 0, // char offset + t; // temporary + while (start < end) { + t = buffer[start++]; + if (t < 128) chunk[i++] = t; + else if (t > 191 && t < 224) + chunk[i++] = ((t & 31) << 6) | (buffer[start++] & 63); + else if (t > 239 && t < 365) { + t = + (((t & 7) << 18) | + ((buffer[start++] & 63) << 12) | + ((buffer[start++] & 63) << 6) | + (buffer[start++] & 63)) - + 0x10000; + chunk[i++] = 0xd800 + (t >> 10); + chunk[i++] = 0xdc00 + (t & 1023); + } else + chunk[i++] = + ((t & 15) << 12) | + ((buffer[start++] & 63) << 6) | + (buffer[start++] & 63); + if (i > 8191) { + (parts || (parts = [])).push(String.fromCharCode(...chunk)); + i = 0; + } + } + if (parts) { + if (i) parts.push(String.fromCharCode(...chunk.slice(0, i))); + return parts.join(""); + } + return String.fromCharCode(...chunk.slice(0, i)); +} + +/** + * Writes a string as UTF8 bytes. + * @param {string} string Source string + * @param {Uint8Array} buffer Destination buffer + * @param {number} offset Destination offset + * @returns {number} Bytes written + */ +export function utf8Write( + str: string, + buffer: Uint8Array | Array, + offset: number +) { + const start = offset; + let c1, // character 1 + c2; // character 2 + for (let i = 0; i < str.length; ++i) { + c1 = str.charCodeAt(i); + if (c1 < 128) { + buffer[offset++] = c1; + } else if (c1 < 2048) { + buffer[offset++] = (c1 >> 6) | 192; + buffer[offset++] = (c1 & 63) | 128; + } else if ( + (c1 & 0xfc00) === 0xd800 && + ((c2 = str.charCodeAt(i + 1)) & 0xfc00) === 0xdc00 + ) { + c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff); + ++i; + buffer[offset++] = (c1 >> 18) | 240; + buffer[offset++] = ((c1 >> 12) & 63) | 128; + buffer[offset++] = ((c1 >> 6) & 63) | 128; + buffer[offset++] = (c1 & 63) | 128; + } else { + buffer[offset++] = (c1 >> 12) | 224; + buffer[offset++] = ((c1 >> 6) & 63) | 128; + buffer[offset++] = (c1 & 63) | 128; + } + } + return offset - start; +} diff --git a/__fixtures__/misc/output/varint.ts b/__fixtures__/misc/output/varint.ts new file mode 100644 index 0000000000..a83418dbc0 --- /dev/null +++ b/__fixtures__/misc/output/varint.ts @@ -0,0 +1,488 @@ +/** +* This file and any referenced files were automatically generated by @cosmology/telescope@latest +* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain +* and run the transpile command or yarn proto command to regenerate this bundle. +*/ + + +// Copyright 2008 Google Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Code generated by the Protocol Buffer compiler is owned by the owner +// of the input file used when generating it. This code is not +// standalone and requires a support library to be linked with it. This +// support library is itself covered by the above license. + +/* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */ + +/** + * Read a 64 bit varint as two JS numbers. + * + * Returns tuple: + * [0]: low bits + * [1]: high bits + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175 + */ +export function varint64read(this: ReaderLike): [number, number] { + let lowBits = 0; + let highBits = 0; + + for (let shift = 0; shift < 28; shift += 7) { + let b = this.buf[this.pos++]; + lowBits |= (b & 0x7f) << shift; + if ((b & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + } + + let middleByte = this.buf[this.pos++]; + + // last four bits of the first 32 bit number + lowBits |= (middleByte & 0x0f) << 28; + + // 3 upper bits are part of the next 32 bit number + highBits = (middleByte & 0x70) >> 4; + + if ((middleByte & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + + for (let shift = 3; shift <= 31; shift += 7) { + let b = this.buf[this.pos++]; + highBits |= (b & 0x7f) << shift; + if ((b & 0x80) == 0) { + this.assertBounds(); + return [lowBits, highBits]; + } + } + + throw new Error("invalid varint"); +} + +/** + * Write a 64 bit varint, given as two JS numbers, to the given bytes array. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344 + */ +export function varint64write(lo: number, hi: number, bytes: number[]): void { + for (let i = 0; i < 28; i = i + 7) { + const shift = lo >>> i; + const hasNext = !(shift >>> 7 == 0 && hi == 0); + const byte = (hasNext ? shift | 0x80 : shift) & 0xff; + bytes.push(byte); + if (!hasNext) { + return; + } + } + + const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4); + const hasMoreBits = !(hi >> 3 == 0); + bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff); + + if (!hasMoreBits) { + return; + } + + for (let i = 3; i < 31; i = i + 7) { + const shift = hi >>> i; + const hasNext = !(shift >>> 7 == 0); + const byte = (hasNext ? shift | 0x80 : shift) & 0xff; + bytes.push(byte); + if (!hasNext) { + return; + } + } + + bytes.push((hi >>> 31) & 0x01); +} + +// constants for binary math +const TWO_PWR_32_DBL = 0x100000000; + +/** + * Parse decimal string of 64 bit integer value as two JS numbers. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function int64FromString(dec: string): { lo: number; hi: number } { + // Check for minus sign. + const minus = dec[0] === "-"; + if (minus) { + dec = dec.slice(1); + } + + // Work 6 decimal digits at a time, acting like we're converting base 1e6 + // digits to binary. This is safe to do with floating point math because + // Number.isSafeInteger(ALL_32_BITS * 1e6) == true. + const base = 1e6; + let lowBits = 0; + let highBits = 0; + + function add1e6digit(begin: number, end?: number) { + // Note: Number('') is 0. + const digit1e6 = Number(dec.slice(begin, end)); + highBits *= base; + lowBits = lowBits * base + digit1e6; + // Carry bits from lowBits to + if (lowBits >= TWO_PWR_32_DBL) { + highBits = highBits + ((lowBits / TWO_PWR_32_DBL) | 0); + lowBits = lowBits % TWO_PWR_32_DBL; + } + } + + add1e6digit(-24, -18); + add1e6digit(-18, -12); + add1e6digit(-12, -6); + add1e6digit(-6); + return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits); +} + +/** + * Losslessly converts a 64-bit signed integer in 32:32 split representation + * into a decimal string. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function int64ToString(lo: number, hi: number): string { + let bits = newBits(lo, hi); + // If we're treating the input as a signed value and the high bit is set, do + // a manual two's complement conversion before the decimal conversion. + const negative = bits.hi & 0x80000000; + if (negative) { + bits = negate(bits.lo, bits.hi); + } + const result = uInt64ToString(bits.lo, bits.hi); + return negative ? "-" + result : result; +} + +/** + * Losslessly converts a 64-bit unsigned integer in 32:32 split representation + * into a decimal string. + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10 + */ +export function uInt64ToString(lo: number, hi: number): string { + ({ lo, hi } = toUnsigned(lo, hi)); + // Skip the expensive conversion if the number is small enough to use the + // built-in conversions. + // Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with + // highBits <= 0x1FFFFF can be safely expressed with a double and retain + // integer precision. + // Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true. + if (hi <= 0x1fffff) { + return String(TWO_PWR_32_DBL * hi + lo); + } + + // What this code is doing is essentially converting the input number from + // base-2 to base-1e7, which allows us to represent the 64-bit range with + // only 3 (very large) digits. Those digits are then trivial to convert to + // a base-10 string. + + // The magic numbers used here are - + // 2^24 = 16777216 = (1,6777216) in base-1e7. + // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7. + + // Split 32:32 representation into 16:24:24 representation so our + // intermediate digits don't overflow. + const low = lo & 0xffffff; + const mid = ((lo >>> 24) | (hi << 8)) & 0xffffff; + const high = (hi >> 16) & 0xffff; + + // Assemble our three base-1e7 digits, ignoring carries. The maximum + // value in a digit at this step is representable as a 48-bit integer, which + // can be stored in a 64-bit floating point number. + let digitA = low + mid * 6777216 + high * 6710656; + let digitB = mid + high * 8147497; + let digitC = high * 2; + + // Apply carries from A to B and from B to C. + const base = 10000000; + if (digitA >= base) { + digitB += Math.floor(digitA / base); + digitA %= base; + } + + if (digitB >= base) { + digitC += Math.floor(digitB / base); + digitB %= base; + } + + // If digitC is 0, then we should have returned in the trivial code path + // at the top for non-safe integers. Given this, we can assume both digitB + // and digitA need leading zeros. + return ( + digitC.toString() + + decimalFrom1e7WithLeadingZeros(digitB) + + decimalFrom1e7WithLeadingZeros(digitA) + ); +} + +function toUnsigned(lo: number, hi: number): { lo: number; hi: number } { + return { lo: lo >>> 0, hi: hi >>> 0 }; +} + +function newBits(lo: number, hi: number): { lo: number; hi: number } { + return { lo: lo | 0, hi: hi | 0 }; +} + +/** + * Returns two's compliment negation of input. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers + */ +function negate(lowBits: number, highBits: number) { + highBits = ~highBits; + if (lowBits) { + lowBits = ~lowBits + 1; + } else { + // If lowBits is 0, then bitwise-not is 0xFFFFFFFF, + // adding 1 to that, results in 0x100000000, which leaves + // the low bits 0x0 and simply adds one to the high bits. + highBits += 1; + } + return newBits(lowBits, highBits); +} + +/** + * Returns decimal representation of digit1e7 with leading zeros. + */ +const decimalFrom1e7WithLeadingZeros = (digit1e7: number) => { + const partial = String(digit1e7); + return "0000000".slice(partial.length) + partial; +}; + +/** + * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)` + * + * Copyright 2008 Google Inc. All rights reserved. + * + * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144 + */ +export function varint32write(value: number, bytes: number[]): void { + if (value >= 0) { + // write value as varint 32 + while (value > 0x7f) { + bytes.push((value & 0x7f) | 0x80); + value = value >>> 7; + } + bytes.push(value); + } else { + for (let i = 0; i < 9; i++) { + bytes.push((value & 127) | 128); + value = value >> 7; + } + bytes.push(1); + } +} + +/** + * Read an unsigned 32 bit varint. + * + * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220 + */ +export function varint32read(this: ReaderLike): number { + let b = this.buf[this.pos++]; + let result = b & 0x7f; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 7; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 14; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + b = this.buf[this.pos++]; + result |= (b & 0x7f) << 21; + if ((b & 0x80) == 0) { + this.assertBounds(); + return result; + } + + // Extract only last 4 bits + b = this.buf[this.pos++]; + result |= (b & 0x0f) << 28; + + for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++) + b = this.buf[this.pos++]; + + if ((b & 0x80) != 0) throw new Error("invalid varint"); + + this.assertBounds(); + + // Result can have 32 bits, convert it to unsigned + return result >>> 0; +} + +type ReaderLike = { + buf: Uint8Array; + pos: number; + len: number; + assertBounds(): void; +}; + +/** + * encode zig zag + */ +export function zzEncode(lo: number, hi: number) { + let mask = hi >> 31; + hi = (((hi << 1) | (lo >>> 31)) ^ mask) >>> 0; + lo = ((lo << 1) ^ mask) >>> 0; + return [lo, hi]; +} + +/** + * decode zig zag + */ +export function zzDecode(lo: number, hi: number) { + let mask = -(lo & 1); + lo = (((lo >>> 1) | (hi << 31)) ^ mask) >>> 0; + hi = ((hi >>> 1) ^ mask) >>> 0; + return [lo, hi]; +} + +/** + * unsigned int32 without moving pos. + */ +export function readUInt32(buf: Uint8Array, pos: number) { + return ( + (buf[pos] | (buf[pos + 1] << 8) | (buf[pos + 2] << 16)) + + buf[pos + 3] * 0x1000000 + ); +} + +/** + * signed int32 without moving pos. + */ +export function readInt32(buf: Uint8Array, pos: number) { + return ( + (buf[pos] | (buf[pos + 1] << 8) | (buf[pos + 2] << 16)) + + (buf[pos + 3] << 24) + ); +} + +/** + * writing varint32 to pos + */ +export function writeVarint32( + val: number, + buf: Uint8Array | number[], + pos: number +) { + while (val > 127) { + buf[pos++] = (val & 127) | 128; + val >>>= 7; + } + buf[pos] = val; +} + +/** + * writing varint64 to pos + */ +export function writeVarint64( + val: { lo: number; hi: number }, + buf: Uint8Array | number[], + pos: number +) { + while (val.hi) { + buf[pos++] = (val.lo & 127) | 128; + val.lo = ((val.lo >>> 7) | (val.hi << 25)) >>> 0; + val.hi >>>= 7; + } + while (val.lo > 127) { + buf[pos++] = (val.lo & 127) | 128; + val.lo = val.lo >>> 7; + } + buf[pos++] = val.lo; +} + +export function int64Length(lo: number, hi: number) { + let part0 = lo, + part1 = ((lo >>> 28) | (hi << 4)) >>> 0, + part2 = hi >>> 24; + return part2 === 0 + ? part1 === 0 + ? part0 < 16384 + ? part0 < 128 + ? 1 + : 2 + : part0 < 2097152 + ? 3 + : 4 + : part1 < 16384 + ? part1 < 128 + ? 5 + : 6 + : part1 < 2097152 + ? 7 + : 8 + : part2 < 128 + ? 9 + : 10; +} + +export function writeFixed32( + val: number, + buf: Uint8Array | number[], + pos: number +) { + buf[pos] = val & 255; + buf[pos + 1] = (val >>> 8) & 255; + buf[pos + 2] = (val >>> 16) & 255; + buf[pos + 3] = val >>> 24; +} + +export function writeByte( + val: number, + buf: Uint8Array | number[], + pos: number +) { + buf[pos] = val & 255; +} diff --git a/__fixtures__/misc/proto/google/api/expr/v1alpha1/eval.proto b/__fixtures__/misc/proto/google/api/expr/v1alpha1/eval.proto new file mode 100644 index 0000000000..0d12e87b88 --- /dev/null +++ b/__fixtures__/misc/proto/google/api/expr/v1alpha1/eval.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package google.api.expr.v1alpha1; + +message ExprValue { + // The ids of the expressions with unknown values. + repeated IdRef exprs = 1; +} + +message IdRef { + // The expression id. + int32 id = 1; +} \ No newline at end of file diff --git a/__fixtures__/misc/proto/misc/eval_request.proto b/__fixtures__/misc/proto/misc/eval_request.proto new file mode 100644 index 0000000000..a2876a7870 --- /dev/null +++ b/__fixtures__/misc/proto/misc/eval_request.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package misc; + +import "google/api/expr/v1alpha1/eval.proto"; + +message EvalRequest { + // Bindings for the external variables. The types SHOULD be compatible + // with the type environment in [CheckRequest][google.api.expr.conformance.v1alpha1.CheckRequest], if checked. + map bindings = 1; + + map refs = 2; +} \ No newline at end of file diff --git a/__fixtures__/output1/google/api/expr/conformance/v1alpha1/conformance_service.ts b/__fixtures__/output1/google/api/expr/conformance/v1alpha1/conformance_service.ts index bab015b521..ca01c8e5d9 100644 --- a/__fixtures__/output1/google/api/expr/conformance/v1alpha1/conformance_service.ts +++ b/__fixtures__/output1/google/api/expr/conformance/v1alpha1/conformance_service.ts @@ -552,7 +552,7 @@ export const EvalRequest_BindingsEntry = { writer.uint32(10).string(message.key); } if (message.value !== undefined) { - google.api.expr.v1alpha1.ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -567,7 +567,7 @@ export const EvalRequest_BindingsEntry = { message.key = reader.string(); break; case 2: - message.value = google.api.expr.v1alpha1.ExprValue.decode(reader, reader.uint32()); + message.value = ExprValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -579,31 +579,31 @@ export const EvalRequest_BindingsEntry = { fromJSON(object: any): EvalRequest_BindingsEntry { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined }; }, toJSON(message: EvalRequest_BindingsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = message.key); - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { const message = createBaseEvalRequest_BindingsEntry(); message.key = object.key ?? ""; - message.value = object.value !== undefined && object.value !== null ? google.api.expr.v1alpha1.ExprValue.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; return message; }, fromSDK(object: EvalRequest_BindingsEntrySDKType): EvalRequest_BindingsEntry { return { key: object?.key, - value: object.value ? google.api.expr.v1alpha1.ExprValue.fromSDK(object.value) : undefined + value: object.value ? ExprValue.fromSDK(object.value) : undefined }; }, toSDK(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toSDK(message.value) : undefined); return obj; } }; diff --git a/__fixtures__/output1/google/logging/v2/logging.ts b/__fixtures__/output1/google/logging/v2/logging.ts index 4a30c171bb..b0c545134f 100644 --- a/__fixtures__/output1/google/logging/v2/logging.ts +++ b/__fixtures__/output1/google/logging/v2/logging.ts @@ -813,7 +813,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { writer.uint32(8).int32(message.key); } if (message.value !== undefined) { - google.rpc.Status.encode(message.value, writer.uint32(18).fork()).ldelim(); + Status.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -828,7 +828,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { message.key = reader.int32(); break; case 2: - message.value = google.rpc.Status.decode(reader, reader.uint32()); + message.value = Status.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -840,31 +840,31 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { fromJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromJSON(object.value) : undefined }; }, toJSON(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = Math.round(message.key)); - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { const message = createBaseWriteLogEntriesPartialErrors_LogEntryErrorsEntry(); message.key = object.key ?? 0; - message.value = object.value !== undefined && object.value !== null ? google.rpc.Status.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? Status.fromPartial(object.value) : undefined; return message; }, fromSDK(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object?.key, - value: object.value ? google.rpc.Status.fromSDK(object.value) : undefined + value: object.value ? Status.fromSDK(object.value) : undefined }; }, toSDK(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toSDK(message.value) : undefined); return obj; } }; diff --git a/__fixtures__/output1/helpers.ts b/__fixtures__/output1/helpers.ts index d14762f911..53124a848b 100644 --- a/__fixtures__/output1/helpers.ts +++ b/__fixtures__/output1/helpers.ts @@ -140,17 +140,17 @@ export const setPaginationParams = (options: Params, pagination?: PageRequest) = } if (typeof pagination?.key !== "undefined") { // String to Uint8Array - // let uint8arr = new Uint8Array(Buffer.from(data,'base64')); + // let uint8arr = new Uint8Array(Buffer.from(data,'base64')); // Uint8Array to String options.params['pagination.key'] = Buffer.from(pagination.key).toString('base64'); } if (typeof pagination?.limit !== "undefined") { - options.params["pagination.limit"] = pagination.limit.toString() + options.params["pagination.limit"] = pagination.limit.toString() } if (typeof pagination?.offset !== "undefined") { - options.params["pagination.offset"] = pagination.offset.toString() - } + options.params["pagination.offset"] = pagination.offset.toString() + } if (typeof pagination?.reverse !== "undefined") { options.params['pagination.reverse'] = pagination.reverse; } @@ -221,22 +221,22 @@ const fromJSON = (object: any): Timestamp => { }; const timestampFromJSON = (object: any): Timestamp => { - return { - seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; + return { + seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; } - + export function fromJsonTimestamp(o: any): Timestamp { - if (o instanceof Date) { - return toTimestamp(o); - } else if (typeof o === "string") { - return toTimestamp(new Date(o)); - } else { - return timestampFromJSON(o); - } + if (o instanceof Date) { + return toTimestamp(o); + } else if (typeof o === "string") { + return toTimestamp(new Date(o)); + } else { + return timestampFromJSON(o); + } } - + function numberToLong(number: number) { return Long.fromNumber(number); } diff --git a/__fixtures__/output1/index.ts b/__fixtures__/output1/index.ts index 38dd89d1eb..b5ebddc0c6 100644 --- a/__fixtures__/output1/index.ts +++ b/__fixtures__/output1/index.ts @@ -3,7 +3,7 @@ * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or yarn proto command to regenerate this bundle. */ - + export * from "./akash/bundle"; export * from "./akash/client"; export * from "./ics23/bundle"; diff --git a/__fixtures__/output2/google/api/expr/conformance/v1alpha1/conformance_service.ts b/__fixtures__/output2/google/api/expr/conformance/v1alpha1/conformance_service.ts index 92abfe1ee3..346320596a 100644 --- a/__fixtures__/output2/google/api/expr/conformance/v1alpha1/conformance_service.ts +++ b/__fixtures__/output2/google/api/expr/conformance/v1alpha1/conformance_service.ts @@ -433,7 +433,7 @@ export const EvalRequest_BindingsEntry = { writer.uint32(10).string(message.key); } if (message.value !== undefined) { - google.api.expr.v1alpha1.ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -448,7 +448,7 @@ export const EvalRequest_BindingsEntry = { message.key = reader.string(); break; case 2: - message.value = google.api.expr.v1alpha1.ExprValue.decode(reader, reader.uint32()); + message.value = ExprValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -460,19 +460,19 @@ export const EvalRequest_BindingsEntry = { fromJSON(object: any): EvalRequest_BindingsEntry { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined }; }, toJSON(message: EvalRequest_BindingsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = message.key); - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { const message = createBaseEvalRequest_BindingsEntry(); message.key = object.key ?? ""; - message.value = object.value !== undefined && object.value !== null ? google.api.expr.v1alpha1.ExprValue.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; return message; } }; diff --git a/__fixtures__/output2/google/logging/v2/logging.ts b/__fixtures__/output2/google/logging/v2/logging.ts index 76e80e18db..b1a5c81d97 100644 --- a/__fixtures__/output2/google/logging/v2/logging.ts +++ b/__fixtures__/output2/google/logging/v2/logging.ts @@ -669,7 +669,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { writer.uint32(8).int32(message.key); } if (message.value !== undefined) { - google.rpc.Status.encode(message.value, writer.uint32(18).fork()).ldelim(); + Status.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -684,7 +684,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { message.key = reader.int32(); break; case 2: - message.value = google.rpc.Status.decode(reader, reader.uint32()); + message.value = Status.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -696,19 +696,19 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { fromJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromJSON(object.value) : undefined }; }, toJSON(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = Math.round(message.key)); - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { const message = createBaseWriteLogEntriesPartialErrors_LogEntryErrorsEntry(); message.key = object.key ?? 0; - message.value = object.value !== undefined && object.value !== null ? google.rpc.Status.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? Status.fromPartial(object.value) : undefined; return message; } }; diff --git a/__fixtures__/output2/helpers.ts b/__fixtures__/output2/helpers.ts index cd20308db2..674ecc2536 100644 --- a/__fixtures__/output2/helpers.ts +++ b/__fixtures__/output2/helpers.ts @@ -142,17 +142,17 @@ export const setPaginationParams = (options: Params, pagination?: PageRequest) = } if (typeof pagination?.key !== "undefined") { // String to Uint8Array - // let uint8arr = new Uint8Array(Buffer.from(data,'base64')); + // let uint8arr = new Uint8Array(Buffer.from(data,'base64')); // Uint8Array to String options.params['pagination.key'] = Buffer.from(pagination.key).toString('base64'); } if (typeof pagination?.limit !== "undefined") { - options.params["pagination.limit"] = pagination.limit.toString() + options.params["pagination.limit"] = pagination.limit.toString() } if (typeof pagination?.offset !== "undefined") { - options.params["pagination.offset"] = pagination.offset.toString() - } + options.params["pagination.offset"] = pagination.offset.toString() + } if (typeof pagination?.reverse !== "undefined") { options.params['pagination.reverse'] = pagination.reverse; } @@ -223,22 +223,22 @@ const fromJSON = (object: any): Timestamp => { }; const timestampFromJSON = (object: any): Timestamp => { - return { - seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO, - nanos: isSet(object.nanos) ? Number(object.nanos) : 0, - }; + return { + seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO, + nanos: isSet(object.nanos) ? Number(object.nanos) : 0, + }; } - + export function fromJsonTimestamp(o: any): Timestamp { - if (o instanceof Date) { - return toTimestamp(o); - } else if (typeof o === "string") { - return toTimestamp(new Date(o)); - } else { - return timestampFromJSON(o); - } + if (o instanceof Date) { + return toTimestamp(o); + } else if (typeof o === "string") { + return toTimestamp(new Date(o)); + } else { + return timestampFromJSON(o); + } } - + function numberToLong(number: number) { return Long.fromNumber(number); } diff --git a/__fixtures__/v-next/outputosmojs/google/api/expr/conformance/v1alpha1/conformance_service.ts b/__fixtures__/v-next/outputosmojs/google/api/expr/conformance/v1alpha1/conformance_service.ts index 001cdec128..d1e89afffc 100644 --- a/__fixtures__/v-next/outputosmojs/google/api/expr/conformance/v1alpha1/conformance_service.ts +++ b/__fixtures__/v-next/outputosmojs/google/api/expr/conformance/v1alpha1/conformance_service.ts @@ -580,7 +580,7 @@ export const EvalRequest_BindingsEntry = { writer.uint32(10).string(message.key); } if (message.value !== undefined) { - google.api.expr.v1alpha1.ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -595,7 +595,7 @@ export const EvalRequest_BindingsEntry = { message.key = reader.string(); break; case 2: - message.value = google.api.expr.v1alpha1.ExprValue.decode(reader, reader.uint32()); + message.value = ExprValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -607,37 +607,37 @@ export const EvalRequest_BindingsEntry = { fromJSON(object: any): EvalRequest_BindingsEntry { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined }; }, toJSON(message: EvalRequest_BindingsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = message.key); - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { const message = createBaseEvalRequest_BindingsEntry(); message.key = object.key ?? ""; - message.value = object.value !== undefined && object.value !== null ? google.api.expr.v1alpha1.ExprValue.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; return message; }, fromSDK(object: EvalRequest_BindingsEntrySDKType): EvalRequest_BindingsEntry { return { key: object?.key, - value: object.value ? google.api.expr.v1alpha1.ExprValue.fromSDK(object.value) : undefined + value: object.value ? ExprValue.fromSDK(object.value) : undefined }; }, fromSDKJSON(object: any): EvalRequest_BindingsEntrySDKType { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromSDKJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromSDKJSON(object.value) : undefined }; }, toSDK(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toSDK(message.value) : undefined); return obj; } }; diff --git a/__fixtures__/v-next/outputosmojs/google/logging/v2/logging.ts b/__fixtures__/v-next/outputosmojs/google/logging/v2/logging.ts index e471cb0d8d..d90a379fd4 100644 --- a/__fixtures__/v-next/outputosmojs/google/logging/v2/logging.ts +++ b/__fixtures__/v-next/outputosmojs/google/logging/v2/logging.ts @@ -842,7 +842,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { writer.uint32(8).int32(message.key); } if (message.value !== undefined) { - google.rpc.Status.encode(message.value, writer.uint32(18).fork()).ldelim(); + Status.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -857,7 +857,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { message.key = reader.int32(); break; case 2: - message.value = google.rpc.Status.decode(reader, reader.uint32()); + message.value = Status.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -869,37 +869,37 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { fromJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromJSON(object.value) : undefined }; }, toJSON(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = Math.round(message.key)); - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { const message = createBaseWriteLogEntriesPartialErrors_LogEntryErrorsEntry(); message.key = object.key ?? 0; - message.value = object.value !== undefined && object.value !== null ? google.rpc.Status.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? Status.fromPartial(object.value) : undefined; return message; }, fromSDK(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object?.key, - value: object.value ? google.rpc.Status.fromSDK(object.value) : undefined + value: object.value ? Status.fromSDK(object.value) : undefined }; }, fromSDKJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromSDKJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromSDKJSON(object.value) : undefined }; }, toSDK(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toSDK(message.value) : undefined); return obj; } }; diff --git a/__fixtures__/v-next/outputv2/google/api/expr/conformance/v1alpha1/conformance_service.ts b/__fixtures__/v-next/outputv2/google/api/expr/conformance/v1alpha1/conformance_service.ts index 21904ca403..902ff55a29 100644 --- a/__fixtures__/v-next/outputv2/google/api/expr/conformance/v1alpha1/conformance_service.ts +++ b/__fixtures__/v-next/outputv2/google/api/expr/conformance/v1alpha1/conformance_service.ts @@ -841,7 +841,7 @@ export const EvalRequest_BindingsEntry = { writer.uint32(10).string(message.key); } if (message.value !== undefined) { - google.api.expr.v1alpha1.ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -856,7 +856,7 @@ export const EvalRequest_BindingsEntry = { message.key = reader.string(); break; case 2: - message.value = google.api.expr.v1alpha1.ExprValue.decode(reader, reader.uint32()); + message.value = ExprValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -868,43 +868,43 @@ export const EvalRequest_BindingsEntry = { fromJSON(object: any): EvalRequest_BindingsEntry { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined }; }, toJSON(message: EvalRequest_BindingsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = message.key); - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { const message = createBaseEvalRequest_BindingsEntry(); message.key = object.key ?? ""; - message.value = object.value !== undefined && object.value !== null ? google.api.expr.v1alpha1.ExprValue.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; return message; }, fromSDK(object: EvalRequest_BindingsEntrySDKType): EvalRequest_BindingsEntry { return { key: object?.key, - value: object.value ? google.api.expr.v1alpha1.ExprValue.fromSDK(object.value) : undefined + value: object.value ? ExprValue.fromSDK(object.value) : undefined }; }, toSDK(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toSDK(message.value) : undefined); return obj; }, fromAmino(object: EvalRequest_BindingsEntryAmino): EvalRequest_BindingsEntry { return { key: object.key, - value: object?.value ? google.api.expr.v1alpha1.ExprValue.fromAmino(object.value) : undefined + value: object?.value ? ExprValue.fromAmino(object.value) : undefined }; }, toAmino(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntryAmino { const obj: any = {}; obj.key = message.key; - obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toAmino(message.value) : undefined; + obj.value = message.value ? ExprValue.toAmino(message.value) : undefined; return obj; }, fromAminoMsg(object: EvalRequest_BindingsEntryAminoMsg): EvalRequest_BindingsEntry { diff --git a/__fixtures__/v-next/outputv2/google/logging/v2/logging.ts b/__fixtures__/v-next/outputv2/google/logging/v2/logging.ts index 00aa177fb5..d2b80afcb1 100644 --- a/__fixtures__/v-next/outputv2/google/logging/v2/logging.ts +++ b/__fixtures__/v-next/outputv2/google/logging/v2/logging.ts @@ -1401,7 +1401,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { writer.uint32(8).int32(message.key); } if (message.value !== undefined) { - google.rpc.Status.encode(message.value, writer.uint32(18).fork()).ldelim(); + Status.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -1416,7 +1416,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { message.key = reader.int32(); break; case 2: - message.value = google.rpc.Status.decode(reader, reader.uint32()); + message.value = Status.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -1428,43 +1428,43 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { fromJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromJSON(object.value) : undefined }; }, toJSON(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = Math.round(message.key)); - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { const message = createBaseWriteLogEntriesPartialErrors_LogEntryErrorsEntry(); message.key = object.key ?? 0; - message.value = object.value !== undefined && object.value !== null ? google.rpc.Status.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? Status.fromPartial(object.value) : undefined; return message; }, fromSDK(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object?.key, - value: object.value ? google.rpc.Status.fromSDK(object.value) : undefined + value: object.value ? Status.fromSDK(object.value) : undefined }; }, toSDK(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toSDK(message.value) : undefined); return obj; }, fromAmino(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntryAmino): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object.key, - value: object?.value ? google.rpc.Status.fromAmino(object.value) : undefined + value: object?.value ? Status.fromAmino(object.value) : undefined }; }, toAmino(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntryAmino { const obj: any = {}; obj.key = message.key; - obj.value = message.value ? google.rpc.Status.toAmino(message.value) : undefined; + obj.value = message.value ? Status.toAmino(message.value) : undefined; return obj; }, fromAminoMsg(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntryAminoMsg): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { diff --git a/__fixtures__/v-next/outputv3/google/api/expr/conformance/v1alpha1/conformance_service.ts b/__fixtures__/v-next/outputv3/google/api/expr/conformance/v1alpha1/conformance_service.ts index 21904ca403..902ff55a29 100644 --- a/__fixtures__/v-next/outputv3/google/api/expr/conformance/v1alpha1/conformance_service.ts +++ b/__fixtures__/v-next/outputv3/google/api/expr/conformance/v1alpha1/conformance_service.ts @@ -841,7 +841,7 @@ export const EvalRequest_BindingsEntry = { writer.uint32(10).string(message.key); } if (message.value !== undefined) { - google.api.expr.v1alpha1.ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -856,7 +856,7 @@ export const EvalRequest_BindingsEntry = { message.key = reader.string(); break; case 2: - message.value = google.api.expr.v1alpha1.ExprValue.decode(reader, reader.uint32()); + message.value = ExprValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -868,43 +868,43 @@ export const EvalRequest_BindingsEntry = { fromJSON(object: any): EvalRequest_BindingsEntry { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined }; }, toJSON(message: EvalRequest_BindingsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = message.key); - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { const message = createBaseEvalRequest_BindingsEntry(); message.key = object.key ?? ""; - message.value = object.value !== undefined && object.value !== null ? google.api.expr.v1alpha1.ExprValue.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; return message; }, fromSDK(object: EvalRequest_BindingsEntrySDKType): EvalRequest_BindingsEntry { return { key: object?.key, - value: object.value ? google.api.expr.v1alpha1.ExprValue.fromSDK(object.value) : undefined + value: object.value ? ExprValue.fromSDK(object.value) : undefined }; }, toSDK(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toSDK(message.value) : undefined); return obj; }, fromAmino(object: EvalRequest_BindingsEntryAmino): EvalRequest_BindingsEntry { return { key: object.key, - value: object?.value ? google.api.expr.v1alpha1.ExprValue.fromAmino(object.value) : undefined + value: object?.value ? ExprValue.fromAmino(object.value) : undefined }; }, toAmino(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntryAmino { const obj: any = {}; obj.key = message.key; - obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toAmino(message.value) : undefined; + obj.value = message.value ? ExprValue.toAmino(message.value) : undefined; return obj; }, fromAminoMsg(object: EvalRequest_BindingsEntryAminoMsg): EvalRequest_BindingsEntry { diff --git a/__fixtures__/v-next/outputv3/google/logging/v2/logging.ts b/__fixtures__/v-next/outputv3/google/logging/v2/logging.ts index 00aa177fb5..d2b80afcb1 100644 --- a/__fixtures__/v-next/outputv3/google/logging/v2/logging.ts +++ b/__fixtures__/v-next/outputv3/google/logging/v2/logging.ts @@ -1401,7 +1401,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { writer.uint32(8).int32(message.key); } if (message.value !== undefined) { - google.rpc.Status.encode(message.value, writer.uint32(18).fork()).ldelim(); + Status.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -1416,7 +1416,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { message.key = reader.int32(); break; case 2: - message.value = google.rpc.Status.decode(reader, reader.uint32()); + message.value = Status.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -1428,43 +1428,43 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { fromJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromJSON(object.value) : undefined }; }, toJSON(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = Math.round(message.key)); - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { const message = createBaseWriteLogEntriesPartialErrors_LogEntryErrorsEntry(); message.key = object.key ?? 0; - message.value = object.value !== undefined && object.value !== null ? google.rpc.Status.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? Status.fromPartial(object.value) : undefined; return message; }, fromSDK(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object?.key, - value: object.value ? google.rpc.Status.fromSDK(object.value) : undefined + value: object.value ? Status.fromSDK(object.value) : undefined }; }, toSDK(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toSDK(message.value) : undefined); return obj; }, fromAmino(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntryAmino): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object.key, - value: object?.value ? google.rpc.Status.fromAmino(object.value) : undefined + value: object?.value ? Status.fromAmino(object.value) : undefined }; }, toAmino(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntryAmino { const obj: any = {}; obj.key = message.key; - obj.value = message.value ? google.rpc.Status.toAmino(message.value) : undefined; + obj.value = message.value ? Status.toAmino(message.value) : undefined; return obj; }, fromAminoMsg(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntryAminoMsg): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { diff --git a/__fixtures__/v-next/outputv4/google/api/expr/conformance/v1alpha1/conformance_service.ts b/__fixtures__/v-next/outputv4/google/api/expr/conformance/v1alpha1/conformance_service.ts index 001cdec128..d1e89afffc 100644 --- a/__fixtures__/v-next/outputv4/google/api/expr/conformance/v1alpha1/conformance_service.ts +++ b/__fixtures__/v-next/outputv4/google/api/expr/conformance/v1alpha1/conformance_service.ts @@ -580,7 +580,7 @@ export const EvalRequest_BindingsEntry = { writer.uint32(10).string(message.key); } if (message.value !== undefined) { - google.api.expr.v1alpha1.ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); + ExprValue.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -595,7 +595,7 @@ export const EvalRequest_BindingsEntry = { message.key = reader.string(); break; case 2: - message.value = google.api.expr.v1alpha1.ExprValue.decode(reader, reader.uint32()); + message.value = ExprValue.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -607,37 +607,37 @@ export const EvalRequest_BindingsEntry = { fromJSON(object: any): EvalRequest_BindingsEntry { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromJSON(object.value) : undefined }; }, toJSON(message: EvalRequest_BindingsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = message.key); - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): EvalRequest_BindingsEntry { const message = createBaseEvalRequest_BindingsEntry(); message.key = object.key ?? ""; - message.value = object.value !== undefined && object.value !== null ? google.api.expr.v1alpha1.ExprValue.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? ExprValue.fromPartial(object.value) : undefined; return message; }, fromSDK(object: EvalRequest_BindingsEntrySDKType): EvalRequest_BindingsEntry { return { key: object?.key, - value: object.value ? google.api.expr.v1alpha1.ExprValue.fromSDK(object.value) : undefined + value: object.value ? ExprValue.fromSDK(object.value) : undefined }; }, fromSDKJSON(object: any): EvalRequest_BindingsEntrySDKType { return { key: isSet(object.key) ? String(object.key) : "", - value: isSet(object.value) ? google.api.expr.v1alpha1.ExprValue.fromSDKJSON(object.value) : undefined + value: isSet(object.value) ? ExprValue.fromSDKJSON(object.value) : undefined }; }, toSDK(message: EvalRequest_BindingsEntry): EvalRequest_BindingsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.api.expr.v1alpha1.ExprValue.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? ExprValue.toSDK(message.value) : undefined); return obj; } }; diff --git a/__fixtures__/v-next/outputv4/google/logging/v2/logging.ts b/__fixtures__/v-next/outputv4/google/logging/v2/logging.ts index e471cb0d8d..d90a379fd4 100644 --- a/__fixtures__/v-next/outputv4/google/logging/v2/logging.ts +++ b/__fixtures__/v-next/outputv4/google/logging/v2/logging.ts @@ -842,7 +842,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { writer.uint32(8).int32(message.key); } if (message.value !== undefined) { - google.rpc.Status.encode(message.value, writer.uint32(18).fork()).ldelim(); + Status.encode(message.value, writer.uint32(18).fork()).ldelim(); } return writer; }, @@ -857,7 +857,7 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { message.key = reader.int32(); break; case 2: - message.value = google.rpc.Status.decode(reader, reader.uint32()); + message.value = Status.decode(reader, reader.uint32()); break; default: reader.skipType(tag & 7); @@ -869,37 +869,37 @@ export const WriteLogEntriesPartialErrors_LogEntryErrorsEntry = { fromJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromJSON(object.value) : undefined }; }, toJSON(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): unknown { const obj: any = {}; message.key !== undefined && (obj.key = Math.round(message.key)); - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toJSON(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toJSON(message.value) : undefined); return obj; }, fromPartial(object: DeepPartial): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { const message = createBaseWriteLogEntriesPartialErrors_LogEntryErrorsEntry(); message.key = object.key ?? 0; - message.value = object.value !== undefined && object.value !== null ? google.rpc.Status.fromPartial(object.value) : undefined; + message.value = object.value !== undefined && object.value !== null ? Status.fromPartial(object.value) : undefined; return message; }, fromSDK(object: WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType): WriteLogEntriesPartialErrors_LogEntryErrorsEntry { return { key: object?.key, - value: object.value ? google.rpc.Status.fromSDK(object.value) : undefined + value: object.value ? Status.fromSDK(object.value) : undefined }; }, fromSDKJSON(object: any): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { return { key: isSet(object.key) ? Number(object.key) : 0, - value: isSet(object.value) ? google.rpc.Status.fromSDKJSON(object.value) : undefined + value: isSet(object.value) ? Status.fromSDKJSON(object.value) : undefined }; }, toSDK(message: WriteLogEntriesPartialErrors_LogEntryErrorsEntry): WriteLogEntriesPartialErrors_LogEntryErrorsEntrySDKType { const obj: any = {}; obj.key = message.key; - message.value !== undefined && (obj.value = message.value ? google.rpc.Status.toSDK(message.value) : undefined); + message.value !== undefined && (obj.value = message.value ? Status.toSDK(message.value) : undefined); return obj; } }; diff --git a/packages/telescope/__tests__/misc.test.ts b/packages/telescope/__tests__/misc.test.ts new file mode 100644 index 0000000000..79411fdeb3 --- /dev/null +++ b/packages/telescope/__tests__/misc.test.ts @@ -0,0 +1,110 @@ +import { TelescopeBuilder } from "../src/builder"; +import { TelescopeOptions } from "@cosmology/types"; +import { TelescopeInput } from "../src"; + +const outPath = __dirname + "/../../../__fixtures__/misc/output"; + +const options: TelescopeOptions = { + env: "v-next", + removeUnusedImports: false, + classesUseArrowFunctions: false, + + interfaces: { + enabled: false, + useUnionTypes: false, + }, + + prototypes: { + enabled: true, + parser: { + keepCase: false, + }, + methods: { + encode: true, + decode: true, + fromJSON: true, + toJSON: true, + fromPartial: true, + toSDK: true, + fromSDK: true, + fromSDKJSON: true, + toAmino: true, + fromAmino: true, + toProto: true, + fromProto: true, + }, + includePackageVar: true, + fieldDefaultIsOptional: false, + useOptionalNullable: true, + allowUndefinedTypes: false, + typingsFormat: { + customTypes: { + useCosmosSDKDec: true, + }, + num64: "bigint", + useDeepPartial: true, + useExact: false, + timestamp: "date", + duration: "duration", + }, + }, + + bundle: { + enabled: true, + }, + + stargateClients: { + enabled: true, + includeCosmosDefaultTypes: true, + }, + + lcdClients: { + enabled: true, + scopedIsExclusive: false, + }, + + rpcClients: { + enabled: true, + camelCase: true, + scopedIsExclusive: false, + enabledServices: [ + "Msg", + "Query", + "Service", + "ReflectionService", + "ABCIApplication", + ], + }, + + reactQuery: { + enabled: true, + needExtraQueryKey: true, + }, + + mobx: { + enabled: true, + }, + + pinia: { + enabled: true, + }, + + aminoEncoding: { + enabled: true, + useRecursiveV2encoding: true, + }, +}; + +const input: TelescopeInput = { + outPath, + protoDirs: [__dirname + "/../../../__fixtures__/misc/proto"], + options, +}; + +const telescope = new TelescopeBuilder(input); + +describe("misc", () => { + it("generates", async () => { + await telescope.build(); + }); +}); diff --git a/packages/telescope/src/imports.ts b/packages/telescope/src/imports.ts index fdd0553199..570311afa8 100644 --- a/packages/telescope/src/imports.ts +++ b/packages/telescope/src/imports.ts @@ -319,7 +319,7 @@ const addDerivativeTypesToImports = ( }); const foundAmino = context.proto.derivedImports.find(a => { if (a.type !== 'Amino') return false; - if (AminoTypeObject.orig === a.symbol.symbolName) { + if (AminoTypeObject.orig === a.symbol.symbolName && a.symbol.ref && a.symbol.source) { // UNTIL you fix the ImportObjs to have ref... let rel = getRelativePath(a.symbol.ref, a.symbol.source); if (rel === AminoTypeObject.path) { diff --git a/packages/telescope/src/parse.ts b/packages/telescope/src/parse.ts index 789ae13e2b..80a4f70d45 100644 --- a/packages/telescope/src/parse.ts +++ b/packages/telescope/src/parse.ts @@ -50,10 +50,10 @@ const makeKeyTypeObj = (ref: ProtoRef, field: any, scope: string[]) => { }, value: { id: 2, - type: field.parsedType.name, + type: field.type, scope: [...scoped], parsedType: { - name: field.type, + name: field.parsedType.name, type: field.parsedType.type }, comment: undefined,