@psalomo/jsonrpc-client 1.1.0 → 1.2.0
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.
- package/README.md +69 -19
- package/dist/browser-standalone.js +782 -37
- package/dist/browser-standalone.min.js +1 -1
- package/dist/chunk-GCIU6ZLN.mjs +395 -0
- package/dist/convenience-DFvZCHOk.d.mts +212 -0
- package/dist/convenience-DFvZCHOk.d.ts +212 -0
- package/dist/convenience.d.ts +9 -1
- package/dist/convenience.d.ts.map +1 -1
- package/dist/generated-types.d.ts +1 -1
- package/dist/index.d.mts +23 -172
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +626 -51
- package/dist/index.mjs +673 -340
- package/dist/no-validation/index.d.mts +6 -0
- package/dist/no-validation/index.d.ts +9 -0
- package/dist/no-validation/index.d.ts.map +1 -0
- package/dist/no-validation/index.js +471 -0
- package/dist/no-validation/index.mjs +95 -0
- package/dist/validated/index.d.ts +54 -0
- package/dist/validated/index.d.ts.map +1 -0
- package/package.json +7 -2
package/dist/index.mjs
CHANGED
@@ -1,211 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
this.data = data;
|
42
|
-
this.name = "JsonRpcClientError";
|
43
|
-
}
|
44
|
-
};
|
45
|
-
var JsonRpcNetworkError = class extends Error {
|
46
|
-
constructor(message, originalError, responseBody) {
|
47
|
-
super(message);
|
48
|
-
this.originalError = originalError;
|
49
|
-
this.responseBody = responseBody;
|
50
|
-
this.name = "JsonRpcNetworkError";
|
51
|
-
}
|
52
|
-
};
|
53
|
-
var NearRpcClient = class _NearRpcClient {
|
54
|
-
endpoint;
|
55
|
-
headers;
|
56
|
-
timeout;
|
57
|
-
retries;
|
58
|
-
validation;
|
59
|
-
constructor(config) {
|
60
|
-
if (typeof config === "string") {
|
61
|
-
this.endpoint = config;
|
62
|
-
this.headers = {};
|
63
|
-
this.timeout = 3e4;
|
64
|
-
this.retries = 3;
|
65
|
-
} else {
|
66
|
-
this.endpoint = config.endpoint;
|
67
|
-
this.headers = config.headers || {};
|
68
|
-
this.timeout = config.timeout || 3e4;
|
69
|
-
this.retries = config.retries || 3;
|
70
|
-
if (config.validation) {
|
71
|
-
this.validation = config.validation;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
/**
|
76
|
-
* Make a raw JSON-RPC request
|
77
|
-
* This is used internally by the standalone RPC functions
|
78
|
-
*/
|
79
|
-
async makeRequest(method, params) {
|
80
|
-
const requestForValidation = {
|
81
|
-
jsonrpc: "2.0",
|
82
|
-
id: REQUEST_ID,
|
83
|
-
method,
|
84
|
-
params: params !== void 0 ? params : null
|
85
|
-
};
|
86
|
-
if (this.validation) {
|
87
|
-
if ("validateMethodRequest" in this.validation) {
|
88
|
-
this.validation.validateMethodRequest(method, requestForValidation);
|
89
|
-
} else {
|
90
|
-
this.validation.validateRequest(requestForValidation);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
const snakeCaseParams = params !== void 0 ? convertKeysToSnakeCase(params) : null;
|
94
|
-
const request = {
|
95
|
-
jsonrpc: "2.0",
|
96
|
-
id: REQUEST_ID,
|
97
|
-
method,
|
98
|
-
params: snakeCaseParams
|
99
|
-
};
|
100
|
-
let lastError = null;
|
101
|
-
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
102
|
-
try {
|
103
|
-
const controller = new AbortController();
|
104
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
105
|
-
const response = await fetch(this.endpoint, {
|
106
|
-
method: "POST",
|
107
|
-
headers: {
|
108
|
-
"Content-Type": "application/json",
|
109
|
-
...this.headers
|
110
|
-
},
|
111
|
-
body: JSON.stringify(request),
|
112
|
-
signal: controller.signal
|
113
|
-
});
|
114
|
-
clearTimeout(timeoutId);
|
115
|
-
let jsonResponse;
|
116
|
-
try {
|
117
|
-
jsonResponse = await response.json();
|
118
|
-
} catch (parseError) {
|
119
|
-
if (!response.ok) {
|
120
|
-
throw new JsonRpcNetworkError(
|
121
|
-
`HTTP error! status: ${response.status} - Failed to parse JSON response`,
|
122
|
-
parseError
|
123
|
-
);
|
124
|
-
}
|
125
|
-
throw new JsonRpcNetworkError(
|
126
|
-
"Failed to parse JSON response",
|
127
|
-
parseError
|
128
|
-
);
|
129
|
-
}
|
130
|
-
if (jsonResponse.error) {
|
131
|
-
throw new JsonRpcClientError(
|
132
|
-
jsonResponse.error.message,
|
133
|
-
jsonResponse.error.code,
|
134
|
-
jsonResponse.error.data
|
135
|
-
);
|
136
|
-
}
|
137
|
-
if (!response.ok) {
|
138
|
-
throw new JsonRpcNetworkError(
|
139
|
-
`HTTP error! status: ${response.status}`,
|
140
|
-
void 0,
|
141
|
-
jsonResponse
|
142
|
-
);
|
143
|
-
}
|
144
|
-
if (this.validation) {
|
145
|
-
this.validation.validateResponse(jsonResponse);
|
146
|
-
}
|
147
|
-
const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
|
148
|
-
if (camelCaseResult && typeof camelCaseResult === "object" && "error" in camelCaseResult) {
|
149
|
-
const errorMessage = camelCaseResult.error;
|
150
|
-
throw new JsonRpcClientError(
|
151
|
-
`RPC Error: ${errorMessage}`,
|
152
|
-
-32e3,
|
153
|
-
// Generic RPC error code
|
154
|
-
camelCaseResult
|
155
|
-
);
|
156
|
-
}
|
157
|
-
if (this.validation && "validateMethodResponse" in this.validation) {
|
158
|
-
const camelCaseResponse = {
|
159
|
-
...jsonResponse,
|
160
|
-
result: camelCaseResult
|
161
|
-
};
|
162
|
-
this.validation.validateMethodResponse(method, camelCaseResponse);
|
163
|
-
}
|
164
|
-
return camelCaseResult;
|
165
|
-
} catch (error) {
|
166
|
-
lastError = error;
|
167
|
-
if (error instanceof JsonRpcClientError) {
|
168
|
-
throw error;
|
169
|
-
}
|
170
|
-
if (attempt === this.retries) {
|
171
|
-
break;
|
172
|
-
}
|
173
|
-
await new Promise(
|
174
|
-
(resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1e3)
|
175
|
-
);
|
176
|
-
}
|
177
|
-
}
|
178
|
-
throw new JsonRpcNetworkError(
|
179
|
-
lastError?.message || "Request failed after all retries",
|
180
|
-
lastError || void 0
|
181
|
-
);
|
182
|
-
}
|
183
|
-
/**
|
184
|
-
* Create a new client with modified configuration
|
185
|
-
*/
|
186
|
-
withConfig(config) {
|
187
|
-
return new _NearRpcClient({
|
188
|
-
endpoint: config.endpoint ?? this.endpoint,
|
189
|
-
headers: config.headers ?? this.headers,
|
190
|
-
timeout: config.timeout ?? this.timeout,
|
191
|
-
retries: config.retries ?? this.retries,
|
192
|
-
...config.validation !== void 0 ? { validation: config.validation } : this.validation !== void 0 ? { validation: this.validation } : {}
|
193
|
-
});
|
194
|
-
}
|
195
|
-
};
|
196
|
-
var defaultClient = new NearRpcClient({
|
197
|
-
endpoint: "https://rpc.mainnet.near.org"
|
198
|
-
});
|
199
|
-
|
200
|
-
// src/types.ts
|
201
|
-
var NearRpcError = class extends Error {
|
202
|
-
constructor(code, message, data) {
|
203
|
-
super(message);
|
204
|
-
this.code = code;
|
205
|
-
this.data = data;
|
206
|
-
this.name = "NearRpcError";
|
207
|
-
}
|
208
|
-
};
|
1
|
+
import {
|
2
|
+
JsonRpcClientError,
|
3
|
+
JsonRpcNetworkError,
|
4
|
+
NearRpcClient,
|
5
|
+
NearRpcError,
|
6
|
+
block,
|
7
|
+
blockEffects,
|
8
|
+
broadcastTxAsync,
|
9
|
+
broadcastTxCommit,
|
10
|
+
changes,
|
11
|
+
chunk,
|
12
|
+
clientConfig,
|
13
|
+
defaultClient,
|
14
|
+
experimentalChanges,
|
15
|
+
experimentalChangesInBlock,
|
16
|
+
experimentalCongestionLevel,
|
17
|
+
experimentalGenesisConfig,
|
18
|
+
experimentalLightClientBlockProof,
|
19
|
+
experimentalLightClientProof,
|
20
|
+
experimentalMaintenanceWindows,
|
21
|
+
experimentalProtocolConfig,
|
22
|
+
experimentalReceipt,
|
23
|
+
experimentalSplitStorageInfo,
|
24
|
+
experimentalTxStatus,
|
25
|
+
experimentalValidatorsOrdered,
|
26
|
+
gasPrice,
|
27
|
+
genesisConfig,
|
28
|
+
health,
|
29
|
+
lightClientProof,
|
30
|
+
maintenanceWindows,
|
31
|
+
networkInfo,
|
32
|
+
nextLightClientBlock,
|
33
|
+
parseCallResultToJson,
|
34
|
+
query,
|
35
|
+
sendTx,
|
36
|
+
status,
|
37
|
+
tx,
|
38
|
+
validators,
|
39
|
+
viewFunctionAsJson
|
40
|
+
} from "./chunk-GCIU6ZLN.mjs";
|
209
41
|
|
210
42
|
// src/index.ts
|
211
43
|
import {
|
@@ -214,102 +46,53 @@ import {
|
|
214
46
|
} from "@psalomo/jsonrpc-types";
|
215
47
|
import { RPC_METHODS } from "@psalomo/jsonrpc-types";
|
216
48
|
|
217
|
-
// src/
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
return client.makeRequest("broadcast_tx_commit", params);
|
265
|
-
}
|
266
|
-
async function changes(client, params) {
|
267
|
-
return client.makeRequest("changes", params);
|
268
|
-
}
|
269
|
-
async function chunk(client, params) {
|
270
|
-
return client.makeRequest("chunk", params);
|
271
|
-
}
|
272
|
-
async function clientConfig(client, params) {
|
273
|
-
return client.makeRequest("client_config", params);
|
274
|
-
}
|
275
|
-
async function gasPrice(client, params) {
|
276
|
-
return client.makeRequest("gas_price", params);
|
277
|
-
}
|
278
|
-
async function genesisConfig(client, params) {
|
279
|
-
return client.makeRequest("genesis_config", params);
|
280
|
-
}
|
281
|
-
async function health(client, params) {
|
282
|
-
return client.makeRequest("health", params);
|
283
|
-
}
|
284
|
-
async function lightClientProof(client, params) {
|
285
|
-
return client.makeRequest("light_client_proof", params);
|
286
|
-
}
|
287
|
-
async function maintenanceWindows(client, params) {
|
288
|
-
return client.makeRequest("maintenance_windows", params);
|
289
|
-
}
|
290
|
-
async function networkInfo(client, params) {
|
291
|
-
return client.makeRequest("network_info", params);
|
292
|
-
}
|
293
|
-
async function nextLightClientBlock(client, params) {
|
294
|
-
return client.makeRequest("next_light_client_block", params);
|
295
|
-
}
|
296
|
-
async function query(client, params) {
|
297
|
-
return client.makeRequest("query", params);
|
298
|
-
}
|
299
|
-
async function sendTx(client, params) {
|
300
|
-
return client.makeRequest("send_tx", params);
|
301
|
-
}
|
302
|
-
async function status(client, params) {
|
303
|
-
return client.makeRequest("status", params);
|
304
|
-
}
|
305
|
-
async function tx(client, params) {
|
306
|
-
return client.makeRequest("tx", params);
|
307
|
-
}
|
308
|
-
async function validators(client, params) {
|
309
|
-
return client.makeRequest("validators", params);
|
310
|
-
}
|
311
|
-
|
312
|
-
// src/convenience.ts
|
49
|
+
// src/validated/index.ts
|
50
|
+
import {
|
51
|
+
CryptoHashSchema,
|
52
|
+
GenesisConfigRequestSchema,
|
53
|
+
GenesisConfigSchema,
|
54
|
+
RpcBlockRequestSchema,
|
55
|
+
RpcBlockResponseSchema,
|
56
|
+
RpcChunkRequestSchema,
|
57
|
+
RpcChunkResponseSchema,
|
58
|
+
RpcClientConfigRequestSchema,
|
59
|
+
RpcClientConfigResponseSchema,
|
60
|
+
RpcCongestionLevelRequestSchema,
|
61
|
+
RpcCongestionLevelResponseSchema,
|
62
|
+
RpcGasPriceRequestSchema,
|
63
|
+
RpcGasPriceResponseSchema,
|
64
|
+
RpcHealthRequestSchema,
|
65
|
+
RpcHealthResponseSchema,
|
66
|
+
RpcLightClientBlockProofRequestSchema,
|
67
|
+
RpcLightClientBlockProofResponseSchema,
|
68
|
+
RpcLightClientExecutionProofRequestSchema,
|
69
|
+
RpcLightClientExecutionProofResponseSchema,
|
70
|
+
RpcLightClientNextBlockRequestSchema,
|
71
|
+
RpcLightClientNextBlockResponseSchema,
|
72
|
+
RpcMaintenanceWindowsRequestSchema,
|
73
|
+
RpcNetworkInfoRequestSchema,
|
74
|
+
RpcNetworkInfoResponseSchema,
|
75
|
+
RpcProtocolConfigRequestSchema,
|
76
|
+
RpcProtocolConfigResponseSchema,
|
77
|
+
RpcQueryRequestSchema,
|
78
|
+
RpcQueryResponseSchema,
|
79
|
+
RpcReceiptRequestSchema,
|
80
|
+
RpcReceiptResponseSchema,
|
81
|
+
RpcSendTransactionRequestSchema,
|
82
|
+
RpcSplitStorageInfoRequestSchema,
|
83
|
+
RpcSplitStorageInfoResponseSchema,
|
84
|
+
RpcStateChangesInBlockByTypeRequestSchema,
|
85
|
+
RpcStateChangesInBlockByTypeResponseSchema,
|
86
|
+
RpcStateChangesInBlockRequestSchema,
|
87
|
+
RpcStateChangesInBlockResponseSchema,
|
88
|
+
RpcStatusRequestSchema,
|
89
|
+
RpcStatusResponseSchema,
|
90
|
+
RpcTransactionResponseSchema,
|
91
|
+
RpcTransactionStatusRequestSchema,
|
92
|
+
RpcValidatorRequestSchema,
|
93
|
+
RpcValidatorResponseSchema,
|
94
|
+
RpcValidatorsOrderedRequestSchema
|
95
|
+
} from "@psalomo/jsonrpc-types";
|
313
96
|
async function viewAccount(client, params) {
|
314
97
|
const queryParams = params.blockId ? {
|
315
98
|
requestType: "view_account",
|
@@ -320,7 +103,7 @@ async function viewAccount(client, params) {
|
|
320
103
|
accountId: params.accountId,
|
321
104
|
finality: params.finality || "final"
|
322
105
|
};
|
323
|
-
return
|
106
|
+
return query2(client, queryParams);
|
324
107
|
}
|
325
108
|
async function viewFunction(client, params) {
|
326
109
|
const baseParams = {
|
@@ -328,10 +111,9 @@ async function viewFunction(client, params) {
|
|
328
111
|
accountId: params.accountId,
|
329
112
|
methodName: params.methodName,
|
330
113
|
argsBase64: params.argsBase64 ?? ""
|
331
|
-
// Default to empty string if no arguments
|
332
114
|
};
|
333
115
|
const queryParams = params.blockId ? { ...baseParams, blockId: params.blockId } : { ...baseParams, finality: params.finality || "final" };
|
334
|
-
return
|
116
|
+
return query2(client, queryParams);
|
335
117
|
}
|
336
118
|
async function viewAccessKey(client, params) {
|
337
119
|
const queryParams = params.blockId ? {
|
@@ -345,7 +127,556 @@ async function viewAccessKey(client, params) {
|
|
345
127
|
publicKey: params.publicKey,
|
346
128
|
finality: params.finality || "final"
|
347
129
|
};
|
348
|
-
return
|
130
|
+
return query2(client, queryParams);
|
131
|
+
}
|
132
|
+
async function experimentalChanges2(client, params) {
|
133
|
+
const requestSchema = RpcStateChangesInBlockByTypeRequestSchema();
|
134
|
+
if (params !== void 0) {
|
135
|
+
try {
|
136
|
+
requestSchema.parse(params);
|
137
|
+
} catch (error) {
|
138
|
+
throw new Error(`Request validation failed: ${error}`);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
const result = await experimentalChanges(client, params);
|
142
|
+
const responseSchema = RpcStateChangesInBlockResponseSchema();
|
143
|
+
try {
|
144
|
+
responseSchema.parse(result);
|
145
|
+
} catch (error) {
|
146
|
+
throw new Error(`Response validation failed: ${error}`);
|
147
|
+
}
|
148
|
+
return result;
|
149
|
+
}
|
150
|
+
async function experimentalChangesInBlock2(client, params) {
|
151
|
+
const requestSchema = RpcStateChangesInBlockRequestSchema();
|
152
|
+
if (params !== void 0) {
|
153
|
+
try {
|
154
|
+
requestSchema.parse(params);
|
155
|
+
} catch (error) {
|
156
|
+
throw new Error(`Request validation failed: ${error}`);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
const result = await experimentalChangesInBlock(client, params);
|
160
|
+
const responseSchema = RpcStateChangesInBlockByTypeResponseSchema();
|
161
|
+
try {
|
162
|
+
responseSchema.parse(result);
|
163
|
+
} catch (error) {
|
164
|
+
throw new Error(`Response validation failed: ${error}`);
|
165
|
+
}
|
166
|
+
return result;
|
167
|
+
}
|
168
|
+
async function experimentalCongestionLevel2(client, params) {
|
169
|
+
const requestSchema = RpcCongestionLevelRequestSchema();
|
170
|
+
if (params !== void 0) {
|
171
|
+
try {
|
172
|
+
requestSchema.parse(params);
|
173
|
+
} catch (error) {
|
174
|
+
throw new Error(`Request validation failed: ${error}`);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
const result = await experimentalCongestionLevel(
|
178
|
+
client,
|
179
|
+
params
|
180
|
+
);
|
181
|
+
const responseSchema = RpcCongestionLevelResponseSchema();
|
182
|
+
try {
|
183
|
+
responseSchema.parse(result);
|
184
|
+
} catch (error) {
|
185
|
+
throw new Error(`Response validation failed: ${error}`);
|
186
|
+
}
|
187
|
+
return result;
|
188
|
+
}
|
189
|
+
async function experimentalGenesisConfig2(client, params) {
|
190
|
+
const requestSchema = GenesisConfigRequestSchema();
|
191
|
+
if (params !== void 0) {
|
192
|
+
try {
|
193
|
+
requestSchema.parse(params);
|
194
|
+
} catch (error) {
|
195
|
+
throw new Error(`Request validation failed: ${error}`);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
const result = await experimentalGenesisConfig(client, params);
|
199
|
+
const responseSchema = GenesisConfigSchema();
|
200
|
+
try {
|
201
|
+
responseSchema.parse(result);
|
202
|
+
} catch (error) {
|
203
|
+
throw new Error(`Response validation failed: ${error}`);
|
204
|
+
}
|
205
|
+
return result;
|
206
|
+
}
|
207
|
+
async function experimentalLightClientBlockProof2(client, params) {
|
208
|
+
const requestSchema = RpcLightClientBlockProofRequestSchema();
|
209
|
+
if (params !== void 0) {
|
210
|
+
try {
|
211
|
+
requestSchema.parse(params);
|
212
|
+
} catch (error) {
|
213
|
+
throw new Error(`Request validation failed: ${error}`);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
const result = await experimentalLightClientBlockProof(
|
217
|
+
client,
|
218
|
+
params
|
219
|
+
);
|
220
|
+
const responseSchema = RpcLightClientBlockProofResponseSchema();
|
221
|
+
try {
|
222
|
+
responseSchema.parse(result);
|
223
|
+
} catch (error) {
|
224
|
+
throw new Error(`Response validation failed: ${error}`);
|
225
|
+
}
|
226
|
+
return result;
|
227
|
+
}
|
228
|
+
async function experimentalLightClientProof2(client, params) {
|
229
|
+
const requestSchema = RpcLightClientExecutionProofRequestSchema();
|
230
|
+
if (params !== void 0) {
|
231
|
+
try {
|
232
|
+
requestSchema.parse(params);
|
233
|
+
} catch (error) {
|
234
|
+
throw new Error(`Request validation failed: ${error}`);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
const result = await experimentalLightClientProof(
|
238
|
+
client,
|
239
|
+
params
|
240
|
+
);
|
241
|
+
const responseSchema = RpcLightClientExecutionProofResponseSchema();
|
242
|
+
try {
|
243
|
+
responseSchema.parse(result);
|
244
|
+
} catch (error) {
|
245
|
+
throw new Error(`Response validation failed: ${error}`);
|
246
|
+
}
|
247
|
+
return result;
|
248
|
+
}
|
249
|
+
async function experimentalMaintenanceWindows2(client, params) {
|
250
|
+
const requestSchema = RpcMaintenanceWindowsRequestSchema();
|
251
|
+
if (params !== void 0) {
|
252
|
+
try {
|
253
|
+
requestSchema.parse(params);
|
254
|
+
} catch (error) {
|
255
|
+
throw new Error(`Request validation failed: ${error}`);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
return experimentalMaintenanceWindows(client, params);
|
259
|
+
}
|
260
|
+
async function experimentalProtocolConfig2(client, params) {
|
261
|
+
const requestSchema = RpcProtocolConfigRequestSchema();
|
262
|
+
if (params !== void 0) {
|
263
|
+
try {
|
264
|
+
requestSchema.parse(params);
|
265
|
+
} catch (error) {
|
266
|
+
throw new Error(`Request validation failed: ${error}`);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
const result = await experimentalProtocolConfig(client, params);
|
270
|
+
const responseSchema = RpcProtocolConfigResponseSchema();
|
271
|
+
try {
|
272
|
+
responseSchema.parse(result);
|
273
|
+
} catch (error) {
|
274
|
+
throw new Error(`Response validation failed: ${error}`);
|
275
|
+
}
|
276
|
+
return result;
|
277
|
+
}
|
278
|
+
async function experimentalReceipt2(client, params) {
|
279
|
+
const requestSchema = RpcReceiptRequestSchema();
|
280
|
+
if (params !== void 0) {
|
281
|
+
try {
|
282
|
+
requestSchema.parse(params);
|
283
|
+
} catch (error) {
|
284
|
+
throw new Error(`Request validation failed: ${error}`);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
const result = await experimentalReceipt(client, params);
|
288
|
+
const responseSchema = RpcReceiptResponseSchema();
|
289
|
+
try {
|
290
|
+
responseSchema.parse(result);
|
291
|
+
} catch (error) {
|
292
|
+
throw new Error(`Response validation failed: ${error}`);
|
293
|
+
}
|
294
|
+
return result;
|
295
|
+
}
|
296
|
+
async function experimentalSplitStorageInfo2(client, params) {
|
297
|
+
const requestSchema = RpcSplitStorageInfoRequestSchema();
|
298
|
+
if (params !== void 0) {
|
299
|
+
try {
|
300
|
+
requestSchema.parse(params);
|
301
|
+
} catch (error) {
|
302
|
+
throw new Error(`Request validation failed: ${error}`);
|
303
|
+
}
|
304
|
+
}
|
305
|
+
const result = await experimentalSplitStorageInfo(
|
306
|
+
client,
|
307
|
+
params
|
308
|
+
);
|
309
|
+
const responseSchema = RpcSplitStorageInfoResponseSchema();
|
310
|
+
try {
|
311
|
+
responseSchema.parse(result);
|
312
|
+
} catch (error) {
|
313
|
+
throw new Error(`Response validation failed: ${error}`);
|
314
|
+
}
|
315
|
+
return result;
|
316
|
+
}
|
317
|
+
async function experimentalTxStatus2(client, params) {
|
318
|
+
const requestSchema = RpcTransactionStatusRequestSchema();
|
319
|
+
if (params !== void 0) {
|
320
|
+
try {
|
321
|
+
requestSchema.parse(params);
|
322
|
+
} catch (error) {
|
323
|
+
throw new Error(`Request validation failed: ${error}`);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
const result = await experimentalTxStatus(client, params);
|
327
|
+
const responseSchema = RpcTransactionResponseSchema();
|
328
|
+
try {
|
329
|
+
responseSchema.parse(result);
|
330
|
+
} catch (error) {
|
331
|
+
throw new Error(`Response validation failed: ${error}`);
|
332
|
+
}
|
333
|
+
return result;
|
334
|
+
}
|
335
|
+
async function experimentalValidatorsOrdered2(client, params) {
|
336
|
+
const requestSchema = RpcValidatorsOrderedRequestSchema();
|
337
|
+
if (params !== void 0) {
|
338
|
+
try {
|
339
|
+
requestSchema.parse(params);
|
340
|
+
} catch (error) {
|
341
|
+
throw new Error(`Request validation failed: ${error}`);
|
342
|
+
}
|
343
|
+
}
|
344
|
+
return experimentalValidatorsOrdered(client, params);
|
345
|
+
}
|
346
|
+
async function block2(client, params) {
|
347
|
+
const requestSchema = RpcBlockRequestSchema();
|
348
|
+
if (params !== void 0) {
|
349
|
+
try {
|
350
|
+
requestSchema.parse(params);
|
351
|
+
} catch (error) {
|
352
|
+
throw new Error(`Request validation failed: ${error}`);
|
353
|
+
}
|
354
|
+
}
|
355
|
+
const result = await block(client, params);
|
356
|
+
const responseSchema = RpcBlockResponseSchema();
|
357
|
+
try {
|
358
|
+
responseSchema.parse(result);
|
359
|
+
} catch (error) {
|
360
|
+
throw new Error(`Response validation failed: ${error}`);
|
361
|
+
}
|
362
|
+
return result;
|
363
|
+
}
|
364
|
+
async function blockEffects2(client, params) {
|
365
|
+
const requestSchema = RpcStateChangesInBlockRequestSchema();
|
366
|
+
if (params !== void 0) {
|
367
|
+
try {
|
368
|
+
requestSchema.parse(params);
|
369
|
+
} catch (error) {
|
370
|
+
throw new Error(`Request validation failed: ${error}`);
|
371
|
+
}
|
372
|
+
}
|
373
|
+
const result = await blockEffects(client, params);
|
374
|
+
const responseSchema = RpcStateChangesInBlockByTypeResponseSchema();
|
375
|
+
try {
|
376
|
+
responseSchema.parse(result);
|
377
|
+
} catch (error) {
|
378
|
+
throw new Error(`Response validation failed: ${error}`);
|
379
|
+
}
|
380
|
+
return result;
|
381
|
+
}
|
382
|
+
async function broadcastTxAsync2(client, params) {
|
383
|
+
const requestSchema = RpcSendTransactionRequestSchema();
|
384
|
+
if (params !== void 0) {
|
385
|
+
try {
|
386
|
+
requestSchema.parse(params);
|
387
|
+
} catch (error) {
|
388
|
+
throw new Error(`Request validation failed: ${error}`);
|
389
|
+
}
|
390
|
+
}
|
391
|
+
const result = await broadcastTxAsync(client, params);
|
392
|
+
const responseSchema = CryptoHashSchema();
|
393
|
+
try {
|
394
|
+
responseSchema.parse(result);
|
395
|
+
} catch (error) {
|
396
|
+
throw new Error(`Response validation failed: ${error}`);
|
397
|
+
}
|
398
|
+
return result;
|
399
|
+
}
|
400
|
+
async function broadcastTxCommit2(client, params) {
|
401
|
+
const requestSchema = RpcSendTransactionRequestSchema();
|
402
|
+
if (params !== void 0) {
|
403
|
+
try {
|
404
|
+
requestSchema.parse(params);
|
405
|
+
} catch (error) {
|
406
|
+
throw new Error(`Request validation failed: ${error}`);
|
407
|
+
}
|
408
|
+
}
|
409
|
+
const result = await broadcastTxCommit(client, params);
|
410
|
+
const responseSchema = RpcTransactionResponseSchema();
|
411
|
+
try {
|
412
|
+
responseSchema.parse(result);
|
413
|
+
} catch (error) {
|
414
|
+
throw new Error(`Response validation failed: ${error}`);
|
415
|
+
}
|
416
|
+
return result;
|
417
|
+
}
|
418
|
+
async function changes2(client, params) {
|
419
|
+
const requestSchema = RpcStateChangesInBlockByTypeRequestSchema();
|
420
|
+
if (params !== void 0) {
|
421
|
+
try {
|
422
|
+
requestSchema.parse(params);
|
423
|
+
} catch (error) {
|
424
|
+
throw new Error(`Request validation failed: ${error}`);
|
425
|
+
}
|
426
|
+
}
|
427
|
+
const result = await changes(client, params);
|
428
|
+
const responseSchema = RpcStateChangesInBlockResponseSchema();
|
429
|
+
try {
|
430
|
+
responseSchema.parse(result);
|
431
|
+
} catch (error) {
|
432
|
+
throw new Error(`Response validation failed: ${error}`);
|
433
|
+
}
|
434
|
+
return result;
|
435
|
+
}
|
436
|
+
async function chunk2(client, params) {
|
437
|
+
const requestSchema = RpcChunkRequestSchema();
|
438
|
+
if (params !== void 0) {
|
439
|
+
try {
|
440
|
+
requestSchema.parse(params);
|
441
|
+
} catch (error) {
|
442
|
+
throw new Error(`Request validation failed: ${error}`);
|
443
|
+
}
|
444
|
+
}
|
445
|
+
const result = await chunk(client, params);
|
446
|
+
const responseSchema = RpcChunkResponseSchema();
|
447
|
+
try {
|
448
|
+
responseSchema.parse(result);
|
449
|
+
} catch (error) {
|
450
|
+
throw new Error(`Response validation failed: ${error}`);
|
451
|
+
}
|
452
|
+
return result;
|
453
|
+
}
|
454
|
+
async function clientConfig2(client, params) {
|
455
|
+
const requestSchema = RpcClientConfigRequestSchema();
|
456
|
+
if (params !== void 0) {
|
457
|
+
try {
|
458
|
+
requestSchema.parse(params);
|
459
|
+
} catch (error) {
|
460
|
+
throw new Error(`Request validation failed: ${error}`);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
const result = await clientConfig(client, params);
|
464
|
+
const responseSchema = RpcClientConfigResponseSchema();
|
465
|
+
try {
|
466
|
+
responseSchema.parse(result);
|
467
|
+
} catch (error) {
|
468
|
+
throw new Error(`Response validation failed: ${error}`);
|
469
|
+
}
|
470
|
+
return result;
|
471
|
+
}
|
472
|
+
async function gasPrice2(client, params) {
|
473
|
+
const requestSchema = RpcGasPriceRequestSchema();
|
474
|
+
if (params !== void 0) {
|
475
|
+
try {
|
476
|
+
requestSchema.parse(params);
|
477
|
+
} catch (error) {
|
478
|
+
throw new Error(`Request validation failed: ${error}`);
|
479
|
+
}
|
480
|
+
}
|
481
|
+
const result = await gasPrice(client, params);
|
482
|
+
const responseSchema = RpcGasPriceResponseSchema();
|
483
|
+
try {
|
484
|
+
responseSchema.parse(result);
|
485
|
+
} catch (error) {
|
486
|
+
throw new Error(`Response validation failed: ${error}`);
|
487
|
+
}
|
488
|
+
return result;
|
489
|
+
}
|
490
|
+
async function genesisConfig2(client, params) {
|
491
|
+
const requestSchema = GenesisConfigRequestSchema();
|
492
|
+
if (params !== void 0) {
|
493
|
+
try {
|
494
|
+
requestSchema.parse(params);
|
495
|
+
} catch (error) {
|
496
|
+
throw new Error(`Request validation failed: ${error}`);
|
497
|
+
}
|
498
|
+
}
|
499
|
+
const result = await genesisConfig(client, params);
|
500
|
+
const responseSchema = GenesisConfigSchema();
|
501
|
+
try {
|
502
|
+
responseSchema.parse(result);
|
503
|
+
} catch (error) {
|
504
|
+
throw new Error(`Response validation failed: ${error}`);
|
505
|
+
}
|
506
|
+
return result;
|
507
|
+
}
|
508
|
+
async function health2(client, params) {
|
509
|
+
const requestSchema = RpcHealthRequestSchema();
|
510
|
+
if (params !== void 0) {
|
511
|
+
try {
|
512
|
+
requestSchema.parse(params);
|
513
|
+
} catch (error) {
|
514
|
+
throw new Error(`Request validation failed: ${error}`);
|
515
|
+
}
|
516
|
+
}
|
517
|
+
const result = await health(client, params);
|
518
|
+
const responseSchema = RpcHealthResponseSchema();
|
519
|
+
try {
|
520
|
+
responseSchema.parse(result);
|
521
|
+
} catch (error) {
|
522
|
+
throw new Error(`Response validation failed: ${error}`);
|
523
|
+
}
|
524
|
+
return result;
|
525
|
+
}
|
526
|
+
async function lightClientProof2(client, params) {
|
527
|
+
const requestSchema = RpcLightClientExecutionProofRequestSchema();
|
528
|
+
if (params !== void 0) {
|
529
|
+
try {
|
530
|
+
requestSchema.parse(params);
|
531
|
+
} catch (error) {
|
532
|
+
throw new Error(`Request validation failed: ${error}`);
|
533
|
+
}
|
534
|
+
}
|
535
|
+
const result = await lightClientProof(client, params);
|
536
|
+
const responseSchema = RpcLightClientExecutionProofResponseSchema();
|
537
|
+
try {
|
538
|
+
responseSchema.parse(result);
|
539
|
+
} catch (error) {
|
540
|
+
throw new Error(`Response validation failed: ${error}`);
|
541
|
+
}
|
542
|
+
return result;
|
543
|
+
}
|
544
|
+
async function maintenanceWindows2(client, params) {
|
545
|
+
const requestSchema = RpcMaintenanceWindowsRequestSchema();
|
546
|
+
if (params !== void 0) {
|
547
|
+
try {
|
548
|
+
requestSchema.parse(params);
|
549
|
+
} catch (error) {
|
550
|
+
throw new Error(`Request validation failed: ${error}`);
|
551
|
+
}
|
552
|
+
}
|
553
|
+
return maintenanceWindows(client, params);
|
554
|
+
}
|
555
|
+
async function networkInfo2(client, params) {
|
556
|
+
const requestSchema = RpcNetworkInfoRequestSchema();
|
557
|
+
if (params !== void 0) {
|
558
|
+
try {
|
559
|
+
requestSchema.parse(params);
|
560
|
+
} catch (error) {
|
561
|
+
throw new Error(`Request validation failed: ${error}`);
|
562
|
+
}
|
563
|
+
}
|
564
|
+
const result = await networkInfo(client, params);
|
565
|
+
const responseSchema = RpcNetworkInfoResponseSchema();
|
566
|
+
try {
|
567
|
+
responseSchema.parse(result);
|
568
|
+
} catch (error) {
|
569
|
+
throw new Error(`Response validation failed: ${error}`);
|
570
|
+
}
|
571
|
+
return result;
|
572
|
+
}
|
573
|
+
async function nextLightClientBlock2(client, params) {
|
574
|
+
const requestSchema = RpcLightClientNextBlockRequestSchema();
|
575
|
+
if (params !== void 0) {
|
576
|
+
try {
|
577
|
+
requestSchema.parse(params);
|
578
|
+
} catch (error) {
|
579
|
+
throw new Error(`Request validation failed: ${error}`);
|
580
|
+
}
|
581
|
+
}
|
582
|
+
const result = await nextLightClientBlock(client, params);
|
583
|
+
const responseSchema = RpcLightClientNextBlockResponseSchema();
|
584
|
+
try {
|
585
|
+
responseSchema.parse(result);
|
586
|
+
} catch (error) {
|
587
|
+
throw new Error(`Response validation failed: ${error}`);
|
588
|
+
}
|
589
|
+
return result;
|
590
|
+
}
|
591
|
+
async function query2(client, params) {
|
592
|
+
const requestSchema = RpcQueryRequestSchema();
|
593
|
+
if (params !== void 0) {
|
594
|
+
try {
|
595
|
+
requestSchema.parse(params);
|
596
|
+
} catch (error) {
|
597
|
+
throw new Error(`Request validation failed: ${error}`);
|
598
|
+
}
|
599
|
+
}
|
600
|
+
const result = await query(client, params);
|
601
|
+
const responseSchema = RpcQueryResponseSchema();
|
602
|
+
try {
|
603
|
+
responseSchema.parse(result);
|
604
|
+
} catch (error) {
|
605
|
+
throw new Error(`Response validation failed: ${error}`);
|
606
|
+
}
|
607
|
+
return result;
|
608
|
+
}
|
609
|
+
async function sendTx2(client, params) {
|
610
|
+
const requestSchema = RpcSendTransactionRequestSchema();
|
611
|
+
if (params !== void 0) {
|
612
|
+
try {
|
613
|
+
requestSchema.parse(params);
|
614
|
+
} catch (error) {
|
615
|
+
throw new Error(`Request validation failed: ${error}`);
|
616
|
+
}
|
617
|
+
}
|
618
|
+
const result = await sendTx(client, params);
|
619
|
+
const responseSchema = RpcTransactionResponseSchema();
|
620
|
+
try {
|
621
|
+
responseSchema.parse(result);
|
622
|
+
} catch (error) {
|
623
|
+
throw new Error(`Response validation failed: ${error}`);
|
624
|
+
}
|
625
|
+
return result;
|
626
|
+
}
|
627
|
+
async function status2(client, params) {
|
628
|
+
const requestSchema = RpcStatusRequestSchema();
|
629
|
+
if (params !== void 0) {
|
630
|
+
try {
|
631
|
+
requestSchema.parse(params);
|
632
|
+
} catch (error) {
|
633
|
+
throw new Error(`Request validation failed: ${error}`);
|
634
|
+
}
|
635
|
+
}
|
636
|
+
const result = await status(client, params);
|
637
|
+
const responseSchema = RpcStatusResponseSchema();
|
638
|
+
try {
|
639
|
+
responseSchema.parse(result);
|
640
|
+
} catch (error) {
|
641
|
+
throw new Error(`Response validation failed: ${error}`);
|
642
|
+
}
|
643
|
+
return result;
|
644
|
+
}
|
645
|
+
async function tx2(client, params) {
|
646
|
+
const requestSchema = RpcTransactionStatusRequestSchema();
|
647
|
+
if (params !== void 0) {
|
648
|
+
try {
|
649
|
+
requestSchema.parse(params);
|
650
|
+
} catch (error) {
|
651
|
+
throw new Error(`Request validation failed: ${error}`);
|
652
|
+
}
|
653
|
+
}
|
654
|
+
const result = await tx(client, params);
|
655
|
+
const responseSchema = RpcTransactionResponseSchema();
|
656
|
+
try {
|
657
|
+
responseSchema.parse(result);
|
658
|
+
} catch (error) {
|
659
|
+
throw new Error(`Response validation failed: ${error}`);
|
660
|
+
}
|
661
|
+
return result;
|
662
|
+
}
|
663
|
+
async function validators2(client, params) {
|
664
|
+
const requestSchema = RpcValidatorRequestSchema();
|
665
|
+
if (params !== void 0) {
|
666
|
+
try {
|
667
|
+
requestSchema.parse(params);
|
668
|
+
} catch (error) {
|
669
|
+
throw new Error(`Request validation failed: ${error}`);
|
670
|
+
}
|
671
|
+
}
|
672
|
+
const result = await validators(client, params);
|
673
|
+
const responseSchema = RpcValidatorResponseSchema();
|
674
|
+
try {
|
675
|
+
responseSchema.parse(result);
|
676
|
+
} catch (error) {
|
677
|
+
throw new Error(`Response validation failed: ${error}`);
|
678
|
+
}
|
679
|
+
return result;
|
349
680
|
}
|
350
681
|
|
351
682
|
// src/validation.ts
|
@@ -427,41 +758,43 @@ export {
|
|
427
758
|
NearRpcClient,
|
428
759
|
NearRpcError,
|
429
760
|
RPC_METHODS,
|
430
|
-
block,
|
431
|
-
blockEffects,
|
432
|
-
broadcastTxAsync,
|
433
|
-
broadcastTxCommit,
|
434
|
-
changes,
|
435
|
-
chunk,
|
436
|
-
clientConfig,
|
761
|
+
block2 as block,
|
762
|
+
blockEffects2 as blockEffects,
|
763
|
+
broadcastTxAsync2 as broadcastTxAsync,
|
764
|
+
broadcastTxCommit2 as broadcastTxCommit,
|
765
|
+
changes2 as changes,
|
766
|
+
chunk2 as chunk,
|
767
|
+
clientConfig2 as clientConfig,
|
437
768
|
NearRpcClient as default,
|
438
769
|
defaultClient,
|
439
770
|
enableValidation,
|
440
|
-
experimentalChanges,
|
441
|
-
experimentalChangesInBlock,
|
442
|
-
experimentalCongestionLevel,
|
443
|
-
experimentalGenesisConfig,
|
444
|
-
experimentalLightClientBlockProof,
|
445
|
-
experimentalLightClientProof,
|
446
|
-
experimentalMaintenanceWindows,
|
447
|
-
experimentalProtocolConfig,
|
448
|
-
experimentalReceipt,
|
449
|
-
experimentalSplitStorageInfo,
|
450
|
-
experimentalTxStatus,
|
451
|
-
experimentalValidatorsOrdered,
|
452
|
-
gasPrice,
|
453
|
-
genesisConfig,
|
454
|
-
health,
|
455
|
-
lightClientProof,
|
456
|
-
maintenanceWindows,
|
457
|
-
networkInfo,
|
458
|
-
nextLightClientBlock,
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
771
|
+
experimentalChanges2 as experimentalChanges,
|
772
|
+
experimentalChangesInBlock2 as experimentalChangesInBlock,
|
773
|
+
experimentalCongestionLevel2 as experimentalCongestionLevel,
|
774
|
+
experimentalGenesisConfig2 as experimentalGenesisConfig,
|
775
|
+
experimentalLightClientBlockProof2 as experimentalLightClientBlockProof,
|
776
|
+
experimentalLightClientProof2 as experimentalLightClientProof,
|
777
|
+
experimentalMaintenanceWindows2 as experimentalMaintenanceWindows,
|
778
|
+
experimentalProtocolConfig2 as experimentalProtocolConfig,
|
779
|
+
experimentalReceipt2 as experimentalReceipt,
|
780
|
+
experimentalSplitStorageInfo2 as experimentalSplitStorageInfo,
|
781
|
+
experimentalTxStatus2 as experimentalTxStatus,
|
782
|
+
experimentalValidatorsOrdered2 as experimentalValidatorsOrdered,
|
783
|
+
gasPrice2 as gasPrice,
|
784
|
+
genesisConfig2 as genesisConfig,
|
785
|
+
health2 as health,
|
786
|
+
lightClientProof2 as lightClientProof,
|
787
|
+
maintenanceWindows2 as maintenanceWindows,
|
788
|
+
networkInfo2 as networkInfo,
|
789
|
+
nextLightClientBlock2 as nextLightClientBlock,
|
790
|
+
parseCallResultToJson,
|
791
|
+
query2 as query,
|
792
|
+
sendTx2 as sendTx,
|
793
|
+
status2 as status,
|
794
|
+
tx2 as tx,
|
795
|
+
validators2 as validators,
|
464
796
|
viewAccessKey,
|
465
797
|
viewAccount,
|
466
|
-
viewFunction
|
798
|
+
viewFunction,
|
799
|
+
viewFunctionAsJson
|
467
800
|
};
|