MCPcopy Create free account
hub / github.com/EOSIO/eosjs-api / apiGen

Function apiGen

src/apigen.js:8–44  ·  view source on GitHub ↗
(version, definitions, config = {})

Source from the content-addressed store, hash-verified

6module.exports = apiGen
7
8function apiGen (version, definitions, config = {}) {
9 const configDefaults = {
10 httpEndpoint: 'http://127.0.0.1:8888',
11 verbose: false,
12 logger: {
13 log: (...args) => config.verbose ? console.log(...args) : null,
14 error: (...args) => config.verbose ? console.error(...args) : null
15 }
16 }
17
18 function applyDefaults(target, defaults) {
19 Object.keys(defaults).forEach(key => {
20 if(target[key] === undefined) {
21 target[key] = defaults[key]
22 }
23 })
24 }
25
26 applyDefaults(config, configDefaults)
27 applyDefaults(config.logger, configDefaults.logger)
28
29 const api = {}
30 const {httpEndpoint} = config
31
32 for (const apiGroup in definitions) {
33 for (const apiMethod in definitions[apiGroup]) {
34 const methodName = camelCase(apiMethod)
35 const url = `${httpEndpoint}/${version}/${apiGroup}/${apiMethod}`
36 api[methodName] = fetchMethod(methodName, url, definitions[apiGroup][apiMethod], config)
37 }
38 }
39 for(const helper in helpers.api) {
40 // Insert `api` as the first parameter to all API helpers
41 api[helper] = (...args) => helpers.api[helper](api, ...args)
42 }
43 return api
44}
45
46function fetchMethod (methodName, url, definition, config) {
47 const {logger} = config

Callers 2

EosApiFunction · 0.85
appgen.test.jsFile · 0.85

Calls 2

applyDefaultsFunction · 0.85
fetchMethodFunction · 0.85

Tested by

no test coverage detected