@hyperweb/telescope 1.15.2 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,43 @@
1
1
  export const externalIcJs = `
2
2
  import { HttpEndpoint } from "@interchainjs/types";
3
- import {
4
- createQueryRpc,
5
- } from '@interchainjs/utils';
6
3
  import { Rpc } from "./helpers";
4
+ import { ClientOptions, createCosmosQueryClient } from "@interchainjs/cosmos";
7
5
 
8
6
  const _rpcClients: Record<string, Rpc> = {};
9
7
 
10
8
  export const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => {
11
- if (typeof rpcEndpoint === 'string') {
12
- return rpcEndpoint;
13
- } else if (!!rpcEndpoint) {
14
- //@ts-ignore
15
- return rpcEndpoint.url;
16
- }
9
+ if (typeof rpcEndpoint === 'string') {
10
+ return rpcEndpoint;
11
+ } else if (!!rpcEndpoint) {
12
+ //@ts-ignore
13
+ return rpcEndpoint.url;
14
+ }
17
15
  }
18
16
 
19
17
  export const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {
20
- const key = getRpcEndpointKey(rpcEndpoint);
21
- if (!key) return;
22
- if (_rpcClients.hasOwnProperty(key)) {
23
- return _rpcClients[key];
24
- }
25
- const rpc = await createRpcClient(rpcEndpoint);
26
- _rpcClients[key] = rpc;
27
- return rpc;
18
+ const key = getRpcEndpointKey(rpcEndpoint);
19
+ if (!key) return;
20
+ if (_rpcClients.hasOwnProperty(key)) {
21
+ return _rpcClients[key];
22
+ }
23
+ const rpc = await createRpcClient(rpcEndpoint);
24
+ _rpcClients[key] = rpc;
25
+ return rpc;
28
26
  }
29
27
 
30
- export const createRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {
31
- return createQueryRpc(rpcEndpoint)
28
+ export const createRpcClient = async (rpcEndpoint: string | HttpEndpoint,
29
+ options?: ClientOptions
30
+ ) => {
31
+ if (typeof rpcEndpoint === 'string') {
32
+ return createCosmosQueryClient(rpcEndpoint, options);
33
+ } else {
34
+ const endpointStr = rpcEndpoint.url;
35
+ const clientOptions = {
36
+ ...options,
37
+ headers: rpcEndpoint.headers
38
+ };
39
+
40
+ return createCosmosQueryClient(endpointStr, clientOptions);
41
+ }
32
42
  }
33
43
  `;
