Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

@asyncapi/generator-components

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/generator-components

Package with reusable components for generation using React render engine

latest
Source
npmnpm
Version
0.6.0
Version published
Weekly downloads
30K
-10.3%
Maintainers
3
Weekly downloads
 
Created
Source

"use strict";

Object.defineProperty(exports, "__esModule", { value: true }); exports.Usage = Usage; var _generatorReactSdk = require("@asyncapi/generator-react-sdk"); var _ErrorHandling = require("../../utils/ErrorHandling"); var _jsxRuntime = require("react/jsx-runtime"); /**

  • @typedef {'python' | 'javascript' } Language
  • Supported programming languages. */var usageConfig = { python: function python(clientName, clientFileName) { return "\nfrom ".concat(clientFileName.replace('.py', ''), " import ").concat(clientName, "\n\nws_client = ").concat(clientName, "()\n\nasync def main():\n await ws_client.connect()\n # use ws_client to send/receive messages\n await ws_client.close()\n"); }, javascript: function javascript(clientName, clientFileName) { return "\nconst ".concat(clientName, " = require('./").concat(clientFileName.replace('.js', ''), "');\nconst wsClient = new ").concat(clientName, "();\n\nasync function main() {\n try {\n await wsClient.connect();\n // use wsClient to send/receive messages\n await wsClient.close();\n } catch (error) {\n console.error('Failed to connect:', error);\n }\n}\n\nmain();\n"); } };

/**

  • Renders a usage example snippet for a generated WebSocket client in a given language.
  • @param {Object} props - Component props
  • @param {string} props.clientName - The exported name of the client.
  • @param {string} props.clientFileName - The file name where the client is defined.
  • @param {Language} props.language - The target language for which to render the usage snippet
  • @returns {JSX.Element} A Text component containing a formatted usage example snippet.
  • @throws {Error} When the specified language is not supported.
  • @throws {Error} When clientName is missing or invalid.
  • @throws {Error} When clientFileName is missing or invalid.
  • @example
  • import { Usage } from "@asyncapi/generator-components";
  • const clientName = "MyClient";
  • const clientFileName = "myClient.js";
  • const language = "javascript";
  • function renderUsage(){
  • return (
  • <Usage 
    
  •    clientName={clientName} 
    
  •    clientFileName={clientFileName} 
    
  •    language={language}
    
  • />
    
  • )
  • }
  • renderUsage(); / function Usage(_ref) { var clientName = _ref.clientName, clientFileName = _ref.clientFileName, language = _ref.language; var supportedLanguages = Object.keys(usageConfig); var snippetFn = usageConfig[language]; if (!snippetFn) { throw (0, _ErrorHandling.unsupportedLanguage)(language, supportedLanguages); } if (typeof clientName !== 'string' || clientName.trim() === '') { throw (0, _ErrorHandling.invalidClientName)(clientName); } if (typeof clientFileName !== 'string' || clientFileName.trim() === '') { throw (0, _ErrorHandling.invalidClientFileName)(clientFileName); } var snippet = snippetFn(clientName, clientFileName); return /#PURE*/(0, _jsxRuntime.jsx)(_generatorReactSdk.Text, { newLines: 2, children: "## Usage\n\n".concat(language, "\n").concat(snippet.trim(), "\n\n") }); }

FAQs

Package last updated on 21 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts