@solana/rpc-core
Advanced tools
Comparing version 2.0.0-experimental.732dc1e to 2.0.0-experimental.847f0a9
@@ -0,3 +1,96 @@ | ||
// src/params-patcher.ts | ||
function visitNode(value, keyPath, onIntegerOverflow) { | ||
if (Array.isArray(value)) { | ||
return value.map( | ||
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow) | ||
); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const propName in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, propName)) { | ||
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow); | ||
} | ||
} | ||
return out; | ||
} else if (typeof value === "bigint") { | ||
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) { | ||
onIntegerOverflow(keyPath, value); | ||
} | ||
return Number(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) { | ||
return visitNode(params, [], onIntegerOverflow); | ||
} | ||
// src/response-patcher-types.ts | ||
var KEYPATH_WILDCARD = {}; | ||
// src/response-patcher-allowed-numeric-values.ts | ||
var ALLOWED_NUMERIC_KEYPATHS = { | ||
getInflationReward: [[KEYPATH_WILDCARD, "commission"]] | ||
}; | ||
// src/response-patcher.ts | ||
function getNextAllowedKeypaths(keyPaths, property) { | ||
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1)); | ||
} | ||
function visitNode2(value, allowedKeypaths) { | ||
if (Array.isArray(value)) { | ||
return value.map((element, ii) => { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii); | ||
return visitNode2(element, nextAllowedKeypaths); | ||
}); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const [propName, innerValue] of Object.entries(value)) { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName); | ||
out[propName] = visitNode2(innerValue, nextAllowedKeypaths); | ||
} | ||
return out; | ||
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted; | ||
// Upcast the value to `bigint` unless an allowed keypath is present. | ||
allowedKeypaths.length === 0) { | ||
return BigInt(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
function patchResponseForSolanaLabsRpc(rawResponse, methodName) { | ||
const allowedKeypaths = methodName ? ALLOWED_NUMERIC_KEYPATHS[methodName] : void 0; | ||
return visitNode2(rawResponse, allowedKeypaths ?? []); | ||
} | ||
// src/index.ts | ||
function createSolanaRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const methodName = p.toString(); | ||
return function(...rawParams) { | ||
const handleIntegerOverflow = config?.onIntegerOverflow; | ||
const params = patchParamsForSolanaLabsRpc( | ||
rawParams, | ||
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0 | ||
); | ||
return { | ||
methodName, | ||
params, | ||
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpc(rawResponse, methodName) | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
export { createSolanaRpcApi }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -0,3 +1,96 @@ | ||
// src/params-patcher.ts | ||
function visitNode(value, keyPath, onIntegerOverflow) { | ||
if (Array.isArray(value)) { | ||
return value.map( | ||
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow) | ||
); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const propName in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, propName)) { | ||
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow); | ||
} | ||
} | ||
return out; | ||
} else if (typeof value === "bigint") { | ||
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) { | ||
onIntegerOverflow(keyPath, value); | ||
} | ||
return Number(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) { | ||
return visitNode(params, [], onIntegerOverflow); | ||
} | ||
// src/response-patcher-types.ts | ||
var KEYPATH_WILDCARD = {}; | ||
// src/response-patcher-allowed-numeric-values.ts | ||
var ALLOWED_NUMERIC_KEYPATHS = { | ||
getInflationReward: [[KEYPATH_WILDCARD, "commission"]] | ||
}; | ||
// src/response-patcher.ts | ||
function getNextAllowedKeypaths(keyPaths, property) { | ||
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1)); | ||
} | ||
function visitNode2(value, allowedKeypaths) { | ||
if (Array.isArray(value)) { | ||
return value.map((element, ii) => { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii); | ||
return visitNode2(element, nextAllowedKeypaths); | ||
}); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const [propName, innerValue] of Object.entries(value)) { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName); | ||
out[propName] = visitNode2(innerValue, nextAllowedKeypaths); | ||
} | ||
return out; | ||
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted; | ||
// Upcast the value to `bigint` unless an allowed keypath is present. | ||
allowedKeypaths.length === 0) { | ||
return BigInt(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
function patchResponseForSolanaLabsRpc(rawResponse, methodName) { | ||
const allowedKeypaths = methodName ? ALLOWED_NUMERIC_KEYPATHS[methodName] : void 0; | ||
return visitNode2(rawResponse, allowedKeypaths ?? []); | ||
} | ||
// src/index.ts | ||
function createSolanaRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const methodName = p.toString(); | ||
return function(...rawParams) { | ||
const handleIntegerOverflow = config?.onIntegerOverflow; | ||
const params = patchParamsForSolanaLabsRpc( | ||
rawParams, | ||
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0 | ||
); | ||
return { | ||
methodName, | ||
params, | ||
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpc(rawResponse, methodName) | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
export { createSolanaRpcApi }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -0,3 +1,96 @@ | ||
// src/params-patcher.ts | ||
function visitNode(value, keyPath, onIntegerOverflow) { | ||
if (Array.isArray(value)) { | ||
return value.map( | ||
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow) | ||
); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const propName in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, propName)) { | ||
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow); | ||
} | ||
} | ||
return out; | ||
} else if (typeof value === "bigint") { | ||
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) { | ||
onIntegerOverflow(keyPath, value); | ||
} | ||
return Number(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) { | ||
return visitNode(params, [], onIntegerOverflow); | ||
} | ||
// src/response-patcher-types.ts | ||
var KEYPATH_WILDCARD = {}; | ||
// src/response-patcher-allowed-numeric-values.ts | ||
var ALLOWED_NUMERIC_KEYPATHS = { | ||
getInflationReward: [[KEYPATH_WILDCARD, "commission"]] | ||
}; | ||
// src/response-patcher.ts | ||
function getNextAllowedKeypaths(keyPaths, property) { | ||
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1)); | ||
} | ||
function visitNode2(value, allowedKeypaths) { | ||
if (Array.isArray(value)) { | ||
return value.map((element, ii) => { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii); | ||
return visitNode2(element, nextAllowedKeypaths); | ||
}); | ||
} else if (typeof value === "object" && value !== null) { | ||
const out = {}; | ||
for (const [propName, innerValue] of Object.entries(value)) { | ||
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName); | ||
out[propName] = visitNode2(innerValue, nextAllowedKeypaths); | ||
} | ||
return out; | ||
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted; | ||
// Upcast the value to `bigint` unless an allowed keypath is present. | ||
allowedKeypaths.length === 0) { | ||
return BigInt(value); | ||
} else { | ||
return value; | ||
} | ||
} | ||
function patchResponseForSolanaLabsRpc(rawResponse, methodName) { | ||
const allowedKeypaths = methodName ? ALLOWED_NUMERIC_KEYPATHS[methodName] : void 0; | ||
return visitNode2(rawResponse, allowedKeypaths ?? []); | ||
} | ||
// src/index.ts | ||
function createSolanaRpcApi(config) { | ||
return new Proxy({}, { | ||
defineProperty() { | ||
return false; | ||
}, | ||
deleteProperty() { | ||
return false; | ||
}, | ||
get(...args) { | ||
const [_, p] = args; | ||
const methodName = p.toString(); | ||
return function(...rawParams) { | ||
const handleIntegerOverflow = config?.onIntegerOverflow; | ||
const params = patchParamsForSolanaLabsRpc( | ||
rawParams, | ||
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0 | ||
); | ||
return { | ||
methodName, | ||
params, | ||
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpc(rawResponse, methodName) | ||
}; | ||
}; | ||
} | ||
}); | ||
} | ||
export { createSolanaRpcApi }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -1,2 +0,12 @@ | ||
export * from './types/jsonRpcApi'; | ||
import { IRpcApi } from '@solana/rpc-transport/dist/types/json-rpc-transport/json-rpc-transport-types'; | ||
import { GetAccountInfoApi } from './rpc-methods/getAccountInfo'; | ||
import { GetBlockHeightApi } from './rpc-methods/getBlockHeight'; | ||
import { GetBlocksApi } from './rpc-methods/getBlocks'; | ||
import { GetInflationRewardApi } from './rpc-methods/getInflationReward'; | ||
type Config = Readonly<{ | ||
onIntegerOverflow?: (methodName: string, keyPath: (number | string)[], value: bigint) => void; | ||
}>; | ||
export type SolanaRpcMethods = GetAccountInfoApi & GetBlockHeightApi & GetBlocksApi & GetInflationRewardApi; | ||
export declare function createSolanaRpcApi(config?: Config): IRpcApi<SolanaRpcMethods>; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@solana/rpc-core", | ||
"version": "2.0.0-experimental.732dc1e", | ||
"version": "2.0.0-experimental.847f0a9", | ||
"description": "A library for making calls to the Solana JSON RPC API", | ||
@@ -49,3 +49,3 @@ "exports": { | ||
"dependencies": { | ||
"@solana/keys": "2.0.0-experimental.732dc1e" | ||
"@solana/keys": "2.0.0-experimental.847f0a9" | ||
}, | ||
@@ -66,2 +66,3 @@ "devDependencies": { | ||
"jest-environment-jsdom": "^29.5.0", | ||
"jest-fetch-mock": "^3.0.3", | ||
"jest-runner-eslint": "^2.0.0", | ||
@@ -76,2 +77,3 @@ "jest-runner-prettier": "^1.0.0", | ||
"version-from-git": "^1.1.1", | ||
"@solana/rpc-transport": "2.0.0-experimental.847f0a9", | ||
"build-scripts": "0.0.0", | ||
@@ -92,3 +94,3 @@ "test-config": "0.0.0", | ||
"compile:typedefs": "tsc -p ./tsconfig.declarations.json", | ||
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch", | ||
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --watch", | ||
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks", | ||
@@ -100,4 +102,6 @@ "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent", | ||
"test:treeshakability:node": "agadoo dist/index.native.js", | ||
"test:typecheck": "tsc --noEmit" | ||
"test:typecheck": "tsc --noEmit", | ||
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --silent", | ||
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --silent" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
86210
33
706
27
1
+ Added@solana/keys@2.0.0-experimental.847f0a9(transitive)
- Removed@solana/keys@2.0.0-experimental.732dc1e(transitive)