Skip to content

refactor: migrate to bun #188

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.yarn
key: yarn-${{ hashFiles('yarn.lock') }}
restore-keys: yarn-
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-bun-

- name: Install modules
run: yarn install
run: bun install

- name: ESLint
run: ./node_modules/.bin/eslint '**/*.ts' --fix
run: bun run eslint '**/*.ts' --fix

- name: Prettier
run: ./node_modules/.bin/prettier --check .
run: bun run prettier --check .
16 changes: 11 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.yarn
key: yarn-${{ hashFiles('yarn.lock') }}
restore-keys: yarn-
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-bun-

- name: Install modules
run: yarn install
run: bun install

- name: Tests
run: ./node_modules/.bin/jest --passWithNoTests
run: bun test
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,41 @@
- Provides the ability to interact with Gno Realms / Packages
- Easy interaction with VM-specific ABCI queries

## Requirements

This project uses [Bun](https://bun.sh/). If you haven't installed Bun yet, you can get it from [bun.com/get](https://bun.com/get).

## Installation

To install `@gnolang/gno-js-client`, use your preferred package manager:

```bash
yarn add @gnolang/gno-js-client
bun add @gnolang/gno-js-client
```

```bash
npm install @gnolang/gno-js-client
```

```bash
yarn add @gnolang/gno-js-client
```

## Testing

This project uses [Bun](https://bun.sh/) for testing. To run the tests:

```bash
# Run all tests
bun test

# Run tests in watch mode
bun test --watch

# Run tests with coverage
bun test --coverage
```

## Documentation

For the sake of keeping the README short and sweet, you can find the documentation and usage examples
Expand Down
461 changes: 461 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import tsEslint from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
import eslintConfigPrettier from 'eslint-config-prettier';

export default [
/** @type {import('eslint').Linter.Config} */
const config = [
eslintConfigPrettier,
pluginJs.configs.recommended,
...tsEslint.configs.recommended,
Expand All @@ -15,8 +16,10 @@ export default [
languageOptions: { globals: globals.browser, parser: tsParser },
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'no-async-promise-executor': 'warn',
'@typescript-eslint/no-unused-vars': 'off', // covered by typescript no-unused-*
},
},
];

export default config;
5 changes: 0 additions & 5 deletions jest.config.json

This file was deleted.

15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
],
"devDependencies": {
"@eslint/js": "^9.31.0",
"@types/jest": "^30.0.0",
"@types/node": "^24.0.14",
"@types/bun": "^1.2.20",
"@typescript-eslint/eslint-plugin": "^8.37.0",
"@typescript-eslint/parser": "^8.37.0",
"eslint": "^9.31.0",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-prettier": "^5.5.1",
"globals": "^16.3.0",
"jest": "^30.0.4",
"prettier": "^3.6.2",
"ts-jest": "^29.4.0",
"ts-proto": "^2.7.5",
"typescript": "^5.8.3",
"typescript-eslint": "^8.37.0"
Expand All @@ -44,10 +41,12 @@
"tsc": "tsc",
"lint": "eslint '**/*.ts' --fix",
"prettier": "prettier --write .",
"build": "yarn tsc",
"test": "jest",
"prepare": "yarn build",
"prepublishOnly": "yarn lint && yarn prettier"
"build": "bun run tsc",
"test": "bun test",
"test:watch": "bun test --watch",
"test:coverage": "bun test --coverage",
"prepare": "bun run build",
"prepublishOnly": "bun run lint && bun run prettier"
},
"dependencies": {
"@cosmjs/ledger-amino": "^0.34.0",
Expand Down
14 changes: 7 additions & 7 deletions src/provider/jsonrpc/jsonrpc.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GnoProvider } from '../provider';
import type { GnoProvider } from '../provider';
import {
ABCIEndpoint,
ABCIResponse,
type ABCIResponse,
JSONRPCProvider,
newRequest,
RestService,
} from '@gnolang/tm2-js-client';
import { FunctionSignature } from '../types';
import type { FunctionSignature } from '../types';
import { VMEndpoint } from '../endpoints';
import {
extractStringFromResponse,
Expand All @@ -30,7 +30,7 @@ export class GnoJSONRPCProvider extends JSONRPCProvider implements GnoProvider {
async evaluateExpression(
packagePath: string,
expression: string,
height?: number
_height?: number
): Promise<string> {
const abciResponse: ABCIResponse = await RestService.post<ABCIResponse>(
this.baseURL,
Expand All @@ -47,7 +47,7 @@ export class GnoJSONRPCProvider extends JSONRPCProvider implements GnoProvider {
return extractStringFromResponse(abciResponse.response.ResponseBase.Data);
}

async getFileContent(packagePath: string, height?: number): Promise<string> {
async getFileContent(packagePath: string, _height?: number): Promise<string> {
const abciResponse: ABCIResponse = await RestService.post<ABCIResponse>(
this.baseURL,
{
Expand All @@ -65,7 +65,7 @@ export class GnoJSONRPCProvider extends JSONRPCProvider implements GnoProvider {

async getFunctionSignatures(
packagePath: string,
height?: number
_height?: number
): Promise<FunctionSignature[]> {
const abciResponse: ABCIResponse = await RestService.post<ABCIResponse>(
this.baseURL,
Expand All @@ -90,7 +90,7 @@ export class GnoJSONRPCProvider extends JSONRPCProvider implements GnoProvider {
async getRenderOutput(
packagePath: string,
path: string,
height?: number
_height?: number
): Promise<string> {
const abciResponse: ABCIResponse = await RestService.post<ABCIResponse>(
this.baseURL,
Expand Down
4 changes: 2 additions & 2 deletions src/provider/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Provider } from '@gnolang/tm2-js-client';
import { FunctionSignature } from './types';
import type { Provider } from '@gnolang/tm2-js-client';
import type { FunctionSignature } from './types';

/**
* GnoProvider is the Provider interface for Gno-specific functionality
Expand Down
14 changes: 7 additions & 7 deletions src/provider/websocket/ws.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GnoProvider } from '../provider';
import type { GnoProvider } from '../provider';
import {
type ABCIResponse,
ABCIEndpoint,
ABCIResponse,
newRequest,
WSProvider,
} from '@gnolang/tm2-js-client';
import { FunctionSignature } from '../types';
import type { FunctionSignature } from '../types';
import { VMEndpoint } from '../endpoints';
import {
extractStringFromResponse,
Expand All @@ -27,7 +27,7 @@ export class GnoWSProvider extends WSProvider implements GnoProvider {
async evaluateExpression(
packagePath: string,
expression: string,
height?: number
_height?: number
): Promise<string> {
const response = await this.sendRequest<ABCIResponse>(
newRequest(ABCIEndpoint.ABCI_QUERY, [
Expand All @@ -44,7 +44,7 @@ export class GnoWSProvider extends WSProvider implements GnoProvider {
return extractStringFromResponse(abciResponse.response.ResponseBase.Data);
}

async getFileContent(packagePath: string, height?: number): Promise<string> {
async getFileContent(packagePath: string, _height?: number): Promise<string> {
const response = await this.sendRequest<ABCIResponse>(
newRequest(ABCIEndpoint.ABCI_QUERY, [
`vm/${VMEndpoint.FILE_CONTENT}`,
Expand All @@ -62,7 +62,7 @@ export class GnoWSProvider extends WSProvider implements GnoProvider {

async getFunctionSignatures(
packagePath: string,
height?: number
_height?: number
): Promise<FunctionSignature[]> {
const response = await this.sendRequest<ABCIResponse>(
newRequest(ABCIEndpoint.ABCI_QUERY, [
Expand All @@ -87,7 +87,7 @@ export class GnoWSProvider extends WSProvider implements GnoProvider {
async getRenderOutput(
packagePath: string,
path: string,
height?: number
_height?: number
): Promise<string> {
const response = await this.sendRequest<ABCIResponse>(
newRequest(ABCIEndpoint.ABCI_QUERY, [
Expand Down
10 changes: 8 additions & 2 deletions src/wallet/utility/utility.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Any, MsgAddPackage, MsgCall, MsgSend } from '../../proto';
import { type Any, MsgAddPackage, MsgCall, MsgSend } from '../../proto';
import { MsgRun } from '../../proto/gno/vm';
import { MsgEndpoint } from '../endpoints';

Expand Down Expand Up @@ -32,11 +32,17 @@ export const fundsToCoins = (funds?: Map<string, number>): string => {
*/
export const defaultTxFee = '1000000ugnot'; // 1 GNOT

export type DecodedMessage<
T extends Record<string, unknown> = Record<string, unknown>,
> = T & {
'@type': MsgEndpoint;
};

/**
* Decodes (and unrolls) Transaction messages into full objects
* @param {Any[]} messages the encoded transaction messages
*/
export const decodeTxMessages = (messages: Any[]): any[] => {
export const decodeTxMessages = (messages: Any[]): DecodedMessage[] => {
return messages.map((m: Any) => {
switch (m.type_url) {
case MsgEndpoint.MSG_CALL: {
Expand Down
12 changes: 6 additions & 6 deletions src/wallet/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
AccountWalletOption,
BroadcastTransactionMap,
CreateWalletOptions,
Signer,
Tx,
TxFee,
type AccountWalletOption,
type BroadcastTransactionMap,
type CreateWalletOptions,
type Signer,
type Tx,
type TxFee,
Wallet,
} from '@gnolang/tm2-js-client';
import { decodeTxMessages, defaultTxFee, fundsToCoins } from './utility';
Expand Down
30 changes: 21 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"outDir": "./bin",
"rootDir": "./src",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"declaration": true,
"strictPropertyInitialization": false
"strictPropertyInitialization": false,
"verbatimModuleSyntax": true,
"types": ["@types/bun"],

// Disable potentially problematic strictest options for this codebase
"exactOptionalPropertyTypes": false,
"noUncheckedIndexedAccess": false,
"noPropertyAccessFromIndexSignature": false,
"checkJs": false
},
"include": ["./src/**/*.ts"],
"exclude": ["./node_modules"]
"include": ["./src/**/*.ts", "./src/**/*.d.ts"],
"exclude": [
"./node_modules",
"**/*.test.ts",
"**/*.spec.ts",
"**/__tests__/**"
]
}
Loading