@psalomo/jsonrpc-client 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,10 @@
1
1
  import { RpcStateChangesInBlockByTypeRequest, RpcStateChangesInBlockResponse, RpcStateChangesInBlockRequest, RpcStateChangesInBlockByTypeResponse, RpcCongestionLevelRequest, RpcCongestionLevelResponse, GenesisConfigRequest, GenesisConfig, RpcLightClientBlockProofRequest, RpcLightClientBlockProofResponse, RpcLightClientExecutionProofRequest, RpcLightClientExecutionProofResponse, RpcMaintenanceWindowsRequest, EXPERIMENTALMaintenanceWindowsResponse, RpcProtocolConfigRequest, RpcProtocolConfigResponse, RpcReceiptRequest, RpcReceiptResponse, RpcSplitStorageInfoRequest, RpcSplitStorageInfoResponse, RpcTransactionStatusRequest, RpcTransactionResponse, RpcValidatorsOrderedRequest, EXPERIMENTALValidatorsOrderedResponse, RpcBlockRequest, RpcBlockResponse, RpcSendTransactionRequest, CryptoHash, RpcChunkRequest, RpcChunkResponse, RpcClientConfigRequest, RpcClientConfigResponse, RpcGasPriceRequest, RpcGasPriceResponse, RpcHealthRequest, RpcHealthResponse, MaintenanceWindowsResponse, RpcNetworkInfoRequest, RpcNetworkInfoResponse, RpcLightClientNextBlockRequest, RpcLightClientNextBlockResponse, RpcQueryRequest, RpcQueryResponse, RpcStatusRequest, RpcStatusResponse, RpcValidatorRequest, RpcValidatorResponse, AccountView, CallResult, AccessKeyView } from '@psalomo/jsonrpc-types';
2
2
 
3
- interface ValidationResult {
4
- validateRequest: (request: JsonRpcRequest) => void;
5
- validateResponse: (response: JsonRpcResponse) => void;
6
- validateMethodRequest?: (method: string, request: JsonRpcRequest) => void;
7
- validateMethodResponse?: (method: string, response: JsonRpcResponse) => void;
8
- }
9
- /**
10
- * Enable validation for the client
11
- * This function should only be called if you want to include schema validation
12
- * Calling this function will include Zod schemas in your bundle
13
- */
14
- declare function enableValidation(): ValidationResult;
15
-
16
3
  interface ClientConfig {
17
4
  endpoint: string;
18
5
  headers?: Record<string, string>;
19
6
  timeout?: number;
20
7
  retries?: number;
21
- validation?: ValidationResult;
22
8
  }
