@hyperweb/telescope 2.0.1 → 2.0.2

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,248 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.internalForBigInt = void 0;
4
- exports.internalForBigInt = `
5
- declare var self: any | undefined;
6
- declare var window: any | undefined;
7
- declare var global: any | undefined;
8
- var globalThis: any = (() => {
9
- if (typeof globalThis !== 'undefined') return globalThis;
10
- if (typeof self !== 'undefined') return self;
11
- if (typeof window !== 'undefined') return window;
12
- if (typeof global !== 'undefined') return global;
13
- throw 'Unable to locate global object';
14
- })();
15
-
16
- const atob: (b64: string) => string =
17
- globalThis.atob ||
18
- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
19
-
20
- export function bytesFromBase64(b64: string): Uint8Array {
21
- const bin = atob(b64);
22
- const arr = new Uint8Array(bin.length);
23
- for (let i = 0; i < bin.length; ++i) {
24
- arr[i] = bin.charCodeAt(i);
25
- }
26
- return arr;
27
- }
28
-
29
- const btoa: (bin: string) => string =
30
- globalThis.btoa ||
31
- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
32
-
33
- export function base64FromBytes(arr: Uint8Array): string {
34
- const bin: string[] = [];
35
- arr.forEach((byte) => {
36
- bin.push(String.fromCharCode(byte));
37
- });
38
- return btoa(bin.join(''));
39
- }
40
-
41
- export interface AminoHeight {
42
- readonly revision_number?: string;
43
- readonly revision_height?: string;
44
- }
45
-
46
- export function omitDefault<T extends string | number | bigint>(
47
- input: T
48
- ): T | undefined {
49
- if (typeof input === 'string') {
50
- return input === '' ? undefined : input;
51
- }
52
-
53
- if (typeof input === 'number') {
54
- return input === 0 ? undefined : input;
55
- }
56
-
57
- if (typeof input === 'bigint') {
58
- return input === BigInt(0) ? undefined : input;
59
- }
60
-
61
- throw new Error(\`Got unsupported type \${typeof input}\`);
62
- }
63
-
64
- interface Duration {
65
- /**
66
- * Signed seconds of the span of time. Must be from -315,576,000,000
67
- * to +315,576,000,000 inclusive. Note: these bounds are computed from:
68
- * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
69
- */
70
- seconds: bigint;
71
- /**
72
- * Signed fractions of a second at nanosecond resolution of the span
73
- * of time. Durations less than one second are represented with a 0
74
- * \`seconds\` field and a positive or negative \`nanos\` field. For durations
75
- * of one second or more, a non-zero value for the \`nanos\` field must be
76
- * of the same sign as the \`seconds\` field. Must be from -999,999,999
77
- * to +999,999,999 inclusive.
78
- */
79
-
80
- nanos: number;
81
- }
82
-
83
- export function toDuration(duration: string): Duration {
84
- return {
85
- seconds: BigInt(Math.floor(parseInt(duration) / 1000000000)),
86
- nanos: parseInt(duration) % 1000000000
87
- };
88
- }
89
-
90
- export function fromDuration(duration: Duration): string {
91
- return (
92
- parseInt(duration.seconds.toString()) * 1000000000 +
93
- duration.nanos
94
- ).toString();
95
- }
96
-
97
- export function isSet(value: any): boolean {
98
- return value !== null && value !== undefined;
99
- }
100
-
101
- export function isObject(value: any): boolean {
102
- return typeof value === 'object' && value !== null;
103
- }
104
-
105
- export interface PageRequest {
106
- key: Uint8Array;
107
- offset: bigint;
108
- limit: bigint;
109
- countTotal: boolean;
110
- reverse: boolean;
111
- }
112
-
113
- export interface PageRequestParams {
114
- 'pagination.key'?: string;
115
- 'pagination.offset'?: string;
116
- 'pagination.limit'?: string;
117
- 'pagination.count_total'?: boolean;
118
- 'pagination.reverse'?: boolean;
119
- }
120
-
121
- export interface Params {
122
- params: PageRequestParams;
123
- }
124
-
125
- export const setPaginationParams = (
126
- options: Params,
127
- pagination?: PageRequest
128
- ) => {
129
- if (!pagination) {
130
- return options;
131
- }
132
-
133
- if (typeof pagination?.countTotal !== 'undefined') {
134
- options.params['pagination.count_total'] = pagination.countTotal;
135
- }
136
- if (typeof pagination?.key !== 'undefined') {
137
- // String to Uint8Array
138
- // let uint8arr = new Uint8Array(Buffer.from(data,'base64'));
139
-
140
- // Uint8Array to String
141
- options.params['pagination.key'] = Buffer.from(pagination.key).toString(
142
- 'base64'
143
- );
144
- }
145
- if (typeof pagination?.limit !== 'undefined') {
146
- options.params['pagination.limit'] = pagination.limit.toString();
147
- }
148
- if (typeof pagination?.offset !== 'undefined') {
149
- options.params['pagination.offset'] = pagination.offset.toString();
150
- }
151
- if (typeof pagination?.reverse !== 'undefined') {
152
- options.params['pagination.reverse'] = pagination.reverse;
153
- }
154
-
155
- return options;
156
- };
157
-
158
- type Builtin =
159
- | Date
160
- | Function
161
- | Uint8Array
162
- | string
163
- | number
164
- | bigint
165
- | boolean
166
- | undefined;
167
-
168
- export type DeepPartial<T> = T extends Builtin
169
- ? T
170
- : T extends Array<infer U>
171
- ? Array<DeepPartial<U>>
172
- : T extends ReadonlyArray<infer U>
173
- ? ReadonlyArray<DeepPartial<U>>
174
- : T extends {}
175
- ? { [K in keyof T]?: DeepPartial<T[K]> }
176
- : Partial<T>;
177
-
178
- type KeysOfUnion<T> = T extends T ? keyof T : never;
179
- export type Exact<P, I extends P> = P extends Builtin
180
- ? P
181
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
182
- Exclude<keyof I, KeysOfUnion<P>>,
183
- never
184
- >;
185
-
186
- export interface Rpc {
187
- request(
188
- service: string,
189
- method: string,
190
- data: Uint8Array
191
- ): Promise<Uint8Array>;
192
- }
193
-
194
- interface Timestamp {
195
- /**
196
- * Represents seconds of UTC time since Unix epoch
197
- * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
198
- * 9999-12-31T23:59:59Z inclusive.
199
- */
200
- seconds: bigint;
201
- /**
202
- * Non-negative fractions of a second at nanosecond resolution. Negative
203
- * second values with fractions must still have non-negative nanos values
204
- * that count forward in time. Must be from 0 to 999,999,999
205
- * inclusive.
206
- */
207
-
208
- nanos: number;
209
- }
210
-
211
- export function toTimestamp(date: Date): Timestamp {
212
- const seconds = numberToLong(date.getTime() / 1_000);
213
- const nanos = (date.getTime() % 1000) * 1000000;
214
- return {
215
- seconds,
216
- nanos
217
- };
218
- }
219
-
220
- export function fromTimestamp(t: Timestamp): Date {
221
- let millis = Number(t.seconds) * 1000;
222
- millis += t.nanos / 1000000;
223
- return new Date(millis);
224
- }
225
-
226
- const timestampFromJSON = (object: any): Timestamp => {
227
- return {
228
- seconds: isSet(object.seconds)
229
- ? BigInt(object.seconds.toString())
230
- : BigInt(0),
231
- nanos: isSet(object.nanos) ? Number(object.nanos) : 0
232
- };
233
- };
234
-
235
- export function fromJsonTimestamp(o: any): Timestamp {
236
- if (o instanceof Date) {
237
- return toTimestamp(o);
238
- } else if (typeof o === 'string') {
239
- return toTimestamp(new Date(o));
240
- } else {
241
- return timestampFromJSON(o);
242
- }
243
- }
244
-
245
- function numberToLong(number: number) {
246
- return BigInt(Math.trunc(number));
247
- }
248
- `;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.types = void 0;
4
- exports.types = `import { BinaryReader, BinaryWriter } from "../../../binary";
5
-
6
- /**
7
- * A type generated by Telescope 1.0.
8
- */
9
- export interface TelescopeGeneratedType {
10
- readonly typeUrl: string;
11
- readonly encode: (
12
- message:
13
- | any
14
- | {
15
- [k: string]: any;
16
- },
17
- writer?: BinaryWriter
18
- ) => BinaryWriter;
19
- readonly decode: (input: BinaryReader | Uint8Array, length?: number) => any;
20
- readonly fromPartial: (object: any) => any;
21
- }
22
-
23
- export type GeneratedType = TelescopeGeneratedType;
24
- `;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVueQueryHelper = void 0;
4
- const getVueQueryHelper = (options) => {
5
- return `import { getRpcClient } from './extern${options.restoreImportExtension ?? ""}'
6
- import {
7
- useQuery,
8
- UseQueryOptions,
9
- } from '@tanstack/vue-query';
10
- import { Ref, isRef } from 'vue'
11
-
12
- import { HttpEndpoint, ProtobufRpcClient } from '@cosmjs/stargate';
13
- ${options.rpcClients.useConnectComet
14
- ? "import { CometClient, connectComet, Tendermint34Client, Tendermint37Client } from '@cosmjs/tendermint-rpc';"
15
- : "import { Tendermint34Client } from '@cosmjs/tendermint-rpc';"}
16
-
17
- export interface VueQueryParams<TResponse, TData = TResponse> {
18
- options?: Omit<UseQueryOptions<TData, Error, TData>, 'queryKey'>;
19
- }
20
-
21
- export interface UseRpcClientQuery<TData> extends VueQueryParams<ProtobufRpcClient, TData> {
22
- rpcEndpoint: Ref<string | HttpEndpoint>;
23
- }
24
-
25
- export interface UseRpcEndpointQuery<TData> extends VueQueryParams<string | HttpEndpoint, TData> {
26
- getter: () => Promise<string | HttpEndpoint>;
27
- }
28
-
29
- export const useRpcEndpoint = <TData = string | HttpEndpoint>({
30
- getter,
31
- options,
32
- }: UseRpcEndpointQuery<TData>) => {
33
- return useQuery<string | HttpEndpoint, Error, TData>({
34
- queryKey: ['rpcEndpoint', getter],
35
- queryFn: async () => {
36
- return await getter();
37
- },
38
- ...options
39
- })
40
- };
41
-
42
- export const useRpcClient = <TData = ProtobufRpcClient>({
43
- rpcEndpoint,
44
- options,
45
- }: UseRpcClientQuery<TData>) => {
46
- let params = {
47
- queryKey: ['rpcClient', rpcEndpoint],
48
- queryFn: async () => {
49
- return await getRpcClient(rpcEndpoint.value);
50
- },
51
- };
52
- if (options && !isRef(options)) {
53
- params = {
54
- ...options,
55
- ...params,
56
- };
57
- }
58
- return useQuery<ProtobufRpcClient | undefined, Error, TData>(params);
59
- };
60
-
61
- ${options.rpcClients.useConnectComet
62
- ? "interface UseTendermintClient extends VueQueryParams<Tendermint34Client | Tendermint37Client | CometClient> {"
63
- : "interface UseTendermintClient extends VueQueryParams<Tendermint34Client> {"}
64
- rpcEndpoint: Ref<string | HttpEndpoint>;
65
- }
66
-
67
- /**
68
- * Hook that uses vue-query to cache a connected tendermint client.
69
- */
70
- export const useTendermintClient = ({
71
- rpcEndpoint,
72
- options,
73
- }: UseTendermintClient) => {
74
- ${options.rpcClients.useConnectComet
75
- ? " const { data: client } = useQuery<Tendermint34Client | Tendermint37Client | CometClient, Error, Tendermint34Client | Tendermint37Client | CometClient>("
76
- : " const { data: client } = useQuery<Tendermint34Client, Error, Tendermint34Client>({"}
77
- queryKey: ['client', 'tendermint', rpcEndpoint],
78
- queryFn: () => ${options.rpcClients.useConnectComet
79
- ? "connectComet(rpcEndpoint.value),"
80
- : "Tendermint34Client.connect(rpcEndpoint.value),"}
81
- // allow overriding
82
- throwOnError: (e) => {
83
- throw new Error(\`Failed to connect to \${rpcEndpoint}\` + '\\n' + e)
84
- },
85
- ...options,
86
- })
87
- return { client }
88
- };
89
- `;
90
- };
91
- exports.getVueQueryHelper = getVueQueryHelper;
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const recursive_1 = require("./recursive");
5
- const utils_1 = require("./utils");
6
- async function run() {
7
- const argv = process.argv.slice(2);
8
- const gitRepoIndex = argv.findIndex((arg) => arg === "--git-repo");
9
- if (gitRepoIndex === -1) {
10
- process.stderr.write("`git-repo` is not specified");
11
- process.exit(1);
12
- }
13
- const [owner, repo] = argv[gitRepoIndex + 1]?.split("/");
14
- if (!owner || !repo) {
15
- process.stderr.write("wrong `git-repo` format (i.e. <owner>/<repository>).");
16
- process.exit(1);
17
- }
18
- const targetsIndex = argv.findIndex((arg) => arg === "--targets");
19
- if (targetsIndex === -1) {
20
- process.stdout.write("`targets` is not specified");
21
- process.exit(1);
22
- }
23
- const targets = argv[targetsIndex + 1]?.split(",");
24
- if (!targets || targets.length === 0) {
25
- process.stderr.write("wrong `targets` format (i.e. <**/*.proto>,<**/*.proto>,<**/*.proto>).");
26
- process.exit(1);
27
- }
28
- const outDirIndex = argv.findIndex((arg) => arg === "--out");
29
- if (outDirIndex === -1) {
30
- process.stdout.write("`out` is not specified, downloading to `proto` folder by default.\n");
31
- }
32
- const outDir = outDirIndex !== -1 ? argv[outDirIndex + 1] : "./proto";
33
- const omitCloneIndex = argv.findIndex((arg) => arg === "--omit-clone");
34
- let omitClone = false;
35
- if (omitCloneIndex !== -1 && argv[omitCloneIndex + 1] === "true") {
36
- omitClone = true;
37
- }
38
- if (omitCloneIndex !== -1 &&
39
- typeof argv[omitCloneIndex + 1] === "undefined") {
40
- omitClone = true;
41
- }
42
- (0, utils_1.removeFolder)("git-modules");
43
- const result = await (0, recursive_1.clone)({
44
- owner,
45
- repo,
46
- outDir: "./git-modules",
47
- });
48
- if (result) {
49
- (0, utils_1.removeFolder)(outDir);
50
- (0, recursive_1.extractProto)({
51
- sources: result,
52
- targets,
53
- outDir,
54
- });
55
- }
56
- }
57
- run();
@@ -1,95 +0,0 @@
1
- import { join, dirname, relative } from 'path';
2
- import { importNamespace, GenericParseContext, createStargateClient, createStargateClientOptions, createStargateClientProtoRegistry, createStargateClientAminoRegistry, createGetTxRpc } from '@cosmology/ast';
3
- import { camel, pascal } from 'case';
4
- import { duplicateImportPathsWithExt, variableSlug, toPosixPath, isPackageIncluded } from '@cosmology/utils';
5
- import { buildAllImportsFromGenericContext } from '../imports';
6
- import { writeAstToFile } from '../utils/files';
7
- export const plugin = (builder, allRegistries, allConverters) => {
8
- builder.options.rpcClients.combinedClient.map((currentClient) => {
9
- if (!allRegistries || !allRegistries.length) {
10
- return;
11
- }
12
- const registryImports = [];
13
- const converterImports = [];
14
- const clientFile = currentClient.fileName;
15
- const ctxRef = {
16
- absolute: '/',
17
- filename: '/',
18
- proto: {
19
- imports: [],
20
- package: currentClient.name,
21
- root: {},
22
- }
23
- };
24
- const ctx = new GenericParseContext(ctxRef, null, builder.options);
25
- const registryVariables = [];
26
- const converterVariables = [];
27
- const filteredRegistries = allRegistries.filter(item => isPackageIncluded(item.package, currentClient.include.patterns));
28
- filteredRegistries.forEach(registry => {
29
- let rel = relative(dirname(clientFile), registry.localname);
30
- if (!rel.startsWith('.'))
31
- rel = `./${rel}`;
32
- rel = toPosixPath(rel);
33
- const variable = variableSlug(registry.localname);
34
- registryVariables.push(variable);
35
- registryImports.push(importNamespace(variable, rel));
36
- });
37
- const filteredConverters = allConverters.filter(item => isPackageIncluded(item.package, currentClient.include.patterns));
38
- filteredConverters.forEach(converter => {
39
- let rel = relative(dirname(clientFile), converter.localname);
40
- if (!rel.startsWith('.'))
41
- rel = `./${rel}`;
42
- rel = toPosixPath(rel);
43
- const variable = variableSlug(converter.localname);
44
- converterVariables.push(variable);
45
- converterImports.push(importNamespace(variable, rel));
46
- });
47
- const name = 'get' + pascal(currentClient.name + 'SigningClient');
48
- const txRpcName = 'get' + pascal(currentClient.name + 'SigningTxRpc');
49
- const prefix = camel(currentClient.name);
50
- const aminos = createStargateClientAminoRegistry({
51
- context: ctx,
52
- aminos: converterVariables,
53
- aminoConverters: prefix + 'AminoConverters'
54
- });
55
- const protos = createStargateClientProtoRegistry({
56
- context: ctx,
57
- registries: registryVariables,
58
- protoTypeRegistry: prefix + 'ProtoRegistry'
59
- });
60
- const clientOptions = createStargateClientOptions({
61
- context: ctx,
62
- name: name + 'Options',
63
- protoTypeRegistry: prefix + 'ProtoRegistry',
64
- aminoConverters: prefix + 'AminoConverters'
65
- });
66
- const clientBody = createStargateClient({
67
- context: ctx,
68
- name,
69
- options: name + 'Options',
70
- });
71
- let getTxRpc;
72
- if (ctx.pluginValue("stargateClients.addGetTxRpc")) {
73
- getTxRpc = createGetTxRpc(ctx, txRpcName, name);
74
- }
75
- const imports = buildAllImportsFromGenericContext(ctx, clientFile);
76
- let importDecls = [...imports, ...registryImports, ...converterImports];
77
- importDecls = duplicateImportPathsWithExt(importDecls, builder.options.restoreImportExtension);
78
- let cProg = importDecls
79
- .concat(aminos)
80
- .concat(protos)
81
- .concat(clientOptions)
82
- .concat(clientBody);
83
- // replace all backslash path for windows
84
- for (let i = 0; i < cProg.length; i++) {
85
- if (cProg[i].source?.value) {
86
- cProg[i].source.value = toPosixPath(cProg[i].source?.value);
87
- }
88
- }
89
- if (getTxRpc) {
90
- cProg = cProg.concat(getTxRpc);
91
- }
92
- const clientOutFile = join(builder.outPath, clientFile);
93
- writeAstToFile(builder.outPath, builder.options, cProg, clientOutFile);
94
- });
95
- };
@@ -1,21 +0,0 @@
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
- `;