Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ts): implement exports generation #181

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/release-ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,3 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: make release-ts

- name: Upload Test Coverage
uses: codecov/codecov-action@v4
with:
files: ./ts/coverage
token: ${{ secrets.CODECOV_TOKEN }}

4 changes: 2 additions & 2 deletions buf.gen.ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins:
strategy: all
path: ./ts/node_modules/.bin/protoc-gen-ts_proto
out: ./ts/src/generated
opt: "esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true"
opt: "esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,exportCommonSymbols=false"
- name: grpc-gateway-ts
path: ./ts/node_modules/.bin/protoc-gen-ts_proto
out: ./.cache/tmp/ts/generated-grpc-js
opt: "esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputServices=grpc-js"
opt: "esModuleInterop=true,forceLong=long,useExactTypes=false,exportCommonSymbols=false,outputServices=grpc-js"
2 changes: 1 addition & 1 deletion docs/proto/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ the granter's account for a deployment.
<a name="akash.deployment.v1.MsgDepositDeploymentResponse"></a>

### MsgDepositDeploymentResponse
MsgCreateDeploymentResponse defines the Msg/CreateDeployment response type.
MsgDepositDeploymentResponse defines response type for the MsgDepositDeployment.



Expand Down
4 changes: 2 additions & 2 deletions docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43721,8 +43721,8 @@ definitions:
akash.deployment.v1.MsgDepositDeploymentResponse:
type: object
description: >-
MsgCreateDeploymentResponse defines the Msg/CreateDeployment response
type.
MsgDepositDeploymentResponse defines response type for the
MsgDepositDeployment.
akash.deployment.v1beta4.MsgCloseDeploymentResponse:
type: object
description: MsgCloseDeploymentResponse defines the Msg/CloseDeployment response type.
Expand Down
2 changes: 1 addition & 1 deletion go/node/deployment/v1/msg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ test-coverage: $(patsubst %, test-coverage-%,$(SUB_TESTS))

.PHONY: test-ts
test-ts: $(AKASH_TS_NODE_MODULES)
cd $(TS_ROOT) && npm run test
cd $(TS_ROOT) && npm run test:ci

.PHONY: test-coverage-ts
test-coverage-ts: $(AKASH_TS_NODE_MODULES)
cd $(TS_ROOT) && npm run test:cov
cd $(TS_ROOT) && npm run test:ci:cov