23
9
  interface JsonRpcRequest<T = unknown> {
24
10
  jsonrpc: '2.0';
@@ -57,7 +43,6 @@ declare class NearRpcClient {
57
43
  readonly headers: Record<string, string>;
58
44
  readonly timeout: number;
59
45
  readonly retries: number;
60
- private readonly validation;
61
46
  constructor(config: string | ClientConfig);
62
47
  /**
63
48
  * Make a raw JSON-RPC request
@@ -95,36 +80,150 @@ declare class NearRpcError extends Error {
95
80
  }
96
81
 
97
82
  interface DynamicRpcMethods {
83
+ /**
84
+ * [Deprecated] Returns changes for a given account, contract or contract code
85
+ * for given block height or hash. Consider using changes instead.
86
+ */
98
87
  experimentalChanges(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
88
+ /**
89
+ * [Deprecated] Returns changes in block for given block height or hash over
90
+ * all transactions for all the types. Includes changes like account_touched,
91
+ * access_key_touched, data_touched, contract_code_touched. Consider using
92
+ * block_effects instead
93
+ */
99
94
  experimentalChangesInBlock(params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
95
+ /**
96
+ * Queries the congestion level of a shard. More info about congestion
97
+ * [here](https://near.github.io/nearcore/architecture/how/receipt-congestion.html?highlight=congestion#receipt-congestion)
98
+ */
100
99
  experimentalCongestionLevel(params?: RpcCongestionLevelRequest): Promise<RpcCongestionLevelResponse>;
100
+ /**
101
+ * [Deprecated] Get initial state and parameters for the genesis block.
102
+ * Consider genesis_config instead.
103
+ */
101
104
  experimentalGenesisConfig(params?: GenesisConfigRequest): Promise<GenesisConfig>;
105
+ /** Returns the proofs for a transaction execution. */
102
106
  experimentalLightClientBlockProof(params?: RpcLightClientBlockProofRequest): Promise<RpcLightClientBlockProofResponse>;
107
+ /** Returns the proofs for a transaction execution. */
103
108
  experimentalLightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
109
+ /**
110
+ * [Deprecated] Returns the future windows for maintenance in current epoch
111
+ * for the specified account. In the maintenance windows, the node will not be
112
+ * block producer or chunk producer. Consider using maintenance_windows
113
+ * instead.
114
+ */
104
115
  experimentalMaintenanceWindows(params?: RpcMaintenanceWindowsRequest): Promise<EXPERIMENTALMaintenanceWindowsResponse>;
116
+ /**
117
+ * A configuration that defines the protocol-level parameters such as
118
+ * gas/storage costs, limits, feature flags, other settings
119
+ */
105
120
  experimentalProtocolConfig(params?: RpcProtocolConfigRequest): Promise<RpcProtocolConfigResponse>;
121
+ /** Fetches a receipt by its ID (as is, without a status or execution outcome) */
106
122
  experimentalReceipt(params?: RpcReceiptRequest): Promise<RpcReceiptResponse>;
123
+ /**
124
+ * Contains the split storage information. More info on split storage
125
+ * [here](https://near-nodes.io/archival/split-storage-archival)
126
+ */
107
127
  experimentalSplitStorageInfo(params?: RpcSplitStorageInfoRequest): Promise<RpcSplitStorageInfoResponse>;
128
+ /**
129
+ * Queries status of a transaction by hash, returning the final transaction
130
+ * result and details of all receipts.
131
+ */
108
132
  experimentalTxStatus(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
133
+ /**
134
+ * Returns the current epoch validators ordered in the block producer order
135
+ * with repetition. This endpoint is solely used for bridge currently and is
136
+ * not intended for other external use cases.
137
+ */
109
138
  experimentalValidatorsOrdered(params?: RpcValidatorsOrderedRequest): Promise<EXPERIMENTALValidatorsOrderedResponse>;
139
+ /** Returns block details for given height or hash */
110
140
  block(params?: RpcBlockRequest): Promise<RpcBlockResponse>;
141
+ /**
142
+ * Returns changes in block for given block height or hash over all
143
+ * transactions for all the types. Includes changes like account_touched,
144
+ * access_key_touched, data_touched, contract_code_touched.
145
+ */
111
146
  blockEffects(params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
147
+ /**
148
+ * [Deprecated] Sends a transaction and immediately returns transaction hash.
149
+ * Consider using send_tx instead.
150
+ */
112
151
  broadcastTxAsync(params?: RpcSendTransactionRequest): Promise<CryptoHash>;
152
+ /**
153
+ * [Deprecated] Sends a transaction and waits until transaction is fully
154
+ * complete. (Has a 10 second timeout). Consider using send_tx instead.
155
+ */
113
156
  broadcastTxCommit(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
157
+ /**
158
+ * Returns changes for a given account, contract or contract code for given
159
+ * block height or hash.
160
+ */
114
161
  changes(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
162
+ /**
163
+ * Returns details of a specific chunk. You can run a block details query to
164
+ * get a valid chunk hash.
165
+ */
115
166
  chunk(params?: RpcChunkRequest): Promise<RpcChunkResponse>;
167
+ /** Queries client node configuration */
116
168
  clientConfig(params?: RpcClientConfigRequest): Promise<RpcClientConfigResponse>;
169
+ /**
170
+ * Returns gas price for a specific block_height or block_hash. Using [null]
171
+ * will return the most recent block's gas price.
172
+ */
117
173
  gasPrice(params?: RpcGasPriceRequest): Promise<RpcGasPriceResponse>;
174
+ /** Get initial state and parameters for the genesis block */
118
175
  genesisConfig(params?: GenesisConfigRequest): Promise<GenesisConfig>;
176
+ /** Returns the current health status of the RPC node the client connects to. */
119
177
  health(params?: RpcHealthRequest): Promise<RpcHealthResponse>;
178
+ /** Returns the proofs for a transaction execution. */
120
179
  lightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
180
+ /**
181
+ * Returns the future windows for maintenance in current epoch for the
182
+ * specified account. In the maintenance windows, the node will not be block
183
+ * producer or chunk producer.
184
+ */
121
185
  maintenanceWindows(params?: RpcMaintenanceWindowsRequest): Promise<MaintenanceWindowsResponse>;
186
+ /**
187
+ * Queries the current state of node network connections. This includes
188
+ * information about active peers, transmitted data, known producers, etc.
189
+ */
122
190
  networkInfo(params?: RpcNetworkInfoRequest): Promise<RpcNetworkInfoResponse>;
191
+ /** Returns the next light client block. */
123
192
  nextLightClientBlock(params?: RpcLightClientNextBlockRequest): Promise<RpcLightClientNextBlockResponse>;
193
+ /**
194
+ * This module allows you to make generic requests to the network. The
195
+ * `RpcQueryRequest` struct takes in a
196
+ * [`BlockReference`](https://docs.rs/near-primitives/0.12.0/near_primitives/types/enum.BlockReference.html)
197
+ * and a
198
+ * [`QueryRequest`](https://docs.rs/near-primitives/0.12.0/near_primitives/views/enum.QueryRequest.html).
199
+ * The `BlockReference` enum allows you to specify a block by `Finality`,
200
+ * `BlockId` or `SyncCheckpoint`. The `QueryRequest` enum provides multiple
201
+ * variants for performing the following actions: - View an account's details
202
+ * - View a contract's code - View the state of an account - View the
203
+ * `AccessKey` of an account - View the `AccessKeyList` of an account - Call a
204
+ * function in a contract deployed on the network.
205
+ */
124
206
  query(params?: RpcQueryRequest): Promise<RpcQueryResponse>;
207
+ /**
208
+ * Sends transaction. Returns the guaranteed execution status and the results
209
+ * the blockchain can provide at the moment.
210
+ */
125
211
  sendTx(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
212
+ /**
213
+ * Requests the status of the connected RPC node. This includes information
214
+ * about sync status, nearcore node version, protocol version, the current set
215
+ * of validators, etc.
216
+ */
126
217
  status(params?: RpcStatusRequest): Promise<RpcStatusResponse>;
218
+ /**
219
+ * Queries status of a transaction by hash and returns the final transaction
220
+ * result.
221
+ */
127
222
  tx(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
223
+ /**
224
+ * Queries active validators on the network. Returns details and the state of
225
+ * validation on the blockchain.
226
+ */
128
227
  validators(params?: RpcValidatorRequest): Promise<RpcValidatorResponse>;
129
228
  }
130
229
  interface ConvenienceMethods {
@@ -150,36 +249,150 @@ interface ConvenienceMethods {
150
249
  interface CompleteClientInterface extends DynamicRpcMethods, ConvenienceMethods {
151
250
  call<TParams = unknown, TResult = unknown>(method: string, params?: TParams): Promise<TResult>;
152
251
  }
252
+ /**
253
+ * [Deprecated] Returns changes for a given account, contract or contract code
254
+ * for given block height or hash. Consider using changes instead.
255
+ */
153
256
  declare function experimentalChanges(client: NearRpcClient, params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
257
+ /**
258
+ * [Deprecated] Returns changes in block for given block height or hash over
259
+ * all transactions for all the types. Includes changes like account_touched,
260
+ * access_key_touched, data_touched, contract_code_touched. Consider using
261
+ * block_effects instead
262
+ */
154
263
  declare function experimentalChangesInBlock(client: NearRpcClient, params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
264
+ /**
265
+ * Queries the congestion level of a shard. More info about congestion
266
+ * [here](https://near.github.io/nearcore/architecture/how/receipt-congestion.html?highlight=congestion#receipt-congestion)
267
+ */
155
268
  declare function experimentalCongestionLevel(client: NearRpcClient, params?: RpcCongestionLevelRequest): Promise<RpcCongestionLevelResponse>;
269
+ /**
270
+ * [Deprecated] Get initial state and parameters for the genesis block.
271
+ * Consider genesis_config instead.
272
+ */
156
273
  declare function experimentalGenesisConfig(client: NearRpcClient, params?: GenesisConfigRequest): Promise<GenesisConfig>;
274
+ /** Returns the proofs for a transaction execution. */
157
275
  declare function experimentalLightClientBlockProof(client: NearRpcClient, params?: RpcLightClientBlockProofRequest): Promise<RpcLightClientBlockProofResponse>;
276
+ /** Returns the proofs for a transaction execution. */
158
277
  declare function experimentalLightClientProof(client: NearRpcClient, params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
278
+ /**
279
+ * [Deprecated] Returns the future windows for maintenance in current epoch
280
+ * for the specified account. In the maintenance windows, the node will not be
281
+ * block producer or chunk producer. Consider using maintenance_windows
282
+ * instead.
283
+ */
159
284
  declare function experimentalMaintenanceWindows(client: NearRpcClient, params?: RpcMaintenanceWindowsRequest): Promise<EXPERIMENTALMaintenanceWindowsResponse>;
285
+ /**
286
+ * A configuration that defines the protocol-level parameters such as
287
+ * gas/storage costs, limits, feature flags, other settings
288
+ */
160
289
  declare function experimentalProtocolConfig(client: NearRpcClient, params?: RpcProtocolConfigRequest): Promise<RpcProtocolConfigResponse>;
290
+ /** Fetches a receipt by its ID (as is, without a status or execution outcome) */
161
291
  declare function experimentalReceipt(client: NearRpcClient, params?: RpcReceiptRequest): Promise<RpcReceiptResponse>;
292
+ /**
293
+ * Contains the split storage information. More info on split storage
294
+ * [here](https://near-nodes.io/archival/split-storage-archival)
295
+ */
162
296
  declare function experimentalSplitStorageInfo(client: NearRpcClient, params?: RpcSplitStorageInfoRequest): Promise<RpcSplitStorageInfoResponse>;
297
+ /**
298
+ * Queries status of a transaction by hash, returning the final transaction
299
+ * result and details of all receipts.
300
+ */
163
301
  declare function experimentalTxStatus(client: NearRpcClient, params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
302
+ /**
303
+ * Returns the current epoch validators ordered in the block producer order
304
+ * with repetition. This endpoint is solely used for bridge currently and is
305
+ * not intended for other external use cases.
306
+ */
164
307
  declare function experimentalValidatorsOrdered(client: NearRpcClient, params?: RpcValidatorsOrderedRequest): Promise<EXPERIMENTALValidatorsOrderedResponse>;
308
+ /** Returns block details for given height or hash */
165
309
  declare function block(client: NearRpcClient, params?: RpcBlockRequest): Promise<RpcBlockResponse>;
310
+ /**
311
+ * Returns changes in block for given block height or hash over all
312
+ * transactions for all the types. Includes changes like account_touched,
313
+ * access_key_touched, data_touched, contract_code_touched.
314
+ */
166
315
  declare function blockEffects(client: NearRpcClient, params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
316
+ /**
317
+ * [Deprecated] Sends a transaction and immediately returns transaction hash.
318
+ * Consider using send_tx instead.
319
+ */
167
320
  declare function broadcastTxAsync(client: NearRpcClient, params?: RpcSendTransactionRequest): Promise<CryptoHash>;
321
+ /**
322
+ * [Deprecated] Sends a transaction and waits until transaction is fully
323
+ * complete. (Has a 10 second timeout). Consider using send_tx instead.
324
+ */
168
325
  declare function broadcastTxCommit(client: NearRpcClient, params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
326
+ /**
327
+ * Returns changes for a given account, contract or contract code for given
328
+ * block height or hash.
329
+ */
169
330
  declare function changes(client: NearRpcClient, params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
331
+ /**
332
+ * Returns details of a specific chunk. You can run a block details query to
333
+ * get a valid chunk hash.
334
+ */
170
335
  declare function chunk(client: NearRpcClient, params?: RpcChunkRequest): Promise<RpcChunkResponse>;
336
+ /** Queries client node configuration */
171
337
  declare function clientConfig(client: NearRpcClient, params?: RpcClientConfigRequest): Promise<RpcClientConfigResponse>;
338
+ /**
339
+ * Returns gas price for a specific block_height or block_hash. Using [null]
340
+ * will return the most recent block's gas price.
341
+ */
172
342
  declare function gasPrice(client: NearRpcClient, params?: RpcGasPriceRequest): Promise<RpcGasPriceResponse>;
343
+ /** Get initial state and parameters for the genesis block */
173
344
  declare function genesisConfig(client: NearRpcClient, params?: GenesisConfigRequest): Promise<GenesisConfig>;
345
+ /** Returns the current health status of the RPC node the client connects to. */
174
346
  declare function health(client: NearRpcClient, params?: RpcHealthRequest): Promise<RpcHealthResponse>;
347
+ /** Returns the proofs for a transaction execution. */
175
348
  declare function lightClientProof(client: NearRpcClient, params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
349
+ /**
350
+ * Returns the future windows for maintenance in current epoch for the
351
+ * specified account. In the maintenance windows, the node will not be block
352
+ * producer or chunk producer.
353
+ */
176
354
  declare function maintenanceWindows(client: NearRpcClient, params?: RpcMaintenanceWindowsRequest): Promise<MaintenanceWindowsResponse>;
355
+ /**
356
+ * Queries the current state of node network connections. This includes
357
+ * information about active peers, transmitted data, known producers, etc.
358
+ */
177
359
  declare function networkInfo(client: NearRpcClient, params?: RpcNetworkInfoRequest): Promise<RpcNetworkInfoResponse>;
360
+ /** Returns the next light client block. */
178
361
  declare function nextLightClientBlock(client: NearRpcClient, params?: RpcLightClientNextBlockRequest): Promise<RpcLightClientNextBlockResponse>;
362
+ /**
363
+ * This module allows you to make generic requests to the network. The
364
+ * `RpcQueryRequest` struct takes in a
365
+ * [`BlockReference`](https://docs.rs/near-primitives/0.12.0/near_primitives/types/enum.BlockReference.html)
366
+ * and a
367
+ * [`QueryRequest`](https://docs.rs/near-primitives/0.12.0/near_primitives/views/enum.QueryRequest.html).
368
+ * The `BlockReference` enum allows you to specify a block by `Finality`,
369
+ * `BlockId` or `SyncCheckpoint`. The `QueryRequest` enum provides multiple
370
+ * variants for performing the following actions: - View an account's details
371
+ * - View a contract's code - View the state of an account - View the
372
+ * `AccessKey` of an account - View the `AccessKeyList` of an account - Call a
373
+ * function in a contract deployed on the network.
374
+ */
179
375
  declare function query(client: NearRpcClient, params?: RpcQueryRequest): Promise<RpcQueryResponse>;
376
+ /**
377
+ * Sends transaction. Returns the guaranteed execution status and the results
378
+ * the blockchain can provide at the moment.
379
+ */
180
380
  declare function sendTx(client: NearRpcClient, params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
381
+ /**
382
+ * Requests the status of the connected RPC node. This includes information
383
+ * about sync status, nearcore node version, protocol version, the current set
384
+ * of validators, etc.
385
+ */
181
386
  declare function status(client: NearRpcClient, params?: RpcStatusRequest): Promise<RpcStatusResponse>;
387
+ /**
388
+ * Queries status of a transaction by hash and returns the final transaction
389
+ * result.
390
+ */
182
391
  declare function tx(client: NearRpcClient, params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
392
+ /**
393
+ * Queries active validators on the network. Returns details and the state of
394
+ * validation on the blockchain.
395
+ */
183
396
  declare function validators(client: NearRpcClient, params?: RpcValidatorRequest): Promise<RpcValidatorResponse>;
184
397
 
185
398
  declare function viewAccount(client: NearRpcClient, params: {
@@ -209,4 +422,4 @@ declare function viewFunctionAsJson<T = unknown>(client: NearRpcClient, params:
209
422
  blockId?: string | number;
210
423
  }): Promise<T>;
211
424
 
212
- export { blockEffects as A, broadcastTxAsync as B, type ConvenienceMethods as C, type DynamicRpcMethods as D, broadcastTxCommit as E, changes as F, chunk as G, clientConfig as H, gasPrice as I, type JsonRpcRequest as J, genesisConfig as K, health as L, lightClientProof as M, NearRpcClient as N, maintenanceWindows as O, networkInfo as P, nextLightClientBlock as Q, type RpcRequest as R, query as S, sendTx as T, status as U, tx as V, validators as W, viewAccount as X, viewFunction as Y, viewAccessKey as Z, type CompleteClientInterface as a, type ClientConfig as b, type JsonRpcResponse as c, defaultClient as d, enableValidation as e, type JsonRpcError as f, JsonRpcClientError as g, JsonRpcNetworkError as h, type RpcResponse as i, type RpcError as j, NearRpcError as k, experimentalChanges as l, experimentalChangesInBlock as m, experimentalCongestionLevel as n, experimentalGenesisConfig as o, parseCallResultToJson as p, experimentalLightClientBlockProof as q, experimentalLightClientProof as r, experimentalMaintenanceWindows as s, experimentalProtocolConfig as t, experimentalReceipt as u, viewFunctionAsJson as v, experimentalSplitStorageInfo as w, experimentalTxStatus as x, experimentalValidatorsOrdered as y, block as z };
425
+ export { broadcastTxAsync as A, broadcastTxCommit as B, type ConvenienceMethods as C, type DynamicRpcMethods as D, changes as E, chunk as F, clientConfig as G, gasPrice as H, genesisConfig as I, type JsonRpcRequest as J, health as K, lightClientProof as L, maintenanceWindows as M, NearRpcClient as N, networkInfo as O, nextLightClientBlock as P, query as Q, type RpcRequest as R, sendTx as S, status as T, tx as U, validators as V, viewAccount as W, viewFunction as X, viewAccessKey as Y, type CompleteClientInterface as a, type ClientConfig as b, type JsonRpcResponse as c, defaultClient as d, type JsonRpcError as e, JsonRpcClientError as f, JsonRpcNetworkError as g, type RpcResponse as h, type RpcError as i, NearRpcError as j, experimentalChanges as k, experimentalChangesInBlock as l, experimentalCongestionLevel as m, experimentalGenesisConfig as n, experimentalLightClientBlockProof as o, parseCallResultToJson as p, experimentalLightClientProof as q, experimentalMaintenanceWindows as r, experimentalProtocolConfig as s, experimentalReceipt as t, experimentalSplitStorageInfo as u, viewFunctionAsJson as v, experimentalTxStatus as w, experimentalValidatorsOrdered as x, block as y, blockEffects as z };