@psalomo/jsonrpc-client 1.0.3 → 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/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: () => import_jsonrpc_types2.JsonRpcRequestSchema,
26
- JsonRpcResponseSchema: () => import_jsonrpc_types2.JsonRpcResponseSchema,
25
+ JsonRpcRequestSchema: () => import_jsonrpc_types3.JsonRpcRequestSchema,
26
+ JsonRpcResponseSchema: () => import_jsonrpc_types3.JsonRpcResponseSchema,
27
27
  NearRpcClient: () => NearRpcClient,
28
28
  NearRpcError: () => NearRpcError,
29
- RPC_METHODS: () => import_jsonrpc_types3.RPC_METHODS,
30
- block: () => block,
31
- blockEffects: () => blockEffects,
32
- broadcastTxAsync: () => broadcastTxAsync,
33
- broadcastTxCommit: () => broadcastTxCommit,
34
- changes: () => changes,
35
- chunk: () => chunk,
36
- clientConfig: () => 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: () => experimentalChanges,
41
- experimentalChangesInBlock: () => experimentalChangesInBlock,
42
- experimentalCongestionLevel: () => experimentalCongestionLevel,
43
- experimentalGenesisConfig: () => experimentalGenesisConfig,
44
- experimentalLightClientBlockProof: () => experimentalLightClientBlockProof,
45
- experimentalLightClientProof: () => experimentalLightClientProof,
46
- experimentalMaintenanceWindows: () => experimentalMaintenanceWindows,
47
- experimentalProtocolConfig: () => experimentalProtocolConfig,
48
- experimentalReceipt: () => experimentalReceipt,
49
- experimentalSplitStorageInfo: () => experimentalSplitStorageInfo,
50
- experimentalTxStatus: () => experimentalTxStatus,
51
- experimentalValidatorsOrdered: () => experimentalValidatorsOrdered,
52
- gasPrice: () => gasPrice,
53
- genesisConfig: () => genesisConfig,
54
- health: () => health,
55
- lightClientProof: () => lightClientProof,
56
- maintenanceWindows: () => maintenanceWindows,
57
- networkInfo: () => networkInfo,
58
- nextLightClientBlock: () => nextLightClientBlock,
59
- query: () => query,
60
- sendTx: () => sendTx,
61
- status: () => status,
62
- tx: () => tx,
63
- validators: () => validators,
64
- viewAccessKey: () => viewAccessKey,
65
- viewAccount: () => viewAccount,
66
- viewFunction: () => viewFunction
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
 
@@ -214,6 +216,15 @@ var NearRpcClient = class _NearRpcClient {
214
216
  this.validation.validateResponse(jsonResponse);
215
217
  }
216
218
  const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
