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): exports all the generated namespaces (#184) #142

Merged
merged 4 commits into from
Apr 9, 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
4 changes: 2 additions & 2 deletions script/protocgen-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for dir in $proto_dirs; do
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

Expand Down Expand Up @@ -72,7 +72,7 @@ for dir in $proto_dirs; do
-I "vendor/github.com/cosmos/cosmos-sdk/third_party/proto" \
--plugin="${AKASH_TS_NODE_BIN}/protoc-gen-ts_proto" \
--ts_proto_out="${AKASH_TS_ROOT}/src/generated" \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false \
--ts_proto_opt=esModuleInterop=true,forceLong=long,outputTypeRegistry=true,useExactTypes=false,outputIndex=true \
$(find "${dir}" -maxdepth 1 -name '*.proto')
done

Expand Down
23 changes: 21 additions & 2 deletions ts/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,30 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "simple-import-sort"],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "ignoreRestSiblings": true }
{
"ignoreRestSiblings": true
}
],
"simple-import-sort/imports": [
"error",
{
"groups": [
["^(@|src|@src)?\\w"],
[
"^(src|main|core|arc-storybook|viz|design-system|placement|reporting|onboarding)(/.*|$)",
"^\\u0000",
"^\\.\\.(?!/?$)",
"^\\.\\./?$",
"^\\./(?=.*/)(?!/?$)",
"^\\.(?!/?$)",
"^\\./?$"
]
]
}
]
}
}
1 change: 1 addition & 0 deletions ts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/dist
/build
/node_modules
tsconfig.paths.json

# Logs
logs
Expand Down
2 changes: 1 addition & 1 deletion ts/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ts/node_modules/.bin/lint-staged --cwd ts
ts/node_modules/.bin/lint-staged --cwd ts
56 changes: 56 additions & 0 deletions ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Akash API TypeScript Bindings

[![npm version](https://badge.fury.io/js/%40akashnetwork%2Fakash-api.svg)](https://badge.fury.io/js/%40akashnetwork%2Fakash-api)
[![License: Apache-2.0](https://img.shields.io/badge/License-apache2.0-yellow.svg)](https://opensource.org/license/apache-2-0)

This package provides TypeScript bindings for the Akash API, generated from protobuf definitions.

## Installation

To install the package, run:

```bash
npm install @akashnetwork/akash-api
```

## Usage

You can import the generated namespaces from the package like this:
```typescript
import * as akashDeploymentV1beta1 from '@akashnetwork/akash-api/akash/deployment/v1beta1';
import * as akashDiscoveryV1 from '@akashnetwork/akash-api/akash/discovery/v1';
// ... and so on for other namespaces
```

### TypeScript 4.5 and above
If you're using TypeScript 4.5 or above, the package exports all the paths of the generated namespaces, so you can import them directly.

### TypeScript below 4.5
If you're using a version of TypeScript below 4.5, the package provides a tsconfig.paths.json file that you can extend in your local TypeScript configuration to resolve the paths. Here's how you can do it: In your tsconfig.json file, add the following:
```json
{
"extends": "@akashnetwork/akash-api/tsconfig.paths.json"
}
```

### Contributing
Contributions are welcome. Please submit a pull request or create an issue to discuss the changes you want to make.

### Contributing to Generated Files

The files in the `src/generated` directory are auto-generated and should not be modified directly. If you need to make changes to these files, follow the steps below:

1. Create a new file in the `src/patch` directory with the same path as the file you want to modify. For example, if you want to modify `src/generated/cosmos/base/v1beta1/coin.ts`, you should create the directory `src/patch/cosmos/base/v1beta1/coin.ts`.

2. Add your changes to a new file in the `src/patch` directory. The new file should have the same name as the file you want to modify.

3. Rename the original file in the `src/generated` directory by appending `.original.ts` to its name. For example, `src/generated/cosmos/base/v1beta1/coin.ts` should be renamed to `src/generated/cosmos/base/v1beta1/coin.original.ts`.

4. Create a new file in the `src/generated` directory with the same name as the original file. This new file should re-export everything from the corresponding file in the `src/patch` directory. For example, the content of `src/generated/cosmos/base/v1beta1/coin.ts` should be:

```typescript
export * from '../../../../patch/cosmos/base/v1beta1/coin';
```

### License
This package is licensed under the Apache-2.0.
25 changes: 25 additions & 0 deletions ts/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const common = {
transform: {
'^.+\\.(t|j)s$': ['ts-jest', { tsconfig: './tsconfig.json' }],
},
rootDir: '.',
setupFiles: ['./test/setup.ts'],
};

module.exports = {
collectCoverageFrom: ['./src/**/*.{js,ts}'],
projects: [
{
displayName: 'unit',
...common,
testMatch: ['<rootDir>/src/**/*.spec.ts'],
setupFilesAfterEnv: ['./test/setup-unit-tests.ts'],
},
{
displayName: 'functional',
...common,
testMatch: ['<rootDir>/test/functional/**/*.spec.ts'],
setupFilesAfterEnv: ['./test/setup-functional-tests.ts'],
},
],
};
Loading
Loading