UNPKG

@darwinia/types

Version:
46 lines (41 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.jsonrpcFromDefinitions = jsonrpcFromDefinitions; exports.typesFromDefinitions = typesFromDefinitions; // Copyright 2017-2022 @darwinia/types authors & contributors // SPDX-License-Identifier: Apache-2.0 function typesFromDefinitions( /* eslint-disable @typescript-eslint/no-explicit-any */ definitions) { let initTypes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return Object.values(definitions).reduce((res, _ref) => { let { types } = _ref; return { ...res, ...types }; }, initTypes); } function jsonrpcFromDefinitions(definitions) { const jsonrpc = {}; Object.keys(definitions).filter(key => Object.keys(definitions[key].rpc || {}).length !== 0).forEach(section => { var _definitions$section$; if (!jsonrpc[section]) { jsonrpc[section] = {}; } Object.entries((_definitions$section$ = definitions[section].rpc) !== null && _definitions$section$ !== void 0 ? _definitions$section$ : {}).forEach(_ref2 => { let [method, def] = _ref2; const isSubscription = !!def.pubsub; jsonrpc[section][method] = { ...def, isSubscription, jsonrpc: `${section}_${method}`, method, section }; }); }); return jsonrpc; }