219
+ if (camelCaseResult && typeof camelCaseResult === "object" && "error" in camelCaseResult) {
220
+ const errorMessage = camelCaseResult.error;
221
+ throw new JsonRpcClientError(
222
+ `RPC Error: ${errorMessage}`,
223
+ -32e3,
224
+ // Generic RPC error code
225
+ camelCaseResult
226
+ );
227
+ }
217
228
  if (this.validation && "validateMethodResponse" in this.validation) {
218
229
  const camelCaseResponse = {
219
230
  ...jsonResponse,
@@ -268,8 +279,8 @@ var NearRpcError = class extends Error {
268
279
  };
269
280
 
270
281
  // src/index.ts
271
- var import_jsonrpc_types2 = require("@psalomo/jsonrpc-types");
272
282
  var import_jsonrpc_types3 = require("@psalomo/jsonrpc-types");
283
+ var import_jsonrpc_types4 = require("@psalomo/jsonrpc-types");
273
284
 
274
285
  // src/generated-types.ts
275
286
  async function experimentalChanges(client, params) {
@@ -367,7 +378,30 @@ async function validators(client, params) {
367
378
  }
368
379
 
369
380
  // src/convenience.ts
370
- async function viewAccount(client, params) {
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) {
371
405
  const queryParams = params.blockId ? {
372
406
  requestType: "view_account",
373
407
  accountId: params.accountId,
@@ -377,20 +411,19 @@ async function viewAccount(client, params) {
377
411
  accountId: params.accountId,
378
412
  finality: params.finality || "final"
379
413
  };
380
- return query(client, queryParams);
414
+ return query2(client, queryParams);
381
415
  }
382
- async function viewFunction(client, params) {
416
+ async function viewFunction2(client, params) {
383
417
  const baseParams = {
384
418
  requestType: "call_function",
385
419
  accountId: params.accountId,
386
420
  methodName: params.methodName,
387
421
  argsBase64: params.argsBase64 ?? ""
388
- // Default to empty string if no arguments
389
422
  };
390
423
  const queryParams = params.blockId ? { ...baseParams, blockId: params.blockId } : { ...baseParams, finality: params.finality || "final" };
391
- return query(client, queryParams);
424
+ return query2(client, queryParams);
392
425
  }
393
- async function viewAccessKey(client, params) {
426
+ async function viewAccessKey2(client, params) {
394
427
  const queryParams = params.blockId ? {
395
428
  requestType: "view_access_key",
396
429
  accountId: params.accountId,
@@ -402,14 +435,563 @@ async function viewAccessKey(client, params) {
402
435
  publicKey: params.publicKey,
403
436
  finality: params.finality || "final"
404
437
  };
405
- return query(client, queryParams);
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;
406
988
  }
407
989
 
408
990
  // src/validation.ts
409
- var import_jsonrpc_types = require("@psalomo/jsonrpc-types");
991
+ var import_jsonrpc_types2 = require("@psalomo/jsonrpc-types");
410
992
  function enableValidation() {
411
- const requestSchema = (0, import_jsonrpc_types.JsonRpcRequestSchema)();
412
- const responseSchema = (0, import_jsonrpc_types.JsonRpcResponseSchema)();
993
+ const requestSchema = (0, import_jsonrpc_types2.JsonRpcRequestSchema)();
994
+ const responseSchema = (0, import_jsonrpc_types2.JsonRpcResponseSchema)();
413
995
  return {
414
996
  validateRequest: (request) => {
415
997
  try {
@@ -433,7 +1015,7 @@ function enableValidation() {
433
1015
  validateMethodRequest: (method, request) => {
434
1016
  try {
435
1017
  requestSchema.parse(request);
436
- const methodSchemas = import_jsonrpc_types.VALIDATION_SCHEMA_MAP[method];
1018
+ const methodSchemas = import_jsonrpc_types2.VALIDATION_SCHEMA_MAP[method];
437
1019
  if (methodSchemas?.requestSchema) {
438
1020
  const methodRequestSchema = methodSchemas.requestSchema();
439
1021
  methodRequestSchema.parse(request);
@@ -448,12 +1030,23 @@ function enableValidation() {
448
1030
  validateMethodResponse: (method, response) => {
449
1031
  try {
450
1032
  responseSchema.parse(response);
451
- const methodSchemas = import_jsonrpc_types.VALIDATION_SCHEMA_MAP[method];
1033
+ if (response.result && typeof response.result === "object" && "error" in response.result) {
1034
+ const serverError = response.result.error;
1035
+ throw new JsonRpcClientError(
1036
+ `Server error: ${serverError}`,
1037
+ -32e3,
1038
+ response.result
1039
+ );
1040
+ }
1041
+ const methodSchemas = import_jsonrpc_types2.VALIDATION_SCHEMA_MAP[method];
452
1042
  if (methodSchemas?.responseSchema) {
453
1043
  const methodResponseSchema = methodSchemas.responseSchema();
454
1044
  methodResponseSchema.parse(response);
455
1045
  }
456
1046
  } catch (error) {
1047
+ if (error instanceof JsonRpcClientError) {
1048
+ throw error;
1049
+ }
457
1050
  throw new JsonRpcClientError(
458
1051
  `Invalid ${method} response: ${error instanceof Error ? error.message : "Unknown error"}`
459
1052
  );
@@ -498,6 +1091,7 @@ function enableValidation() {
498
1091
  maintenanceWindows,
499
1092
  networkInfo,
500
1093
  nextLightClientBlock,
1094
+ parseCallResultToJson,
501
1095
  query,
502
1096
  sendTx,
503
1097
  status,
@@ -505,5 +1099,6 @@ function enableValidation() {
505
1099
  validators,
506
1100
  viewAccessKey,
507
1101
  viewAccount,
508
- viewFunction
1102
+ viewFunction,
1103
+ viewFunctionAsJson
509
1104
  });