-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature automatically generate Typescript client based on openRPC doc…
…umentation (#545) * feat: add code auto gen client * feat: remove petstore-openrpc.json * feat: ok gen rooch client types * feat: auto gen client * feat: auto gen rooch typescript client ok * feat: remove deps * feat: update utils comment
- Loading branch information
Showing
13 changed files
with
4,337 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,7 @@ dist/ | |
build/ | ||
|
||
# Doc generation output | ||
docs/ | ||
docs/ | ||
|
||
# client generation output | ||
generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"node": ">=18.0.0" | ||
}, | ||
"packageManager": "[email protected]", | ||
"type": "module", | ||
"scripts": { | ||
"clean": "rm -rf tsconfig.tsbuildinfo ./dist", | ||
"dev": "vite", | ||
|
@@ -25,7 +26,8 @@ | |
"eslint:check": "eslint --max-warnings=0 .", | ||
"eslint:fix": "pnpm run eslint:check --fix", | ||
"lint": "pnpm run eslint:check && pnpm run prettier:check", | ||
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix" | ||
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix", | ||
"gen:client": "node ./tools/generator/main.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -57,21 +59,22 @@ | |
"@iarna/toml": "^2.2.5", | ||
"@size-limit/preset-small-lib": "^8.2.4", | ||
"@types/node": "^18.15.11", | ||
"eslint": "8.23.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
"eslint-config-airbnb-typescript": "17.0.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"json-schema-ref-parser": "6.1.0", | ||
"msw": "^1.2.1", | ||
"prettier": "^3.0.0", | ||
"ts-retry-promise": "^0.7.0", | ||
"tsx": "^3.12.7", | ||
"typedoc": "^0.24.1", | ||
"typescript": "^5.0.4", | ||
"vite": "^4.2.3", | ||
"vite-plugin-dts": "^3.3.1", | ||
"vitest": "^0.32.0", | ||
"wait-on": "^7.0.1", | ||
"eslint": "8.23.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
"eslint-config-airbnb-typescript": "17.0.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"prettier": "2.6.2" | ||
"wait-on": "^7.0.1" | ||
}, | ||
"dependencies": { | ||
"@noble/curves": "^1.0.0", | ||
|
@@ -80,6 +83,7 @@ | |
"@scure/bip32": "^1.3.0", | ||
"@scure/bip39": "^1.2.0", | ||
"@suchipi/femver": "^1.0.0", | ||
"ejs": "^3.1.9", | ||
"events": "^3.3.0", | ||
"superstruct": "^1.0.3", | ||
"tweetnacl": "^1.0.3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// This file was generated by `yarn gen:client`. Please, do not modify it. | ||
import { RequestManager, Client } from "@open-rpc/client-js"; | ||
import { | ||
ExecuteTransactionResponseView, | ||
FunctionCallView, | ||
AnnotatedFunctionReturnValueView, | ||
AccessPath, | ||
AnnotatedStateView, | ||
EventFilterView, | ||
AnnotatedEventView, | ||
StructTag, | ||
PageView_for_Nullable_AnnotatedEventView_and_uint64, | ||
StateView, | ||
Hex, | ||
TransactionView, | ||
TransactionExecutionInfoView, | ||
PageView_for_Nullable_TransactionExecutionInfoView_and_uint128, | ||
} from "./types"; | ||
|
||
export class RoochClient extends Client { | ||
constructor(requestManager: RequestManager) { | ||
super(requestManager); | ||
} | ||
|
||
async getRpcApiVersion(): Promise<string | undefined> { | ||
const resp = await this.request({ | ||
method: "rpc.discover", | ||
params: [], | ||
}); | ||
|
||
return resp.info.version as string; | ||
} | ||
|
||
// Send the signed transaction in bcs hex format This method blocks waiting for the transaction to be executed. | ||
async rooch_executeRawTransaction( | ||
tx_bcs_hex: Uint8Array, | ||
): Promise<ExecuteTransactionResponseView> { | ||
const resp = await this.request({ | ||
method: "rooch_executeRawTransaction", | ||
params: [tx_bcs_hex], | ||
}); | ||
|
||
return resp as ExecuteTransactionResponseView; | ||
} | ||
|
||
// Execute a read-only function call The function do not change the state of Application | ||
async rooch_executeViewFunction( | ||
function_call: FunctionCallView, | ||
): Promise<AnnotatedFunctionReturnValueView[]> { | ||
const resp = await this.request({ | ||
method: "rooch_executeViewFunction", | ||
params: [function_call], | ||
}); | ||
|
||
return resp as AnnotatedFunctionReturnValueView[]; | ||
} | ||
|
||
// Get the annotated states by access_path The annotated states include the decoded move value of the state | ||
async rooch_getAnnotatedStates( | ||
access_path: AccessPath, | ||
): Promise<AnnotatedStateView | null[]> { | ||
const resp = await this.request({ | ||
method: "rooch_getAnnotatedStates", | ||
params: [access_path], | ||
}); | ||
|
||
return resp as AnnotatedStateView | null[]; | ||
} | ||
|
||
// Get the events by event filter | ||
async rooch_getEvents( | ||
filter: EventFilterView, | ||
): Promise<AnnotatedEventView | null[]> { | ||
const resp = await this.request({ | ||
method: "rooch_getEvents", | ||
params: [filter], | ||
}); | ||
|
||
return resp as AnnotatedEventView | null[]; | ||
} | ||
|
||
// Get the events by event handle id | ||
async rooch_getEventsByEventHandle( | ||
event_handle_type: StructTag, | ||
cursor: number, | ||
limit: number, | ||
): Promise<PageView_for_Nullable_AnnotatedEventView_and_uint64> { | ||
const resp = await this.request({ | ||
method: "rooch_getEventsByEventHandle", | ||
params: [event_handle_type, cursor, limit], | ||
}); | ||
|
||
return resp as PageView_for_Nullable_AnnotatedEventView_and_uint64; | ||
} | ||
|
||
// Get the states by access_path | ||
async rooch_getStates(access_path: AccessPath): Promise<StateView | null[]> { | ||
const resp = await this.request({ | ||
method: "rooch_getStates", | ||
params: [access_path], | ||
}); | ||
|
||
return resp as StateView | null[]; | ||
} | ||
|
||
async rooch_getTransactionByHash(hash: Hex): Promise<TransactionView> { | ||
const resp = await this.request({ | ||
method: "rooch_getTransactionByHash", | ||
params: [hash], | ||
}); | ||
|
||
return resp as TransactionView; | ||
} | ||
|
||
async rooch_getTransactionByIndex( | ||
start: number, | ||
limit: number, | ||
): Promise<TransactionView[]> { | ||
const resp = await this.request({ | ||
method: "rooch_getTransactionByIndex", | ||
params: [start, limit], | ||
}); | ||
|
||
return resp as TransactionView[]; | ||
} | ||
|
||
async rooch_getTransactionInfosByTxHash( | ||
tx_hashes: Hex[], | ||
): Promise<TransactionExecutionInfoView | null[]> { | ||
const resp = await this.request({ | ||
method: "rooch_getTransactionInfosByTxHash", | ||
params: [tx_hashes], | ||
}); | ||
|
||
return resp as TransactionExecutionInfoView | null[]; | ||
} | ||
|
||
async rooch_getTransactionInfosByTxOrder( | ||
cursor: number, | ||
limit: number, | ||
): Promise<PageView_for_Nullable_TransactionExecutionInfoView_and_uint128> { | ||
const resp = await this.request({ | ||
method: "rooch_getTransactionInfosByTxOrder", | ||
params: [cursor, limit], | ||
}); | ||
|
||
return resp as PageView_for_Nullable_TransactionExecutionInfoView_and_uint128; | ||
} | ||
|
||
// Send the signed transaction in bcs hex format This method does not block waiting for the transaction to be executed. | ||
async rooch_sendRawTransaction(tx_bcs_hex: Uint8Array): Promise<Hex> { | ||
const resp = await this.request({ | ||
method: "rooch_sendRawTransaction", | ||
params: [tx_bcs_hex], | ||
}); | ||
|
||
return resp as Hex; | ||
} | ||
} | ||
|
||
// This file was generated by `yarn gen:client`. Please, do not modify it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// This file was generated by `yarn gen:client`. Please, do not modify it. | ||
export * from "./types"; | ||
export * from "./client"; | ||
|
||
// This file was generated by `yarn gen:client`. Please, do not modify it. |
Oops, something went wrong.