.PHONY: test-go
test-go: export GO111MODULE := $(GO111MODULE)
Expand Down
114 changes: 38 additions & 76 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.build.json && npm run format",
"postbuild": "script/generate-exports.js",
"postbuild": "script/generate-exports.js && script/generate-exports.js",
"format": "prettier --write \"$AKASH_TS_ROOT/**/*.{js,jsx,ts,tsx,css,json}\" --config ./.prettierrc --log-level silent",
"lint": "eslint src",
"lint:fix": "npm run lint -- --fix",
"test": "jest --selectProjects unit functional",
"test:ci": "echo \"No tests present...\"",
"test:ci:cov": "echo \"No tests present...\"",
"test:cov": "jest --selectProjects unit functional --coverage",
"test:functional": "jest --selectProjects functional",
"test:functional:cov": "jest --selectProjects functional --coverage",
Expand Down Expand Up @@ -67,82 +69,42 @@
"@grpc/grpc-js": "^1.10.6"
},
"exports": {
"./": "./dist/index.js",
"./typeRegistry": "./dist/generated/typeRegistry.js",
"./akash/deployment/v1beta3/query": "./dist/generated/akash/deployment/v1beta3/query.js",
"./deprecated/akash/cert/v1beta1": "./dist/deprecated/index.akash.cert.v1beta1.js",
"./deprecated/akash/market/v1beta1": "./dist/deprecated/index.akash.market.v1beta1.js",
"./v1beta1": "./dist/index.v1beta1.js",
"./v1beta2": "./dist/index.v1beta2.js",
"./typeRegistry": "./dist/typeRegistry.js",
"./akash/audit/v1": "./dist/index.akash.audit.v1.js",
"./akash/audit/v1/grpc-js": "./dist/index.akash.audit.v1.grpc-js.js",
"./akash/base/attributes/v1": "./dist/index.akash.base.attributes.v1.js",
"./akash/base/resources/v1beta4": "./dist/index.akash.base.resources.v1beta4.js",
"./akash/cert/v1": "./dist/index.akash.cert.v1.js",
"./akash/cert/v1/grpc-js": "./dist/index.akash.cert.v1.grpc-js.js",
"./akash/deployment/v1": "./dist/index.akash.deployment.v1.js",
"./akash/deployment/v1beta4": "./dist/index.akash.deployment.v1beta4.js",
"./akash/deployment/v1beta4/grpc-js": "./dist/index.akash.deployment.v1beta4.grpc-js.js",
"./akash/discovery/v1": "./dist/index.akash.discovery.v1.js",
"./akash/escrow/v1": "./dist/index.akash.escrow.v1.js",
"./akash/gov/v1beta3": "./dist/index.akash.gov.v1beta3.js",
"./akash/inflation/v1beta2": "./dist/index.akash.inflation.v1beta2.js",
"./akash/inflation/v1beta3": "./dist/index.akash.inflation.v1beta3.js",
"./akash/inventory/v1": "./dist/index.akash.inventory.v1.js",
"./akash/inventory/v1/grpc-js": "./dist/index.akash.inventory.v1.grpc-js.js",
"./akash/manifest/v2beta3": "./dist/index.akash.manifest.v2beta3.js",
"./akash/manifest/v2beta3/grpc-js": "./dist/index.akash.manifest.v2beta3.grpc-js.js",
"./akash/market/v1": "./dist/index.akash.market.v1.js",
"./akash/market/v1beta5": "./dist/index.akash.market.v1beta5.js",
"./akash/market/v1beta5/grpc-js": "./dist/index.akash.market.v1beta5.grpc-js.js",
"./akash/provider/lease/v1": "./dist/index.akash.provider.lease.v1.js",
"./akash/provider/lease/v1/grpc-js": "./dist/index.akash.provider.lease.v1.grpc-js.js",
"./akash/provider/v1": "./dist/index.akash.provider.v1.js",
"./akash/provider/v1/grpc-js": "./dist/index.akash.provider.v1.grpc-js.js",
"./akash/provider/v1beta4": "./dist/index.akash.provider.v1beta4.js",
"./akash/provider/v1beta4/grpc-js": "./dist/index.akash.provider.v1beta4.grpc-js.js",
"./akash/staking/v1beta3": "./dist/index.akash.staking.v1beta3.js",
"./akash/staking/v1beta3/grpc-js": "./dist/index.akash.staking.v1beta3.grpc-js.js",
"./akash/take/v1": "./dist/index.akash.take.v1.js",
"./akash/take/v1/grpc-js": "./dist/index.akash.take.v1.grpc-js.js",
"./v1": "./dist/index.v1.js",
"./v1beta3": "./dist/index.v1beta3.js",
"./v1beta4": "./dist/index.v1beta4.js",
"./akash/audit": "./dist/generated/index.akash.audit.js",
"./akash/audit/v1": "./dist/generated/index.akash.audit.v1.js",
"./akash/audit/v1/grpc-js": "./dist/generated/index.akash.audit.v1.grpc-js.js",
"./akash/base/attributes": "./dist/generated/index.akash.base.attributes.js",
"./akash/base/attributes/v1": "./dist/generated/index.akash.base.attributes.v1.js",
"./akash/base": "./dist/generated/index.akash.base.js",
"./akash/base/resources": "./dist/generated/index.akash.base.resources.js",
"./akash/base/resources/v1beta4": "./dist/generated/index.akash.base.resources.v1beta4.js",
"./akash/cert": "./dist/generated/index.akash.cert.js",
"./akash/cert/v1": "./dist/generated/index.akash.cert.v1.js",
"./akash/cert/v1/grpc-js": "./dist/generated/index.akash.cert.v1.grpc-js.js",
"./akash": "./dist/generated/index.akash.js",
"./akash/deployment": "./dist/generated/index.akash.deployment.js",
"./akash/deployment/v1": "./dist/generated/index.akash.deployment.v1.js",
"./akash/deployment/v1beta4": "./dist/generated/index.akash.deployment.v1beta4.js",
"./akash/deployment/v1beta4/grpc-js": "./dist/generated/index.akash.deployment.v1beta4.grpc-js.js",
"./akash/discovery": "./dist/generated/index.akash.discovery.js",
"./akash/discovery/v1": "./dist/generated/index.akash.discovery.v1.js",
"./akash/escrow": "./dist/generated/index.akash.escrow.js",
"./akash/escrow/v1": "./dist/generated/index.akash.escrow.v1.js",
"./akash/gov": "./dist/generated/index.akash.gov.js",
"./akash/gov/v1beta3": "./dist/generated/index.akash.gov.v1beta3.js",
"./akash/inflation": "./dist/generated/index.akash.inflation.js",
"./akash/inflation/v1beta2": "./dist/generated/index.akash.inflation.v1beta2.js",
"./akash/inflation/v1beta3": "./dist/generated/index.akash.inflation.v1beta3.js",
"./akash/inventory": "./dist/generated/index.akash.inventory.js",
"./akash/inventory/v1": "./dist/generated/index.akash.inventory.v1.js",
"./akash/inventory/v1/grpc-js": "./dist/generated/index.akash.inventory.v1.grpc-js.js",
"./akash/manifest": "./dist/generated/index.akash.manifest.js",
"./akash/manifest/v2beta3": "./dist/generated/index.akash.manifest.v2beta3.js",
"./akash/manifest/v2beta3/grpc-js": "./dist/generated/index.akash.manifest.v2beta3.grpc-js.js",
"./akash/market": "./dist/generated/index.akash.market.js",
"./akash/market/v1": "./dist/generated/index.akash.market.v1.js",
"./akash/market/v1beta5": "./dist/generated/index.akash.market.v1beta5.js",
"./akash/market/v1beta5/grpc-js": "./dist/generated/index.akash.market.v1beta5.grpc-js.js",
"./akash/provider": "./dist/generated/index.akash.provider.js",
"./akash/provider/lease": "./dist/generated/index.akash.provider.lease.js",
"./akash/provider/lease/v1": "./dist/generated/index.akash.provider.lease.v1.js",
"./akash/provider/lease/v1/grpc-js": "./dist/generated/index.akash.provider.lease.v1.grpc-js.js",
"./akash/provider/v1": "./dist/generated/index.akash.provider.v1.js",
"./akash/provider/v1/grpc-js": "./dist/generated/index.akash.provider.v1.grpc-js.js",
"./akash/provider/v1beta4": "./dist/generated/index.akash.provider.v1beta4.js",
"./akash/provider/v1beta4/grpc-js": "./dist/generated/index.akash.provider.v1beta4.grpc-js.js",
"./akash/staking": "./dist/generated/index.akash.staking.js",
"./akash/staking/v1beta3": "./dist/generated/index.akash.staking.v1beta3.js",
"./akash/staking/v1beta3/grpc-js": "./dist/generated/index.akash.staking.v1beta3.grpc-js.js",
"./akash/take": "./dist/generated/index.akash.take.js",
"./akash/take/v1": "./dist/generated/index.akash.take.v1.js",
"./akash/take/v1/grpc-js": "./dist/generated/index.akash.take.v1.grpc-js.js",
"./amino": "./dist/generated/index.amino.js",
"./cosmos/base": "./dist/generated/index.cosmos.base.js",
"./cosmos/base/query": "./dist/generated/index.cosmos.base.query.js",
"./cosmos/base/query/v1beta1": "./dist/generated/index.cosmos.base.query.v1beta1.js",
"./cosmos/base/v1beta1": "./dist/generated/index.cosmos.base.v1beta1.js",
"./cosmos": "./dist/generated/index.cosmos.js",
"./cosmos/msg": "./dist/generated/index.cosmos.msg.js",
"./cosmos/msg/v1": "./dist/generated/index.cosmos.msg.v1.js",
"./cosmos_proto": "./dist/generated/index.cosmos_proto.js",
"./gogoproto": "./dist/generated/index.gogoproto.js",
"./google/api": "./dist/generated/index.google.api.js",
"./google": "./dist/generated/index.google.js",
"./google/protobuf": "./dist/generated/index.google.protobuf.js",
"./k8s": "./dist/generated/index.k8s.js",
"./k8s/io/apimachinery": "./dist/generated/index.k8s.io.apimachinery.js",
"./k8s/io/apimachinery/pkg/api": "./dist/generated/index.k8s.io.apimachinery.pkg.api.js",
"./k8s/io/apimachinery/pkg/api/resource": "./dist/generated/index.k8s.io.apimachinery.pkg.api.resource.js",
"./k8s/io/apimachinery/pkg": "./dist/generated/index.k8s.io.apimachinery.pkg.js",
"./k8s/io": "./dist/generated/index.k8s.io.js"
"./v1beta5": "./dist/index.v1beta5.js",
"./v2beta3": "./dist/index.v2beta3.js"
}
}
4 changes: 2 additions & 2 deletions ts/script/generate-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");
const path = require("path");
const staticExports = require("../static-exports.json");

