@keplr-wallet/stores 0.13.33 → 0.13.35

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.
@@ -5,13 +5,22 @@ export interface JsonRpcBatchRequest {
5
5
  params: unknown;
6
6
  id: string;
7
7
  }
8
+ export interface JsonRpcBatchRequestError {
9
+ code: number;
10
+ message: string;
11
+ data?: unknown;
12
+ }
8
13
  /**
9
14
  * Observable query for batched JSON-RPC requests.
10
15
  * Manages an array of `JsonRpcBatchRequest` and returns a map of results keyed by request ID.
16
+ * Per-request errors (when the batch HTTP call succeeds but individual calls fail)
17
+ * are surfaced via `perRequestErrors`.
11
18
  */
12
19
  export declare class ObservableJsonRpcBatchQuery<T = unknown> extends ObservableQuery<Record<string, T>> {
13
20
  protected readonly requests: JsonRpcBatchRequest[];
21
+ protected _perRequestErrors: Record<string, JsonRpcBatchRequestError>;
14
22
  constructor(sharedContext: QuerySharedContext, baseURL: string, url: string, requests: JsonRpcBatchRequest[], options?: Partial<QueryOptions>);
23
+ get perRequestErrors(): Readonly<Record<string, JsonRpcBatchRequestError>>;
15
24
  protected getCacheKey(): string;
16
25
  protected fetchResponse(abortController: AbortController): Promise<{
17
26
  headers: any;
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
9
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
10
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -14,14 +20,22 @@ const query_1 = require("./query");
14
20
  const simple_fetch_1 = require("@keplr-wallet/simple-fetch");
15
21
  const crypto_1 = require("@keplr-wallet/crypto");
16
22
  const buffer_1 = require("buffer/");
23
+ const mobx_1 = require("mobx");
17
24
  /**
18
25
  * Observable query for batched JSON-RPC requests.
19
26
  * Manages an array of `JsonRpcBatchRequest` and returns a map of results keyed by request ID.
27
+ * Per-request errors (when the batch HTTP call succeeds but individual calls fail)
28
+ * are surfaced via `perRequestErrors`.
20
29
  */
21
30
  class ObservableJsonRpcBatchQuery extends query_1.ObservableQuery {
22
31
  constructor(sharedContext, baseURL, url, requests, options = {}) {
23
32
  super(sharedContext, baseURL, url, options);
24
33
  this.requests = requests;
34
+ this._perRequestErrors = {};
35
+ (0, mobx_1.makeObservable)(this);
36
+ }
37
+ get perRequestErrors() {
38
+ return this._perRequestErrors;
25
39
  }
26
40
  getCacheKey() {
27
41
  const requestsHash = buffer_1.Buffer.from(crypto_1.Hash.sha256(buffer_1.Buffer.from(JSON.stringify(this.requests, (_, value) => {
@@ -34,6 +48,11 @@ class ObservableJsonRpcBatchQuery extends query_1.ObservableQuery {
34
48
  }
35
49
  fetchResponse(abortController) {
36
50
  return __awaiter(this, void 0, void 0, function* () {
51
+ // Clear prior per-request errors so a retry/HTTP failure doesn't leak
52
+ // stale errors from a previous successful fetch.
53
+ (0, mobx_1.runInAction)(() => {
54
+ this._perRequestErrors = {};
55
+ });
37
56
  const batchBody = this.requests.map((req) => ({
38
57
  jsonrpc: "2.0",
39
58
  method: req.method,
@@ -57,12 +76,31 @@ class ObservableJsonRpcBatchQuery extends query_1.ObservableQuery {
57
76
  throw new Error("Invalid batch response");
58
77
  }
59
78
  const data = {};
79
+ const perRequestErrors = {};
80
+ const responded = new Set();
60
81
  for (const res of response.data) {
82
+ const id = String(res.id);
83
+ responded.add(id);
61
84
  if (res.error) {
85
+ perRequestErrors[id] = res.error;
62
86
  continue;
63
87
  }
64
- data[String(res.id)] = res.result;
88
+ data[id] = res.result;
65
89
  }
90
+ // Servers may silently omit IDs on partial failures — synthesize an error
91
+ // so callers can't sit in permanent loading on a missing response.
92
+ for (const req of this.requests) {
93
+ const id = String(req.id);
94
+ if (!responded.has(id)) {
95
+ perRequestErrors[id] = {
96
+ code: -32603,
97
+ message: `No response for request id ${id}`,
98
+ };
99
+ }
100
+ }
101
+ (0, mobx_1.runInAction)(() => {
102
+ this._perRequestErrors = perRequestErrors;
103
+ });
66
104
  return {
67
105
  headers: response.headers,
68
106
  data,
@@ -70,5 +108,8 @@ class ObservableJsonRpcBatchQuery extends query_1.ObservableQuery {
70
108
  });
71
109
  }
72
110
  }
111
+ __decorate([
112
+ mobx_1.observable.ref
113
+ ], ObservableJsonRpcBatchQuery.prototype, "_perRequestErrors", void 0);
73
114
  exports.ObservableJsonRpcBatchQuery = ObservableJsonRpcBatchQuery;
74
115
  //# sourceMappingURL=json-rpc-batch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-rpc-batch.js","sourceRoot":"","sources":["../../../src/common/query/json-rpc-batch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAwD;AAExD,6DAAyD;AAEzD,iDAA4C;AAC5C,oCAAiC;AAQjC;;;GAGG;AACH,MAAa,2BAAyC,SAAQ,uBAE7D;IACC,YACE,aAAiC,EACjC,OAAe,EACf,GAAW,EACQ,QAA+B,EAClD,UAAiC,EAAE;QAEnC,KAAK,CAAC,aAAa,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QAHzB,aAAQ,GAAR,QAAQ,CAAuB;IAIpD,CAAC;IAEkB,WAAW;QAC5B,MAAM,YAAY,GAAG,eAAM,CAAC,IAAI,CAC9B,aAAI,CAAC,MAAM,CACT,eAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YACzC,IAAI,OAAO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(x)"],
5
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keplr-wallet/stores",
3
- "version": "0.13.33",
3
+ "version": "0.13.35",
4
4
  "main": "build/index.js",
5
5
  "author": "chainapsis",
6
6
  "license": "Apache-2.0",
@@ -21,18 +21,18 @@
21
21
  "typecheck": "npx tsc -p tsconfig.check.json"
22
22
  },
23
23
  "devDependencies": {
24
- "@keplr-wallet/provider-mock": "0.13.33"
24
+ "@keplr-wallet/provider-mock": "0.13.35"
25
25
  },
26
26
  "dependencies": {
27
27
  "@ethersproject/address": "^5.7.0",
28
- "@keplr-wallet/common": "0.13.33",
29
- "@keplr-wallet/cosmos": "0.13.33",
30
- "@keplr-wallet/crypto": "0.13.33",
31
- "@keplr-wallet/mobx-utils": "0.13.33",
32
- "@keplr-wallet/proto-types": "0.13.33",
33
- "@keplr-wallet/simple-fetch": "0.13.33",
34
- "@keplr-wallet/types": "0.13.33",
35
- "@keplr-wallet/unit": "0.13.33",
28
+ "@keplr-wallet/common": "0.13.35",
29
+ "@keplr-wallet/cosmos": "0.13.35",
30
+ "@keplr-wallet/crypto": "0.13.35",
31
+ "@keplr-wallet/mobx-utils": "0.13.35",
32
+ "@keplr-wallet/proto-types": "0.13.35",
33
+ "@keplr-wallet/simple-fetch": "0.13.35",
34
+ "@keplr-wallet/types": "0.13.35",
35
+ "@keplr-wallet/unit": "0.13.35",
36
36
  "buffer": "^6.0.3",
37
37
  "deepmerge": "^4.2.2",
38
38
  "eventemitter3": "^4.0.7",
@@ -44,5 +44,5 @@
44
44
  "mobx": "^6",
45
45
  "mobx-utils": "^6"
46
46
  },
47
- "gitHead": "14cdeb29fdea7b1ef5eff3c17f37e9406b224336"
47
+ "gitHead": "d6feb9514cc94558d0567593f426ea03c3cabaf0"
48
48
  }
@@ -4,6 +4,7 @@ import { simpleFetch } from "@keplr-wallet/simple-fetch";
4
4
  import { JsonRpcResponse } from "@keplr-wallet/types";
5
5
  import { Hash } from "@keplr-wallet/crypto";
6
6
  import { Buffer } from "buffer/";
7
+ import { makeObservable, observable, runInAction } from "mobx";
7
8
 
8
9
  export interface JsonRpcBatchRequest {
9
10
  method: string;
@@ -11,13 +12,24 @@ export interface JsonRpcBatchRequest {
11
12
  id: string;
12
13
  }
13
14
 
15
+ export interface JsonRpcBatchRequestError {
16
+ code: number;
17
+ message: string;
18
+ data?: unknown;
19
+ }
20
+
14
21
  /**
15
22
  * Observable query for batched JSON-RPC requests.
16
23
  * Manages an array of `JsonRpcBatchRequest` and returns a map of results keyed by request ID.
24
+ * Per-request errors (when the batch HTTP call succeeds but individual calls fail)
25
+ * are surfaced via `perRequestErrors`.
17
26
  */
18
27
  export class ObservableJsonRpcBatchQuery<T = unknown> extends ObservableQuery<
19
28
  Record<string, T>
20
29
  > {
30
+ @observable.ref
31
+ protected _perRequestErrors: Record<string, JsonRpcBatchRequestError> = {};
32
+
21
33
  constructor(
22
34
  sharedContext: QuerySharedContext,
23
35
  baseURL: string,
@@ -26,6 +38,11 @@ export class ObservableJsonRpcBatchQuery<T = unknown> extends ObservableQuery<
26
38
  options: Partial<QueryOptions> = {}
27
39
  ) {
28
40
  super(sharedContext, baseURL, url, options);
41
+ makeObservable(this);
42
+ }
43
+
44
+ get perRequestErrors(): Readonly<Record<string, JsonRpcBatchRequestError>> {
45
+ return this._perRequestErrors;
29
46
  }
30
47
 
31
48
  protected override getCacheKey(): string {
@@ -48,6 +65,12 @@ export class ObservableJsonRpcBatchQuery<T = unknown> extends ObservableQuery<
48
65
  protected override async fetchResponse(
49
66
  abortController: AbortController
50
67
  ): Promise<{ headers: any; data: Record<string, T> }> {
68
+ // Clear prior per-request errors so a retry/HTTP failure doesn't leak
69
+ // stale errors from a previous successful fetch.
70
+ runInAction(() => {
71
+ this._perRequestErrors = {};
72
+ });
73
+
51
74
  const batchBody = this.requests.map((req) => ({
52
75
  jsonrpc: "2.0",
53
76
  method: req.method,
@@ -78,15 +101,36 @@ export class ObservableJsonRpcBatchQuery<T = unknown> extends ObservableQuery<
78
101
  }
79
102
 
80
103
  const data: Record<string, T> = {};
104
+ const perRequestErrors: Record<string, JsonRpcBatchRequestError> = {};
105
+ const responded = new Set<string>();
81
106
 
82
107
  for (const res of response.data) {
108
+ const id = String(res.id);
109
+ responded.add(id);
83
110
  if (res.error) {
111
+ perRequestErrors[id] = res.error;
84
112
  continue;
85
113
  }
86
114
 
87
- data[String(res.id)] = res.result as T;
115
+ data[id] = res.result as T;
88
116
  }
89
117
 
118
+ // Servers may silently omit IDs on partial failures — synthesize an error
119
+ // so callers can't sit in permanent loading on a missing response.
120
+ for (const req of this.requests) {
121
+ const id = String(req.id);
122
+ if (!responded.has(id)) {
123
+ perRequestErrors[id] = {
124
+ code: -32603,
125
+ message: `No response for request id ${id}`,
126
+ };
127
+ }
128
+ }
129
+
130
+ runInAction(() => {
131
+ this._perRequestErrors = perRequestErrors;
132
+ });
133
+
90
134
  return {
91
135
  headers: response.headers,
92
136
  data,