Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
// Collect RPCOptions for each method to be displayed as Help
// ----------------------------------------------------------
const helpMap = Object.assign(
{},
...[].concat(
...Object.keys(methodMap).map(k =>
({[k]: methodMap[k].rpcOptions || {}})
)
)
);
// Build Jayson Server with flattened methodMap
// --------------------------------------------
const server = new Server(methodMap);
// Self-Documenting Help response
// ------------------------------
server.method('help', new Method({
handler: (args, callback) => {
if (args && args.namespace) {
callback(null, Object.assign(
{},
...[].concat(
...Object.keys(helpMap).map((k: string) => {
if(k.match(`^${args.namespace}`)) {
return ({[k]: helpMap[k]})
}
})
)
));
import jayson from 'jayson'
import rpcMethods from './rpcMethods'
const serverOptions = {
useContext: true, // permits passing extra data object to RPC methods as 'server context'
}
export default new jayson.Server(rpcMethods, serverOptions)
import { fromJSONObject, saveJobRunTree } from '../../entity/JobRun'
import { logger } from '../../logging'
import { ServerContext } from './../handleMessage'
import jayson from 'jayson'
// default invalid params error
const { INVALID_PARAMS } = jayson.Server.errors
const invalidParamsError = new jayson.Server().error(INVALID_PARAMS)
export default async (
payload: object,
context: ServerContext,
callback: jayson.JSONRPCCallbackTypePlain,
) => {
try {
const jobRun = fromJSONObject(payload)
jobRun.chainlinkNodeId = context.chainlinkNodeId
await saveJobRunTree(jobRun)
callback(null, 'success')
} catch (e) {
logger.error(e)
callback(invalidParamsError)
}
}
import jayson from 'jayson'
import * as rpcMethods from './rpcMethods'
const serverOptions = {
useContext: true, // permits passing extra data object to RPC methods as 'server context'
}
export const rpcServer = new jayson.Server(rpcMethods, serverOptions)
// broken typing for server.call - should be able to accept 3 arguments
// https://github.com/tedeh/jayson#server-context
// https://github.com/tedeh/jayson/pull/152
type callFunction = (
request: jayson.JSONRPCRequestLike | Array,
context: object,
originalCallback?: jayson.JSONRPCCallbackType,
) => void
export const callRPCServer: callFunction = rpcServer.call.bind(rpcServer)