@solana/rpc-transport-http
Advanced tools
Comparing version 2.0.0-experimental.d06660c to 2.0.0-experimental.d3890b7
@@ -0,21 +1,5 @@ | ||
import { SolanaError, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN } from '@solana/errors'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -57,5 +41,5 @@ accept: true, | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, { | ||
headers: badHeaders | ||
}); | ||
} | ||
@@ -110,5 +94,5 @@ } | ||
}; | ||
const response = await e(url, requestInfo); | ||
const response = await fetch(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, { | ||
message: response.statusText, | ||
@@ -115,0 +99,0 @@ statusCode: response.status |
@@ -0,21 +1,5 @@ | ||
import { SolanaError, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN } from '@solana/errors'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// ../fetch-impl/dist/index.browser.js | ||
var e = globalThis.fetch; | ||
// src/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -57,5 +41,5 @@ accept: true, | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, { | ||
headers: badHeaders | ||
}); | ||
} | ||
@@ -110,5 +94,5 @@ } | ||
}; | ||
const response = await e(url, requestInfo); | ||
const response = await fetch(url, requestInfo); | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, { | ||
message: response.statusText, | ||
@@ -115,0 +99,0 @@ statusCode: response.status |
@@ -1,20 +0,5 @@ | ||
import { fetch } from 'undici'; | ||
import { SolanaError, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN } from '@solana/errors'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/http-transport-errors.ts | ||
var SolanaHttpError = class extends Error { | ||
statusCode; | ||
constructor(details) { | ||
super(`HTTP error (${details.statusCode}): ${details.message}`); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.statusCode = details.statusCode; | ||
} | ||
get name() { | ||
return "SolanaHttpError"; | ||
} | ||
}; | ||
// src/http-transport-headers.ts | ||
var DISALLOWED_HEADERS = { | ||
@@ -56,5 +41,5 @@ accept: true, | ||
if (badHeaders.length > 0) { | ||
throw new Error( | ||
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.` | ||
); | ||
throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, { | ||
headers: badHeaders | ||
}); | ||
} | ||
@@ -104,3 +89,3 @@ } | ||
if (!response.ok) { | ||
throw new SolanaHttpError({ | ||
throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, { | ||
message: response.statusText, | ||
@@ -107,0 +92,0 @@ statusCode: response.status |
{ | ||
"name": "@solana/rpc-transport-http", | ||
"version": "2.0.0-experimental.d06660c", | ||
"version": "2.0.0-experimental.d3890b7", | ||
"description": "An RPC transport that uses HTTP requests", | ||
@@ -50,3 +50,4 @@ "exports": { | ||
"undici": "^6.6.2", | ||
"@solana/rpc-spec": "2.0.0-experimental.d06660c" | ||
"@solana/errors": "2.0.0-experimental.d3890b7", | ||
"@solana/rpc-spec": "2.0.0-experimental.d3890b7" | ||
}, | ||
@@ -62,2 +63,3 @@ "bundlewatch": { | ||
"scripts": { | ||
"benchmark": "./src/__benchmarks__/run.ts", | ||
"compile:js": "tsup --config build-scripts/tsup.config.package.ts", | ||
@@ -64,0 +66,0 @@ "compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/@solana/build-scripts/add-js-extension-to-types.mjs", |
@@ -219,3 +219,27 @@ [![npm][npm-image]][npm-url] | ||
```ts | ||
// TODO: Your turn; send us a pull request with an example. | ||
import { RpcTransport } from '@solana/rpc-spec'; | ||
import { createHttpTransport } from '@solana/rpc-transport-http'; | ||
// Create a transport for each RPC server | ||
const transports = [ | ||
createHttpTransport({ url: 'https://mainnet-beta.my-server-1.com' }), | ||
createHttpTransport({ url: 'https://mainnet-beta.my-server-2.com' }), | ||
createHttpTransport({ url: 'https://mainnet-beta.my-server-2.com' }), | ||
]; | ||
// A failover transport that will try each transport in order until one succeeds before failing | ||
async function failoverTransport<TResponse>(...args: Parameters<RpcTransport>): Promise<TResponse> { | ||
let requestError; | ||
for (const transport of transports) { | ||
try { | ||
return await transport(...args); | ||
} catch (err) { | ||
requestError = err; | ||
console.error(err); | ||
} | ||
} | ||
throw requestError; | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
245
78191
3
20
622
6
+ Added@solana/errors@2.0.0-experimental.d3890b7(transitive)
+ Added@solana/rpc-spec@2.0.0-experimental.d3890b7(transitive)
+ Added@solana/rpc-spec-types@2.0.0-experimental.d3890b7(transitive)
+ Addedchalk@5.4.1(transitive)
+ Addedcommander@12.1.0(transitive)
- Removed@solana/rpc-spec@2.0.0-experimental.d06660c(transitive)
- Removed@solana/rpc-spec-types@2.0.0-experimental.d06660c(transitive)