diff --git a/jest.config.js b/jest.config.js index 8da7cbf..3a39cca 100644 --- a/jest.config.js +++ b/jest.config.js @@ -42,10 +42,10 @@ module.exports = { // bump this back up to 80% when we have more tests coverageThreshold: { global: { - branches: 28.15, + branches: 28.3, functions: 22.72, - lines: 32.91, - statements: 32.77, + lines: 33.74, + statements: 33.6, }, }, diff --git a/package.json b/package.json index d894137..4568561 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build": "tsc --project tsconfig.build.json && cp src/theme/OpenRPCDocMethod.css dist/theme/OpenRPCDocMethod.css", "build:clean": "rimraf dist && yarn build", "build:watch": "yarn build && tsc --project tsconfig.build.json --watch", + "link:setup": "rm -rf ./node_modules/@docusaurus/theme-common", "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:dependencies && yarn lint:changelog", "lint:changelog": "auto-changelog validate", "lint:dependencies": "depcheck", @@ -111,5 +112,9 @@ "@metamask/open-rpc-docs-react>@stoplight/mosaic>@fortawesome/fontawesome-svg-core": false, "@metamask/open-rpc-docs-react>@stoplight/mosaic>@fortawesome/fontawesome-svg-core>@fortawesome/fontawesome-common-types": false } + }, + "resolutions": { + "@metamask/open-rpc-docs-react": "portal:/Users/shanejonas/code/metamask/openrpc-docs-react", + "joi": "17.6.0" } } diff --git a/src/content-docs-enhanced-open-rpc/index.ts b/src/content-docs-enhanced-open-rpc/index.ts index 71eb9ff..8f3959d 100644 --- a/src/content-docs-enhanced-open-rpc/index.ts +++ b/src/content-docs-enhanced-open-rpc/index.ts @@ -42,9 +42,9 @@ async function docsPluginEnhanced( const path = join(options.path, options.openrpc.path); const openrpcPluginInstance: any = openrpcPlugin(context, { + ...options.openrpc, id: options.id, path, - openrpcDocument: options.openrpc.openrpcDocument, }); if (openrpcPluginInstance === undefined) { throw new Error('openrpcPluginInstance is undefined'); diff --git a/src/index.ts b/src/index.ts index bd5c268..39ab7aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-template-curly-in-string */ /* eslint-disable no-restricted-globals */ /** * See https://v2.docusaurus.io/docs/lifecycle-apis if you need more help! @@ -14,8 +15,6 @@ import path, { join } from 'path'; // import {compile} from '@mdx-js/mdx' -// import openRPCToMarkdown from './openrpc-to-mdx'; - /** * Put your plugin's options in here. * @@ -28,6 +27,7 @@ export type DocusaurusOpenRPCOptions = { // either a file path, or uri to a document. openrpcDocument: string; path: string; + requestTemplate?: string | Record; }; /** @@ -64,6 +64,25 @@ export default function docusaurusOpenRpc( const aliasedSource = (source: string) => `${posixPath(path.resolve(pluginDataDirRoot, options.id, source))}`; + console.log('OPTIONS=', typeof options.requestTemplate); + let reqTemplate: any = { + js: 'await window.fetch(\n "${serverUrl}",\n {\n method: "POST",\n headers: {\n "Content-Type": "application/json"\n },\n body: JSON.stringify(${jsonRpcRequest})\n }\n).then((res) => res.json());', + curl: "curl -X POST -H 'Content-Type: application/json' --data ${jsonRpcRequest} ${serverUrl}", + python: + 'import requests\n\nrequests.request(\n "POST",\n "${serverUrl}",\n headers={\n "Content-Type": "application/json"\n },\n data=${jsonRpcRequest}\n)', + }; + + if (typeof options.requestTemplate === 'string') { + reqTemplate = { + js: options.requestTemplate, + }; + } else if (typeof options.requestTemplate === 'object') { + reqTemplate = { + ...reqTemplate, + ...options.requestTemplate, + }; + } + return { // change this to something unique, or caches may conflict! name: 'docusaurus-openrpc', @@ -92,10 +111,12 @@ export default function docusaurusOpenRpc( async contentLoaded({ content, actions }) { const { openrpcDocument, loadedVersions } = content; + console.log('reqTemplate', reqTemplate); const propsFilePath = await actions.createData( 'props.json', JSON.stringify({ path: options.path, + requestTemplate: reqTemplate, openrpcDocument, }), ); diff --git a/src/theme/OpenRPCDocMethod.tsx b/src/theme/OpenRPCDocMethod.tsx index 3e607b6..a66678f 100644 --- a/src/theme/OpenRPCDocMethod.tsx +++ b/src/theme/OpenRPCDocMethod.tsx @@ -4,7 +4,6 @@ import { Sidebar, } from "@docusaurus/plugin-content-docs/src/sidebars/types"; import Layout from '@theme/Layout'; -const {useDocRouteMetadata} = require('@docusaurus/theme-common/internal'); import {ExamplePairingObject, MethodObject, ContentDescriptorObject} from '@open-rpc/meta-schema'; import { InteractiveMethod, Method} from '@metamask/open-rpc-docs-react'; import { join } from 'path'; @@ -105,6 +104,8 @@ export default function OpenRPCDocMethod(props: any) { method.examples = method.examples || getExamplesFromMethod(method); const [selectedExamplePairing, setSelectedExamplePairing] = React.useState(method.examples[0]); + // requestTemplate + return (
@@ -142,7 +143,7 @@ export default function OpenRPCDocMethod(props: any) {
- {method && } + {method && }
diff --git a/yarn.lock b/yarn.lock index b6f0804..7a10ac0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3115,9 +3115,9 @@ __metadata: languageName: node linkType: hard -"@metamask/open-rpc-docs-react@npm:^0.1.2": - version: 0.1.2 - resolution: "@metamask/open-rpc-docs-react@npm:0.1.2" +"@metamask/open-rpc-docs-react@portal:/Users/shanejonas/code/metamask/openrpc-docs-react::locator=%40metamask%2Fdocusaurus-openrpc%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@metamask/open-rpc-docs-react@portal:/Users/shanejonas/code/metamask/openrpc-docs-react::locator=%40metamask%2Fdocusaurus-openrpc%40workspace%3A." dependencies: "@json-schema-tools/traverse": ^1.10.1 "@open-rpc/examples": ^1.6.1 @@ -3130,15 +3130,15 @@ __metadata: "@stoplight/mosaic-code-viewer": ^1.32 hash-color-material: ^1.1.3 lodash: ^4.17.15 + openapi-url-resolver: ^1.0.8 qs: ^6.11.1 react-markdown: ^8.0.7 react-syntax-highlighter: ^15.4.3 peerDependencies: react: ^17.0.2 react-dom: ^17.0.2 - checksum: 2f9f0e1c8ed4292a9c7402273c02a84db78740966b64aec3cd325b8c279924b98dc8e63685e8fb37d4a05e0a0e491515f93af8b649e66106c3c2d9e529b2c740 languageName: node - linkType: hard + linkType: soft "@nodelib/fs.scandir@npm:2.1.5": version: 2.1.5 @@ -3580,7 +3580,7 @@ __metadata: languageName: node linkType: hard -"@sideway/formula@npm:^3.0.1": +"@sideway/formula@npm:^3.0.0": version: 3.0.1 resolution: "@sideway/formula@npm:3.0.1" checksum: e4beeebc9dbe2ff4ef0def15cec0165e00d1612e3d7cea0bc9ce5175c3263fc2c818b679bd558957f49400ee7be9d4e5ac90487e1625b4932e15c4aa7919c57a @@ -10953,16 +10953,16 @@ __metadata: languageName: node linkType: hard -"joi@npm:^17.6.0": - version: 17.11.0 - resolution: "joi@npm:17.11.0" +"joi@npm:17.6.0": + version: 17.6.0 + resolution: "joi@npm:17.6.0" dependencies: "@hapi/hoek": ^9.0.0 "@hapi/topo": ^5.0.0 "@sideway/address": ^4.1.3 - "@sideway/formula": ^3.0.1 + "@sideway/formula": ^3.0.0 "@sideway/pinpoint": ^2.0.0 - checksum: 3a4e9ecba345cdafe585e7ed8270a44b39718e11dff3749aa27e0001a63d578b75100c062be28e6f48f960b594864034e7a13833f33fbd7ad56d5ce6b617f9bf + checksum: eaf62f6c02f2edb1042f1ab04fc23a5918a2cb8f54bec84c6e1033624d8a462c10ae9518af55a3ba84f1793960450d58094eda308e7ef93c17edd4e3c8ef31d5 languageName: node linkType: hard @@ -12828,6 +12828,13 @@ __metadata: languageName: node linkType: hard +"openapi-url-resolver@npm:^1.0.8": + version: 1.0.8 + resolution: "openapi-url-resolver@npm:1.0.8" + checksum: 26ab7a6103f44b5c9435540e4dcd18e8103453ab597f05e38be897bf89953b817841416cf3e219fb4b4add14174550e07a20fbb7cb30cc972948fd210360944a + languageName: node + linkType: hard + "opener@npm:^1.5.2": version: 1.5.2 resolution: "opener@npm:1.5.2"