@lidofinance/rpc 0.23.0 → 0.25.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.cjs CHANGED
@@ -40,7 +40,7 @@ $parcel$export($f5c96785547d6405$exports, "ExhaustedIterationError", function ()
40
40
  $parcel$export($f5c96785547d6405$exports, "iterateUrls", function () { return $f5c96785547d6405$export$874e79e4fbe19379; });
41
41
  class $f5c96785547d6405$export$544290ca59c30f2b extends Error {
42
42
  constructor(message){
43
- super(message !== null && message !== void 0 ? message : "Iteration ended without success");
43
+ super(message ?? "Iteration ended without success");
44
44
  }
45
45
  }
46
46
  const $f5c96785547d6405$export$874e79e4fbe19379 = async (urls, callback, onError)=>{
@@ -53,7 +53,7 @@ const $f5c96785547d6405$export$874e79e4fbe19379 = async (urls, callback, onError
53
53
  if (typeof Response !== "undefined" && response instanceof Response && !response.ok) continue;
54
54
  return response;
55
55
  } catch (error) {
56
- onError === null || onError === void 0 ? void 0 : onError(error);
56
+ onError?.(error);
57
57
  lastError = error;
58
58
  }
59
59
  // If there are no succeeded responses, return last not thrown
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;ACoBO,MAAM,4CAAqB,CAAC,KAAK,OACtC,MAAM,KAAK;QACT,GAAG,IAAI;QACP,QAAQ;QACR,SAAS;YACP,GAAG,KAAK,OAAO;YACf,gBAAgB;QAClB;QACA,MAAM,KAAK,SAAS,CAAC,KAAK,IAAI;IAChC;;;;;;;AC7BK,MAAM,kDAAgC;IAC3C,YAAY,OAAgB,CAAE;QAC5B,KAAK,CAAC,oBAAA,qBAAA,UAAW,iCAAiC;IACpD;AACF;AAEO,MAAM,4CAAc,OACzB,MACA,UACA,UACe;IACf,IAAI;IACJ,IAAI;IAEJ,KAAK,MAAM,OAAO,KAChB,IAAI;QACF,MAAM,WAAW,MAAM,SAAS;QAChC,eAAe;QAEf,6CAA6C;QAC7C,IAAI,OAAO,aAAa,eAAe,oBAAoB,YAAY,CAAC,SAAS,EAAE,EACjF,QAAQ;QAGV,OAAO;IACT,EAAE,OAAO,OAAO;QACd,oBAAA,qBAAA,KAAA,IAAA,QAAU;QACV,YAAY;IACd;IAGF,8DAA8D;IAC9D,IAAI,gBAAgB,IAAI,EACtB,OAAO;IAET,qDAAqD;IACrD,IAAI,aAAa,IAAI,EACnB,MAAM,UAAS;IAEjB,+BAA+B;IAC/B,MAAM,IAAI,4CAAyB;AACrC;;","sources":["packages/core/rpc/src/index.ts","packages/core/rpc/src/fetchRpc.ts","packages/core/rpc/src/iterateUrls.ts"],"sourcesContent":["import 'isomorphic-fetch'\n\nexport * from './fetchRpc'\nexport * from './iterateUrls'\n","export type FetchRpcInitBody = {\n jsonrpc: '1.0' | '2.0' | string\n method: string\n params?: unknown\n id?: string | number | null\n}\n\n// eslint-disable-next-line no-undef\nexport type FetchRpcInit = Omit<RequestInit, 'body' | 'method'> & {\n method?: 'POST'\n body: FetchRpcInitBody | FetchRpcInitBody[]\n}\n\n// Need Extension type so we can extend fetchRPC with metrics tracking or caching\nexport type FetchRpc<Extension extends Record<string | number, unknown> | void = void> = (\n url: string,\n init: FetchRpcInit,\n extension: Extension,\n) => Promise<Response>\n\nexport const fetchRpc: FetchRpc = (url, init) =>\n fetch(url, {\n ...init,\n method: 'POST',\n headers: {\n ...init.headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(init.body),\n })\n","export class ExhaustedIterationError extends Error {\n constructor(message?: string) {\n super(message ?? 'Iteration ended without success')\n }\n}\n\nexport const iterateUrls = async <T>(\n urls: [string, ...string[]],\n callback: (url: string) => T | Promise<T>,\n onError?: (error: unknown) => unknown,\n): Promise<T> => {\n let lastResponse: T | undefined\n let lastError: unknown | undefined\n\n for (const url of urls) {\n try {\n const response = await callback(url)\n lastResponse = response\n\n // We want to return first succeeded response\n if (typeof Response !== 'undefined' && response instanceof Response && !response.ok) {\n continue\n }\n\n return response\n } catch (error) {\n onError?.(error)\n lastError = error\n }\n }\n\n // If there are no succeeded responses, return last not thrown\n if (lastResponse != null) {\n return lastResponse\n }\n // If there are no responses at all, throw last error\n if (lastError != null) {\n throw lastError\n }\n // This should not be reachable\n throw new ExhaustedIterationError()\n}\n"],"names":[],"version":3,"file":"index.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;ACoBO,MAAM,4CAAqB,CAAC,KAAK,OACtC,MAAM,KAAK;QACT,GAAG,IAAI;QACP,QAAQ;QACR,SAAS;YACP,GAAG,KAAK,OAAO;YACf,gBAAgB;QAClB;QACA,MAAM,KAAK,SAAS,CAAC,KAAK,IAAI;IAChC;;;;;;;AC7BK,MAAM,kDAAgC;IAC3C,YAAY,OAAgB,CAAE;QAC5B,KAAK,CAAC,WAAW;IACnB;AACF;AAEO,MAAM,4CAAc,OACzB,MACA,UACA,UACe;IACf,IAAI;IACJ,IAAI;IAEJ,KAAK,MAAM,OAAO,KAChB,IAAI;QACF,MAAM,WAAW,MAAM,SAAS;QAChC,eAAe;QAEf,6CAA6C;QAC7C,IAAI,OAAO,aAAa,eAAe,oBAAoB,YAAY,CAAC,SAAS,EAAE,EACjF,QAAQ;QAGV,OAAO;IACT,EAAE,OAAO,OAAO;QACd,UAAU;QACV,YAAY;IACd;IAGF,8DAA8D;IAC9D,IAAI,gBAAgB,IAAI,EACtB,OAAO;IAET,qDAAqD;IACrD,IAAI,aAAa,IAAI,EACnB,MAAM,UAAS;IAEjB,+BAA+B;IAC/B,MAAM,IAAI,4CAAyB;AACrC;;","sources":["packages/core/rpc/src/index.ts","packages/core/rpc/src/fetchRpc.ts","packages/core/rpc/src/iterateUrls.ts"],"sourcesContent":["import 'isomorphic-fetch'\n\nexport * from './fetchRpc'\nexport * from './iterateUrls'\n","export type FetchRpcInitBody = {\n jsonrpc: '1.0' | '2.0' | string\n method: string\n params?: unknown\n id?: string | number | null\n}\n\n// eslint-disable-next-line no-undef\nexport type FetchRpcInit = Omit<RequestInit, 'body' | 'method'> & {\n method?: 'POST'\n body: FetchRpcInitBody | FetchRpcInitBody[]\n}\n\n// Need Extension type so we can extend fetchRPC with metrics tracking or caching\nexport type FetchRpc<Extension extends Record<string | number, unknown> | void = void> = (\n url: string,\n init: FetchRpcInit,\n extension: Extension,\n) => Promise<Response>\n\nexport const fetchRpc: FetchRpc = (url, init) =>\n fetch(url, {\n ...init,\n method: 'POST',\n headers: {\n ...init.headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(init.body),\n })\n","export class ExhaustedIterationError extends Error {\n constructor(message?: string) {\n super(message ?? 'Iteration ended without success')\n }\n}\n\nexport const iterateUrls = async <T>(\n urls: [string, ...string[]],\n callback: (url: string) => T | Promise<T>,\n onError?: (error: unknown) => unknown,\n): Promise<T> => {\n let lastResponse: T | undefined\n let lastError: unknown | undefined\n\n for (const url of urls) {\n try {\n const response = await callback(url)\n lastResponse = response\n\n // We want to return first succeeded response\n if (typeof Response !== 'undefined' && response instanceof Response && !response.ok) {\n continue\n }\n\n return response\n } catch (error) {\n onError?.(error)\n lastError = error\n }\n }\n\n // If there are no succeeded responses, return last not thrown\n if (lastResponse != null) {\n return lastResponse\n }\n // If there are no responses at all, throw last error\n if (lastError != null) {\n throw lastError\n }\n // This should not be reachable\n throw new ExhaustedIterationError()\n}\n"],"names":[],"version":3,"file":"index.cjs.map"}
package/dist/index.mjs CHANGED
@@ -24,7 +24,7 @@ $parcel$export($83a6df06ccf0d0e9$exports, "ExhaustedIterationError", function ()
24
24
  $parcel$export($83a6df06ccf0d0e9$exports, "iterateUrls", function () { return $83a6df06ccf0d0e9$export$874e79e4fbe19379; });
25
25
  class $83a6df06ccf0d0e9$export$544290ca59c30f2b extends Error {
26
26
  constructor(message){
27
- super(message !== null && message !== void 0 ? message : "Iteration ended without success");
27
+ super(message ?? "Iteration ended without success");
28
28
  }
29
29
  }
30
30
  const $83a6df06ccf0d0e9$export$874e79e4fbe19379 = async (urls, callback, onError)=>{
@@ -37,7 +37,7 @@ const $83a6df06ccf0d0e9$export$874e79e4fbe19379 = async (urls, callback, onError
37
37
  if (typeof Response !== "undefined" && response instanceof Response && !response.ok) continue;
38
38
  return response;
39
39
  } catch (error) {
40
- onError === null || onError === void 0 ? void 0 : onError(error);
40
+ onError?.(error);
41
41
  lastError = error;
42
42
  }
43
43
  // If there are no succeeded responses, return last not thrown
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;ACoBO,MAAM,4CAAqB,CAAC,KAAK,OACtC,MAAM,KAAK;QACT,GAAG,IAAI;QACP,QAAQ;QACR,SAAS;YACP,GAAG,KAAK,OAAO;YACf,gBAAgB;QAClB;QACA,MAAM,KAAK,SAAS,CAAC,KAAK,IAAI;IAChC;;;;;;;AC7BK,MAAM,kDAAgC;IAC3C,YAAY,OAAgB,CAAE;QAC5B,KAAK,CAAC,oBAAA,qBAAA,UAAW,iCAAiC;IACpD;AACF;AAEO,MAAM,4CAAc,OACzB,MACA,UACA,UACe;IACf,IAAI;IACJ,IAAI;IAEJ,KAAK,MAAM,OAAO,KAChB,IAAI;QACF,MAAM,WAAW,MAAM,SAAS;QAChC,eAAe;QAEf,6CAA6C;QAC7C,IAAI,OAAO,aAAa,eAAe,oBAAoB,YAAY,CAAC,SAAS,EAAE,EACjF,QAAQ;QAGV,OAAO;IACT,EAAE,OAAO,OAAO;QACd,oBAAA,qBAAA,KAAA,IAAA,QAAU;QACV,YAAY;IACd;IAGF,8DAA8D;IAC9D,IAAI,gBAAgB,IAAI,EACtB,OAAO;IAET,qDAAqD;IACrD,IAAI,aAAa,IAAI,EACnB,MAAM,UAAS;IAEjB,+BAA+B;IAC/B,MAAM,IAAI,4CAAyB;AACrC;;","sources":["packages/core/rpc/src/index.ts","packages/core/rpc/src/fetchRpc.ts","packages/core/rpc/src/iterateUrls.ts"],"sourcesContent":["import 'isomorphic-fetch'\n\nexport * from './fetchRpc'\nexport * from './iterateUrls'\n","export type FetchRpcInitBody = {\n jsonrpc: '1.0' | '2.0' | string\n method: string\n params?: unknown\n id?: string | number | null\n}\n\n// eslint-disable-next-line no-undef\nexport type FetchRpcInit = Omit<RequestInit, 'body' | 'method'> & {\n method?: 'POST'\n body: FetchRpcInitBody | FetchRpcInitBody[]\n}\n\n// Need Extension type so we can extend fetchRPC with metrics tracking or caching\nexport type FetchRpc<Extension extends Record<string | number, unknown> | void = void> = (\n url: string,\n init: FetchRpcInit,\n extension: Extension,\n) => Promise<Response>\n\nexport const fetchRpc: FetchRpc = (url, init) =>\n fetch(url, {\n ...init,\n method: 'POST',\n headers: {\n ...init.headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(init.body),\n })\n","export class ExhaustedIterationError extends Error {\n constructor(message?: string) {\n super(message ?? 'Iteration ended without success')\n }\n}\n\nexport const iterateUrls = async <T>(\n urls: [string, ...string[]],\n callback: (url: string) => T | Promise<T>,\n onError?: (error: unknown) => unknown,\n): Promise<T> => {\n let lastResponse: T | undefined\n let lastError: unknown | undefined\n\n for (const url of urls) {\n try {\n const response = await callback(url)\n lastResponse = response\n\n // We want to return first succeeded response\n if (typeof Response !== 'undefined' && response instanceof Response && !response.ok) {\n continue\n }\n\n return response\n } catch (error) {\n onError?.(error)\n lastError = error\n }\n }\n\n // If there are no succeeded responses, return last not thrown\n if (lastResponse != null) {\n return lastResponse\n }\n // If there are no responses at all, throw last error\n if (lastError != null) {\n throw lastError\n }\n // This should not be reachable\n throw new ExhaustedIterationError()\n}\n"],"names":[],"version":3,"file":"index.mjs.map"}
1
+ {"mappings":";;;;;AAAA;;;;ACoBO,MAAM,4CAAqB,CAAC,KAAK,OACtC,MAAM,KAAK;QACT,GAAG,IAAI;QACP,QAAQ;QACR,SAAS;YACP,GAAG,KAAK,OAAO;YACf,gBAAgB;QAClB;QACA,MAAM,KAAK,SAAS,CAAC,KAAK,IAAI;IAChC;;;;;;;AC7BK,MAAM,kDAAgC;IAC3C,YAAY,OAAgB,CAAE;QAC5B,KAAK,CAAC,WAAW;IACnB;AACF;AAEO,MAAM,4CAAc,OACzB,MACA,UACA,UACe;IACf,IAAI;IACJ,IAAI;IAEJ,KAAK,MAAM,OAAO,KAChB,IAAI;QACF,MAAM,WAAW,MAAM,SAAS;QAChC,eAAe;QAEf,6CAA6C;QAC7C,IAAI,OAAO,aAAa,eAAe,oBAAoB,YAAY,CAAC,SAAS,EAAE,EACjF,QAAQ;QAGV,OAAO;IACT,EAAE,OAAO,OAAO;QACd,UAAU;QACV,YAAY;IACd;IAGF,8DAA8D;IAC9D,IAAI,gBAAgB,IAAI,EACtB,OAAO;IAET,qDAAqD;IACrD,IAAI,aAAa,IAAI,EACnB,MAAM,UAAS;IAEjB,+BAA+B;IAC/B,MAAM,IAAI,4CAAyB;AACrC;;","sources":["packages/core/rpc/src/index.ts","packages/core/rpc/src/fetchRpc.ts","packages/core/rpc/src/iterateUrls.ts"],"sourcesContent":["import 'isomorphic-fetch'\n\nexport * from './fetchRpc'\nexport * from './iterateUrls'\n","export type FetchRpcInitBody = {\n jsonrpc: '1.0' | '2.0' | string\n method: string\n params?: unknown\n id?: string | number | null\n}\n\n// eslint-disable-next-line no-undef\nexport type FetchRpcInit = Omit<RequestInit, 'body' | 'method'> & {\n method?: 'POST'\n body: FetchRpcInitBody | FetchRpcInitBody[]\n}\n\n// Need Extension type so we can extend fetchRPC with metrics tracking or caching\nexport type FetchRpc<Extension extends Record<string | number, unknown> | void = void> = (\n url: string,\n init: FetchRpcInit,\n extension: Extension,\n) => Promise<Response>\n\nexport const fetchRpc: FetchRpc = (url, init) =>\n fetch(url, {\n ...init,\n method: 'POST',\n headers: {\n ...init.headers,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(init.body),\n })\n","export class ExhaustedIterationError extends Error {\n constructor(message?: string) {\n super(message ?? 'Iteration ended without success')\n }\n}\n\nexport const iterateUrls = async <T>(\n urls: [string, ...string[]],\n callback: (url: string) => T | Promise<T>,\n onError?: (error: unknown) => unknown,\n): Promise<T> => {\n let lastResponse: T | undefined\n let lastError: unknown | undefined\n\n for (const url of urls) {\n try {\n const response = await callback(url)\n lastResponse = response\n\n // We want to return first succeeded response\n if (typeof Response !== 'undefined' && response instanceof Response && !response.ok) {\n continue\n }\n\n return response\n } catch (error) {\n onError?.(error)\n lastError = error\n }\n }\n\n // If there are no succeeded responses, return last not thrown\n if (lastResponse != null) {\n return lastResponse\n }\n // If there are no responses at all, throw last error\n if (lastError != null) {\n throw lastError\n }\n // This should not be reachable\n throw new ExhaustedIterationError()\n}\n"],"names":[],"version":3,"file":"index.mjs.map"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Fetch extension to use it with RPC endpoints",
4
4
  "repository": "git@github.com:lidofinance/warehouse.git",
5
5
  "license": "MIT",
6
- "version": "0.23.0",
6
+ "version": "0.25.0",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
@@ -23,7 +23,7 @@
23
23
  "test": "jest"
24
24
  },
25
25
  "devDependencies": {
26
- "@lidofinance/config-prettier": "~0.23.0",
26
+ "@lidofinance/config-prettier": "~0.25.0",
27
27
  "@types/jest": "^29.2.4",
28
28
  "jest": "^29.3.1",
29
29
  "ts-jest": "^29.0.3"