@hyperweb/telescope 1.15.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.
- package/README.md +1529 -0
- package/main/build.js +183 -0
- package/main/builder.js +229 -0
- package/main/bundle.js +162 -0
- package/main/bundler.js +100 -0
- package/main/cli.js +71 -0
- package/main/cmds.js +28 -0
- package/main/commands/download.js +122 -0
- package/main/commands/generate.js +151 -0
- package/main/commands/install.js +143 -0
- package/main/commands/transpile.js +197 -0
- package/main/contracts/generate.js +31 -0
- package/main/contracts/install.js +107 -0
- package/main/contracts/message-composer.js +31 -0
- package/main/contracts/react-query.js +31 -0
- package/main/contracts/recoil.js +31 -0
- package/main/file.js +20 -0
- package/main/generators/create-aggregated-lcd-client.js +87 -0
- package/main/generators/create-all-stargate-clients.js +96 -0
- package/main/generators/create-amino-converters.js +43 -0
- package/main/generators/create-bundle.js +83 -0
- package/main/generators/create-cosmwasm-bundle.js +15 -0
- package/main/generators/create-custom-stargate-clients.js +100 -0
- package/main/generators/create-helpers.js +119 -0
- package/main/generators/create-index.js +75 -0
- package/main/generators/create-lcd-client-all.js +116 -0
- package/main/generators/create-lcd-client-scoped.js +89 -0
- package/main/generators/create-lcd-clients.js +78 -0
- package/main/generators/create-mcp-server.js +1853 -0
- package/main/generators/create-mobx-bundle.js +52 -0
- package/main/generators/create-msg-funcs.js +132 -0
- package/main/generators/create-pinia-store-bundle.js +50 -0
- package/main/generators/create-pinia-store.js +90 -0
- package/main/generators/create-query-funcs.js +133 -0
- package/main/generators/create-react-query-bundle.js +103 -0
- package/main/generators/create-registries.js +49 -0
- package/main/generators/create-root-readme.js +259 -0
- package/main/generators/create-rpc-msg-client-all.js +135 -0
- package/main/generators/create-rpc-msg-client-scoped.js +114 -0
- package/main/generators/create-rpc-msg-clients.js +116 -0
- package/main/generators/create-rpc-ops-bundle.js +119 -0
- package/main/generators/create-rpc-query-client-all.js +137 -0
- package/main/generators/create-rpc-query-client-scoped.js +110 -0
- package/main/generators/create-rpc-query-clients.js +198 -0
- package/main/generators/create-sdk-module-stargate-clients.js +95 -0
- package/main/generators/create-stargate-clients.js +96 -0
- package/main/generators/create-types.js +164 -0
- package/main/generators/customize-utils.js +50 -0
- package/main/helpers/__test__/internalTimestamp.js +49 -0
- package/main/helpers/__test__/internalTimestampBigint.js +45 -0
- package/main/helpers/binary-coder.js +535 -0
- package/main/helpers/decimals.js +111 -0
- package/main/helpers/external-comet.js +52 -0
- package/main/helpers/external-icjs.js +36 -0
- package/main/helpers/external.js +31 -0
- package/main/helpers/grpc-gateway.js +348 -0
- package/main/helpers/grpc-web.js +14 -0
- package/main/helpers/helper-func-types-interface.js +106 -0
- package/main/helpers/helper-func-types.js +93 -0
- package/main/helpers/index.js +38 -0
- package/main/helpers/internal-for-bigint.js +259 -0
- package/main/helpers/internal.js +240 -0
- package/main/helpers/json-safe.js +12 -0
- package/main/helpers/mobx.js +80 -0
- package/main/helpers/pinia-endpoint.js +20 -0
- package/main/helpers/react-query-hooks-icjs.js +223 -0
- package/main/helpers/react-query-hooks.js +258 -0
- package/main/helpers/react-query.js +93 -0
- package/main/helpers/registry-helper.js +229 -0
- package/main/helpers/types-helper.js +165 -0
- package/main/helpers/utf8-helper.js +146 -0
- package/main/helpers/varint.js +486 -0
- package/main/helpers/vue-query-hooks.js +226 -0
- package/main/imports.js +416 -0
- package/main/index.js +24 -0
- package/main/parse.js +194 -0
- package/main/prompt.js +64 -0
- package/main/protod/bufbuild.js +87 -0
- package/main/protod/config.js +30 -0
- package/main/protod/git-repo.js +58 -0
- package/main/protod/index.js +17 -0
- package/main/protod/recursive.js +134 -0
- package/main/protod/types.js +2 -0
- package/main/protod/utils.js +91 -0
- package/main/telescope.js +10 -0
- package/main/types.js +2 -0
- package/main/utils/common-create-bundle.js +29 -0
- package/main/utils/contracts.js +39 -0
- package/main/utils/files.js +138 -0
- package/main/utils/index.js +163 -0
- package/main/utils/unused.js +73 -0
- package/module/build.js +176 -0
- package/module/builder.js +222 -0
- package/module/bundle.js +128 -0
- package/module/bundler.js +96 -0
- package/module/cli.js +44 -0
- package/module/cmds.js +22 -0
- package/module/commands/download.js +94 -0
- package/module/commands/generate.js +123 -0
- package/module/commands/install.js +141 -0
- package/module/commands/transpile.js +169 -0
- package/module/contracts/generate.js +29 -0
- package/module/contracts/install.js +105 -0
- package/module/contracts/message-composer.js +29 -0
- package/module/contracts/react-query.js +29 -0
- package/module/contracts/recoil.js +29 -0
- package/module/file.js +18 -0
- package/module/generators/create-aggregated-lcd-client.js +83 -0
- package/module/generators/create-all-stargate-clients.js +92 -0
- package/module/generators/create-amino-converters.js +39 -0
- package/module/generators/create-bundle.js +79 -0
- package/module/generators/create-cosmwasm-bundle.js +11 -0
- package/module/generators/create-custom-stargate-clients.js +96 -0
- package/module/generators/create-helpers.js +112 -0
- package/module/generators/create-index.js +45 -0
- package/module/generators/create-lcd-client-all.js +89 -0
- package/module/generators/create-lcd-client-scoped.js +62 -0
- package/module/generators/create-lcd-clients.js +74 -0
- package/module/generators/create-mcp-server.js +1849 -0
- package/module/generators/create-mobx-bundle.js +25 -0
- package/module/generators/create-msg-funcs.js +128 -0
- package/module/generators/create-pinia-store-bundle.js +23 -0
- package/module/generators/create-pinia-store.js +86 -0
- package/module/generators/create-query-funcs.js +129 -0
- package/module/generators/create-react-query-bundle.js +76 -0
- package/module/generators/create-registries.js +45 -0
- package/module/generators/create-root-readme.js +255 -0
- package/module/generators/create-rpc-msg-client-all.js +108 -0
- package/module/generators/create-rpc-msg-client-scoped.js +87 -0
- package/module/generators/create-rpc-msg-clients.js +112 -0
- package/module/generators/create-rpc-ops-bundle.js +92 -0
- package/module/generators/create-rpc-query-client-all.js +110 -0
- package/module/generators/create-rpc-query-client-scoped.js +83 -0
- package/module/generators/create-rpc-query-clients.js +198 -0
- package/module/generators/create-sdk-module-stargate-clients.js +91 -0
- package/module/generators/create-stargate-clients.js +92 -0
- package/module/generators/create-types.js +137 -0
- package/module/generators/customize-utils.js +46 -0
- package/module/helpers/__test__/internalTimestamp.js +39 -0
- package/module/helpers/__test__/internalTimestampBigint.js +38 -0
- package/module/helpers/binary-coder.js +531 -0
- package/module/helpers/decimals.js +108 -0
- package/module/helpers/external-comet.js +49 -0
- package/module/helpers/external-icjs.js +33 -0
- package/module/helpers/external.js +28 -0
- package/module/helpers/grpc-gateway.js +345 -0
- package/module/helpers/grpc-web.js +11 -0
- package/module/helpers/helper-func-types-interface.js +102 -0
- package/module/helpers/helper-func-types.js +89 -0
- package/module/helpers/index.js +22 -0
- package/module/helpers/internal-for-bigint.js +255 -0
- package/module/helpers/internal.js +236 -0
- package/module/helpers/json-safe.js +9 -0
- package/module/helpers/mobx.js +77 -0
- package/module/helpers/pinia-endpoint.js +17 -0
- package/module/helpers/react-query-hooks-icjs.js +219 -0
- package/module/helpers/react-query-hooks.js +254 -0
- package/module/helpers/react-query.js +89 -0
- package/module/helpers/registry-helper.js +225 -0
- package/module/helpers/types-helper.js +161 -0
- package/module/helpers/utf8-helper.js +143 -0
- package/module/helpers/varint.js +483 -0
- package/module/helpers/vue-query-hooks.js +222 -0
- package/module/imports.js +382 -0
- package/module/index.js +8 -0
- package/module/parse.js +185 -0
- package/module/prompt.js +58 -0
- package/module/protod/bufbuild.js +76 -0
- package/module/protod/config.js +27 -0
- package/module/protod/git-repo.js +54 -0
- package/module/protod/index.js +1 -0
- package/module/protod/recursive.js +125 -0
- package/module/protod/types.js +1 -0
- package/module/protod/utils.js +77 -0
- package/module/telescope.js +8 -0
- package/module/types.js +1 -0
- package/module/utils/common-create-bundle.js +25 -0
- package/module/utils/contracts.js +33 -0
- package/module/utils/files.js +106 -0
- package/module/utils/index.js +143 -0
- package/module/utils/unused.js +47 -0
- package/package.json +115 -0
- package/src/build.ts +255 -0
- package/src/builder.ts +302 -0
- package/src/bundle.ts +160 -0
- package/src/bundler.ts +153 -0
- package/src/cli.js +51 -0
- package/src/cmds.js +25 -0
- package/src/commands/download.ts +120 -0
- package/src/commands/generate.ts +156 -0
- package/src/commands/install.ts +154 -0
- package/src/commands/transpile.ts +198 -0
- package/src/contracts/generate.ts +33 -0
- package/src/contracts/install.ts +118 -0
- package/src/contracts/message-composer.ts +34 -0
- package/src/contracts/react-query.ts +33 -0
- package/src/contracts/recoil.ts +32 -0
- package/src/file.js +20 -0
- package/src/generators/create-aggregated-lcd-client.ts +133 -0
- package/src/generators/create-all-stargate-clients.ts +121 -0
- package/src/generators/create-amino-converters.ts +62 -0
- package/src/generators/create-bundle.ts +97 -0
- package/src/generators/create-cosmwasm-bundle.ts +17 -0
- package/src/generators/create-custom-stargate-clients.ts +128 -0
- package/src/generators/create-helpers.ts +196 -0
- package/src/generators/create-index.ts +72 -0
- package/src/generators/create-lcd-client-all.ts +139 -0
- package/src/generators/create-lcd-client-scoped.ts +109 -0
- package/src/generators/create-lcd-clients.ts +108 -0
- package/src/generators/create-mcp-server.ts +1902 -0
- package/src/generators/create-mobx-bundle.ts +31 -0
- package/src/generators/create-msg-funcs.ts +219 -0
- package/src/generators/create-pinia-store-bundle.ts +35 -0
- package/src/generators/create-pinia-store.ts +121 -0
- package/src/generators/create-query-funcs.ts +224 -0
- package/src/generators/create-react-query-bundle.ts +111 -0
- package/src/generators/create-registries.ts +70 -0
- package/src/generators/create-root-readme.ts +316 -0
- package/src/generators/create-rpc-msg-client-all.ts +167 -0
- package/src/generators/create-rpc-msg-client-scoped.ts +147 -0
- package/src/generators/create-rpc-msg-clients.ts +165 -0
- package/src/generators/create-rpc-ops-bundle.ts +155 -0
- package/src/generators/create-rpc-query-client-all.ts +173 -0
- package/src/generators/create-rpc-query-client-scoped.ts +142 -0
- package/src/generators/create-rpc-query-clients.ts +304 -0
- package/src/generators/create-sdk-module-stargate-clients.ts +120 -0
- package/src/generators/create-stargate-clients.ts +123 -0
- package/src/generators/create-types.ts +236 -0
- package/src/generators/customize-utils.ts +54 -0
- package/src/helpers/__test__/internalTimestamp.test.ts +79 -0
- package/src/helpers/__test__/internalTimestamp.ts +58 -0
- package/src/helpers/__test__/internalTimestampBigint.test.ts +78 -0
- package/src/helpers/__test__/internalTimestampBigint.ts +58 -0
- package/src/helpers/binary-coder.ts +533 -0
- package/src/helpers/decimals.ts +108 -0
- package/src/helpers/external-comet.ts +49 -0
- package/src/helpers/external-icjs.ts +33 -0
- package/src/helpers/external.ts +28 -0
- package/src/helpers/grpc-gateway.ts +345 -0
- package/src/helpers/grpc-web.ts +11 -0
- package/src/helpers/helper-func-types-interface.ts +104 -0
- package/src/helpers/helper-func-types.ts +91 -0
- package/src/helpers/index.ts +22 -0
- package/src/helpers/internal-for-bigint.ts +257 -0
- package/src/helpers/internal.ts +238 -0
- package/src/helpers/json-safe.ts +11 -0
- package/src/helpers/mobx.ts +77 -0
- package/src/helpers/pinia-endpoint.ts +17 -0
- package/src/helpers/react-query-hooks-icjs.ts +223 -0
- package/src/helpers/react-query-hooks.ts +266 -0
- package/src/helpers/react-query.ts +101 -0
- package/src/helpers/registry-helper.ts +227 -0
- package/src/helpers/types-helper.ts +169 -0
- package/src/helpers/utf8-helper.ts +143 -0
- package/src/helpers/varint.ts +483 -0
- package/src/helpers/vue-query-hooks.ts +224 -0
- package/src/imports.ts +499 -0
- package/src/index.ts +12 -0
- package/src/parse.ts +243 -0
- package/src/prompt.js +65 -0
- package/src/protod/bufbuild.spec.ts +80 -0
- package/src/protod/bufbuild.ts +95 -0
- package/src/protod/config.ts +30 -0
- package/src/protod/git-repo.ts +74 -0
- package/src/protod/index.ts +1 -0
- package/src/protod/recursive.spec.ts +164 -0
- package/src/protod/recursive.ts +180 -0
- package/src/protod/test-data/.protod.config.json +42 -0
- package/src/protod/test-data/buf.lock +23 -0
- package/src/protod/test-data/buf.yaml +25 -0
- package/src/protod/test-data/buf2.yaml +20 -0
- package/src/protod/test-data/cosmos/buf.lock +23 -0
- package/src/protod/test-data/cosmos/crypto/secp256k1/keys.proto +38 -0
- package/src/protod/test-data/model.proto +101 -0
- package/src/protod/types.ts +55 -0
- package/src/protod/utils.spec.ts +68 -0
- package/src/protod/utils.ts +90 -0
- package/src/telescope.js +9 -0
- package/src/types.ts +46 -0
- package/src/utils/common-create-bundle.ts +62 -0
- package/src/utils/contracts.ts +37 -0
- package/src/utils/files.ts +145 -0
- package/src/utils/index.ts +150 -0
- package/src/utils/unused.ts +52 -0
- package/types/build.d.ts +41 -0
- package/types/builder.d.ts +50 -0
- package/types/bundle.d.ts +30 -0
- package/types/bundler.d.ts +31 -0
- package/types/cli.d.ts +1 -0
- package/types/cmds.d.ts +11 -0
- package/types/commands/download.d.ts +5 -0
- package/types/commands/generate.d.ts +2 -0
- package/types/commands/install.d.ts +2 -0
- package/types/commands/transpile.d.ts +4 -0
- package/types/contracts/generate.d.ts +2 -0
- package/types/contracts/install.d.ts +2 -0
- package/types/contracts/message-composer.d.ts +2 -0
- package/types/contracts/react-query.d.ts +2 -0
- package/types/contracts/recoil.d.ts +2 -0
- package/types/file.d.ts +2 -0
- package/types/generators/create-aggregated-lcd-client.d.ts +2 -0
- package/types/generators/create-all-stargate-clients.d.ts +3 -0
- package/types/generators/create-amino-converters.d.ts +3 -0
- package/types/generators/create-bundle.d.ts +3 -0
- package/types/generators/create-combined-stargate-clients.d.ts +3 -0
- package/types/generators/create-cosmwasm-bundle.d.ts +2 -0
- package/types/generators/create-custom-stargate-clients.d.ts +3 -0
- package/types/generators/create-helpers.d.ts +2 -0
- package/types/generators/create-index.d.ts +2 -0
- package/types/generators/create-lcd-client-all.d.ts +3 -0
- package/types/generators/create-lcd-client-scoped.d.ts +3 -0
- package/types/generators/create-lcd-clients.d.ts +3 -0
- package/types/generators/create-mcp-server.d.ts +3 -0
- package/types/generators/create-mobx-bundle.d.ts +2 -0
- package/types/generators/create-msg-funcs.d.ts +3 -0
- package/types/generators/create-pinia-store-bundle.d.ts +2 -0
- package/types/generators/create-pinia-store.d.ts +3 -0
- package/types/generators/create-query-funcs.d.ts +3 -0
- package/types/generators/create-react-query-bundle.d.ts +2 -0
- package/types/generators/create-registries.d.ts +3 -0
- package/types/generators/create-root-readme.d.ts +2 -0
- package/types/generators/create-rpc-msg-client-all.d.ts +3 -0
- package/types/generators/create-rpc-msg-client-scoped.d.ts +3 -0
- package/types/generators/create-rpc-msg-clients.d.ts +3 -0
- package/types/generators/create-rpc-ops-bundle.d.ts +2 -0
- package/types/generators/create-rpc-query-client-all.d.ts +3 -0
- package/types/generators/create-rpc-query-client-scoped.d.ts +3 -0
- package/types/generators/create-rpc-query-clients.d.ts +3 -0
- package/types/generators/create-scoped-stargate-clients.d.ts +3 -0
- package/types/generators/create-sdk-module-stargate-clients.d.ts +3 -0
- package/types/generators/create-stargate-clients.d.ts +3 -0
- package/types/generators/create-types.d.ts +3 -0
- package/types/generators/create-unified-stargate-clients.d.ts +3 -0
- package/types/generators/customize-utils.d.ts +2 -0
- package/types/helpers/__test__/internalTimestamp.d.ts +21 -0
- package/types/helpers/__test__/internalTimestampBigint.d.ts +20 -0
- package/types/helpers/binary-coder.d.ts +2 -0
- package/types/helpers/decimals.d.ts +1 -0
- package/types/helpers/external-comet.d.ts +1 -0
- package/types/helpers/external-icjs.d.ts +1 -0
- package/types/helpers/external.d.ts +1 -0
- package/types/helpers/generated-type.d.ts +1 -0
- package/types/helpers/grpc-gateway.d.ts +1 -0
- package/types/helpers/grpc-web.d.ts +1 -0
- package/types/helpers/helper-func-types-interface.d.ts +2 -0
- package/types/helpers/helper-func-types.d.ts +2 -0
- package/types/helpers/index.d.ts +22 -0
- package/types/helpers/internal-for-bigint.d.ts +2 -0
- package/types/helpers/internal.d.ts +2 -0
- package/types/helpers/internalForBigInt.d.ts +1 -0
- package/types/helpers/json-safe.d.ts +1 -0
- package/types/helpers/mobx.d.ts +1 -0
- package/types/helpers/pinia-endpoint.d.ts +1 -0
- package/types/helpers/react-query-hooks-icjs.d.ts +2 -0
- package/types/helpers/react-query-hooks.d.ts +2 -0
- package/types/helpers/react-query.d.ts +2 -0
- package/types/helpers/registry-helper.d.ts +2 -0
- package/types/helpers/types-helper.d.ts +2 -0
- package/types/helpers/types.d.ts +1 -0
- package/types/helpers/utf8-helper.d.ts +1 -0
- package/types/helpers/varint.d.ts +1 -0
- package/types/helpers/vue-query-hooks.d.ts +2 -0
- package/types/helpers/vue-query.d.ts +2 -0
- package/types/imports.d.ts +17 -0
- package/types/index.d.ts +6 -0
- package/types/parse.d.ts +15 -0
- package/types/prompt.d.ts +3 -0
- package/types/protod/bufbuild.d.ts +6 -0
- package/types/protod/config.d.ts +7 -0
- package/types/protod/git-repo.d.ts +11 -0
- package/types/protod/index.d.ts +1 -0
- package/types/protod/proto-download.d.ts +2 -0
- package/types/protod/recursive.d.ts +4 -0
- package/types/protod/types.d.ts +49 -0
- package/types/protod/utils.d.ts +11 -0
- package/types/telescope.d.ts +2 -0
- package/types/types.d.ts +43 -0
- package/types/utils/common-create-bundle.d.ts +18 -0
- package/types/utils/contracts.d.ts +6 -0
- package/types/utils/files.d.ts +5 -0
- package/types/utils/index.d.ts +16 -0
- package/types/utils/unused.d.ts +5 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { writeContentToFile } from "../utils/files";
|
|
2
|
+
import { join, basename } from "path";
|
|
3
|
+
import { makeAliasNameWithPackageAtEnd } from "@cosmology/utils";
|
|
4
|
+
/**
|
|
5
|
+
* Gets the aliased function name if it's duplicated across multiple files
|
|
6
|
+
*/
|
|
7
|
+
function getAliasedFunctionName(builder, functionName, packageName) {
|
|
8
|
+
const duplicatedHelperFuncs = builder.store.getHelperFuncsInMultipleFiles();
|
|
9
|
+
const isDuplicated = duplicatedHelperFuncs.includes(functionName);
|
|
10
|
+
if (isDuplicated) {
|
|
11
|
+
const serialNumber = builder.store.getAndIncTypeSerialNumber(functionName);
|
|
12
|
+
if (serialNumber > 0) {
|
|
13
|
+
return makeAliasNameWithPackageAtEnd({ package: packageName, name: functionName });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return functionName;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Cleans up comments by removing lint directives and technical annotations
|
|
20
|
+
*/
|
|
21
|
+
function cleanComment(comment) {
|
|
22
|
+
if (!comment)
|
|
23
|
+
return comment;
|
|
24
|
+
// Remove lint directives and technical annotations
|
|
25
|
+
const cleanedComment = comment
|
|
26
|
+
// Remove buf:lint:ignore directives
|
|
27
|
+
.replace(/buf:lint:ignore\s+[A-Z_]+/gi, '')
|
|
28
|
+
// Remove other common lint directives
|
|
29
|
+
.replace(/lint:ignore[:\s]+[A-Z_]+/gi, '')
|
|
30
|
+
// Remove protolint directives
|
|
31
|
+
.replace(/protolint:disable[:\s]+[A-Z_]+/gi, '')
|
|
32
|
+
// Remove eslint directives
|
|
33
|
+
.replace(/eslint-disable[:\s-]+[a-z-]+/gi, '')
|
|
34
|
+
// Remove multiple consecutive spaces
|
|
35
|
+
.replace(/\s+/g, ' ')
|
|
36
|
+
// Remove leading/trailing whitespace
|
|
37
|
+
.trim();
|
|
38
|
+
return cleanedComment;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets the project name from the output path
|
|
42
|
+
*/
|
|
43
|
+
function getProjectName(outPath) {
|
|
44
|
+
return basename(outPath);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the appropriate import path for a function, considering bundle exports
|
|
48
|
+
*/
|
|
49
|
+
function getImportPath(builder, functionName, packageName, projectName, sourceFilename) {
|
|
50
|
+
const duplicatedHelperFuncs = builder.store.getHelperFuncsInMultipleFiles();
|
|
51
|
+
const isDuplicated = duplicatedHelperFuncs.includes(functionName);
|
|
52
|
+
// If the function is duplicated (and thus potentially aliased), it should be available in the bundle
|
|
53
|
+
if (isDuplicated) {
|
|
54
|
+
// Check the aliased function name to see if it would be different
|
|
55
|
+
const aliasedName = getAliasedFunctionName(builder, functionName, packageName);
|
|
56
|
+
if (aliasedName !== functionName) {
|
|
57
|
+
// Extract the top-level package name (e.g., 'akash' from 'akash.audit.v1beta2')
|
|
58
|
+
const topLevelPackage = packageName.split('.')[0];
|
|
59
|
+
// Function is aliased and should be available in bundle
|
|
60
|
+
return `${projectName}/${topLevelPackage}/bundle`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// If we have source filename info, use the full file path
|
|
64
|
+
// This handles all functions with specific file locations
|
|
65
|
+
if (sourceFilename) {
|
|
66
|
+
// Remove .ts extension and convert to proper import path
|
|
67
|
+
const filePath = sourceFilename.replace(/\.ts$/, '');
|
|
68
|
+
return `${projectName}/${filePath}`;
|
|
69
|
+
}
|
|
70
|
+
// Fallback: import from the specific package path
|
|
71
|
+
return `${projectName}/${packageName.replace(/\./g, '/')}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets all types for a package by looking at export objects and filtering out extended forms
|
|
75
|
+
*/
|
|
76
|
+
function getTypesForPackage(builder, packageName) {
|
|
77
|
+
const types = [];
|
|
78
|
+
// Get all contexts for this package
|
|
79
|
+
const packageContexts = builder.contexts.filter(ctx => ctx.ref.proto.package === packageName);
|
|
80
|
+
packageContexts.forEach(context => {
|
|
81
|
+
// Get types from this context
|
|
82
|
+
const contextTypes = context.types.filter(type => !type.isNested);
|
|
83
|
+
contextTypes.forEach(typeInfo => {
|
|
84
|
+
const typeName = typeInfo.name;
|
|
85
|
+
// Filter out extended forms (these are created during code generation but not in the types array)
|
|
86
|
+
if (!typeName.endsWith('ProtoMsg') &&
|
|
87
|
+
!typeName.endsWith('Amino') &&
|
|
88
|
+
!typeName.endsWith('AminoMsg') &&
|
|
89
|
+
!typeName.endsWith('Encoded') &&
|
|
90
|
+
!typeName.endsWith('SDKType')) {
|
|
91
|
+
// Get the actual source file from the store mapping
|
|
92
|
+
const typeFiles = builder.store.getTypeFilesMapping(typeName);
|
|
93
|
+
let sourceFile;
|
|
94
|
+
if (typeFiles && typeFiles.length > 0) {
|
|
95
|
+
// Use the first (or most relevant) file where this type is defined
|
|
96
|
+
sourceFile = typeFiles[0];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Fallback to context ref filename if not in mapping
|
|
100
|
+
sourceFile = context.ref.filename.replace(/\.proto$/, '.ts');
|
|
101
|
+
}
|
|
102
|
+
types.push({
|
|
103
|
+
name: typeName,
|
|
104
|
+
sourceFile
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
// Remove duplicates and sort
|
|
110
|
+
const uniqueTypes = types.filter((type, index, self) => index === self.findIndex(t => t.name === type.name));
|
|
111
|
+
return uniqueTypes.sort((a, b) => a.name.localeCompare(b.name));
|
|
112
|
+
}
|
|
113
|
+
export const plugin = (builder) => {
|
|
114
|
+
if (!builder.options.readme.enabled && !builder.options.mcpServer.enabled) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const readmePath = join(builder.outPath, "README.md");
|
|
118
|
+
const projectName = getProjectName(builder.outPath);
|
|
119
|
+
// Get function mappings from builder
|
|
120
|
+
const functionMappings = builder.getFunctionMappings();
|
|
121
|
+
// Generate package documentation
|
|
122
|
+
let packageDocs = "";
|
|
123
|
+
Object.keys(functionMappings).sort().forEach(packageName => {
|
|
124
|
+
const packageServices = functionMappings[packageName];
|
|
125
|
+
// Check if package has any methods before adding it
|
|
126
|
+
const hasQueryMethods = packageServices.Query && Object.keys(packageServices.Query).length > 0;
|
|
127
|
+
const hasMsgMethods = packageServices.Msg && Object.keys(packageServices.Msg).length > 0;
|
|
128
|
+
if (!hasQueryMethods && !hasMsgMethods) {
|
|
129
|
+
return; // Skip empty packages
|
|
130
|
+
}
|
|
131
|
+
packageDocs += `## ${packageName}\n\n`;
|
|
132
|
+
// Types section
|
|
133
|
+
const types = getTypesForPackage(builder, packageName);
|
|
134
|
+
if (types && types.length > 0) {
|
|
135
|
+
packageDocs += `### Types\n\n`;
|
|
136
|
+
packageDocs += `| Type | Name | Source |\n`;
|
|
137
|
+
packageDocs += `| --- | --- | --- |\n`;
|
|
138
|
+
types.forEach(type => {
|
|
139
|
+
packageDocs += `| Type | \`${type.name}\` | [View source ↗](${type.sourceFile}) |\n`;
|
|
140
|
+
});
|
|
141
|
+
packageDocs += '\n';
|
|
142
|
+
}
|
|
143
|
+
// Query section
|
|
144
|
+
if (packageServices.Query) {
|
|
145
|
+
packageDocs += `### Query Methods\n\n`;
|
|
146
|
+
const queryMethods = Object.keys(packageServices.Query);
|
|
147
|
+
queryMethods.forEach((methodName, index) => {
|
|
148
|
+
const method = packageServices.Query[methodName];
|
|
149
|
+
// Get the aliased function name using the same logic as bundler
|
|
150
|
+
const aliasedFunctionName = getAliasedFunctionName(builder, method.functionName, packageName);
|
|
151
|
+
const aliasedHookName = getAliasedFunctionName(builder, method.hookName, packageName);
|
|
152
|
+
packageDocs += `**${methodName}**\n\n`;
|
|
153
|
+
// Add comment directly after title (if exists)
|
|
154
|
+
if (method.comment) {
|
|
155
|
+
packageDocs += `${cleanComment(method.comment)}\n\n`;
|
|
156
|
+
}
|
|
157
|
+
// Add import code block
|
|
158
|
+
const functionImportPath = getImportPath(builder, method.functionName, packageName, projectName, method.sourceFilename);
|
|
159
|
+
const hookImportPath = method.hookName ? getImportPath(builder, method.hookName, packageName, projectName, method.hookSourceFilename) : functionImportPath;
|
|
160
|
+
packageDocs += `\`\`\`ts\n`;
|
|
161
|
+
packageDocs += `import { ${aliasedFunctionName} } from '${functionImportPath}'\n`;
|
|
162
|
+
if (method.hookName && aliasedHookName !== aliasedFunctionName) {
|
|
163
|
+
packageDocs += `import { ${aliasedHookName} } from '${hookImportPath}'\n`;
|
|
164
|
+
}
|
|
165
|
+
packageDocs += `\`\`\`\n\n`;
|
|
166
|
+
// Add function details in organized format
|
|
167
|
+
packageDocs += `| Field | Value | Source |\n`;
|
|
168
|
+
packageDocs += `| --- | --- | --- |\n`;
|
|
169
|
+
// Function source
|
|
170
|
+
const functionSourcePath = method.sourceFilename || `${packageName.replace(/\./g, '/')}/query.rpc.func.ts`;
|
|
171
|
+
packageDocs += `| Function | \`${aliasedFunctionName}\` | [View source ↗](${functionSourcePath}) |\n`;
|
|
172
|
+
// Hook source (React)
|
|
173
|
+
if (method.hookName && aliasedHookName !== aliasedFunctionName) {
|
|
174
|
+
const hookSourcePath = method.hookSourceFilename || `${packageName.replace(/\./g, '/')}/query.rpc.react.ts`;
|
|
175
|
+
packageDocs += `| Hook | \`${aliasedHookName}\` | [View source ↗](${hookSourcePath}) |\n`;
|
|
176
|
+
}
|
|
177
|
+
// Request type source
|
|
178
|
+
if (method.requestType) {
|
|
179
|
+
const requestSourcePath = method.typeSourceFilename || `${packageName.replace(/\./g, '/')}/query.ts`;
|
|
180
|
+
packageDocs += `| Request | \`${method.requestType}\` | [View source ↗](${requestSourcePath}) |\n`;
|
|
181
|
+
}
|
|
182
|
+
// Response type source
|
|
183
|
+
if (method.responseType) {
|
|
184
|
+
const responseSourcePath = method.typeSourceFilename || `${packageName.replace(/\./g, '/')}/query.ts`;
|
|
185
|
+
packageDocs += `| Response | \`${method.responseType}\` | [View source ↗](${responseSourcePath}) |\n`;
|
|
186
|
+
}
|
|
187
|
+
// Add spacing between methods (but not after the last one)
|
|
188
|
+
if (index < queryMethods.length - 1) {
|
|
189
|
+
packageDocs += '\n---\n\n';
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
packageDocs += '\n';
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// Transaction section
|
|
197
|
+
if (packageServices.Msg) {
|
|
198
|
+
packageDocs += `### Transaction Methods\n\n`;
|
|
199
|
+
const msgMethods = Object.keys(packageServices.Msg);
|
|
200
|
+
msgMethods.forEach((methodName, index) => {
|
|
201
|
+
const method = packageServices.Msg[methodName];
|
|
202
|
+
// Get the aliased function name using the same logic as bundler
|
|
203
|
+
const aliasedFunctionName = getAliasedFunctionName(builder, method.functionName, packageName);
|
|
204
|
+
const aliasedHookName = getAliasedFunctionName(builder, method.hookName, packageName);
|
|
205
|
+
packageDocs += `**${methodName}**\n\n`;
|
|
206
|
+
// Add comment directly after title (if exists)
|
|
207
|
+
if (method.comment) {
|
|
208
|
+
packageDocs += `${cleanComment(method.comment)}\n\n`;
|
|
209
|
+
}
|
|
210
|
+
// Add import code block
|
|
211
|
+
const functionImportPath = getImportPath(builder, method.functionName, packageName, projectName, method.sourceFilename);
|
|
212
|
+
const hookImportPath = method.hookName ? getImportPath(builder, method.hookName, packageName, projectName, method.hookSourceFilename) : functionImportPath;
|
|
213
|
+
packageDocs += `\`\`\`ts\n`;
|
|
214
|
+
packageDocs += `import { ${aliasedFunctionName} } from '${functionImportPath}'\n`;
|
|
215
|
+
if (method.hookName && aliasedHookName !== aliasedFunctionName) {
|
|
216
|
+
packageDocs += `import { ${aliasedHookName} } from '${hookImportPath}'\n`;
|
|
217
|
+
}
|
|
218
|
+
packageDocs += `\`\`\`\n\n`;
|
|
219
|
+
// Add function details in organized format
|
|
220
|
+
packageDocs += `| Field | Value | Source |\n`;
|
|
221
|
+
packageDocs += `| --- | --- | --- |\n`;
|
|
222
|
+
// Function source
|
|
223
|
+
const functionSourcePath = method.sourceFilename || `${packageName.replace(/\./g, '/')}/tx.rpc.func.ts`;
|
|
224
|
+
packageDocs += `| Function | \`${aliasedFunctionName}\` | [View source ↗](${functionSourcePath}) |\n`;
|
|
225
|
+
// Hook source (React)
|
|
226
|
+
if (method.hookName && aliasedHookName !== aliasedFunctionName) {
|
|
227
|
+
const hookSourcePath = method.hookSourceFilename || `${packageName.replace(/\./g, '/')}/tx.rpc.react.ts`;
|
|
228
|
+
packageDocs += `| Hook | \`${aliasedHookName}\` | [View source ↗](${hookSourcePath}) |\n`;
|
|
229
|
+
}
|
|
230
|
+
// Request type source
|
|
231
|
+
if (method.requestType) {
|
|
232
|
+
const requestSourcePath = method.typeSourceFilename || `${packageName.replace(/\./g, '/')}/tx.ts`;
|
|
233
|
+
packageDocs += `| Request | \`${method.requestType}\` | [View source ↗](${requestSourcePath}) |\n`;
|
|
234
|
+
}
|
|
235
|
+
// Response type source
|
|
236
|
+
if (method.responseType) {
|
|
237
|
+
const responseSourcePath = method.typeSourceFilename || `${packageName.replace(/\./g, '/')}/tx.ts`;
|
|
238
|
+
packageDocs += `| Response | \`${method.responseType}\` | [View source ↗](${responseSourcePath}) |\n`;
|
|
239
|
+
}
|
|
240
|
+
// Add spacing between methods (but not after the last one)
|
|
241
|
+
if (index < msgMethods.length - 1) {
|
|
242
|
+
packageDocs += '\n---\n\n';
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
packageDocs += '\n';
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
// Add spacing between packages
|
|
250
|
+
packageDocs += '\n';
|
|
251
|
+
});
|
|
252
|
+
const readmeContent = `# Package Documentation
|
|
253
|
+
${packageDocs}`;
|
|
254
|
+
writeContentToFile(builder.outPath, builder.options, readmeContent, readmePath);
|
|
255
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as dotty from 'dotty';
|
|
2
|
+
import { createEmptyProtoRef, getNestedProto } from '@cosmology/proto-parser';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { createScopedRpcFactory, createScopedGrpcWebMsgFactory, createRpcMsgExtension, importStmt } from '@cosmology/ast';
|
|
5
|
+
import { fixlocalpaths, getRelativePath } from '../utils';
|
|
6
|
+
import { aggregateImports, getDepsFromQueries, getImportStatements } from '../imports';
|
|
7
|
+
import { TelescopeParseContext } from '../build';
|
|
8
|
+
import { pascal } from 'case';
|
|
9
|
+
export const plugin = (builder, bundler) => {
|
|
10
|
+
// if not enabled, exit
|
|
11
|
+
if (!builder.options?.rpcClients?.enabled) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (builder.options?.rpcClients?.inline) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// if no scopes, do them all!
|
|
18
|
+
if (!builder.options.rpcClients.scoped ||
|
|
19
|
+
!builder.options.rpcClients.scoped.length ||
|
|
20
|
+
!builder.options.rpcClients.scopedIsExclusive) {
|
|
21
|
+
return makeAllRPCBundles(builder, bundler);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const getFileName = (dir, filename) => {
|
|
25
|
+
filename = filename.replace(/\.ts$/, '');
|
|
26
|
+
const localname = join(dir, filename + '.tx');
|
|
27
|
+
return localname + '.ts';
|
|
28
|
+
};
|
|
29
|
+
const makeAllRPCBundles = (builder, bundler) => {
|
|
30
|
+
if (!builder.options.rpcClients.bundle)
|
|
31
|
+
return;
|
|
32
|
+
const dir = bundler.bundle.base;
|
|
33
|
+
const filename = 'rpc';
|
|
34
|
+
// refs with services
|
|
35
|
+
const refs = builder.store.getProtos().filter((ref) => {
|
|
36
|
+
const proto = getNestedProto(ref.traversed);
|
|
37
|
+
if (!proto?.Msg || proto.Msg?.type !== 'Service') {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
const check = refs.filter((ref) => {
|
|
43
|
+
const [base] = ref.proto.package.split('.');
|
|
44
|
+
return base === bundler.bundle.base;
|
|
45
|
+
});
|
|
46
|
+
if (!check.length) {
|
|
47
|
+
// if there are no services
|
|
48
|
+
// exit the plugin
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const packages = refs.reduce((m, ref) => {
|
|
52
|
+
const [base] = ref.proto.package.split('.');
|
|
53
|
+
if (base === 'cosmos' || base === bundler.bundle.base)
|
|
54
|
+
return [...new Set([...m, ref.proto.package])];
|
|
55
|
+
return m;
|
|
56
|
+
}, []);
|
|
57
|
+
const methodName = 'createRPCMsgClient';
|
|
58
|
+
const localname = getFileName(dir, filename ?? 'rpc');
|
|
59
|
+
const obj = {};
|
|
60
|
+
builder.rpcMsgClients.forEach(file => {
|
|
61
|
+
// ADD all option
|
|
62
|
+
// which defaults to including cosmos
|
|
63
|
+
// and defaults to base for each
|
|
64
|
+
if (!packages.includes(file.package)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const f = localname;
|
|
68
|
+
const f2 = file.localname;
|
|
69
|
+
const importPath = getRelativePath(f, f2);
|
|
70
|
+
dotty.put(obj, file.package, importPath);
|
|
71
|
+
});
|
|
72
|
+
const ctx = new TelescopeParseContext(createEmptyProtoRef(dir, localname), builder.store, builder.options);
|
|
73
|
+
let rpcast;
|
|
74
|
+
let msgExt = [];
|
|
75
|
+
let txRpcImport = [];
|
|
76
|
+
switch (builder.options?.rpcClients?.type) {
|
|
77
|
+
case "grpc-gateway":
|
|
78
|
+
case "tendermint":
|
|
79
|
+
ctx.proto.addUtil('Rpc');
|
|
80
|
+
rpcast = createScopedRpcFactory(obj, methodName, 'MsgClientImpl', // make option later,
|
|
81
|
+
ctx.options);
|
|
82
|
+
if (ctx.proto.pluginValue('env') === 'v-next' && ctx.proto.pluginValue('rpcClients.extensions') && ctx.proto.pluginValue('stargateClients.addGetTxRpc')) {
|
|
83
|
+
const txRpcName = 'getSigning' + pascal(bundler.bundle.base + 'TxRpc');
|
|
84
|
+
txRpcImport = importStmt([txRpcName], `./client${ctx.options.restoreImportExtension ?? ""}`);
|
|
85
|
+
msgExt = createRpcMsgExtension(ctx.proto, txRpcName);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "grpc-web":
|
|
89
|
+
ctx.proto.addUtil('grpc');
|
|
90
|
+
ctx.proto.addUtil('NodeHttpTransport');
|
|
91
|
+
rpcast = createScopedGrpcWebMsgFactory(obj, methodName, 'MsgClientImpl', // make option later,
|
|
92
|
+
ctx.options);
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
const serviceImports = getDepsFromQueries(ctx.queries, localname);
|
|
98
|
+
const imports = aggregateImports(ctx, serviceImports, localname);
|
|
99
|
+
const importStmts = getImportStatements(localname, [...fixlocalpaths(imports)], builder.options);
|
|
100
|
+
const prog = []
|
|
101
|
+
.concat(txRpcImport)
|
|
102
|
+
.concat(importStmts)
|
|
103
|
+
.concat(rpcast)
|
|
104
|
+
.concat(msgExt);
|
|
105
|
+
const writeFilename = bundler.getFilename(localname);
|
|
106
|
+
bundler.writeAst(prog, writeFilename);
|
|
107
|
+
bundler.addToBundleToPackage(`${dir}.ClientFactory`, localname);
|
|
108
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as dotty from 'dotty';
|
|
2
|
+
import { createEmptyProtoRef } from '@cosmology/proto-parser';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { createScopedRpcFactory, createScopedGrpcWebMsgFactory, createRpcMsgExtension, importStmt } from '@cosmology/ast';
|
|
5
|
+
import { fixlocalpaths, getRelativePath } from '../utils';
|
|
6
|
+
import { aggregateImports, getDepsFromQueries, getImportStatements } from '../imports';
|
|
7
|
+
import { TelescopeParseContext } from '../build';
|
|
8
|
+
import { pascal } from 'case';
|
|
9
|
+
export const plugin = (builder, bundler) => {
|
|
10
|
+
// if not enabled, exit
|
|
11
|
+
if (!builder.options?.rpcClients?.enabled) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (builder.options?.rpcClients?.inline) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// we have scopes!
|
|
18
|
+
builder.options.rpcClients.scoped?.forEach(rpc => {
|
|
19
|
+
if (rpc.dir !== bundler.bundle.base)
|
|
20
|
+
return;
|
|
21
|
+
makeRPC(builder, bundler, rpc);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const getFileName = (dir, filename) => {
|
|
25
|
+
filename = filename.replace(/\.ts$/, '');
|
|
26
|
+
const localname = join(dir, filename + '.tx');
|
|
27
|
+
return localname + '.ts';
|
|
28
|
+
};
|
|
29
|
+
const makeRPC = (builder, bundler, rpc) => {
|
|
30
|
+
const dir = rpc.dir;
|
|
31
|
+
const packages = rpc.packages;
|
|
32
|
+
const methodName = rpc.methodNameTx ?? 'createRPCMsgClient';
|
|
33
|
+
const localname = getFileName(dir, rpc.filename ?? 'rpc');
|
|
34
|
+
const obj = {};
|
|
35
|
+
builder.rpcMsgClients.forEach(file => {
|
|
36
|
+
// ADD all option
|
|
37
|
+
// which defaults to including cosmos
|
|
38
|
+
// and defaults to base for each
|
|
39
|
+
if (!packages.includes(file.package)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const f = localname;
|
|
43
|
+
const f2 = file.localname;
|
|
44
|
+
const importPath = getRelativePath(f, f2);
|
|
45
|
+
dotty.put(obj, file.package, importPath);
|
|
46
|
+
});
|
|
47
|
+
const ctx = new TelescopeParseContext(createEmptyProtoRef(dir, localname), builder.store, builder.options);
|
|
48
|
+
let rpcast;
|
|
49
|
+
let msgExt = [];
|
|
50
|
+
let txRpcImport = [];
|
|
51
|
+
switch (builder.options?.rpcClients?.type) {
|
|
52
|
+
case "grpc-gateway":
|
|
53
|
+
// TODO no working scoped clients for grpc-gateway right now
|
|
54
|
+
case "tendermint":
|
|
55
|
+
// TODO add addUtil to generic context
|
|
56
|
+
ctx.proto.addUtil('Rpc');
|
|
57
|
+
rpcast = createScopedRpcFactory(obj, methodName, 'MsgClientImpl', // make option later,
|
|
58
|
+
ctx.options);
|
|
59
|
+
if (rpc.isAll && ctx.proto.pluginValue('env') === 'v-next' && ctx.proto.pluginValue('rpcClients.extensions') && ctx.proto.pluginValue('stargateClients.addGetTxRpc')) {
|
|
60
|
+
const txRpcName = 'getSigning' + pascal(bundler.bundle.base + 'TxRpc');
|
|
61
|
+
txRpcImport = importStmt([txRpcName], `./client${ctx.options.restoreImportExtension ?? ""}`);
|
|
62
|
+
msgExt = createRpcMsgExtension(ctx.proto, txRpcName);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case "grpc-web":
|
|
66
|
+
ctx.proto.addUtil('grpc');
|
|
67
|
+
ctx.proto.addUtil('NodeHttpTransport');
|
|
68
|
+
rpcast = createScopedGrpcWebMsgFactory(obj, methodName, 'MsgClientImpl', // make option later,
|
|
69
|
+
ctx.options);
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
const serviceImports = getDepsFromQueries(ctx.queries, localname);
|
|
75
|
+
const imports = aggregateImports(ctx, serviceImports, localname);
|
|
76
|
+
const importStmts = getImportStatements(localname, [...fixlocalpaths(imports)], builder.options);
|
|
77
|
+
const prog = []
|
|
78
|
+
.concat(txRpcImport)
|
|
79
|
+
.concat(importStmts)
|
|
80
|
+
.concat(rpcast)
|
|
81
|
+
.concat(msgExt);
|
|
82
|
+
const filename = bundler.getFilename(localname);
|
|
83
|
+
bundler.writeAst(prog, filename);
|
|
84
|
+
if (rpc.addToBundle) {
|
|
85
|
+
bundler.addToBundleToPackage(`${dir}.ClientFactory`, localname);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { buildAllImports, getDepsFromQueries } from '../imports';
|
|
2
|
+
import { createRpcClientClass, createRpcClientInterface, createGRPCGatewayMsgClass, GetDesc, getMethodDesc, grpcWebRpcInterface, createGrpcWebMsgInterface, createGrpcWebMsgClass, getGrpcWebImpl, createRpcClientImpl } from '@cosmology/ast';
|
|
3
|
+
import { getNestedProto } from '@cosmology/proto-parser';
|
|
4
|
+
import { parse } from '../parse';
|
|
5
|
+
import { camel, getQueryMethodNames, swapKeyValue } from '@cosmology/utils';
|
|
6
|
+
export const plugin = (builder, bundler) => {
|
|
7
|
+
// if (!builder.options.rpcClients.enabled) {
|
|
8
|
+
// return;
|
|
9
|
+
// }
|
|
10
|
+
const instantRpcBundlerFiles = {};
|
|
11
|
+
const mutationContexts = bundler
|
|
12
|
+
.contexts
|
|
13
|
+
.filter(context => context.mutations.length > 0);
|
|
14
|
+
const clients = mutationContexts.map(c => {
|
|
15
|
+
const enabled = c.proto.pluginValue('rpcClients.enabled');
|
|
16
|
+
if (!enabled)
|
|
17
|
+
return;
|
|
18
|
+
const inline = c.proto.pluginValue('rpcClients.inline');
|
|
19
|
+
if (inline)
|
|
20
|
+
return;
|
|
21
|
+
if (c.proto.isExcluded())
|
|
22
|
+
return;
|
|
23
|
+
const useCamelCase = c.proto.pluginValue("rpcClients.camelCase");
|
|
24
|
+
const localname = bundler.getLocalFilename(c.ref, 'rpc.msg');
|
|
25
|
+
const filename = bundler.getFilename(localname);
|
|
26
|
+
const ctx = bundler.getFreshContext(c);
|
|
27
|
+
// get mutations, services
|
|
28
|
+
parse(ctx);
|
|
29
|
+
const proto = getNestedProto(c.ref.traversed);
|
|
30
|
+
// hard-coding, for now, only Msg service
|
|
31
|
+
if (!proto?.Msg || proto.Msg?.type !== 'Service') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
////////
|
|
35
|
+
const asts = [];
|
|
36
|
+
const bundlerFile = {
|
|
37
|
+
proto: c.ref.filename,
|
|
38
|
+
package: c.ref.proto.package,
|
|
39
|
+
localname,
|
|
40
|
+
filename,
|
|
41
|
+
isMsg: true
|
|
42
|
+
};
|
|
43
|
+
switch (c.proto.pluginValue("rpcClients.type")) {
|
|
44
|
+
case 'grpc-gateway':
|
|
45
|
+
asts.push(createGRPCGatewayMsgClass(ctx.generic, proto.Msg));
|
|
46
|
+
break;
|
|
47
|
+
case 'grpc-web':
|
|
48
|
+
asts.push(createGrpcWebMsgInterface(ctx.generic, proto.Msg));
|
|
49
|
+
asts.push(createGrpcWebMsgClass(ctx.generic, proto.Msg));
|
|
50
|
+
asts.push(GetDesc(ctx.generic, proto.Msg));
|
|
51
|
+
const Desces = getMethodDesc(ctx.generic, proto.Msg);
|
|
52
|
+
for (let i = 0; i < Desces.length; i++) {
|
|
53
|
+
const element = Desces[i];
|
|
54
|
+
asts.push(element);
|
|
55
|
+
}
|
|
56
|
+
asts.push(grpcWebRpcInterface());
|
|
57
|
+
asts.push(getGrpcWebImpl(ctx.generic));
|
|
58
|
+
break;
|
|
59
|
+
case 'tendermint':
|
|
60
|
+
default:
|
|
61
|
+
asts.push(createRpcClientInterface(ctx.generic, proto.Msg));
|
|
62
|
+
const svc = proto.Msg;
|
|
63
|
+
const instantOps = c.options.rpcClients?.instantOps ?? [];
|
|
64
|
+
instantOps.forEach((item) => {
|
|
65
|
+
let nameMapping = {
|
|
66
|
+
...swapKeyValue(item.nameMapping?.All ?? {}),
|
|
67
|
+
...swapKeyValue(item.nameMapping?.Msg ?? {})
|
|
68
|
+
};
|
|
69
|
+
// get all query methods
|
|
70
|
+
const patterns = item.include?.patterns;
|
|
71
|
+
const serviceTypes = item.include?.serviceTypes;
|
|
72
|
+
if (serviceTypes && !serviceTypes.includes("Tx")) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const methodKeys = getQueryMethodNames(bundlerFile.package, Object.keys(svc.methods ?? {}), patterns, useCamelCase ? camel : String);
|
|
76
|
+
if (!methodKeys || !methodKeys.length) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
asts.push(createRpcClientInterface(ctx.generic, svc, item.className, methodKeys, nameMapping));
|
|
80
|
+
bundlerFile.instantExportedMethods = methodKeys.map((key) => svc.methods[key]);
|
|
81
|
+
if (!instantRpcBundlerFiles[item.className]) {
|
|
82
|
+
instantRpcBundlerFiles[item.className] = [];
|
|
83
|
+
}
|
|
84
|
+
instantRpcBundlerFiles[item.className].push({ ...bundlerFile });
|
|
85
|
+
});
|
|
86
|
+
asts.push(createRpcClientClass(ctx.generic, proto.Msg));
|
|
87
|
+
const env = c.proto.pluginValue('env');
|
|
88
|
+
if (env === 'v-next') {
|
|
89
|
+
asts.push(createRpcClientImpl(ctx.generic, svc));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
////////
|
|
93
|
+
const serviceImports = getDepsFromQueries(ctx.mutations, localname);
|
|
94
|
+
// TODO we do NOT need all imports...
|
|
95
|
+
const imports = buildAllImports(ctx, serviceImports, localname);
|
|
96
|
+
const prog = []
|
|
97
|
+
.concat(imports)
|
|
98
|
+
.concat(ctx.body)
|
|
99
|
+
.concat(asts);
|
|
100
|
+
bundler.writeAst(prog, filename);
|
|
101
|
+
bundler.addToBundle(c, localname);
|
|
102
|
+
return {
|
|
103
|
+
package: c.ref.proto.package,
|
|
104
|
+
localname,
|
|
105
|
+
filename
|
|
106
|
+
};
|
|
107
|
+
}).filter(Boolean);
|
|
108
|
+
bundler.addRPCMsgClients(clients);
|
|
109
|
+
Object.keys(instantRpcBundlerFiles).forEach((className) => {
|
|
110
|
+
bundler.addStateManagers(`instantRpc_${className}`, instantRpcBundlerFiles[className]);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { aggregateImports, getImportStatements } from "../imports";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { createInstantRpcInterface, createInstantRpcClass, } from "@cosmology/ast";
|
|
4
|
+
import { TelescopeParseContext } from "../build";
|
|
5
|
+
import { writeAstToFile } from "../utils/files";
|
|
6
|
+
import { fixlocalpaths } from "../utils";
|
|
7
|
+
import * as dotty from "dotty";
|
|
8
|
+
import { createEmptyProtoRef } from "@cosmology/proto-parser";
|
|
9
|
+
import { camel } from "@cosmology/utils";
|
|
10
|
+
import { variableSlug } from "@cosmology/utils";
|
|
11
|
+
import { swapKeyValue } from "@cosmology/utils";
|
|
12
|
+
import { buildImports } from "@cosmology/utils";
|
|
13
|
+
export const plugin = (builder) => {
|
|
14
|
+
if (!builder.options.rpcClients?.enabled ||
|
|
15
|
+
!builder.options.rpcClients?.instantOps?.length) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const localname = "service-ops.ts";
|
|
19
|
+
// get mapping of packages and rpc query filenames.
|
|
20
|
+
// create proto ref for context
|
|
21
|
+
const pkg = "@root";
|
|
22
|
+
const ref = createEmptyProtoRef(pkg, localname);
|
|
23
|
+
// create context
|
|
24
|
+
const context = new TelescopeParseContext(ref, builder.store, builder.options);
|
|
25
|
+
const pkgImports = [];
|
|
26
|
+
const ast = builder.options.rpcClients.instantOps.reduce((ast, instantOpsConfig) => {
|
|
27
|
+
const bundlerFiles = builder.stateManagers[`instantRpc_${instantOpsConfig.className}`];
|
|
28
|
+
if (!bundlerFiles || !bundlerFiles.length) {
|
|
29
|
+
return ast;
|
|
30
|
+
}
|
|
31
|
+
let nameMapping = instantOpsConfig.nameMapping;
|
|
32
|
+
return ast.concat(createRpcOpsAst(context, instantOpsConfig.className, pkgImports, nameMapping, bundlerFiles));
|
|
33
|
+
}, []);
|
|
34
|
+
// generate imports added by context.addUtil
|
|
35
|
+
const imports = fixlocalpaths(aggregateImports(context, {}, localname));
|
|
36
|
+
const importStmts = getImportStatements(localname, imports, builder.options);
|
|
37
|
+
// construct the AST
|
|
38
|
+
const prog = [].concat(importStmts).concat(buildImports(pkgImports)).concat(ast);
|
|
39
|
+
// write the file.
|
|
40
|
+
const filename = join(builder.outPath, localname);
|
|
41
|
+
builder.files.push(localname);
|
|
42
|
+
writeAstToFile(builder.outPath, builder.options, prog, filename);
|
|
43
|
+
};
|
|
44
|
+
// bundlerFiles.filter(file => file.localname.indexOf("rpc.msg") !== -1)
|
|
45
|
+
function createRpcOpsAst(context, className, pkgImports, nameMapping, bundlerFiles) {
|
|
46
|
+
const extendInterfaces = [];
|
|
47
|
+
const instantMapping = {};
|
|
48
|
+
const camelRpcMethods = context.generic.pluginValue("rpcClients.camelCase");
|
|
49
|
+
let txNameMapping = {
|
|
50
|
+
...swapKeyValue(nameMapping?.All ?? {}),
|
|
51
|
+
...swapKeyValue(nameMapping?.Msg ?? {})
|
|
52
|
+
};
|
|
53
|
+
let queryNameMapping = {
|
|
54
|
+
...swapKeyValue(nameMapping?.All ?? {}),
|
|
55
|
+
...swapKeyValue(nameMapping?.Query ?? {})
|
|
56
|
+
};
|
|
57
|
+
bundlerFiles.forEach((bundlerFile) => {
|
|
58
|
+
const isMsg = bundlerFile.isMsg;
|
|
59
|
+
const currentNameMapping = isMsg ? txNameMapping : queryNameMapping;
|
|
60
|
+
const path = `./${bundlerFile.localname.replace(/\.ts$/, "")}`;
|
|
61
|
+
const importedVarName = variableSlug(path);
|
|
62
|
+
if (pkgImports &&
|
|
63
|
+
!pkgImports.some((item) => item.importedAs === importedVarName)) {
|
|
64
|
+
pkgImports.push({
|
|
65
|
+
type: "typeImport",
|
|
66
|
+
name: importedVarName,
|
|
67
|
+
import: path,
|
|
68
|
+
importedAs: importedVarName,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
extendInterfaces.push({
|
|
72
|
+
importedVarName: importedVarName,
|
|
73
|
+
interfaceName: className,
|
|
74
|
+
});
|
|
75
|
+
bundlerFile.instantExportedMethods?.forEach((method) => {
|
|
76
|
+
const methodName = camelRpcMethods ? camel(method.name) : method.name;
|
|
77
|
+
const nameWithPkg = `${bundlerFile.package}.${methodName}`;
|
|
78
|
+
const methodAlias = currentNameMapping && currentNameMapping[nameWithPkg]
|
|
79
|
+
? currentNameMapping[nameWithPkg]
|
|
80
|
+
: methodName;
|
|
81
|
+
dotty.put(instantMapping, methodAlias, {
|
|
82
|
+
methodName,
|
|
83
|
+
importedVarName,
|
|
84
|
+
isMsg
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return [
|
|
89
|
+
createInstantRpcInterface(className, extendInterfaces),
|
|
90
|
+
createInstantRpcClass(context.generic, className, instantMapping),
|
|
91
|
+
];
|
|
92
|
+
}
|