From 1bbb08e9445951f0127b5e33d582806385688a9d Mon Sep 17 00:00:00 2001 From: Gefei Hou Date: Mon, 25 Nov 2024 18:08:40 +0800 Subject: [PATCH] Added generation for combined clients in root directory, added docs accordingly --- README.md | 66 +++++++++ .../outputinstantrpc/akash-cosmos-client.ts | 84 ++++++++++++ .../outputinstantrpc/cosmos-ibc-client.ts | 69 ++++++++++ packages/telescope/README.md | 66 +++++++++ .../__tests__/telescope-instant-rpc.test.ts | 25 ++++ packages/telescope/src/builder.ts | 13 ++ .../create-combined-stargate-clients.ts | 128 ++++++++++++++++++ .../src/generators/create-stargate-clients.ts | 3 +- .../create-combined-stargate-clients.d.ts | 3 + packages/types/src/telescope.ts | 7 + packages/types/types/telescope.d.ts | 7 + packages/utils/src/proto.ts | 12 ++ packages/utils/types/proto.d.ts | 7 + 13 files changed, 489 insertions(+), 1 deletion(-) create mode 100644 __fixtures__/v-next/outputinstantrpc/akash-cosmos-client.ts create mode 100644 __fixtures__/v-next/outputinstantrpc/cosmos-ibc-client.ts create mode 100644 packages/telescope/src/generators/create-combined-stargate-clients.ts create mode 100644 packages/telescope/types/generators/create-combined-stargate-clients.d.ts diff --git a/README.md b/README.md index c776dad23..9e9efbdd8 100644 --- a/README.md +++ b/README.md @@ -443,6 +443,9 @@ See [LCD Clients](#lcd-clients) for more info. | `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] | | `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` | | `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` | + `rpcClients.combinedClient.name` | assign the client name like `{name}AminoConverters`, `get{name}SigningClient` etc | `undefined` +| `rpcClients.combinedClient.fileName` | assign the file name of generated client in root directory | `undefined` +| `rpcClients.combinedClient.include.patterns` | determine which proto files will be imported for the current client such as `cosmos.gov.v1beta1.**` | `undefined` See [RPC Clients](#rpc-clients) for more info. @@ -1060,6 +1063,69 @@ export class CosmosAuthAccount { } ``` +## Combined Clients Methods + +Using combined option to generate multiple module clients + +For example, for this config: +```js +{ + combinedClient: [ + { + name: "CosmosIbc", + fileName: "cosmos-ibc-client.ts", + include: { + patterns: [ + "cosmos.gov.v1beta1*", + "cosmos.gov.v1*", + "ibc.core.channel.*", + ], + }, + }, + { + name: "AkashCosmos", + fileName: "akash-cosmos-client.ts", + include: { + patterns: [ + "cosmos.group.v1*", + "cosmos.nft.v1beta1*", + "akash.**.v1beta2", + "akash.audit.v1beta1*", + ], + }, + }, + ], +} +``` + +There'll be client files (`cosmos-ibc-client.ts`, `akash-cosmos-client.ts`) generated in the root folder according to fileName in the setting. +The combined client will import proto files accroding to include.patterns. (The protos can come from different modules) +For example the cosmos-ibc-client.ts will be like: +```ts +export const cosmosIbcAminoConverters = { + ...cosmosGovV1TxAmino.AminoConverter, + ...cosmosGovV1beta1TxAmino.AminoConverter, + ...ibcCoreChannelV1TxAmino.AminoConverter +}; +export const cosmosIbcProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [...cosmosGovV1TxRegistry.registry, ...cosmosGovV1beta1TxRegistry.registry, ...ibcCoreChannelV1TxRegistry.registry]; +export const getCosmosIbcSigningClientOptions = ({ + defaultTypes = defaultRegistryTypes +}: { + ... +}; +export const getCosmosIbcSigningClient = async ({ + rpcEndpoint, + signer, + defaultTypes = defaultRegistryTypes +}: { + rpcEndpoint: string | HttpEndpoint; + signer: OfflineSigner; + defaultTypes?: ReadonlyArray<[string, GeneratedType]>; +}) => { + ... +}; +``` + ## Manually registering types This example is with `osmosis` module in `osmojs`, but it is the same pattern for any module. diff --git a/__fixtures__/v-next/outputinstantrpc/akash-cosmos-client.ts b/__fixtures__/v-next/outputinstantrpc/akash-cosmos-client.ts new file mode 100644 index 000000000..ec4b92f2c --- /dev/null +++ b/__fixtures__/v-next/outputinstantrpc/akash-cosmos-client.ts @@ -0,0 +1,84 @@ +import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing"; +import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate"; +import { HttpEndpoint } from "@cosmjs/tendermint-rpc"; +import { createRpcClient } from "./extern"; +import { DeliverTxResponse, EncodeObject, StdFee, TxRpc, SigningClientParams } from "./types"; +import * as akashAuditV1beta1AuditRegistry from "./akash/audit/v1beta1/audit.registry"; +import * as akashAuditV1beta2AuditRegistry from "./akash/audit/v1beta2/audit.registry"; +import * as akashCertV1beta2CertRegistry from "./akash/cert/v1beta2/cert.registry"; +import * as akashDeploymentV1beta2ServiceRegistry from "./akash/deployment/v1beta2/service.registry"; +import * as akashMarketV1beta2ServiceRegistry from "./akash/market/v1beta2/service.registry"; +import * as akashProviderV1beta2ProviderRegistry from "./akash/provider/v1beta2/provider.registry"; +import * as cosmosGroupV1TxRegistry from "./cosmos/group/v1/tx.registry"; +import * as cosmosNftV1beta1TxRegistry from "./cosmos/nft/v1beta1/tx.registry"; +import * as akashAuditV1beta1AuditAmino from "./akash/audit/v1beta1/audit.amino"; +import * as akashAuditV1beta2AuditAmino from "./akash/audit/v1beta2/audit.amino"; +import * as akashCertV1beta2CertAmino from "./akash/cert/v1beta2/cert.amino"; +import * as akashDeploymentV1beta2ServiceAmino from "./akash/deployment/v1beta2/service.amino"; +import * as akashMarketV1beta2ServiceAmino from "./akash/market/v1beta2/service.amino"; +import * as akashProviderV1beta2ProviderAmino from "./akash/provider/v1beta2/provider.amino"; +import * as cosmosGroupV1TxAmino from "./cosmos/group/v1/tx.amino"; +import * as cosmosNftV1beta1TxAmino from "./cosmos/nft/v1beta1/tx.amino"; +export const akashCosmosAminoConverters = { + ...akashAuditV1beta1AuditAmino.AminoConverter, + ...akashAuditV1beta2AuditAmino.AminoConverter, + ...akashCertV1beta2CertAmino.AminoConverter, + ...akashDeploymentV1beta2ServiceAmino.AminoConverter, + ...akashMarketV1beta2ServiceAmino.AminoConverter, + ...akashProviderV1beta2ProviderAmino.AminoConverter, + ...cosmosGroupV1TxAmino.AminoConverter, + ...cosmosNftV1beta1TxAmino.AminoConverter +}; +export const akashCosmosProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [...akashAuditV1beta1AuditRegistry.registry, ...akashAuditV1beta2AuditRegistry.registry, ...akashCertV1beta2CertRegistry.registry, ...akashDeploymentV1beta2ServiceRegistry.registry, ...akashMarketV1beta2ServiceRegistry.registry, ...akashProviderV1beta2ProviderRegistry.registry, ...cosmosGroupV1TxRegistry.registry, ...cosmosNftV1beta1TxRegistry.registry]; +export const getAkashCosmosSigningClientOptions = ({ + defaultTypes = defaultRegistryTypes +}: { + defaultTypes?: ReadonlyArray<[string, GeneratedType]>; +} = {}): { + registry: Registry; + aminoTypes: AminoTypes; +} => { + const registry = new Registry([...defaultTypes, ...akashCosmosProtoRegistry]); + const aminoTypes = new AminoTypes({ + ...akashCosmosAminoConverters + }); + return { + registry, + aminoTypes + }; +}; +export const getAkashCosmosSigningClient = async ({ + rpcEndpoint, + signer, + defaultTypes = defaultRegistryTypes +}: { + rpcEndpoint: string | HttpEndpoint; + signer: OfflineSigner; + defaultTypes?: ReadonlyArray<[string, GeneratedType]>; +}) => { + const { + registry, + aminoTypes + } = getAkashCosmosSigningClientOptions({ + defaultTypes + }); + const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, { + registry: (registry as any), + aminoTypes + }); + return client; +}; +export const getAkashCosmosSigningTxRpc = async ({ + rpcEndpoint, + signer +}: SigningClientParams) => { + let txRpc = (await createRpcClient(rpcEndpoint) as TxRpc); + const signingClient = await getAkashCosmosSigningClient({ + rpcEndpoint, + signer + }); + txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => { + return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise); + }; + return txRpc; +}; \ No newline at end of file diff --git a/__fixtures__/v-next/outputinstantrpc/cosmos-ibc-client.ts b/__fixtures__/v-next/outputinstantrpc/cosmos-ibc-client.ts new file mode 100644 index 000000000..9a98ee7f0 --- /dev/null +++ b/__fixtures__/v-next/outputinstantrpc/cosmos-ibc-client.ts @@ -0,0 +1,69 @@ +import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing"; +import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate"; +import { HttpEndpoint } from "@cosmjs/tendermint-rpc"; +import { createRpcClient } from "./extern"; +import { DeliverTxResponse, EncodeObject, StdFee, TxRpc, SigningClientParams } from "./types"; +import * as cosmosGovV1TxRegistry from "./cosmos/gov/v1/tx.registry"; +import * as cosmosGovV1beta1TxRegistry from "./cosmos/gov/v1beta1/tx.registry"; +import * as ibcCoreChannelV1TxRegistry from "./ibc/core/channel/v1/tx.registry"; +import * as cosmosGovV1TxAmino from "./cosmos/gov/v1/tx.amino"; +import * as cosmosGovV1beta1TxAmino from "./cosmos/gov/v1beta1/tx.amino"; +import * as ibcCoreChannelV1TxAmino from "./ibc/core/channel/v1/tx.amino"; +export const cosmosIbcAminoConverters = { + ...cosmosGovV1TxAmino.AminoConverter, + ...cosmosGovV1beta1TxAmino.AminoConverter, + ...ibcCoreChannelV1TxAmino.AminoConverter +}; +export const cosmosIbcProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [...cosmosGovV1TxRegistry.registry, ...cosmosGovV1beta1TxRegistry.registry, ...ibcCoreChannelV1TxRegistry.registry]; +export const getCosmosIbcSigningClientOptions = ({ + defaultTypes = defaultRegistryTypes +}: { + defaultTypes?: ReadonlyArray<[string, GeneratedType]>; +} = {}): { + registry: Registry; + aminoTypes: AminoTypes; +} => { + const registry = new Registry([...defaultTypes, ...cosmosIbcProtoRegistry]); + const aminoTypes = new AminoTypes({ + ...cosmosIbcAminoConverters + }); + return { + registry, + aminoTypes + }; +}; +export const getCosmosIbcSigningClient = async ({ + rpcEndpoint, + signer, + defaultTypes = defaultRegistryTypes +}: { + rpcEndpoint: string | HttpEndpoint; + signer: OfflineSigner; + defaultTypes?: ReadonlyArray<[string, GeneratedType]>; +}) => { + const { + registry, + aminoTypes + } = getCosmosIbcSigningClientOptions({ + defaultTypes + }); + const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, { + registry: (registry as any), + aminoTypes + }); + return client; +}; +export const getCosmosIbcSigningTxRpc = async ({ + rpcEndpoint, + signer +}: SigningClientParams) => { + let txRpc = (await createRpcClient(rpcEndpoint) as TxRpc); + const signingClient = await getCosmosIbcSigningClient({ + rpcEndpoint, + signer + }); + txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => { + return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise); + }; + return txRpc; +}; \ No newline at end of file diff --git a/packages/telescope/README.md b/packages/telescope/README.md index c776dad23..9e9efbdd8 100644 --- a/packages/telescope/README.md +++ b/packages/telescope/README.md @@ -443,6 +443,9 @@ See [LCD Clients](#lcd-clients) for more info. | `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] | | `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` | | `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` | + `rpcClients.combinedClient.name` | assign the client name like `{name}AminoConverters`, `get{name}SigningClient` etc | `undefined` +| `rpcClients.combinedClient.fileName` | assign the file name of generated client in root directory | `undefined` +| `rpcClients.combinedClient.include.patterns` | determine which proto files will be imported for the current client such as `cosmos.gov.v1beta1.**` | `undefined` See [RPC Clients](#rpc-clients) for more info. @@ -1060,6 +1063,69 @@ export class CosmosAuthAccount { } ``` +## Combined Clients Methods + +Using combined option to generate multiple module clients + +For example, for this config: +```js +{ + combinedClient: [ + { + name: "CosmosIbc", + fileName: "cosmos-ibc-client.ts", + include: { + patterns: [ + "cosmos.gov.v1beta1*", + "cosmos.gov.v1*", + "ibc.core.channel.*", + ], + }, + }, + { + name: "AkashCosmos", + fileName: "akash-cosmos-client.ts", + include: { + patterns: [ + "cosmos.group.v1*", + "cosmos.nft.v1beta1*", + "akash.**.v1beta2", + "akash.audit.v1beta1*", + ], + }, + }, + ], +} +``` + +There'll be client files (`cosmos-ibc-client.ts`, `akash-cosmos-client.ts`) generated in the root folder according to fileName in the setting. +The combined client will import proto files accroding to include.patterns. (The protos can come from different modules) +For example the cosmos-ibc-client.ts will be like: +```ts +export const cosmosIbcAminoConverters = { + ...cosmosGovV1TxAmino.AminoConverter, + ...cosmosGovV1beta1TxAmino.AminoConverter, + ...ibcCoreChannelV1TxAmino.AminoConverter +}; +export const cosmosIbcProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [...cosmosGovV1TxRegistry.registry, ...cosmosGovV1beta1TxRegistry.registry, ...ibcCoreChannelV1TxRegistry.registry]; +export const getCosmosIbcSigningClientOptions = ({ + defaultTypes = defaultRegistryTypes +}: { + ... +}; +export const getCosmosIbcSigningClient = async ({ + rpcEndpoint, + signer, + defaultTypes = defaultRegistryTypes +}: { + rpcEndpoint: string | HttpEndpoint; + signer: OfflineSigner; + defaultTypes?: ReadonlyArray<[string, GeneratedType]>; +}) => { + ... +}; +``` + ## Manually registering types This example is with `osmosis` module in `osmojs`, but it is the same pattern for any module. diff --git a/packages/telescope/__tests__/telescope-instant-rpc.test.ts b/packages/telescope/__tests__/telescope-instant-rpc.test.ts index bfe2b084e..1d3eb19c9 100644 --- a/packages/telescope/__tests__/telescope-instant-rpc.test.ts +++ b/packages/telescope/__tests__/telescope-instant-rpc.test.ts @@ -213,6 +213,31 @@ const options: TelescopeOptions = { }, }, ], + combinedClient: [ + { + name: "CosmosIbc", + fileName: "cosmos-ibc-client.ts", + include: { + patterns: [ + "cosmos.gov.v1beta1*", + "cosmos.gov.v1*", + "ibc.core.channel.*", + ], + }, + }, + { + name: "AkashCosmos", + fileName: "akash-cosmos-client.ts", + include: { + patterns: [ + "cosmos.group.v1*", + "cosmos.nft.v1beta1*", + "akash.**.v1beta2", + "akash.audit.v1beta1*", + ], + }, + }, + ], }, reactQuery: { diff --git a/packages/telescope/src/builder.ts b/packages/telescope/src/builder.ts index e531738fb..61ae06351 100644 --- a/packages/telescope/src/builder.ts +++ b/packages/telescope/src/builder.ts @@ -23,6 +23,7 @@ import { plugin as createMsgFuncs } from './generators/create-msg-funcs'; import { plugin as createReactQueryBundle } from './generators/create-react-query-bundle'; import { plugin as createMobxBundle } from './generators/create-mobx-bundle'; import { plugin as createStargateClients } from './generators/create-stargate-clients'; +import { plugin as createCombinedStargateClients } from './generators/create-combined-stargate-clients'; import { plugin as createBundle } from './generators/create-bundle'; import { plugin as createIndex } from './generators/create-index'; import { plugin as createHelpers } from './generators/create-helpers'; @@ -146,6 +147,8 @@ export class TelescopeBuilder { customizeUtils(this); + const allConverters = []; + const allRegistries = []; // [x] get bundle of all packages const bundles = bundlePackages(this.store).map((bundle) => { // store bundleFile in filesToInclude @@ -171,10 +174,20 @@ export class TelescopeBuilder { // [x] write out one client for each base package, referencing the last two steps createStargateClients(this, bundler); + if (bundler.registries) { + allRegistries.push(...bundler.registries) + } + if (bundler.converters) { + allConverters.push(...bundler.converters) + } return bundler; }); + if (this.options.rpcClients.combinedClient && this.options.rpcClients.combinedClient.length !== 0) { + createCombinedStargateClients(this, allRegistries, allConverters) + } + // post run plugins bundles.forEach((bundler) => { createLCDClientsScoped(this, bundler); diff --git a/packages/telescope/src/generators/create-combined-stargate-clients.ts b/packages/telescope/src/generators/create-combined-stargate-clients.ts new file mode 100644 index 000000000..22d1c5e06 --- /dev/null +++ b/packages/telescope/src/generators/create-combined-stargate-clients.ts @@ -0,0 +1,128 @@ +import { Bundler } from '../bundler'; +import { TelescopeBuilder } from '../builder'; +import { join, dirname, relative } from 'path'; +import { + importNamespace, + GenericParseContext, + createStargateClient, + createStargateClientOptions, + createStargateClientProtoRegistry, + createStargateClientAminoRegistry, + createGetTxRpc +} from '@cosmology/ast'; +import { ProtoRef } from '@cosmology/types'; +import { camel, pascal } from 'case'; +import { duplicateImportPathsWithExt, variableSlug, toPosixPath, isPackageIncluded } from '@cosmology/utils'; +import { buildAllImportsFromGenericContext } from '../imports'; +import { writeAstToFile } from '../utils/files'; +import { BundlerFile } from '../types'; +import minimatch from "minimatch"; + +export const plugin = ( + builder: TelescopeBuilder, + allRegistries: BundlerFile[], + allConverters: BundlerFile[] +) => { + builder.options.rpcClients.combinedClient.map((currentClient) => { + + if (!allRegistries || !allRegistries.length) { + return; + } + + const registryImports = []; + const converterImports = []; + + const clientFile = currentClient.fileName + const ctxRef: ProtoRef = { + absolute: '/', + filename: '/', + proto: { + imports: [], + package: currentClient.name, + root: {}, + } + }; + const ctx = new GenericParseContext(ctxRef, null, builder.options); + + const registryVariables = []; + const converterVariables = []; + const filteredRegistries = allRegistries.filter(item => + isPackageIncluded(item.package, currentClient.include.patterns) + ); + filteredRegistries.forEach(registry => { + let rel = relative(dirname(clientFile), registry.localname); + if (!rel.startsWith('.')) rel = `./${rel}`; + rel = toPosixPath(rel) + const variable = variableSlug(registry.localname); + registryVariables.push(variable); + registryImports.push(importNamespace(variable, rel)); + }); + + const filteredConverters = allConverters.filter(item => + isPackageIncluded(item.package, currentClient.include.patterns) + ); + filteredConverters.forEach(converter => { + let rel = relative(dirname(clientFile), converter.localname); + if (!rel.startsWith('.')) rel = `./${rel}`; + rel = toPosixPath(rel) + const variable = variableSlug(converter.localname); + converterVariables.push(variable); + converterImports.push(importNamespace(variable, rel)); + }); + const name = 'get' + pascal(currentClient.name + 'SigningClient'); + const txRpcName = 'get' + pascal(currentClient.name + 'SigningTxRpc'); + const prefix = camel(currentClient.name); + const aminos = createStargateClientAminoRegistry({ + context: ctx, + aminos: converterVariables, + aminoConverters: prefix + 'AminoConverters' + }); + const protos = createStargateClientProtoRegistry({ + context: ctx, + registries: registryVariables, + protoTypeRegistry: prefix + 'ProtoRegistry' + }); + const clientOptions = createStargateClientOptions({ + context: ctx, + name: name + 'Options', + protoTypeRegistry: prefix + 'ProtoRegistry', + aminoConverters: prefix + 'AminoConverters' + }); + const clientBody = createStargateClient({ + context: ctx, + name, + options: name + 'Options', + }); + + let getTxRpc; + + if (ctx.pluginValue("stargateClients.addGetTxRpc")) { + getTxRpc = createGetTxRpc(ctx, txRpcName, name); + } + + const imports = buildAllImportsFromGenericContext(ctx, clientFile); + + let importDecls = [...imports, ...registryImports, ...converterImports]; + + importDecls = duplicateImportPathsWithExt(importDecls, builder.options.restoreImportExtension); + + let cProg = importDecls + .concat(aminos) + .concat(protos) + .concat(clientOptions) + .concat(clientBody); + + // replace all backslash path for windows + for (let i = 0; i < cProg.length; i++) { + if (cProg[i].source?.value) { + cProg[i].source.value = toPosixPath(cProg[i].source?.value) + } + } + + if (getTxRpc) { + cProg = cProg.concat(getTxRpc); + } + const clientOutFile = join(builder.outPath, clientFile); + writeAstToFile(builder.outPath, builder.options, cProg, clientOutFile); + }) +}; diff --git a/packages/telescope/src/generators/create-stargate-clients.ts b/packages/telescope/src/generators/create-stargate-clients.ts index c173898cf..807f44d2b 100644 --- a/packages/telescope/src/generators/create-stargate-clients.ts +++ b/packages/telescope/src/generators/create-stargate-clients.ts @@ -47,6 +47,7 @@ export const plugin = ( bundler.registries.forEach(registry => { let rel = relative(dirname(clientFile), registry.localname); if (!rel.startsWith('.')) rel = `./${rel}`; + rel = toPosixPath(rel) const variable = variableSlug(registry.localname); registryVariables.push(variable); registryImports.push(importNamespace(variable, rel)); @@ -55,6 +56,7 @@ export const plugin = ( bundler.converters.forEach(converter => { let rel = relative(dirname(clientFile), converter.localname); if (!rel.startsWith('.')) rel = `./${rel}`; + rel = toPosixPath(rel) const variable = variableSlug(converter.localname); converterVariables.push(variable); converterImports.push(importNamespace(variable, rel)); @@ -113,7 +115,6 @@ export const plugin = ( if (getTxRpc) { cProg = cProg.concat(getTxRpc); } - const clientOutFile = join(builder.outPath, clientFile); bundler.writeAst(cProg, clientOutFile); diff --git a/packages/telescope/types/generators/create-combined-stargate-clients.d.ts b/packages/telescope/types/generators/create-combined-stargate-clients.d.ts new file mode 100644 index 000000000..3ec94a9eb --- /dev/null +++ b/packages/telescope/types/generators/create-combined-stargate-clients.d.ts @@ -0,0 +1,3 @@ +import { TelescopeBuilder } from '../builder'; +import { BundlerFile } from '../types'; +export declare const plugin: (builder: TelescopeBuilder, allRegistries: BundlerFile[], allConverters: BundlerFile[]) => void; diff --git a/packages/types/src/telescope.ts b/packages/types/src/telescope.ts index eec768dfe..3fadc45eb 100644 --- a/packages/types/src/telescope.ts +++ b/packages/types/src/telescope.ts @@ -278,6 +278,13 @@ export interface TelescopeOpts { }; }[]; useConnectComet?: boolean; + combinedClient?: { + name: string; + fileName: string; + include?: { + patterns?: string[]; + }; + }[]; }; helperFuncCreators?: { enabled: boolean; diff --git a/packages/types/types/telescope.d.ts b/packages/types/types/telescope.d.ts index 49d60aad2..c47f9ac39 100644 --- a/packages/types/types/telescope.d.ts +++ b/packages/types/types/telescope.d.ts @@ -225,6 +225,13 @@ export interface TelescopeOpts { }; }[]; useConnectComet?: boolean; + combinedClient?: { + name: string; + fileName: string; + include?: { + patterns?: string[]; + }; + }[]; }; helperFuncCreators?: { enabled: boolean; diff --git a/packages/utils/src/proto.ts b/packages/utils/src/proto.ts index aa74ec32c..bc2980544 100644 --- a/packages/utils/src/proto.ts +++ b/packages/utils/src/proto.ts @@ -165,6 +165,18 @@ export const isRefIncluded = ( return false; }; +/** + * test if a package is included in certain pattern. + * @param input is a package. + * @param patterns to match the package + * @returns bool + */ +export const isPackageIncluded = (input, patterns)=>{ + return patterns.some(pattern => { + return minimatch(input, pattern) +}) +} + /** * test if a proto ref is excluded from the operation. * @param ref a ProtoRef with proto file info and package. diff --git a/packages/utils/types/proto.d.ts b/packages/utils/types/proto.d.ts index a6bfd31ef..4247b4d4a 100644 --- a/packages/utils/types/proto.d.ts +++ b/packages/utils/types/proto.d.ts @@ -36,6 +36,13 @@ export declare const isRefIncluded: (ref: ProtoRef, include?: { packages?: string[]; protos?: string[]; }) => boolean; +/** + * test if a package is included in certain pattern. + * @param input is a package. + * @param patterns to match the package + * @returns bool + */ +export declare const isPackageIncluded: (input: any, patterns: any) => any; /** * test if a proto ref is excluded from the operation. * @param ref a ProtoRef with proto file info and package.