@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.js
CHANGED
@@ -22,48 +22,50 @@ var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
23
23
|
JsonRpcClientError: () => JsonRpcClientError,
|
24
24
|
JsonRpcNetworkError: () => JsonRpcNetworkError,
|
25
|
-
JsonRpcRequestSchema: () =>
|
26
|
-
JsonRpcResponseSchema: () =>
|
25
|
+
JsonRpcRequestSchema: () => import_jsonrpc_types3.JsonRpcRequestSchema,
|
26
|
+
JsonRpcResponseSchema: () => import_jsonrpc_types3.JsonRpcResponseSchema,
|
27
27
|
NearRpcClient: () => NearRpcClient,
|
28
28
|
NearRpcError: () => NearRpcError,
|
29
|
-
RPC_METHODS: () =>
|
30
|
-
block: () =>
|
31
|
-
blockEffects: () =>
|
32
|
-
broadcastTxAsync: () =>
|
33
|
-
broadcastTxCommit: () =>
|
34
|
-
changes: () =>
|
35
|
-
chunk: () =>
|
36
|
-
clientConfig: () =>
|
29
|
+
RPC_METHODS: () => import_jsonrpc_types4.RPC_METHODS,
|
30
|
+
block: () => block2,
|
31
|
+
blockEffects: () => blockEffects2,
|
32
|
+
broadcastTxAsync: () => broadcastTxAsync2,
|
33
|
+
broadcastTxCommit: () => broadcastTxCommit2,
|
34
|
+
changes: () => changes2,
|
35
|
+
chunk: () => chunk2,
|
36
|
+
clientConfig: () => clientConfig2,
|
37
37
|
default: () => NearRpcClient,
|
38
38
|
defaultClient: () => defaultClient,
|
39
39
|
enableValidation: () => enableValidation,
|
40
|
-
experimentalChanges: () =>
|
41
|
-
experimentalChangesInBlock: () =>
|
42
|
-
experimentalCongestionLevel: () =>
|
43
|
-
experimentalGenesisConfig: () =>
|
44
|
-
experimentalLightClientBlockProof: () =>
|
45
|
-
experimentalLightClientProof: () =>
|
46
|
-
experimentalMaintenanceWindows: () =>
|
47
|
-
experimentalProtocolConfig: () =>
|
48
|
-
experimentalReceipt: () =>
|
49
|
-
experimentalSplitStorageInfo: () =>
|
50
|
-
experimentalTxStatus: () =>
|
51
|
-
experimentalValidatorsOrdered: () =>
|
52
|
-
gasPrice: () =>
|
53
|
-
genesisConfig: () =>
|
54
|
-
health: () =>
|
55
|
-
lightClientProof: () =>
|
56
|
-
maintenanceWindows: () =>
|
57
|
-
networkInfo: () =>
|
58
|
-
nextLightClientBlock: () =>
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
40
|
+
experimentalChanges: () => experimentalChanges2,
|
41
|
+
experimentalChangesInBlock: () => experimentalChangesInBlock2,
|
42
|
+
experimentalCongestionLevel: () => experimentalCongestionLevel2,
|
43
|
+
experimentalGenesisConfig: () => experimentalGenesisConfig2,
|
44
|
+
experimentalLightClientBlockProof: () => experimentalLightClientBlockProof2,
|
45
|
+
experimentalLightClientProof: () => experimentalLightClientProof2,
|
46
|
+
experimentalMaintenanceWindows: () => experimentalMaintenanceWindows2,
|
47
|
+
experimentalProtocolConfig: () => experimentalProtocolConfig2,
|
48
|
+
experimentalReceipt: () => experimentalReceipt2,
|
49
|
+
experimentalSplitStorageInfo: () => experimentalSplitStorageInfo2,
|
50
|
+
experimentalTxStatus: () => experimentalTxStatus2,
|
51
|
+
experimentalValidatorsOrdered: () => experimentalValidatorsOrdered2,
|
52
|
+
gasPrice: () => gasPrice2,
|
53
|
+
genesisConfig: () => genesisConfig2,
|
54
|
+
health: () => health2,
|
55
|
+
lightClientProof: () => lightClientProof2,
|
56
|
+
maintenanceWindows: () => maintenanceWindows2,
|
57
|
+
networkInfo: () => networkInfo2,
|
58
|
+
nextLightClientBlock: () => nextLightClientBlock2,
|
59
|
+
parseCallResultToJson: () => parseCallResultToJson,
|
60
|
+
query: () => query2,
|
61
|
+
sendTx: () => sendTx2,
|
62
|
+
status: () => status2,
|
63
|
+
tx: () => tx2,
|
64
|
+
validators: () => validators2,
|
65
|
+
viewAccessKey: () => viewAccessKey2,
|
66
|
+
viewAccount: () => viewAccount2,
|
67
|
+
viewFunction: () => viewFunction2,
|
68
|
+
viewFunctionAsJson: () => viewFunctionAsJson
|
67
69
|
});
|
68
70
|
module.exports = __toCommonJS(index_exports);
|
69
71
|
|
@@ -277,8 +279,8 @@ var NearRpcError = class extends Error {
|
|
277
279
|
};
|
278
280
|
|
279
281
|
// src/index.ts
|
280
|
-
var import_jsonrpc_types2 = require("@psalomo/jsonrpc-types");
|
281
282
|
var import_jsonrpc_types3 = require("@psalomo/jsonrpc-types");
|
283
|
+
var import_jsonrpc_types4 = require("@psalomo/jsonrpc-types");
|
282
284
|
|
283
285
|
// src/generated-types.ts
|
284
286
|
async function experimentalChanges(client, params) {
|
@@ -376,7 +378,30 @@ async function validators(client, params) {
|
|
376
378
|
}
|
377
379
|
|
378
380
|
// src/convenience.ts
|
379
|
-
async function
|
381
|
+
async function viewFunction(client, params) {
|
382
|
+
const baseParams = {
|
383
|
+
requestType: "call_function",
|
384
|
+
accountId: params.accountId,
|
385
|
+
methodName: params.methodName,
|
386
|
+
argsBase64: params.argsBase64 ?? ""
|
387
|
+
// Default to empty string if no arguments
|
388
|
+
};
|
389
|
+
const queryParams = params.blockId ? { ...baseParams, blockId: params.blockId } : { ...baseParams, finality: params.finality || "final" };
|
390
|
+
return query(client, queryParams);
|
391
|
+
}
|
392
|
+
function parseCallResultToJson(callResult) {
|
393
|
+
const bytes = new Uint8Array(callResult.result);
|
394
|
+
const text = new TextDecoder().decode(bytes);
|
395
|
+
return JSON.parse(text);
|
396
|
+
}
|
397
|
+
async function viewFunctionAsJson(client, params) {
|
398
|
+
const result = await viewFunction(client, params);
|
399
|
+
return parseCallResultToJson(result);
|
400
|
+
}
|
401
|
+
|
402
|
+
// src/validated/index.ts
|
403
|
+
var import_jsonrpc_types = require("@psalomo/jsonrpc-types");
|
404
|
+
async function viewAccount2(client, params) {
|
380
405
|
const queryParams = params.blockId ? {
|
381
406
|
requestType: "view_account",
|
382
407
|
accountId: params.accountId,
|
@@ -386,20 +411,19 @@ async function viewAccount(client, params) {
|
|
386
411
|
accountId: params.accountId,
|
387
412
|
finality: params.finality || "final"
|
388
413
|
};
|
389
|
-
return
|
414
|
+
return query2(client, queryParams);
|
390
415
|
}
|
391
|
-
async function
|
416
|
+
async function viewFunction2(client, params) {
|
392
417
|
const baseParams = {
|
393
418
|
requestType: "call_function",
|
394
419
|
accountId: params.accountId,
|
395
420
|
methodName: params.methodName,
|
396
421
|
argsBase64: params.argsBase64 ?? ""
|
397
|
-
// Default to empty string if no arguments
|
398
422
|
};
|
399
423
|
const queryParams = params.blockId ? { ...baseParams, blockId: params.blockId } : { ...baseParams, finality: params.finality || "final" };
|
400
|
-
return
|
424
|
+
return query2(client, queryParams);
|
401
425
|
}
|
402
|
-
async function
|
426
|
+
async function viewAccessKey2(client, params) {
|
403
427
|
const queryParams = params.blockId ? {
|
404
428
|
requestType: "view_access_key",
|
405
429
|
accountId: params.accountId,
|
@@ -411,14 +435,563 @@ async function viewAccessKey(client, params) {
|
|
411
435
|
publicKey: params.publicKey,
|
412
436
|
finality: params.finality || "final"
|
413
437
|
};
|
414
|
-
return
|
438
|
+
return query2(client, queryParams);
|
439
|
+
}
|
440
|
+
async function experimentalChanges2(client, params) {
|
441
|
+
const requestSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockByTypeRequestSchema)();
|
442
|
+
if (params !== void 0) {
|
443
|
+
try {
|
444
|
+
requestSchema.parse(params);
|
445
|
+
} catch (error) {
|
446
|
+
throw new Error(`Request validation failed: ${error}`);
|
447
|
+
}
|
448
|
+
}
|
449
|
+
const result = await experimentalChanges(client, params);
|
450
|
+
const responseSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockResponseSchema)();
|
451
|
+
try {
|
452
|
+
responseSchema.parse(result);
|
453
|
+
} catch (error) {
|
454
|
+
throw new Error(`Response validation failed: ${error}`);
|
455
|
+
}
|
456
|
+
return result;
|
457
|
+
}
|
458
|
+
async function experimentalChangesInBlock2(client, params) {
|
459
|
+
const requestSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockRequestSchema)();
|
460
|
+
if (params !== void 0) {
|
461
|
+
try {
|
462
|
+
requestSchema.parse(params);
|
463
|
+
} catch (error) {
|
464
|
+
throw new Error(`Request validation failed: ${error}`);
|
465
|
+
}
|
466
|
+
}
|
467
|
+
const result = await experimentalChangesInBlock(client, params);
|
468
|
+
const responseSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockByTypeResponseSchema)();
|
469
|
+
try {
|
470
|
+
responseSchema.parse(result);
|
471
|
+
} catch (error) {
|
472
|
+
throw new Error(`Response validation failed: ${error}`);
|
473
|
+
}
|
474
|
+
return result;
|
475
|
+
}
|
476
|
+
async function experimentalCongestionLevel2(client, params) {
|
477
|
+
const requestSchema = (0, import_jsonrpc_types.RpcCongestionLevelRequestSchema)();
|
478
|
+
if (params !== void 0) {
|
479
|
+
try {
|
480
|
+
requestSchema.parse(params);
|
481
|
+
} catch (error) {
|
482
|
+
throw new Error(`Request validation failed: ${error}`);
|
483
|
+
}
|
484
|
+
}
|
485
|
+
const result = await experimentalCongestionLevel(
|
486
|
+
client,
|
487
|
+
params
|
488
|
+
);
|
489
|
+
const responseSchema = (0, import_jsonrpc_types.RpcCongestionLevelResponseSchema)();
|
490
|
+
try {
|
491
|
+
responseSchema.parse(result);
|
492
|
+
} catch (error) {
|
493
|
+
throw new Error(`Response validation failed: ${error}`);
|
494
|
+
}
|
495
|
+
return result;
|
496
|
+
}
|
497
|
+
async function experimentalGenesisConfig2(client, params) {
|
498
|
+
const requestSchema = (0, import_jsonrpc_types.GenesisConfigRequestSchema)();
|
499
|
+
if (params !== void 0) {
|
500
|
+
try {
|
501
|
+
requestSchema.parse(params);
|
502
|
+
} catch (error) {
|
503
|
+
throw new Error(`Request validation failed: ${error}`);
|
504
|
+
}
|
505
|
+
}
|
506
|
+
const result = await experimentalGenesisConfig(client, params);
|
507
|
+
const responseSchema = (0, import_jsonrpc_types.GenesisConfigSchema)();
|
508
|
+
try {
|
509
|
+
responseSchema.parse(result);
|
510
|
+
} catch (error) {
|
511
|
+
throw new Error(`Response validation failed: ${error}`);
|
512
|
+
}
|
513
|
+
return result;
|
514
|
+
}
|
515
|
+
async function experimentalLightClientBlockProof2(client, params) {
|
516
|
+
const requestSchema = (0, import_jsonrpc_types.RpcLightClientBlockProofRequestSchema)();
|
517
|
+
if (params !== void 0) {
|
518
|
+
try {
|
519
|
+
requestSchema.parse(params);
|
520
|
+
} catch (error) {
|
521
|
+
throw new Error(`Request validation failed: ${error}`);
|
522
|
+
}
|
523
|
+
}
|
524
|
+
const result = await experimentalLightClientBlockProof(
|
525
|
+
client,
|
526
|
+
params
|
527
|
+
);
|
528
|
+
const responseSchema = (0, import_jsonrpc_types.RpcLightClientBlockProofResponseSchema)();
|
529
|
+
try {
|
530
|
+
responseSchema.parse(result);
|
531
|
+
} catch (error) {
|
532
|
+
throw new Error(`Response validation failed: ${error}`);
|
533
|
+
}
|
534
|
+
return result;
|
535
|
+
}
|
536
|
+
async function experimentalLightClientProof2(client, params) {
|
537
|
+
const requestSchema = (0, import_jsonrpc_types.RpcLightClientExecutionProofRequestSchema)();
|
538
|
+
if (params !== void 0) {
|
539
|
+
try {
|
540
|
+
requestSchema.parse(params);
|
541
|
+
} catch (error) {
|
542
|
+
throw new Error(`Request validation failed: ${error}`);
|
543
|
+
}
|
544
|
+
}
|
545
|
+
const result = await experimentalLightClientProof(
|
546
|
+
client,
|
547
|
+
params
|
548
|
+
);
|
549
|
+
const responseSchema = (0, import_jsonrpc_types.RpcLightClientExecutionProofResponseSchema)();
|
550
|
+
try {
|
551
|
+
responseSchema.parse(result);
|
552
|
+
} catch (error) {
|
553
|
+
throw new Error(`Response validation failed: ${error}`);
|
554
|
+
}
|
555
|
+
return result;
|
556
|
+
}
|
557
|
+
async function experimentalMaintenanceWindows2(client, params) {
|
558
|
+
const requestSchema = (0, import_jsonrpc_types.RpcMaintenanceWindowsRequestSchema)();
|
559
|
+
if (params !== void 0) {
|
560
|
+
try {
|
561
|
+
requestSchema.parse(params);
|
562
|
+
} catch (error) {
|
563
|
+
throw new Error(`Request validation failed: ${error}`);
|
564
|
+
}
|
565
|
+
}
|
566
|
+
return experimentalMaintenanceWindows(client, params);
|
567
|
+
}
|
568
|
+
async function experimentalProtocolConfig2(client, params) {
|
569
|
+
const requestSchema = (0, import_jsonrpc_types.RpcProtocolConfigRequestSchema)();
|
570
|
+
if (params !== void 0) {
|
571
|
+
try {
|
572
|
+
requestSchema.parse(params);
|
573
|
+
} catch (error) {
|
574
|
+
throw new Error(`Request validation failed: ${error}`);
|
575
|
+
}
|
576
|
+
}
|
577
|
+
const result = await experimentalProtocolConfig(client, params);
|
578
|
+
const responseSchema = (0, import_jsonrpc_types.RpcProtocolConfigResponseSchema)();
|
579
|
+
try {
|
580
|
+
responseSchema.parse(result);
|
581
|
+
} catch (error) {
|
582
|
+
throw new Error(`Response validation failed: ${error}`);
|
583
|
+
}
|
584
|
+
return result;
|
585
|
+
}
|
586
|
+
async function experimentalReceipt2(client, params) {
|
587
|
+
const requestSchema = (0, import_jsonrpc_types.RpcReceiptRequestSchema)();
|
588
|
+
if (params !== void 0) {
|
589
|
+
try {
|
590
|
+
requestSchema.parse(params);
|
591
|
+
} catch (error) {
|
592
|
+
throw new Error(`Request validation failed: ${error}`);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
const result = await experimentalReceipt(client, params);
|
596
|
+
const responseSchema = (0, import_jsonrpc_types.RpcReceiptResponseSchema)();
|
597
|
+
try {
|
598
|
+
responseSchema.parse(result);
|
599
|
+
} catch (error) {
|
600
|
+
throw new Error(`Response validation failed: ${error}`);
|
601
|
+
}
|
602
|
+
return result;
|
603
|
+
}
|
604
|
+
async function experimentalSplitStorageInfo2(client, params) {
|
605
|
+
const requestSchema = (0, import_jsonrpc_types.RpcSplitStorageInfoRequestSchema)();
|
606
|
+
if (params !== void 0) {
|
607
|
+
try {
|
608
|
+
requestSchema.parse(params);
|
609
|
+
} catch (error) {
|
610
|
+
throw new Error(`Request validation failed: ${error}`);
|
611
|
+
}
|
612
|
+
}
|
613
|
+
const result = await experimentalSplitStorageInfo(
|
614
|
+
client,
|
615
|
+
params
|
616
|
+
);
|
617
|
+
const responseSchema = (0, import_jsonrpc_types.RpcSplitStorageInfoResponseSchema)();
|
618
|
+
try {
|
619
|
+
responseSchema.parse(result);
|
620
|
+
} catch (error) {
|
621
|
+
throw new Error(`Response validation failed: ${error}`);
|
622
|
+
}
|
623
|
+
return result;
|
624
|
+
}
|
625
|
+
async function experimentalTxStatus2(client, params) {
|
626
|
+
const requestSchema = (0, import_jsonrpc_types.RpcTransactionStatusRequestSchema)();
|
627
|
+
if (params !== void 0) {
|
628
|
+
try {
|
629
|
+
requestSchema.parse(params);
|
630
|
+
} catch (error) {
|
631
|
+
throw new Error(`Request validation failed: ${error}`);
|
632
|
+
}
|
633
|
+
}
|
634
|
+
const result = await experimentalTxStatus(client, params);
|
635
|
+
const responseSchema = (0, import_jsonrpc_types.RpcTransactionResponseSchema)();
|
636
|
+
try {
|
637
|
+
responseSchema.parse(result);
|
638
|
+
} catch (error) {
|
639
|
+
throw new Error(`Response validation failed: ${error}`);
|
640
|
+
}
|
641
|
+
return result;
|
642
|
+
}
|
643
|
+
async function experimentalValidatorsOrdered2(client, params) {
|
644
|
+
const requestSchema = (0, import_jsonrpc_types.RpcValidatorsOrderedRequestSchema)();
|
645
|
+
if (params !== void 0) {
|
646
|
+
try {
|
647
|
+
requestSchema.parse(params);
|
648
|
+
} catch (error) {
|
649
|
+
throw new Error(`Request validation failed: ${error}`);
|
650
|
+
}
|
651
|
+
}
|
652
|
+
return experimentalValidatorsOrdered(client, params);
|
653
|
+
}
|
654
|
+
async function block2(client, params) {
|
655
|
+
const requestSchema = (0, import_jsonrpc_types.RpcBlockRequestSchema)();
|
656
|
+
if (params !== void 0) {
|
657
|
+
try {
|
658
|
+
requestSchema.parse(params);
|
659
|
+
} catch (error) {
|
660
|
+
throw new Error(`Request validation failed: ${error}`);
|
661
|
+
}
|
662
|
+
}
|
663
|
+
const result = await block(client, params);
|
664
|
+
const responseSchema = (0, import_jsonrpc_types.RpcBlockResponseSchema)();
|
665
|
+
try {
|
666
|
+
responseSchema.parse(result);
|
667
|
+
} catch (error) {
|
668
|
+
throw new Error(`Response validation failed: ${error}`);
|
669
|
+
}
|
670
|
+
return result;
|
671
|
+
}
|
672
|
+
async function blockEffects2(client, params) {
|
673
|
+
const requestSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockRequestSchema)();
|
674
|
+
if (params !== void 0) {
|
675
|
+
try {
|
676
|
+
requestSchema.parse(params);
|
677
|
+
} catch (error) {
|
678
|
+
throw new Error(`Request validation failed: ${error}`);
|
679
|
+
}
|
680
|
+
}
|
681
|
+
const result = await blockEffects(client, params);
|
682
|
+
const responseSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockByTypeResponseSchema)();
|
683
|
+
try {
|
684
|
+
responseSchema.parse(result);
|
685
|
+
} catch (error) {
|
686
|
+
throw new Error(`Response validation failed: ${error}`);
|
687
|
+
}
|
688
|
+
return result;
|
689
|
+
}
|
690
|
+
async function broadcastTxAsync2(client, params) {
|
691
|
+
const requestSchema = (0, import_jsonrpc_types.RpcSendTransactionRequestSchema)();
|
692
|
+
if (params !== void 0) {
|
693
|
+
try {
|
694
|
+
requestSchema.parse(params);
|
695
|
+
} catch (error) {
|
696
|
+
throw new Error(`Request validation failed: ${error}`);
|
697
|
+
}
|
698
|
+
}
|
699
|
+
const result = await broadcastTxAsync(client, params);
|
700
|
+
const responseSchema = (0, import_jsonrpc_types.CryptoHashSchema)();
|
701
|
+
try {
|
702
|
+
responseSchema.parse(result);
|
703
|
+
} catch (error) {
|
704
|
+
throw new Error(`Response validation failed: ${error}`);
|
705
|
+
}
|
706
|
+
return result;
|
707
|
+
}
|
708
|
+
async function broadcastTxCommit2(client, params) {
|
709
|
+
const requestSchema = (0, import_jsonrpc_types.RpcSendTransactionRequestSchema)();
|
710
|
+
if (params !== void 0) {
|
711
|
+
try {
|
712
|
+
requestSchema.parse(params);
|
713
|
+
} catch (error) {
|
714
|
+
throw new Error(`Request validation failed: ${error}`);
|
715
|
+
}
|
716
|
+
}
|
717
|
+
const result = await broadcastTxCommit(client, params);
|
718
|
+
const responseSchema = (0, import_jsonrpc_types.RpcTransactionResponseSchema)();
|
719
|
+
try {
|
720
|
+
responseSchema.parse(result);
|
721
|
+
} catch (error) {
|
722
|
+
throw new Error(`Response validation failed: ${error}`);
|
723
|
+
}
|
724
|
+
return result;
|
725
|
+
}
|
726
|
+
async function changes2(client, params) {
|
727
|
+
const requestSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockByTypeRequestSchema)();
|
728
|
+
if (params !== void 0) {
|
729
|
+
try {
|
730
|
+
requestSchema.parse(params);
|
731
|
+
} catch (error) {
|
732
|
+
throw new Error(`Request validation failed: ${error}`);
|
733
|
+
}
|
734
|
+
}
|
735
|
+
const result = await changes(client, params);
|
736
|
+
const responseSchema = (0, import_jsonrpc_types.RpcStateChangesInBlockResponseSchema)();
|
737
|
+
try {
|
738
|
+
responseSchema.parse(result);
|
739
|
+
} catch (error) {
|
740
|
+
throw new Error(`Response validation failed: ${error}`);
|
741
|
+
}
|
742
|
+
return result;
|
743
|
+
}
|
744
|
+
async function chunk2(client, params) {
|
745
|
+
const requestSchema = (0, import_jsonrpc_types.RpcChunkRequestSchema)();
|
746
|
+
if (params !== void 0) {
|
747
|
+
try {
|
748
|
+
requestSchema.parse(params);
|
749
|
+
} catch (error) {
|
750
|
+
throw new Error(`Request validation failed: ${error}`);
|
751
|
+
}
|
752
|
+
}
|
753
|
+
const result = await chunk(client, params);
|
754
|
+
const responseSchema = (0, import_jsonrpc_types.RpcChunkResponseSchema)();
|
755
|
+
try {
|
756
|
+
responseSchema.parse(result);
|
757
|
+
} catch (error) {
|
758
|
+
throw new Error(`Response validation failed: ${error}`);
|
759
|
+
}
|
760
|
+
return result;
|
761
|
+
}
|
762
|
+
async function clientConfig2(client, params) {
|
763
|
+
const requestSchema = (0, import_jsonrpc_types.RpcClientConfigRequestSchema)();
|
764
|
+
if (params !== void 0) {
|
765
|
+
try {
|
766
|
+
requestSchema.parse(params);
|
767
|
+
} catch (error) {
|
768
|
+
throw new Error(`Request validation failed: ${error}`);
|
769
|
+
}
|
770
|
+
}
|
771
|
+
const result = await clientConfig(client, params);
|
772
|
+
const responseSchema = (0, import_jsonrpc_types.RpcClientConfigResponseSchema)();
|
773
|
+
try {
|
774
|
+
responseSchema.parse(result);
|
775
|
+
} catch (error) {
|
776
|
+
throw new Error(`Response validation failed: ${error}`);
|
777
|
+
}
|
778
|
+
return result;
|
779
|
+
}
|
780
|
+
async function gasPrice2(client, params) {
|
781
|
+
const requestSchema = (0, import_jsonrpc_types.RpcGasPriceRequestSchema)();
|
782
|
+
if (params !== void 0) {
|
783
|
+
try {
|
784
|
+
requestSchema.parse(params);
|
785
|
+
} catch (error) {
|
786
|
+
throw new Error(`Request validation failed: ${error}`);
|
787
|
+
}
|
788
|
+
}
|
789
|
+
const result = await gasPrice(client, params);
|
790
|
+
const responseSchema = (0, import_jsonrpc_types.RpcGasPriceResponseSchema)();
|
791
|
+
try {
|
792
|
+
responseSchema.parse(result);
|
793
|
+
} catch (error) {
|
794
|
+
throw new Error(`Response validation failed: ${error}`);
|
795
|
+
}
|
796
|
+
return result;
|
797
|
+
}
|
798
|
+
async function genesisConfig2(client, params) {
|
799
|
+
const requestSchema = (0, import_jsonrpc_types.GenesisConfigRequestSchema)();
|
800
|
+
if (params !== void 0) {
|
801
|
+
try {
|
802
|
+
requestSchema.parse(params);
|
803
|
+
} catch (error) {
|
804
|
+
throw new Error(`Request validation failed: ${error}`);
|
805
|
+
}
|
806
|
+
}
|
807
|
+
const result = await genesisConfig(client, params);
|
808
|
+
const responseSchema = (0, import_jsonrpc_types.GenesisConfigSchema)();
|
809
|
+
try {
|
810
|
+
responseSchema.parse(result);
|
811
|
+
} catch (error) {
|
812
|
+
throw new Error(`Response validation failed: ${error}`);
|
813
|
+
}
|
814
|
+
return result;
|
815
|
+
}
|
816
|
+
async function health2(client, params) {
|
817
|
+
const requestSchema = (0, import_jsonrpc_types.RpcHealthRequestSchema)();
|
818
|
+
if (params !== void 0) {
|
819
|
+
try {
|
820
|
+
requestSchema.parse(params);
|
821
|
+
} catch (error) {
|
822
|
+
throw new Error(`Request validation failed: ${error}`);
|
823
|
+
}
|
824
|
+
}
|
825
|
+
const result = await health(client, params);
|
826
|
+
const responseSchema = (0, import_jsonrpc_types.RpcHealthResponseSchema)();
|
827
|
+
try {
|
828
|
+
responseSchema.parse(result);
|
829
|
+
} catch (error) {
|
830
|
+
throw new Error(`Response validation failed: ${error}`);
|
831
|
+
}
|
832
|
+
return result;
|
833
|
+
}
|
834
|
+
async function lightClientProof2(client, params) {
|
835
|
+
const requestSchema = (0, import_jsonrpc_types.RpcLightClientExecutionProofRequestSchema)();
|
836
|
+
if (params !== void 0) {
|
837
|
+
try {
|
838
|
+
requestSchema.parse(params);
|
839
|
+
} catch (error) {
|
840
|
+
throw new Error(`Request validation failed: ${error}`);
|
841
|
+
}
|
842
|
+
}
|
843
|
+
const result = await lightClientProof(client, params);
|
844
|
+
const responseSchema = (0, import_jsonrpc_types.RpcLightClientExecutionProofResponseSchema)();
|
845
|
+
try {
|
846
|
+
responseSchema.parse(result);
|
847
|
+
} catch (error) {
|
848
|
+
throw new Error(`Response validation failed: ${error}`);
|
849
|
+
}
|
850
|
+
return result;
|
851
|
+
}
|
852
|
+
async function maintenanceWindows2(client, params) {
|
853
|
+
const requestSchema = (0, import_jsonrpc_types.RpcMaintenanceWindowsRequestSchema)();
|
854
|
+
if (params !== void 0) {
|
855
|
+
try {
|
856
|
+
requestSchema.parse(params);
|
857
|
+
} catch (error) {
|
858
|
+
throw new Error(`Request validation failed: ${error}`);
|
859
|
+
}
|
860
|
+
}
|
861
|
+
return maintenanceWindows(client, params);
|
862
|
+
}
|
863
|
+
async function networkInfo2(client, params) {
|
864
|
+
const requestSchema = (0, import_jsonrpc_types.RpcNetworkInfoRequestSchema)();
|
865
|
+
if (params !== void 0) {
|
866
|
+
try {
|
867
|
+
requestSchema.parse(params);
|
868
|
+
} catch (error) {
|
869
|
+
throw new Error(`Request validation failed: ${error}`);
|
870
|
+
}
|
871
|
+
}
|
872
|
+
const result = await networkInfo(client, params);
|
873
|
+
const responseSchema = (0, import_jsonrpc_types.RpcNetworkInfoResponseSchema)();
|
874
|
+
try {
|
875
|
+
responseSchema.parse(result);
|
876
|
+
} catch (error) {
|
877
|
+
throw new Error(`Response validation failed: ${error}`);
|
878
|
+
}
|
879
|
+
return result;
|
880
|
+
}
|
881
|
+
async function nextLightClientBlock2(client, params) {
|
882
|
+
const requestSchema = (0, import_jsonrpc_types.RpcLightClientNextBlockRequestSchema)();
|
883
|
+
if (params !== void 0) {
|
884
|
+
try {
|
885
|
+
requestSchema.parse(params);
|
886
|
+
} catch (error) {
|
887
|
+
throw new Error(`Request validation failed: ${error}`);
|
888
|
+
}
|
889
|
+
}
|
890
|
+
const result = await nextLightClientBlock(client, params);
|
891
|
+
const responseSchema = (0, import_jsonrpc_types.RpcLightClientNextBlockResponseSchema)();
|
892
|
+
try {
|
893
|
+
responseSchema.parse(result);
|
894
|
+
} catch (error) {
|
895
|
+
throw new Error(`Response validation failed: ${error}`);
|
896
|
+
}
|
897
|
+
return result;
|
898
|
+
}
|
899
|
+
async function query2(client, params) {
|
900
|
+
const requestSchema = (0, import_jsonrpc_types.RpcQueryRequestSchema)();
|
901
|
+
if (params !== void 0) {
|
902
|
+
try {
|
903
|
+
requestSchema.parse(params);
|
904
|
+
} catch (error) {
|
905
|
+
throw new Error(`Request validation failed: ${error}`);
|
906
|
+
}
|
907
|
+
}
|
908
|
+
const result = await query(client, params);
|
909
|
+
const responseSchema = (0, import_jsonrpc_types.RpcQueryResponseSchema)();
|
910
|
+
try {
|
911
|
+
responseSchema.parse(result);
|
912
|
+
} catch (error) {
|
913
|
+
throw new Error(`Response validation failed: ${error}`);
|
914
|
+
}
|
915
|
+
return result;
|
916
|
+
}
|
917
|
+
async function sendTx2(client, params) {
|
918
|
+
const requestSchema = (0, import_jsonrpc_types.RpcSendTransactionRequestSchema)();
|
919
|
+
if (params !== void 0) {
|
920
|
+
try {
|
921
|
+
requestSchema.parse(params);
|
922
|
+
} catch (error) {
|
923
|
+
throw new Error(`Request validation failed: ${error}`);
|
924
|
+
}
|
925
|
+
}
|
926
|
+
const result = await sendTx(client, params);
|
927
|
+
const responseSchema = (0, import_jsonrpc_types.RpcTransactionResponseSchema)();
|
928
|
+
try {
|
929
|
+
responseSchema.parse(result);
|
930
|
+
} catch (error) {
|
931
|
+
throw new Error(`Response validation failed: ${error}`);
|
932
|
+
}
|
933
|
+
return result;
|
934
|
+
}
|
935
|
+
async function status2(client, params) {
|
936
|
+
const requestSchema = (0, import_jsonrpc_types.RpcStatusRequestSchema)();
|
937
|
+
if (params !== void 0) {
|
938
|
+
try {
|
939
|
+
requestSchema.parse(params);
|
940
|
+
} catch (error) {
|
941
|
+
throw new Error(`Request validation failed: ${error}`);
|
942
|
+
}
|
943
|
+
}
|
944
|
+
const result = await status(client, params);
|
945
|
+
const responseSchema = (0, import_jsonrpc_types.RpcStatusResponseSchema)();
|
946
|
+
try {
|
947
|
+
responseSchema.parse(result);
|
948
|
+
} catch (error) {
|
949
|
+
throw new Error(`Response validation failed: ${error}`);
|
950
|
+
}
|
951
|
+
return result;
|
952
|
+
}
|
953
|
+
async function tx2(client, params) {
|
954
|
+
const requestSchema = (0, import_jsonrpc_types.RpcTransactionStatusRequestSchema)();
|
955
|
+
if (params !== void 0) {
|
956
|
+
try {
|
957
|
+
requestSchema.parse(params);
|
958
|
+
} catch (error) {
|
959
|
+
throw new Error(`Request validation failed: ${error}`);
|
960
|
+
}
|
961
|
+
}
|
962
|
+
const result = await tx(client, params);
|
963
|
+
const responseSchema = (0, import_jsonrpc_types.RpcTransactionResponseSchema)();
|
964
|
+
try {
|
965
|
+
responseSchema.parse(result);
|
966
|
+
} catch (error) {
|
967
|
+
throw new Error(`Response validation failed: ${error}`);
|
968
|
+
}
|
969
|
+
return result;
|
970
|
+
}
|
971
|
+
async function validators2(client, params) {
|
972
|
+
const requestSchema = (0, import_jsonrpc_types.RpcValidatorRequestSchema)();
|
973
|
+
if (params !== void 0) {
|
974
|
+
try {
|
975
|
+
requestSchema.parse(params);
|
976
|
+
} catch (error) {
|
977
|
+
throw new Error(`Request validation failed: ${error}`);
|
978
|
+
}
|
979
|
+
}
|
980
|
+
const result = await validators(client, params);
|
981
|
+
const responseSchema = (0, import_jsonrpc_types.RpcValidatorResponseSchema)();
|
982
|
+
try {
|
983
|
+
responseSchema.parse(result);
|
984
|
+
} catch (error) {
|
985
|
+
throw new Error(`Response validation failed: ${error}`);
|
986
|
+
}
|
987
|
+
return result;
|
415
988
|
}
|
416
989
|
|
417
990
|
// src/validation.ts
|
418
|
-
var
|
991
|
+
var import_jsonrpc_types2 = require("@psalomo/jsonrpc-types");
|
419
992
|
function enableValidation() {
|
420
|
-
const requestSchema = (0,
|
421
|
-
const responseSchema = (0,
|
993
|
+
const requestSchema = (0, import_jsonrpc_types2.JsonRpcRequestSchema)();
|
994
|
+
const responseSchema = (0, import_jsonrpc_types2.JsonRpcResponseSchema)();
|
422
995
|
return {
|
423
996
|
validateRequest: (request) => {
|
424
997
|
try {
|
@@ -442,7 +1015,7 @@ function enableValidation() {
|
|
442
1015
|
validateMethodRequest: (method, request) => {
|
443
1016
|
try {
|
444
1017
|
requestSchema.parse(request);
|
445
|
-
const methodSchemas =
|
1018
|
+
const methodSchemas = import_jsonrpc_types2.VALIDATION_SCHEMA_MAP[method];
|
446
1019
|
if (methodSchemas?.requestSchema) {
|
447
1020
|
const methodRequestSchema = methodSchemas.requestSchema();
|
448
1021
|
methodRequestSchema.parse(request);
|
@@ -465,7 +1038,7 @@ function enableValidation() {
|
|
465
1038
|
response.result
|
466
1039
|
);
|
467
1040
|
}
|
468
|
-
const methodSchemas =
|
1041
|
+
const methodSchemas = import_jsonrpc_types2.VALIDATION_SCHEMA_MAP[method];
|
469
1042
|
if (methodSchemas?.responseSchema) {
|
470
1043
|
const methodResponseSchema = methodSchemas.responseSchema();
|
471
1044
|
methodResponseSchema.parse(response);
|
@@ -518,6 +1091,7 @@ function enableValidation() {
|
|
518
1091
|
maintenanceWindows,
|
519
1092
|
networkInfo,
|
520
1093
|
nextLightClientBlock,
|
1094
|
+
parseCallResultToJson,
|
521
1095
|
query,
|
522
1096
|
sendTx,
|
523
1097
|
status,
|
@@ -525,5 +1099,6 @@ function enableValidation() {
|
|
525
1099
|
validators,
|
526
1100
|
viewAccessKey,
|
527
1101
|
viewAccount,
|
528
|
-
viewFunction
|
1102
|
+
viewFunction,
|
1103
|
+
viewFunctionAsJson
|
529
1104
|
});
|