@@ -0,0 +1,21 @@
1
+ export const generatedType = `import { BinaryReader, BinaryWriter } from "../../../binary";
2
+
3
+ /**
4
+ * A type generated by Telescope 1.0.
5
+ */
6
+ export interface TelescopeGeneratedType {
7
+ readonly typeUrl: string;
8
+ readonly encode: (
9
+ message:
10
+ | any
11
+ | {
12
+ [k: string]: any;
13
+ },
14
+ writer?: BinaryWriter
15
+ ) => BinaryWriter;
16
+ readonly decode: (input: BinaryReader | Uint8Array, length?: number) => any;
17
+ readonly fromPartial: (object: any) => any;
18
+ }
19
+
20
+ export type GeneratedType = TelescopeGeneratedType;
21
+ `;
@@ -0,0 +1,245 @@
1
+ export const internalForBigInt = `
2
+ declare var self: any | undefined;
3
+ declare var window: any | undefined;
4
+ declare var global: any | undefined;
5
+ var globalThis: any = (() => {
6
+ if (typeof globalThis !== 'undefined') return globalThis;
7
+ if (typeof self !== 'undefined') return self;
8
+ if (typeof window !== 'undefined') return window;
9
+ if (typeof global !== 'undefined') return global;
10
+ throw 'Unable to locate global object';
11
+ })();
12
+
13
+ const atob: (b64: string) => string =
14
+ globalThis.atob ||
15
+ ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
16
+
17
+ export function bytesFromBase64(b64: string): Uint8Array {
18
+ const bin = atob(b64);
19
+ const arr = new Uint8Array(bin.length);
20
+ for (let i = 0; i < bin.length; ++i) {
21
+ arr[i] = bin.charCodeAt(i);
22
+ }
23
+ return arr;
24
+ }
25
+
26
+ const btoa: (bin: string) => string =
27
+ globalThis.btoa ||
28
+ ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
29
+
30
+ export function base64FromBytes(arr: Uint8Array): string {
31
+ const bin: string[] = [];
32
+ arr.forEach((byte) => {
33
+ bin.push(String.fromCharCode(byte));
34
+ });
35
+ return btoa(bin.join(''));
36
+ }
37
+
38
+ export interface AminoHeight {
39
+ readonly revision_number?: string;
40
+ readonly revision_height?: string;
41
+ }
42
+
43
+ export function omitDefault<T extends string | number | bigint>(
44
+ input: T
45
+ ): T | undefined {
46
+ if (typeof input === 'string') {
47
+ return input === '' ? undefined : input;
48
+ }
49
+
50
+ if (typeof input === 'number') {
51
+ return input === 0 ? undefined : input;
52
+ }
53
+
54
+ if (typeof input === 'bigint') {
55
+ return input === BigInt(0) ? undefined : input;
56
+ }
57
+
58
+ throw new Error(\`Got unsupported type \${typeof input}\`);
59
+ }
60
+
61
+ interface Duration {
62
+ /**
63
+ * Signed seconds of the span of time. Must be from -315,576,000,000
64
+ * to +315,576,000,000 inclusive. Note: these bounds are computed from:
65
+ * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
66
+ */
67
+ seconds: bigint;
68
+ /**
69
+ * Signed fractions of a second at nanosecond resolution of the span
70
+ * of time. Durations less than one second are represented with a 0
71
+ * \`seconds\` field and a positive or negative \`nanos\` field. For durations
72
+ * of one second or more, a non-zero value for the \`nanos\` field must be
73
+ * of the same sign as the \`seconds\` field. Must be from -999,999,999
74
+ * to +999,999,999 inclusive.
75
+ */
76
+
77
+ nanos: number;
78
+ }
79
+
80
+ export function toDuration(duration: string): Duration {
81
+ return {
82
+ seconds: BigInt(Math.floor(parseInt(duration) / 1000000000)),
83
+ nanos: parseInt(duration) % 1000000000
84
+ };
85
+ }
86
+
87
+ export function fromDuration(duration: Duration): string {
88
+ return (
89
+ parseInt(duration.seconds.toString()) * 1000000000 +
90
+ duration.nanos
91
+ ).toString();
92
+ }
93
+
94
+ export function isSet(value: any): boolean {
95
+ return value !== null && value !== undefined;
96
+ }
97
+
98
+ export function isObject(value: any): boolean {
99
+ return typeof value === 'object' && value !== null;
100
+ }
101
+
102
+ export interface PageRequest {
103
+ key: Uint8Array;
104
+ offset: bigint;
105
+ limit: bigint;
106
+ countTotal: boolean;
107
+ reverse: boolean;
108
+ }
109
+
110
+ export interface PageRequestParams {
111
+ 'pagination.key'?: string;
112
+ 'pagination.offset'?: string;
113
+ 'pagination.limit'?: string;
114
+ 'pagination.count_total'?: boolean;
115
+ 'pagination.reverse'?: boolean;
116
+ }
117
+
118
+ export interface Params {
119
+ params: PageRequestParams;
120
+ }
121
+
122
+ export const setPaginationParams = (
123
+ options: Params,
124
+ pagination?: PageRequest
125
+ ) => {
126
+ if (!pagination) {
127
+ return options;
128
+ }
129
+
130
+ if (typeof pagination?.countTotal !== 'undefined') {
131
+ options.params['pagination.count_total'] = pagination.countTotal;
132
+ }
133
+ if (typeof pagination?.key !== 'undefined') {
134
+ // String to Uint8Array
135
+ // let uint8arr = new Uint8Array(Buffer.from(data,'base64'));
136
+
137
+ // Uint8Array to String
138
+ options.params['pagination.key'] = Buffer.from(pagination.key).toString(
139
+ 'base64'
140
+ );
141
+ }
142
+ if (typeof pagination?.limit !== 'undefined') {
143
+ options.params['pagination.limit'] = pagination.limit.toString();
144
+ }
145
+ if (typeof pagination?.offset !== 'undefined') {
146
+ options.params['pagination.offset'] = pagination.offset.toString();
147
+ }
148
+ if (typeof pagination?.reverse !== 'undefined') {
149
+ options.params['pagination.reverse'] = pagination.reverse;
150
+ }
151
+
152
+ return options;
153
+ };
154
+
155
+ type Builtin =
156
+ | Date
157
+ | Function
158
+ | Uint8Array
159
+ | string
160
+ | number
161
+ | bigint
162
+ | boolean
163
+ | undefined;
164
+
165
+ export type DeepPartial<T> = T extends Builtin
166
+ ? T
167
+ : T extends Array<infer U>
168
+ ? Array<DeepPartial<U>>
169
+ : T extends ReadonlyArray<infer U>
170
+ ? ReadonlyArray<DeepPartial<U>>
171
+ : T extends {}
172
+ ? { [K in keyof T]?: DeepPartial<T[K]> }
173
+ : Partial<T>;
174
+
175
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
176
+ export type Exact<P, I extends P> = P extends Builtin
177
+ ? P
178
+ : P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
179
+ Exclude<keyof I, KeysOfUnion<P>>,
180
+ never
181
+ >;
182
+
183
+ export interface Rpc {
184
+ request(
185
+ service: string,
186
+ method: string,
187
+ data: Uint8Array
188
+ ): Promise<Uint8Array>;
189
+ }
190
+
191
+ interface Timestamp {
192
+ /**
193
+ * Represents seconds of UTC time since Unix epoch
194
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
195
+ * 9999-12-31T23:59:59Z inclusive.
196
+ */
197
+ seconds: bigint;
198
+ /**
199
+ * Non-negative fractions of a second at nanosecond resolution. Negative
200
+ * second values with fractions must still have non-negative nanos values
201
+ * that count forward in time. Must be from 0 to 999,999,999
202
+ * inclusive.
203
+ */
204
+
205
+ nanos: number;
206
+ }
207
+
208
+ export function toTimestamp(date: Date): Timestamp {
209
+ const seconds = numberToLong(date.getTime() / 1_000);
210
+ const nanos = (date.getTime() % 1000) * 1000000;
211
+ return {
212
+ seconds,
213
+ nanos
214
+ };
215
+ }
216
+
217
+ export function fromTimestamp(t: Timestamp): Date {
218
+ let millis = Number(t.seconds) * 1000;
219
+ millis += t.nanos / 1000000;
220
+ return new Date(millis);
221
+ }
222
+
223
+ const timestampFromJSON = (object: any): Timestamp => {
224
+ return {
225
+ seconds: isSet(object.seconds)
226
+ ? BigInt(object.seconds.toString())
227
+ : BigInt(0),
228
+ nanos: isSet(object.nanos) ? Number(object.nanos) : 0
229
+ };
230
+ };
231
+
232
+ export function fromJsonTimestamp(o: any): Timestamp {
233
+ if (o instanceof Date) {
234
+ return toTimestamp(o);
235
+ } else if (typeof o === 'string') {
236
+ return toTimestamp(new Date(o));
237
+ } else {
238
+ return timestampFromJSON(o);
239
+ }
240
+ }
241
+
242
+ function numberToLong(number: number) {
243
+ return BigInt(Math.trunc(number));
244
+ }
245
+ `;
@@ -0,0 +1,21 @@
1
+ export const types = `import { BinaryReader, BinaryWriter } from "../../../binary";
2
+
3
+ /**
4
+ * A type generated by Telescope 1.0.
5
+ */
6
+ export interface TelescopeGeneratedType {
7
+ readonly typeUrl: string;
8
+ readonly encode: (
9
+ message:
10
+ | any
11
+ | {
12
+ [k: string]: any;
13
+ },
14
+ writer?: BinaryWriter
15
+ ) => BinaryWriter;
16
+ readonly decode: (input: BinaryReader | Uint8Array, length?: number) => any;
17
+ readonly fromPartial: (object: any) => any;
18
+ }
19
+
20
+ export type GeneratedType = TelescopeGeneratedType;
21
+ `;
@@ -0,0 +1,87 @@
1
+ export const getVueQueryHelper = (options) => {
2
+ return `import { getRpcClient } from './extern${options.restoreImportExtension ?? ""}'
3
+ import {
4
+ useQuery,
5
+ UseQueryOptions,
6
+ } from '@tanstack/vue-query';
7
+ import { Ref, isRef } from 'vue'
8
+
9
+ import { HttpEndpoint, ProtobufRpcClient } from '@cosmjs/stargate';
10
+ ${options.rpcClients.useConnectComet
11
+ ? "import { CometClient, connectComet, Tendermint34Client, Tendermint37Client } from '@cosmjs/tendermint-rpc';"
12
+ : "import { Tendermint34Client } from '@cosmjs/tendermint-rpc';"}
13
+
14
+ export interface VueQueryParams<TResponse, TData = TResponse> {
15
+ options?: Omit<UseQueryOptions<TData, Error, TData>, 'queryKey'>;
16
+ }
17
+
18
+ export interface UseRpcClientQuery<TData> extends VueQueryParams<ProtobufRpcClient, TData> {
19
+ rpcEndpoint: Ref<string | HttpEndpoint>;
20
+ }
21
+
22
+ export interface UseRpcEndpointQuery<TData> extends VueQueryParams<string | HttpEndpoint, TData> {
23
+ getter: () => Promise<string | HttpEndpoint>;
24
+ }
25
+
26
+ export const useRpcEndpoint = <TData = string | HttpEndpoint>({
27
+ getter,
28
+ options,
29
+ }: UseRpcEndpointQuery<TData>) => {
30
+ return useQuery<string | HttpEndpoint, Error, TData>({
31
+ queryKey: ['rpcEndpoint', getter],
32
+ queryFn: async () => {
33
+ return await getter();
34
+ },
35
+ ...options
36
+ })
37
+ };
38
+
39
+ export const useRpcClient = <TData = ProtobufRpcClient>({
40
+ rpcEndpoint,
41
+ options,
42
+ }: UseRpcClientQuery<TData>) => {
43
+ let params = {
44
+ queryKey: ['rpcClient', rpcEndpoint],
45
+ queryFn: async () => {
46
+ return await getRpcClient(rpcEndpoint.value);
47
+ },
48
+ };
49
+ if (options && !isRef(options)) {
50
+ params = {
51
+ ...options,
52
+ ...params,
53
+ };
54
+ }
55
+ return useQuery<ProtobufRpcClient | undefined, Error, TData>(params);
56
+ };
57
+
58
+ ${options.rpcClients.useConnectComet
59
+ ? "interface UseTendermintClient extends VueQueryParams<Tendermint34Client | Tendermint37Client | CometClient> {"
60
+ : "interface UseTendermintClient extends VueQueryParams<Tendermint34Client> {"}
61
+ rpcEndpoint: Ref<string | HttpEndpoint>;
62
+ }
63
+
64
+ /**
65
+ * Hook that uses vue-query to cache a connected tendermint client.
66
+ */
67
+ export const useTendermintClient = ({
68
+ rpcEndpoint,
69
+ options,
70
+ }: UseTendermintClient) => {
71
+ ${options.rpcClients.useConnectComet
72
+ ? " const { data: client } = useQuery<Tendermint34Client | Tendermint37Client | CometClient, Error, Tendermint34Client | Tendermint37Client | CometClient>("
73
+ : " const { data: client } = useQuery<Tendermint34Client, Error, Tendermint34Client>({"}
74
+ queryKey: ['client', 'tendermint', rpcEndpoint],
75
+ queryFn: () => ${options.rpcClients.useConnectComet
76
+ ? "connectComet(rpcEndpoint.value),"
77
+ : "Tendermint34Client.connect(rpcEndpoint.value),"}
78
+ // allow overriding
79
+ throwOnError: (e) => {
80
+ throw new Error(\`Failed to connect to \${rpcEndpoint}\` + '\\n' + e)
81
+ },
82
+ ...options,
83
+ })
84
+ return { client }
85
+ };
86
+ `;
87
+ };
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import { clone, extractProto } from "./recursive";
3
+ import { removeFolder } from "./utils";
4
+ async function run() {
5
+ const argv = process.argv.slice(2);
6
+ const gitRepoIndex = argv.findIndex((arg) => arg === "--git-repo");
7
+ if (gitRepoIndex === -1) {
8
+ process.stderr.write("`git-repo` is not specified");
9
+ process.exit(1);
10
+ }
11
+ const [owner, repo] = argv[gitRepoIndex + 1]?.split("/");
12
+ if (!owner || !repo) {
13
+ process.stderr.write("wrong `git-repo` format (i.e. <owner>/<repository>).");
14
+ process.exit(1);
15
+ }
16
+ const targetsIndex = argv.findIndex((arg) => arg === "--targets");
17
+ if (targetsIndex === -1) {
18
+ process.stdout.write("`targets` is not specified");
19
+ process.exit(1);
20
+ }
21
+ const targets = argv[targetsIndex + 1]?.split(",");
22
+ if (!targets || targets.length === 0) {
23
+ process.stderr.write("wrong `targets` format (i.e. <**/*.proto>,<**/*.proto>,<**/*.proto>).");
24
+ process.exit(1);
25
+ }
26
+ const outDirIndex = argv.findIndex((arg) => arg === "--out");
27
+ if (outDirIndex === -1) {
28
+ process.stdout.write("`out` is not specified, downloading to `proto` folder by default.\n");
29
+ }
30
+ const outDir = outDirIndex !== -1 ? argv[outDirIndex + 1] : "./proto";
31
+ const omitCloneIndex = argv.findIndex((arg) => arg === "--omit-clone");
32
+ let omitClone = false;
33
+ if (omitCloneIndex !== -1 && argv[omitCloneIndex + 1] === "true") {
34
+ omitClone = true;
35
+ }
36
+ if (omitCloneIndex !== -1 &&
37
+ typeof argv[omitCloneIndex + 1] === "undefined") {
38
+ omitClone = true;
39
+ }
40
+ removeFolder("git-modules");
41
+ const result = await clone({
42
+ owner,
43
+ repo,
44
+ outDir: "./git-modules",
45
+ });
46
+ if (result) {
47
+ removeFolder(outDir);
48
+ extractProto({
49
+ sources: result,
50
+ targets,
51
+ outDir,
52
+ });
53
+ }
54
+ }
55
+ run();
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperweb/telescope",
3
- "version": "1.15.2",
3
+ "version": "1.17.0",
4
4
  "description": "A TypeScript Transpiler for Cosmos Protobufs",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/hyperweb-io/telescope/tree/master/packages/telescope#readme",
@@ -90,10 +90,10 @@
90
90
  "@babel/parser": "^7.23.6",
91
91
  "@babel/traverse": "7.23.6",
92
92
  "@babel/types": "7.23.6",
93
- "@cosmology/ast": "^1.11.2",
94
- "@cosmology/proto-parser": "^1.10.10",
95
- "@cosmology/types": "^1.12.6",
96
- "@cosmology/utils": "^1.10.8",
93
+ "@cosmology/ast": "^1.12.0",
94
+ "@cosmology/proto-parser": "^1.11.0",
95
+ "@cosmology/types": "^1.13.0",
96
+ "@cosmology/utils": "^1.11.0",
97
97
  "@cosmwasm/ts-codegen": "0.35.7",
98
98
  "@types/parse-package-name": "0.1.0",
99
99
  "case": "1.6.3",
@@ -111,5 +111,5 @@
111
111
  "rimraf": "5.0.0",
112
112
  "yaml": "^2.3.4"
113
113
  },
114
- "gitHead": "47f7e41efbcf1fed47d33fe22a105efc799cf91b"
114
+ "gitHead": "4c0ea11d1549f6a91c3b14a7b8a9f8b5a023ae09"
115
115
  }