const distDir = path.resolve(__dirname, "../dist/generated");
const distDir = path.resolve(__dirname, "../dist");
const files = fs.readdirSync(distDir);
const paths = files.reduce((acc, file) => {
const match = file.match(/index.(.*)\.d\.ts/);
Expand All @@ -14,7 +14,7 @@ const paths = files.reduce((acc, file) => {
const slashedPath = dottedPath.replace(/\./g, "/");
const resolvedPath = fs.existsSync(`./dist/patch/index.${dottedPath}.js`)
? `./dist/patch/index.${dottedPath}`
: `./dist/generated/index.${dottedPath}`;
: `./dist/index.${dottedPath}`;

acc.tsconfig[`@akashnetwork/akash-api/${slashedPath}`] = [resolvedPath];
acc.package[`./${slashedPath}`] = `${resolvedPath}.js`;
Expand Down
78 changes: 78 additions & 0 deletions ts/script/generate-index-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node

const fs = require("fs/promises");
const path = require("path");

async function getAllPaths(dir) {
let results = [];

const entries = await fs.readdir(dir, { withFileTypes: true });

for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
const subEntries = await getAllPaths(fullPath);
results = results.concat(subEntries);
} else {
results.push(fullPath);
}
}

return results;
}

const EXCLUSIONS = ["genesis", "params", "service", "query"];

(async () => {
const directory = path.resolve(__dirname, "../src/generated");
const allPaths = await getAllPaths(directory);
const root = `${process.cwd()}/ts/src/generated/`;
const nsWithExports = allPaths
.filter((path) => !path.endsWith("d.ts") && path.endsWith(".ts"))
.reduce((acc, path) => {
const relativePath = path.replace(root, "").replace(".ts", "");
const pathParts = relativePath.split("/");
const [fileName] = pathParts.splice(pathParts.length - 1, 1);

const ns = pathParts.join(".");

if (!ns || !ns.includes("akash")) {
return acc;
}

if (!acc[ns]) {
acc[ns] = [];
}

acc[ns].push(relativePath);

const version = pathParts[pathParts.length - 1];

if (EXCLUSIONS.includes(fileName)) {
return acc;
}

if (!acc[version]) {
acc[version] = [];
}

acc[version].push(relativePath);

return acc;
}, {});

const namespaces = Object.keys(nsWithExports);

namespaces.forEach((ns) => {
const nsExports = nsWithExports[ns];
const content = nsExports.reduce((acc, file) => {
return `${acc}export * from "./${file}";\n`;
}, "");

fs.writeFile(
path.resolve(__dirname, `../src/generated/index.${ns}.ts`),
content,
"utf8",
);
});
})();
2 changes: 0 additions & 2 deletions ts/src/generated/akash/audit/v1/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions ts/src/generated/akash/cert/v1/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ts/src/generated/akash/deployment/v1/msg.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions ts/src/generated/akash/inventory/v1/service.grpc-js.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading