-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Problem
The RpcQueryRequestSchema supports 8 different request types, but we only have convenience functions for 3 of them.
Current Status
✅ Have convenience functions for:
view_account→viewAccount()view_access_key→viewAccessKey()call_function→viewFunction()
❌ Missing convenience functions for:
view_codeview_stateview_access_key_listview_global_contract_codeview_global_contract_code_by_account_id
Proposed Solution
Option 1: Manual Implementation
Add the missing convenience functions to /packages/jsonrpc-client/src/convenience.ts following the existing pattern.
Option 2: Auto-generation (Recommended)
Since all convenience functions follow the same pattern, they could be auto-generated:
- Parse
RpcQueryRequestSchemato extract all request types - For each request type, generate a convenience function that:
- Takes appropriate parameters based on the schema
- Constructs query params with blockId/finality logic
- Calls the generic
query()function - Returns the properly typed result
Benefits of auto-generation:
- Ensures complete coverage of all request types
- Maintains consistency across all convenience functions
- Automatically stays in sync with OpenAPI spec updates
- Reduces manual maintenance
Implementation Notes
The pattern for all convenience functions is:
export async function viewSomething(
client: NearRpcClient,
params: {
// specific params for this request type
finality?: 'final' | 'near-final' | 'optimistic';
blockId?: string | number;
}
): Promise<SpecificReturnType> {
const queryParams = params.blockId
? { requestType: 'view_something', ...specificParams, blockId: params.blockId }
: { requestType: 'view_something', ...specificParams, finality: params.finality || 'final' };
return query(client, queryParams) as Promise<SpecificReturnType>;
}The generator would need to:
- Map request types to function names (e.g.,
view_access_key_list→viewAccessKeyList) - Extract required parameters from the schema
- Map to appropriate return types from
RpcQueryResponseSchema
Related Files
/packages/jsonrpc-client/src/convenience.ts- Current convenience functions/packages/jsonrpc-types/src/schemas.ts- RpcQueryRequestSchema definition (line 2634)/tools/codegen/generate.ts- Could be extended to generate convenience functions
Metadata
Metadata
Assignees
Labels
No labels