"use strict"; // P A C K A G E S const dedent = require("dedent"); const fetch = require("make-fetch-happen").defaults({ cacheManager: "./cache" }); const fs = require("graceful-fs"); const html = require("choo-async/html"); const raw = require("nanohtml/raw"); // V A R I A B L E const apiFileLink = process.env.NODE_ENV === "development" ? "https://rawgit.com/lbryio/lbry/master/docs/api.json" : "https://cdn.rawgit.com/lbryio/lbry/5b3103e4/docs/api.json" ; const apiScripts = ""; // E X P O R T module.exports = exports = () => async () => parseApiFile().then(response => html`
${raw(createApiContent(response).join(""))}
${raw(apiScripts)} `); // H E L P E R S function createApiContent(apiDetails) { const apiContent = []; for (const apiDetail of apiDetails) { const apiDetailsReturns = JSON.parse(JSON.stringify(apiDetail.returns)); apiContent.push(`

${apiDetail.name}

${apiDetail.description}

${apiDetail.arguments.length ? `

Arguments

` : ""}

Returns

${dedent(apiDetailsReturns)}
// example(s) for ${apiDetail.name} to come later
`); } return apiContent; } function createApiSidebar(apiDetails) { const apiSidebar = []; for (const apiDetail of apiDetails) { apiSidebar.push(`
  • ${apiDetail.name}
  • `); } return apiSidebar; } function parseApiFile() { return fetch(apiFileLink).then(() => fetch(apiFileLink, { cache: "no-cache" // forces a conditional request })).then(res => res.json().then(body => body)); // res.status 304 = cache validated } function renderArguments(args) { const argumentContent = []; for (const arg of args) { argumentContent.push(`
  • ${arg.name}
    ${arg.is_required === true ? "" : "optional" }${arg.type}
    ${arg.description.replace(//g, ">")}
  • `); } return argumentContent; }