@psalomo/jsonrpc-client 0.4.0 → 1.0.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 +12 -12
- package/dist/__tests__/test-utils.d.ts +5 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -0
- package/dist/browser-standalone.js +4038 -13674
- package/dist/browser-standalone.min.js +1 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/convenience.d.ts +21 -0
- package/dist/convenience.d.ts.map +1 -0
- package/dist/generated-functions.d.ts +3 -0
- package/dist/generated-functions.d.ts.map +1 -0
- package/dist/generated-types.d.ts +84 -0
- package/dist/generated-types.d.ts.map +1 -0
- package/dist/index.d.mts +133 -72
- package/dist/index.d.ts +10 -137
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +335 -105
- package/dist/index.mjs +307 -110
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.d.ts +14 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +10 -6
package/dist/index.mjs
CHANGED
@@ -1,24 +1,4 @@
|
|
1
1
|
// src/client.ts
|
2
|
-
import {
|
3
|
-
JsonRpcRequestSchema,
|
4
|
-
JsonRpcResponseSchema,
|
5
|
-
RPC_METHODS
|
6
|
-
} from "@psalomo/jsonrpc-types";
|
7
|
-
var JsonRpcClientError = class extends Error {
|
8
|
-
constructor(message, code, data) {
|
9
|
-
super(message);
|
10
|
-
this.code = code;
|
11
|
-
this.data = data;
|
12
|
-
this.name = "JsonRpcClientError";
|
13
|
-
}
|
14
|
-
};
|
15
|
-
var JsonRpcNetworkError = class extends Error {
|
16
|
-
constructor(message, originalError) {
|
17
|
-
super(message);
|
18
|
-
this.originalError = originalError;
|
19
|
-
this.name = "JsonRpcNetworkError";
|
20
|
-
}
|
21
|
-
};
|
22
2
|
function camelToSnake(str) {
|
23
3
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
24
4
|
}
|
@@ -53,60 +33,61 @@ function convertKeysToCamelCase(obj) {
|
|
53
33
|
}
|
54
34
|
return converted;
|
55
35
|
}
|
56
|
-
var
|
36
|
+
var REQUEST_ID = "dontcare";
|
37
|
+
var JsonRpcClientError = class extends Error {
|
38
|
+
constructor(message, code, data) {
|
39
|
+
super(message);
|
40
|
+
this.code = code;
|
41
|
+
this.data = data;
|
42
|
+
this.name = "JsonRpcClientError";
|
43
|
+
}
|
44
|
+
};
|
45
|
+
var JsonRpcNetworkError = class extends Error {
|
46
|
+
constructor(message, originalError) {
|
47
|
+
super(message);
|
48
|
+
this.originalError = originalError;
|
49
|
+
this.name = "JsonRpcNetworkError";
|
50
|
+
}
|
51
|
+
};
|
52
|
+
var NearRpcClient = class _NearRpcClient {
|
57
53
|
endpoint;
|
58
54
|
headers;
|
59
55
|
timeout;
|
60
56
|
retries;
|
61
|
-
|
62
|
-
requestIdCounter = 0;
|
57
|
+
validation;
|
63
58
|
constructor(config) {
|
64
59
|
if (typeof config === "string") {
|
65
60
|
this.endpoint = config;
|
66
|
-
this.headers = {
|
67
|
-
"Content-Type": "application/json"
|
68
|
-
};
|
61
|
+
this.headers = {};
|
69
62
|
this.timeout = 3e4;
|
70
63
|
this.retries = 3;
|
71
|
-
this.validateResponses = true;
|
72
64
|
} else {
|
73
65
|
this.endpoint = config.endpoint;
|
74
|
-
this.headers = {
|
75
|
-
"Content-Type": "application/json",
|
76
|
-
...config.headers
|
77
|
-
};
|
66
|
+
this.headers = config.headers || {};
|
78
67
|
this.timeout = config.timeout || 3e4;
|
79
68
|
this.retries = config.retries || 3;
|
80
|
-
|
69
|
+
if (config.validation) {
|
70
|
+
this.validation = config.validation;
|
71
|
+
}
|
81
72
|
}
|
82
73
|
}
|
83
74
|
/**
|
84
|
-
*
|
75
|
+
* Make a raw JSON-RPC request
|
76
|
+
* This is used internally by the standalone RPC functions
|
85
77
|
*/
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
/**
|
90
|
-
* Make a raw JSON-RPC call
|
91
|
-
* This method is public to allow dynamic calls to any RPC method
|
92
|
-
*/
|
93
|
-
async call(method, params) {
|
94
|
-
const requestId = this.generateRequestId();
|
95
|
-
const snakeCaseParams = params ? convertKeysToSnakeCase(params) : void 0;
|
78
|
+
async makeRequest(method, params) {
|
79
|
+
const snakeCaseParams = params ? convertKeysToSnakeCase(params) : params;
|
96
80
|
const request = {
|
97
81
|
jsonrpc: "2.0",
|
98
|
-
id:
|
82
|
+
id: REQUEST_ID,
|
99
83
|
method,
|
100
84
|
params: snakeCaseParams
|
101
85
|
};
|
102
|
-
if (this.
|
103
|
-
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
`Invalid request format: ${error instanceof Error ? error.message : "Unknown error"}`,
|
108
|
-
error
|
109
|
-
);
|
86
|
+
if (this.validation) {
|
87
|
+
if ("validateMethodRequest" in this.validation) {
|
88
|
+
this.validation.validateMethodRequest(method, request);
|
89
|
+
} else {
|
90
|
+
this.validation.validateRequest(request);
|
110
91
|
}
|
111
92
|
}
|
112
93
|
let lastError = null;
|
@@ -116,84 +97,81 @@ var NearRpcClient = class {
|
|
116
97
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
117
98
|
const response = await fetch(this.endpoint, {
|
118
99
|
method: "POST",
|
119
|
-
headers:
|
100
|
+
headers: {
|
101
|
+
"Content-Type": "application/json",
|
102
|
+
...this.headers
|
103
|
+
},
|
120
104
|
body: JSON.stringify(request),
|
121
105
|
signal: controller.signal
|
122
106
|
});
|
123
107
|
clearTimeout(timeoutId);
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
108
|
+
if (!response.ok) {
|
109
|
+
throw new JsonRpcNetworkError(
|
110
|
+
`HTTP error! status: ${response.status}`
|
111
|
+
);
|
112
|
+
}
|
113
|
+
let jsonResponse;
|
114
|
+
try {
|
115
|
+
jsonResponse = await response.json();
|
116
|
+
} catch (parseError) {
|
117
|
+
throw new JsonRpcNetworkError(
|
118
|
+
"Failed to parse JSON response",
|
119
|
+
parseError
|
120
|
+
);
|
121
|
+
}
|
122
|
+
if (this.validation) {
|
123
|
+
this.validation.validateResponse(jsonResponse);
|
133
124
|
}
|
134
|
-
|
135
|
-
if (rpcResponse.error) {
|
125
|
+
if (jsonResponse.error) {
|
136
126
|
throw new JsonRpcClientError(
|
137
|
-
|
138
|
-
|
139
|
-
|
127
|
+
jsonResponse.error.message,
|
128
|
+
jsonResponse.error.code,
|
129
|
+
jsonResponse.error.data
|
140
130
|
);
|
141
131
|
}
|
142
|
-
|
143
|
-
|
132
|
+
const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
|
133
|
+
if (this.validation && "validateMethodResponse" in this.validation) {
|
134
|
+
const camelCaseResponse = {
|
135
|
+
...jsonResponse,
|
136
|
+
result: camelCaseResult
|
137
|
+
};
|
138
|
+
this.validation.validateMethodResponse(method, camelCaseResponse);
|
144
139
|
}
|
145
|
-
const camelCaseResult = rpcResponse.result ? convertKeysToCamelCase(rpcResponse.result) : rpcResponse.result;
|
146
140
|
return camelCaseResult;
|
147
141
|
} catch (error) {
|
148
142
|
lastError = error;
|
149
143
|
if (error instanceof JsonRpcClientError) {
|
150
144
|
throw error;
|
151
145
|
}
|
152
|
-
if (attempt
|
153
|
-
|
154
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
155
|
-
continue;
|
146
|
+
if (attempt === this.retries) {
|
147
|
+
break;
|
156
148
|
}
|
149
|
+
await new Promise(
|
150
|
+
(resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1e3)
|
151
|
+
);
|
157
152
|
}
|
158
153
|
}
|
159
154
|
throw new JsonRpcNetworkError(
|
160
|
-
|
161
|
-
lastError
|
155
|
+
lastError?.message || "Request failed after all retries",
|
156
|
+
lastError || void 0
|
162
157
|
);
|
163
158
|
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
159
|
+
/**
|
160
|
+
* Create a new client with modified configuration
|
161
|
+
*/
|
162
|
+
withConfig(config) {
|
163
|
+
return new _NearRpcClient({
|
164
|
+
endpoint: config.endpoint ?? this.endpoint,
|
165
|
+
headers: config.headers ?? this.headers,
|
166
|
+
timeout: config.timeout ?? this.timeout,
|
167
|
+
retries: config.retries ?? this.retries,
|
168
|
+
...config.validation !== void 0 ? { validation: config.validation } : this.validation !== void 0 ? { validation: this.validation } : {}
|
169
|
+
});
|
174
170
|
}
|
175
|
-
NearRpcClient.prototype[methodName] = function(params) {
|
176
|
-
return this.call(method, params);
|
177
|
-
};
|
178
|
-
});
|
179
|
-
NearRpcClient.prototype.viewAccount = function(params) {
|
180
|
-
return this.query({
|
181
|
-
requestType: "view_account",
|
182
|
-
...params
|
183
|
-
});
|
184
|
-
};
|
185
|
-
NearRpcClient.prototype.viewFunction = function(params) {
|
186
|
-
return this.query({
|
187
|
-
requestType: "call_function",
|
188
|
-
...params
|
189
|
-
});
|
190
|
-
};
|
191
|
-
NearRpcClient.prototype.viewAccessKey = function(params) {
|
192
|
-
return this.query({
|
193
|
-
requestType: "view_access_key",
|
194
|
-
...params
|
195
|
-
});
|
196
171
|
};
|
172
|
+
var defaultClient = new NearRpcClient({
|
173
|
+
endpoint: "https://rpc.mainnet.near.org"
|
174
|
+
});
|
197
175
|
|
198
176
|
// src/types.ts
|
199
177
|
var NearRpcError = class extends Error {
|
@@ -210,7 +188,193 @@ import {
|
|
210
188
|
JsonRpcRequestSchema as JsonRpcRequestSchema2,
|
211
189
|
JsonRpcResponseSchema as JsonRpcResponseSchema2
|
212
190
|
} from "@psalomo/jsonrpc-types";
|
213
|
-
import { RPC_METHODS
|
191
|
+
import { RPC_METHODS } from "@psalomo/jsonrpc-types";
|
192
|
+
|
193
|
+
// src/generated-types.ts
|
194
|
+
async function experimentalChanges(client, params) {
|
195
|
+
return client.makeRequest("EXPERIMENTAL_changes", params);
|
196
|
+
}
|
197
|
+
async function experimentalChangesInBlock(client, params) {
|
198
|
+
return client.makeRequest("EXPERIMENTAL_changes_in_block", params);
|
199
|
+
}
|
200
|
+
async function experimentalCongestionLevel(client, params) {
|
201
|
+
return client.makeRequest("EXPERIMENTAL_congestion_level", params);
|
202
|
+
}
|
203
|
+
async function experimentalGenesisConfig(client, params) {
|
204
|
+
return client.makeRequest("EXPERIMENTAL_genesis_config", params);
|
205
|
+
}
|
206
|
+
async function experimentalLightClientBlockProof(client, params) {
|
207
|
+
return client.makeRequest("EXPERIMENTAL_light_client_block_proof", params);
|
208
|
+
}
|
209
|
+
async function experimentalLightClientProof(client, params) {
|
210
|
+
return client.makeRequest("EXPERIMENTAL_light_client_proof", params);
|
211
|
+
}
|
212
|
+
async function experimentalMaintenanceWindows(client, params) {
|
213
|
+
return client.makeRequest("EXPERIMENTAL_maintenance_windows", params);
|
214
|
+
}
|
215
|
+
async function experimentalProtocolConfig(client, params) {
|
216
|
+
return client.makeRequest("EXPERIMENTAL_protocol_config", params);
|
217
|
+
}
|
218
|
+
async function experimentalReceipt(client, params) {
|
219
|
+
return client.makeRequest("EXPERIMENTAL_receipt", params);
|
220
|
+
}
|
221
|
+
async function experimentalSplitStorageInfo(client, params) {
|
222
|
+
return client.makeRequest("EXPERIMENTAL_split_storage_info", params);
|
223
|
+
}
|
224
|
+
async function experimentalTxStatus(client, params) {
|
225
|
+
return client.makeRequest("EXPERIMENTAL_tx_status", params);
|
226
|
+
}
|
227
|
+
async function experimentalValidatorsOrdered(client, params) {
|
228
|
+
return client.makeRequest("EXPERIMENTAL_validators_ordered", params);
|
229
|
+
}
|
230
|
+
async function block(client, params) {
|
231
|
+
return client.makeRequest("block", params);
|
232
|
+
}
|
233
|
+
async function broadcastTxAsync(client, params) {
|
234
|
+
return client.makeRequest("broadcast_tx_async", params);
|
235
|
+
}
|
236
|
+
async function broadcastTxCommit(client, params) {
|
237
|
+
return client.makeRequest("broadcast_tx_commit", params);
|
238
|
+
}
|
239
|
+
async function changes(client, params) {
|
240
|
+
return client.makeRequest("changes", params);
|
241
|
+
}
|
242
|
+
async function chunk(client, params) {
|
243
|
+
return client.makeRequest("chunk", params);
|
244
|
+
}
|
245
|
+
async function clientConfig(client, params) {
|
246
|
+
return client.makeRequest("client_config", params);
|
247
|
+
}
|
248
|
+
async function gasPrice(client, params) {
|
249
|
+
return client.makeRequest("gas_price", params);
|
250
|
+
}
|
251
|
+
async function health(client, params) {
|
252
|
+
return client.makeRequest("health", params);
|
253
|
+
}
|
254
|
+
async function lightClientProof(client, params) {
|
255
|
+
return client.makeRequest("light_client_proof", params);
|
256
|
+
}
|
257
|
+
async function networkInfo(client, params) {
|
258
|
+
return client.makeRequest("network_info", params);
|
259
|
+
}
|
260
|
+
async function nextLightClientBlock(client, params) {
|
261
|
+
return client.makeRequest("next_light_client_block", params);
|
262
|
+
}
|
263
|
+
async function query(client, params) {
|
264
|
+
return client.makeRequest("query", params);
|
265
|
+
}
|
266
|
+
async function sendTx(client, params) {
|
267
|
+
return client.makeRequest("send_tx", params);
|
268
|
+
}
|
269
|
+
async function status(client, params) {
|
270
|
+
return client.makeRequest("status", params);
|
271
|
+
}
|
272
|
+
async function tx(client, params) {
|
273
|
+
return client.makeRequest("tx", params);
|
274
|
+
}
|
275
|
+
async function validators(client, params) {
|
276
|
+
return client.makeRequest("validators", params);
|
277
|
+
}
|
278
|
+
|
279
|
+
// src/convenience.ts
|
280
|
+
async function viewAccount(client, params) {
|
281
|
+
const queryParams = params.blockId ? {
|
282
|
+
requestType: "view_account",
|
283
|
+
accountId: params.accountId,
|
284
|
+
blockId: params.blockId
|
285
|
+
} : {
|
286
|
+
requestType: "view_account",
|
287
|
+
accountId: params.accountId,
|
288
|
+
finality: params.finality || "final"
|
289
|
+
};
|
290
|
+
return query(client, queryParams);
|
291
|
+
}
|
292
|
+
async function viewFunction(client, params) {
|
293
|
+
const baseParams = {
|
294
|
+
requestType: "call_function",
|
295
|
+
accountId: params.accountId,
|
296
|
+
methodName: params.methodName,
|
297
|
+
argsBase64: params.argsBase64 ?? ""
|
298
|
+
// Default to empty string if no arguments
|
299
|
+
};
|
300
|
+
const queryParams = params.blockId ? { ...baseParams, blockId: params.blockId } : { ...baseParams, finality: params.finality || "final" };
|
301
|
+
return query(client, queryParams);
|
302
|
+
}
|
303
|
+
async function viewAccessKey(client, params) {
|
304
|
+
const queryParams = params.blockId ? {
|
305
|
+
requestType: "view_access_key",
|
306
|
+
accountId: params.accountId,
|
307
|
+
publicKey: params.publicKey,
|
308
|
+
blockId: params.blockId
|
309
|
+
} : {
|
310
|
+
requestType: "view_access_key",
|
311
|
+
accountId: params.accountId,
|
312
|
+
publicKey: params.publicKey,
|
313
|
+
finality: params.finality || "final"
|
314
|
+
};
|
315
|
+
return query(client, queryParams);
|
316
|
+
}
|
317
|
+
|
318
|
+
// src/validation.ts
|
319
|
+
import {
|
320
|
+
JsonRpcRequestSchema,
|
321
|
+
JsonRpcResponseSchema,
|
322
|
+
VALIDATION_SCHEMA_MAP
|
323
|
+
} from "@psalomo/jsonrpc-types";
|
324
|
+
function enableValidation() {
|
325
|
+
const requestSchema = JsonRpcRequestSchema();
|
326
|
+
const responseSchema = JsonRpcResponseSchema();
|
327
|
+
return {
|
328
|
+
validateRequest: (request) => {
|
329
|
+
try {
|
330
|
+
requestSchema.parse(request);
|
331
|
+
} catch (error) {
|
332
|
+
throw new JsonRpcNetworkError(
|
333
|
+
`Invalid request format: ${error instanceof Error ? error.message : "Unknown error"}`,
|
334
|
+
error
|
335
|
+
);
|
336
|
+
}
|
337
|
+
},
|
338
|
+
validateResponse: (response) => {
|
339
|
+
try {
|
340
|
+
responseSchema.parse(response);
|
341
|
+
} catch (error) {
|
342
|
+
throw new JsonRpcClientError(
|
343
|
+
`Invalid response format: ${error instanceof Error ? error.message : "Unknown error"}`
|
344
|
+
);
|
345
|
+
}
|
346
|
+
},
|
347
|
+
validateMethodRequest: (method, request) => {
|
348
|
+
try {
|
349
|
+
requestSchema.parse(request);
|
350
|
+
const methodSchemas = VALIDATION_SCHEMA_MAP[method];
|
351
|
+
if (methodSchemas?.requestSchema) {
|
352
|
+
const methodRequestSchema = methodSchemas.requestSchema();
|
353
|
+
methodRequestSchema.parse(request);
|
354
|
+
}
|
355
|
+
} catch (error) {
|
356
|
+
throw new JsonRpcNetworkError(
|
357
|
+
`Invalid ${method} request: ${error instanceof Error ? error.message : "Unknown error"}`,
|
358
|
+
error
|
359
|
+
);
|
360
|
+
}
|
361
|
+
},
|
362
|
+
validateMethodResponse: (method, response) => {
|
363
|
+
try {
|
364
|
+
responseSchema.parse(response);
|
365
|
+
const methodSchemas = VALIDATION_SCHEMA_MAP[method];
|
366
|
+
if (methodSchemas?.responseSchema) {
|
367
|
+
const methodResponseSchema = methodSchemas.responseSchema();
|
368
|
+
methodResponseSchema.parse(response);
|
369
|
+
}
|
370
|
+
} catch (error) {
|
371
|
+
throw new JsonRpcClientError(
|
372
|
+
`Invalid ${method} response: ${error instanceof Error ? error.message : "Unknown error"}`
|
373
|
+
);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
};
|
377
|
+
}
|
214
378
|
export {
|
215
379
|
JsonRpcClientError,
|
216
380
|
JsonRpcNetworkError,
|
@@ -218,6 +382,39 @@ export {
|
|
218
382
|
JsonRpcResponseSchema2 as JsonRpcResponseSchema,
|
219
383
|
NearRpcClient,
|
220
384
|
NearRpcError,
|
221
|
-
|
222
|
-
|
385
|
+
RPC_METHODS,
|
386
|
+
block,
|
387
|
+
broadcastTxAsync,
|
388
|
+
broadcastTxCommit,
|
389
|
+
changes,
|
390
|
+
chunk,
|
391
|
+
clientConfig,
|
392
|
+
NearRpcClient as default,
|
393
|
+
defaultClient,
|
394
|
+
enableValidation,
|
395
|
+
experimentalChanges,
|
396
|
+
experimentalChangesInBlock,
|
397
|
+
experimentalCongestionLevel,
|
398
|
+
experimentalGenesisConfig,
|
399
|
+
experimentalLightClientBlockProof,
|
400
|
+
experimentalLightClientProof,
|
401
|
+
experimentalMaintenanceWindows,
|
402
|
+
experimentalProtocolConfig,
|
403
|
+
experimentalReceipt,
|
404
|
+
experimentalSplitStorageInfo,
|
405
|
+
experimentalTxStatus,
|
406
|
+
experimentalValidatorsOrdered,
|
407
|
+
gasPrice,
|
408
|
+
health,
|
409
|
+
lightClientProof,
|
410
|
+
networkInfo,
|
411
|
+
nextLightClientBlock,
|
412
|
+
query,
|
413
|
+
sendTx,
|
414
|
+
status,
|
415
|
+
tx,
|
416
|
+
validators,
|
417
|
+
viewAccessKey,
|
418
|
+
viewAccount,
|
419
|
+
viewFunction
|
223
420
|
};
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
export interface RpcRequest {
|
2
|
+
jsonrpc: '2.0';
|
3
|
+
id: string | number;
|
4
|
+
method: string;
|
5
|
+
params: unknown;
|
6
|
+
}
|
7
|
+
export interface RpcResponse<T = unknown> {
|
8
|
+
jsonrpc: '2.0';
|
9
|
+
id: string | number;
|
10
|
+
result?: T;
|
11
|
+
error?: RpcError;
|
12
|
+
}
|
13
|
+
export interface RpcError {
|
14
|
+
code: number;
|
15
|
+
message: string;
|
16
|
+
data?: unknown;
|
17
|
+
}
|
18
|
+
export declare class NearRpcError extends Error {
|
19
|
+
code: number;
|
20
|
+
data?: unknown | undefined;
|
21
|
+
constructor(code: number, message: string, data?: unknown | undefined);
|
22
|
+
}
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,qBAAa,YAAa,SAAQ,KAAK;IAE5B,IAAI,EAAE,MAAM;IAEZ,IAAI,CAAC,EAAE,OAAO;gBAFd,IAAI,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACR,IAAI,CAAC,EAAE,OAAO,YAAA;CAKxB"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { JsonRpcRequest, JsonRpcResponse } from './client.js';
|
2
|
+
export interface ValidationResult {
|
3
|
+
validateRequest: (request: JsonRpcRequest) => void;
|
4
|
+
validateResponse: (response: JsonRpcResponse) => void;
|
5
|
+
validateMethodRequest?: (method: string, request: JsonRpcRequest) => void;
|
6
|
+
validateMethodResponse?: (method: string, response: JsonRpcResponse) => void;
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* Enable validation for the client
|
10
|
+
* This function should only be called if you want to include schema validation
|
11
|
+
* Calling this function will include Zod schemas in your bundle
|
12
|
+
*/
|
13
|
+
export declare function enableValidation(): ValidationResult;
|
14
|
+
//# sourceMappingURL=validation.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,eAAe,EAGhB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACnD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACtD,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1E,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CAC9E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,CA+DnD"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@psalomo/jsonrpc-client",
|
3
|
-
"version": "0.
|
3
|
+
"version": "1.0.0",
|
4
4
|
"description": "TypeScript client for NEAR Protocol JSON-RPC API",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.mjs",
|
@@ -17,7 +17,9 @@
|
|
17
17
|
],
|
18
18
|
"scripts": {
|
19
19
|
"prebuild": "cd ../../tools/codegen && npx tsx generate-client-interface.ts",
|
20
|
-
"build": "tsup",
|
20
|
+
"build": "tsup && rollup -c",
|
21
|
+
"build:node": "tsup",
|
22
|
+
"build:browser": "rollup -c",
|
21
23
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
22
24
|
"clean": "rm -rf dist",
|
23
25
|
"typecheck": "tsc --noEmit",
|
@@ -28,15 +30,17 @@
|
|
28
30
|
"test:coverage": "vitest run --coverage"
|
29
31
|
},
|
30
32
|
"dependencies": {
|
31
|
-
"@psalomo/jsonrpc-types": "^0.1.0"
|
32
|
-
"cross-fetch": "^4.0.0",
|
33
|
-
"zod": "^3.22.4"
|
33
|
+
"@psalomo/jsonrpc-types": "^0.1.0"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
37
|
+
"@rollup/plugin-terser": "^0.4.4",
|
38
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
39
|
+
"@types/node": "^20.11.0",
|
36
40
|
"prettier": "^3.2.5",
|
41
|
+
"rollup": "^4.45.1",
|
37
42
|
"tsup": "^8.0.2",
|
38
43
|
"typescript": "^5.3.3",
|
39
|
-
"@types/node": "^20.11.0",
|
40
44
|
"vitest": "^1.2.2"
|
41
45
|
},
|
42
46
|
"publishConfig": {
|