@asyncapi/generator 2.7.1 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/docs/api.md +32 -0
- package/docs/baked-in-templates.md +100 -0
- package/docs/configuration-file.md +49 -31
- package/docs/template.md +22 -3
- package/lib/generator.js +31 -3
- package/lib/templates/BakedInTemplatesList.json +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/.ageneratorrc +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/README.md +12 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/ClientClass.js +42 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/ClientClass.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/ClientFields.js +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/ClientFields.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/Connect.js +60 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/Connect.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/Constructor.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/Constructor.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/HandleMessage.js +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/HandleMessage.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/RegisterErrorHandler.js +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/RegisterErrorHandler.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/SendEchoMessage.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/SendEchoMessage.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/template/client.dart.js +181 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/template/client.dart.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/template/pubspec.yaml.js +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/template/pubspec.yaml.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/ClientClass.js +32 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/ClientFields.js +12 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/Connect.js +49 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/Constructor.js +16 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/HandleMessage.js +14 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/RegisterErrorHandler.js +14 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/SendEchoMessage.js +20 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/example.dart +36 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/package.json +54 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/template/client.dart.js +24 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/template/pubspec.yaml.js +16 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/.ageneratorrc +25 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/README.md +28 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/ClientConnector.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/ClientConnector.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/ClientFields.js +19 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/ClientFields.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/ConnectorFields.js +22 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/ConnectorFields.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/EchoWebSocket.js +40 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/EchoWebSocket.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/HandleError.js +20 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/HandleError.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/InitConnector.js +47 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/InitConnector.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/OnClose.js +23 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/OnClose.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/OnOpen.js +25 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/OnOpen.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/OnTextMessageHandler.js +29 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/OnTextMessageHandler.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/dependencies/ClientDependencies.js +29 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/dependencies/ClientDependencies.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/dependencies/ConnectorDependencies.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/components/dependencies/ConnectorDependencies.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/java/com/asyncapi/client.java.js +154 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/java/com/asyncapi/client.java.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/java/com/asyncapi/connector.java.js +108 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/java/com/asyncapi/connector.java.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/java/com/asyncapi/models/model.js +52 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/java/com/asyncapi/models/model.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/resources/AppProperties.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/__transpiled/template/src/main/resources/AppProperties.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/ClientConnector.js +17 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/ClientFields.js +10 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/ConnectorFields.js +11 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/EchoWebSocket.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/HandleError.js +14 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/InitConnector.js +41 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/OnClose.js +16 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/OnOpen.js +16 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/OnTextMessageHandler.js +25 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/dependencies/ClientDependencies.js +23 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/components/dependencies/ConnectorDependencies.js +20 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/package.json +63 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/.dockerignore +5 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/.mvn/wrapper/MavenWrapperDownloader.java +93 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/.mvn/wrapper/maven-wrapper.properties +20 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/README.md +58 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/mvnw +332 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/mvnw.cmd +206 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/pom.xml +125 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/src/main/docker/Dockerfile.jvm +98 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/src/main/java/com/asyncapi/client.java.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/src/main/java/com/asyncapi/connector.java.js +16 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/src/main/java/com/asyncapi/models/model.js +36 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/template/src/main/resources/AppProperties.js +19 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/.ageneratorrc +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/README.md +10 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/AvailableOperations.js +34 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/AvailableOperations.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/ClientClass.js +47 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/ClientClass.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/Connect.js +63 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/Connect.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/Constructor.js +29 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/Constructor.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/HandleMessage.js +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/HandleMessage.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/MessageExamples.js +29 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/MessageExamples.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/ModuleExport.js +18 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/ModuleExport.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/OperationHeader.js +19 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/OperationHeader.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/RegisterErrorHandler.js +25 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/RegisterErrorHandler.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/SendOperation.js +53 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/SendOperation.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/example.js +43 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/example.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/README.md.js +166 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/README.md.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js +216 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/AvailableOperations.js +20 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/ClientClass.js +32 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/Connect.js +54 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/Constructor.js +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/HandleMessage.js +14 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/MessageExamples.js +25 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/ModuleExport.js +11 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/OperationHeader.js +12 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/RegisterErrorHandler.js +18 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/SendOperation.js +44 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/example.js +42 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/package.json +54 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/template/README.md.js +106 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/template/client.js.js +24 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/.ageneratorrc +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/README.md +53 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/ClientClass.js +61 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/ClientClass.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Connect.js +58 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Connect.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Constructor.js +55 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Constructor.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/HandleError.js +25 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/HandleError.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/HandleMessage.js +24 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/HandleMessage.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/InitSignature.js +34 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/InitSignature.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/QueryParamsArgumentsDocs.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/QueryParamsArgumentsDocs.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/QueryParamsVariables.js +36 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/QueryParamsVariables.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/RegisterErrorHandler.js +23 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/RegisterErrorHandler.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/RegisterOutgoingProcessor.js +26 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/RegisterOutgoingProcessor.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Requires.js +24 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Requires.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Send.js +41 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Send.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/SendOperation.js +56 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/SendOperation.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/client.py.js +379 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/client.py.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/models.js +15 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/models.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/requirements.txt.js +19 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/requirements.txt.js.map +1 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/ClientClass.js +47 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/Connect.js +49 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/Constructor.js +42 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/HandleError.js +18 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/HandleMessage.js +17 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/InitSignature.js +24 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/QueryParamsArgumentsDocs.js +19 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/QueryParamsVariables.js +27 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/RegisterErrorHandler.js +16 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/RegisterOutgoingProcessor.js +19 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/Requires.js +15 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/Send.js +33 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/SendOperation.js +50 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/example-slack.py +21 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/example.py +41 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/package.json +54 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/template/client.py.js +23 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/template/models.js +5 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/template/requirements.txt.js +13 -0
- package/lib/templates/bakedInTemplates.js +53 -0
- package/package.json +8 -3
- package/test/__mocks__/@npmcli/arborist.js +0 -11
- package/test/__mocks__/@npmcli/config.js +0 -3
- package/test/__mocks__/fs.extra.js +0 -3
- package/test/__mocks__/loglevel.js +0 -3
- package/test/__mocks__/resolve-from.js +0 -8
- package/test/__mocks__/resolve-pkg.js +0 -8
- package/test/__snapshots__/integration.test.js.snap +0 -419
- package/test/docs/apiwithref.json +0 -41
- package/test/docs/dummy.yml +0 -390
- package/test/docs/dummyV3.yml +0 -31
- package/test/docs/shared.json +0 -27
- package/test/docs/ws.yml +0 -36
- package/test/generator.test.js +0 -629
- package/test/hooksRegistry.test.js +0 -173
- package/test/integration.test.js +0 -203
- package/test/parser.test.js +0 -205
- package/test/renderer.test.js +0 -62
- package/test/templateConfigValidator.test.js +0 -294
- package/test/test-project/.yarncr.yml +0 -3
- package/test/test-project/README.md +0 -8
- package/test/test-project/docker-compose.yml +0 -16
- package/test/test-project/package.json +0 -24
- package/test/test-project/test-global.test.js +0 -37
- package/test/test-project/test-project.test.js +0 -102
- package/test/test-project/test-registry.test.js +0 -62
- package/test/test-project/test.sh +0 -104
- package/test/test-project/verdaccio/config.yaml +0 -22
- package/test/test-project/verdaccio/htpasswd +0 -1
- package/test/test-templates/nunjucks-template/package-lock.json +0 -4062
- package/test/test-templates/nunjucks-template/package.json +0 -21
- package/test/test-templates/nunjucks-template/template/test-file.md +0 -5
- package/test/test-templates/react-template/.ageneratorrc +0 -33
- package/test/test-templates/react-template/package.json +0 -14
- package/test/test-templates/react-template/template/conditionalFile.txt +0 -0
- package/test/test-templates/react-template/template/conditionalFolder/conditionalFile.txt +0 -0
- package/test/test-templates/react-template/template/conditionalFolder2/input.txt +0 -0
- package/test/test-templates/react-template/template/models.js +0 -6
- package/test/test-templates/react-template/template/test-file.md.js +0 -11
- package/test/utils.test.js +0 -129
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('source-map-support/register');
|
|
4
|
+
var generatorReactSdk = require('@asyncapi/generator-react-sdk');
|
|
5
|
+
var generatorHelpers = require('@asyncapi/generator-helpers');
|
|
6
|
+
var generatorComponents = require('@asyncapi/generator-components');
|
|
7
|
+
var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/react/cjs/react-jsx-runtime.production.min.js');
|
|
8
|
+
|
|
9
|
+
function Constructor({
|
|
10
|
+
serverUrl
|
|
11
|
+
}) {
|
|
12
|
+
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
13
|
+
indent: 2,
|
|
14
|
+
children: `/*
|
|
15
|
+
* Constructor to initialize the WebSocket client
|
|
16
|
+
* @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.
|
|
17
|
+
*/
|
|
18
|
+
constructor(url) {
|
|
19
|
+
this.url = url || '${serverUrl}';
|
|
20
|
+
this.websocket = null;
|
|
21
|
+
this.messageHandlers = [];
|
|
22
|
+
this.errorHandlers = [];
|
|
23
|
+
}
|
|
24
|
+
`
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Connect({
|
|
29
|
+
title
|
|
30
|
+
}) {
|
|
31
|
+
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
32
|
+
newLines: 2,
|
|
33
|
+
indent: 2,
|
|
34
|
+
children: `// Method to establish a WebSocket connection
|
|
35
|
+
connect() {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
this.websocket = new WebSocket(this.url);
|
|
38
|
+
|
|
39
|
+
// On successful connection
|
|
40
|
+
this.websocket.onopen = () => {
|
|
41
|
+
console.log('Connected to ${title} server');
|
|
42
|
+
resolve();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// On receiving a message
|
|
46
|
+
this.websocket.onmessage = (event) => {
|
|
47
|
+
if (this.messageHandlers.length > 0) {
|
|
48
|
+
// Call custom message handlers
|
|
49
|
+
this.messageHandlers.forEach(handler => {
|
|
50
|
+
if (typeof handler === 'function') {
|
|
51
|
+
this.handleMessage(event.data, handler);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
// Default message logging
|
|
56
|
+
console.log('Message received:', event.data);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// On error first call custom error handlers, then default error behavior
|
|
61
|
+
this.websocket.onerror = (error) => {
|
|
62
|
+
if (this.errorHandlers.length > 0) {
|
|
63
|
+
// Call custom error handlers
|
|
64
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
65
|
+
} else {
|
|
66
|
+
// Default error behavior
|
|
67
|
+
console.error('WebSocket Error:', error);
|
|
68
|
+
}
|
|
69
|
+
reject(error);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// On connection close
|
|
73
|
+
this.websocket.onclose = () => {
|
|
74
|
+
console.log('Disconnected from ${title} server');
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function RegisterErrorHandler() {
|
|
82
|
+
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
83
|
+
newLines: 2,
|
|
84
|
+
indent: 2,
|
|
85
|
+
children: `// Method to register custom error handlers
|
|
86
|
+
registerErrorHandler(handler) {
|
|
87
|
+
if (typeof handler === 'function') {
|
|
88
|
+
this.errorHandlers.push(handler);
|
|
89
|
+
} else {
|
|
90
|
+
console.warn('Error handler must be a function');
|
|
91
|
+
}
|
|
92
|
+
}`
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function HandleMessage() {
|
|
97
|
+
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
98
|
+
newLines: 2,
|
|
99
|
+
indent: 2,
|
|
100
|
+
children: `// Method to handle message with callback
|
|
101
|
+
handleMessage(message, cb) {
|
|
102
|
+
if (cb) cb(message);
|
|
103
|
+
}`
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function SendOperation({
|
|
108
|
+
sendOperations,
|
|
109
|
+
clientName
|
|
110
|
+
}) {
|
|
111
|
+
if (!sendOperations || sendOperations.length === 0) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
115
|
+
children: sendOperations.map(operation => /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
116
|
+
newLines: 2,
|
|
117
|
+
indent: 2,
|
|
118
|
+
children: `
|
|
119
|
+
/**
|
|
120
|
+
* Sends a ${operation.id()} message over the WebSocket connection.
|
|
121
|
+
*
|
|
122
|
+
* @param {Object} message - The message payload to send. Should match the schema defined in the AsyncAPI document.
|
|
123
|
+
* @param {WebSocket} [socket] - The WebSocket connection to use. If not provided, the client's own connection will be used.
|
|
124
|
+
* @throws {TypeError} If message cannot be stringified to JSON
|
|
125
|
+
* @throws {Error} If WebSocket connection is not in OPEN state
|
|
126
|
+
*/
|
|
127
|
+
static ${operation.id()}(message, socket) {
|
|
128
|
+
try {
|
|
129
|
+
socket.send(JSON.stringify(message));
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error('Error sending ${operation.id()} message:', error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Instance method version of ${operation.id()} that uses the client's own WebSocket connection.
|
|
136
|
+
* @param {Object} message - The message payload to send
|
|
137
|
+
* @throws {Error} If WebSocket connection is not established
|
|
138
|
+
*/
|
|
139
|
+
${operation.id()}(message){
|
|
140
|
+
if(!this.websocket){
|
|
141
|
+
throw new Error('WebSocket connection not established. Call connect() first.');
|
|
142
|
+
}
|
|
143
|
+
${clientName}.${operation.id()}(message, this.websocket);
|
|
144
|
+
}
|
|
145
|
+
`
|
|
146
|
+
}))
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function ModuleExport({
|
|
151
|
+
clientName
|
|
152
|
+
}) {
|
|
153
|
+
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
154
|
+
children: `module.exports = ${clientName};`
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function ClientClass({
|
|
159
|
+
clientName,
|
|
160
|
+
serverUrl,
|
|
161
|
+
title,
|
|
162
|
+
sendOperations
|
|
163
|
+
}) {
|
|
164
|
+
return /*#__PURE__*/jsxRuntime.jsxs(generatorReactSdk.Text, {
|
|
165
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
166
|
+
newLines: 2,
|
|
167
|
+
children: `class ${clientName} {`
|
|
168
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Constructor, {
|
|
169
|
+
serverUrl: serverUrl
|
|
170
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Connect, {
|
|
171
|
+
title: title
|
|
172
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.RegisterMessageHandler, {
|
|
173
|
+
language: "javascript",
|
|
174
|
+
methodParams: ['handler']
|
|
175
|
+
}), /*#__PURE__*/jsxRuntime.jsx(RegisterErrorHandler, {}), /*#__PURE__*/jsxRuntime.jsx(HandleMessage, {}), /*#__PURE__*/jsxRuntime.jsx(SendOperation, {
|
|
176
|
+
sendOperations: sendOperations,
|
|
177
|
+
clientName: clientName
|
|
178
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.CloseConnection, {
|
|
179
|
+
language: "javascript"
|
|
180
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
181
|
+
children: '}'
|
|
182
|
+
}), /*#__PURE__*/jsxRuntime.jsx(ModuleExport, {
|
|
183
|
+
clientName: clientName
|
|
184
|
+
})]
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function client_js ({
|
|
189
|
+
asyncapi,
|
|
190
|
+
params
|
|
191
|
+
}) {
|
|
192
|
+
const server = generatorHelpers.getServer(asyncapi.servers(), params.server);
|
|
193
|
+
const info = generatorHelpers.getInfo(asyncapi);
|
|
194
|
+
const title = generatorHelpers.getTitle(asyncapi);
|
|
195
|
+
const clientName = generatorHelpers.getClientName(asyncapi, params.appendClientSuffix, params.customClientName);
|
|
196
|
+
const serverUrl = generatorHelpers.getServerUrl(server);
|
|
197
|
+
const sendOperations = asyncapi.operations().filterBySend();
|
|
198
|
+
return /*#__PURE__*/jsxRuntime.jsxs(generatorReactSdk.File, {
|
|
199
|
+
name: params.clientFileName,
|
|
200
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(generatorComponents.FileHeaderInfo, {
|
|
201
|
+
info: info,
|
|
202
|
+
server: server,
|
|
203
|
+
language: "javascript"
|
|
204
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.DependencyProvider, {
|
|
205
|
+
language: "javascript"
|
|
206
|
+
}), /*#__PURE__*/jsxRuntime.jsx(ClientClass, {
|
|
207
|
+
clientName: clientName,
|
|
208
|
+
serverUrl: serverUrl,
|
|
209
|
+
title: title,
|
|
210
|
+
sendOperations: sendOperations
|
|
211
|
+
})]
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
module.exports = client_js;
|
|
216
|
+
//# sourceMappingURL=client.js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/Connect.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/RegisterErrorHandler.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/HandleMessage.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/SendOperation.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ModuleExport.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ClientClass.js","../../../../../../../../packages/templates/clients/websocket/javascript/template/client.js.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Constructor({ serverUrl }) {\n return (\n <Text indent={2}>\n {\n `/*\n * Constructor to initialize the WebSocket client\n * @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.\n*/\nconstructor(url) {\n this.url = url || '${serverUrl}';\n this.websocket = null;\n this.messageHandlers = [];\n this.errorHandlers = [];\n}\n`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Connect({ title }) {\n return (\n <Text newLines={2} indent={2}>\n {\n `// Method to establish a WebSocket connection\nconnect() {\n return new Promise((resolve, reject) => {\n this.websocket = new WebSocket(this.url);\n\n // On successful connection\n this.websocket.onopen = () => {\n console.log('Connected to ${title} server');\n resolve();\n };\n\n // On receiving a message\n this.websocket.onmessage = (event) => {\n if (this.messageHandlers.length > 0) {\n // Call custom message handlers\n this.messageHandlers.forEach(handler => {\n if (typeof handler === 'function') {\n this.handleMessage(event.data, handler);\n }\n });\n } else {\n // Default message logging\n console.log('Message received:', event.data);\n }\n };\n\n // On error first call custom error handlers, then default error behavior\n this.websocket.onerror = (error) => {\n if (this.errorHandlers.length > 0) {\n // Call custom error handlers\n this.errorHandlers.forEach(handler => handler(error));\n } else {\n // Default error behavior\n console.error('WebSocket Error:', error);\n }\n reject(error);\n };\n\n // On connection close\n this.websocket.onclose = () => {\n console.log('Disconnected from ${title} server');\n };\n });\n}`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function RegisterErrorHandler() {\n return (\n <Text newLines={2} indent={2}>\n {\n `// Method to register custom error handlers\nregisterErrorHandler(handler) {\n if (typeof handler === 'function') {\n this.errorHandlers.push(handler);\n } else {\n console.warn('Error handler must be a function');\n }\n}`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function HandleMessage() {\n return (\n <Text newLines={2} indent={2}>\n {\n `// Method to handle message with callback\nhandleMessage(message, cb) {\n if (cb) cb(message);\n}`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function SendOperation({ sendOperations, clientName }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n }\n\n return (\n <>\n {sendOperations.map((operation) => (\n <Text newLines={2} indent={2}>\n {`\n/**\n * Sends a ${operation.id()} message over the WebSocket connection.\n * \n * @param {Object} message - The message payload to send. Should match the schema defined in the AsyncAPI document.\n * @param {WebSocket} [socket] - The WebSocket connection to use. If not provided, the client's own connection will be used.\n * @throws {TypeError} If message cannot be stringified to JSON\n * @throws {Error} If WebSocket connection is not in OPEN state\n */\nstatic ${operation.id()}(message, socket) {\n try {\n socket.send(JSON.stringify(message));\n } catch (error) {\n console.error('Error sending ${operation.id()} message:', error);\n }\n}\n/**\n * Instance method version of ${operation.id()} that uses the client's own WebSocket connection.\n * @param {Object} message - The message payload to send\n * @throws {Error} If WebSocket connection is not established\n */\n${operation.id()}(message){\n if(!this.websocket){\n throw new Error('WebSocket connection not established. Call connect() first.');\n }\n ${clientName}.${operation.id()}(message, this.websocket);\n}\n `}\n </Text>\n ))}\n </>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function ModuleExport({ clientName }) {\n return (\n <Text>\n {\n `module.exports = ${clientName};`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { Connect } from './Connect';\nimport { RegisterErrorHandler } from './RegisterErrorHandler';\nimport { HandleMessage } from './HandleMessage';\nimport { SendOperation } from './SendOperation';\nimport { CloseConnection, RegisterMessageHandler } from '@asyncapi/generator-components';\nimport { ModuleExport } from './ModuleExport';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations}) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <Constructor serverUrl={serverUrl} />\n <Connect title={title} />\n <RegisterMessageHandler \n language=\"javascript\" \n methodParams={['handler']}\n />\n <RegisterErrorHandler />\n <HandleMessage />\n <SendOperation sendOperations={sendOperations} clientName={clientName} />\n <CloseConnection language=\"javascript\" />\n <Text>\n {'}'}\n </Text>\n <ModuleExport clientName={clientName} />\n </Text>\n );\n}\n","import { File } from '@asyncapi/generator-react-sdk';\nimport { getClientName, getServerUrl, getServer, getInfo, getTitle } from '@asyncapi/generator-helpers';\nimport { FileHeaderInfo, DependencyProvider } from '@asyncapi/generator-components';\nimport { ClientClass } from '../components/ClientClass';\n\nexport default function ({ asyncapi, params }) {\n const server = getServer(asyncapi.servers(), params.server);\n const info = getInfo(asyncapi);\n const title = getTitle(asyncapi);\n const clientName = getClientName(asyncapi, params.appendClientSuffix, params.customClientName);\n const serverUrl = getServerUrl(server);\n const sendOperations = asyncapi.operations().filterBySend();\n return (\n <File name={params.clientFileName}>\n <FileHeaderInfo\n info={info}\n server={server}\n language=\"javascript\"\n />\n <DependencyProvider language=\"javascript\"/>\n <ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />\n </File>\n );\n}\n"],"names":["Constructor","serverUrl","_jsx","Text","indent","children","Connect","title","newLines","RegisterErrorHandler","HandleMessage","SendOperation","sendOperations","clientName","length","_Fragment","map","operation","id","ModuleExport","ClientClass","_jsxs","RegisterMessageHandler","language","methodParams","CloseConnection","asyncapi","params","server","getServer","servers","info","getInfo","getTitle","getClientName","appendClientSuffix","customClientName","getServerUrl","operations","filterBySend","File","name","clientFileName","FileHeaderInfo","DependencyProvider"],"mappings":";;;;;;;;AAEO,SAASA,WAAWA,CAAC;AAAEC,EAAAA,SAAAA;AAAU,CAAC,EAAE;EACzC,oBACEC,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,MAAM,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAEZ,CAAA;AACR;AACA;AACA;AACA;AACA,qBAAA,EAAuBJ,SAAS,CAAA;AAChC;AACA;AACA;AACA;AACA,CAAA;AAAC,GAES,CAAC,CAAA;AAEX;;AClBO,SAASK,OAAOA,CAAC;AAAEC,EAAAA,KAAAA;AAAM,CAAC,EAAE;EACjC,oBACEL,cAAA,CAACC,sBAAI,EAAA;AAACK,IAAAA,QAAQ,EAAE,CAAE;AAACJ,IAAAA,MAAM,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAEzB,CAAA;AACR;AACA;AACA;AACA;AACA;AACA;AACA,gCAAA,EAAkCE,KAAK,CAAA;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qCAAA,EAAuCA,KAAK,CAAA;AAC5C;AACA;AACA,CAAA,CAAA;AAAE,GAEQ,CAAC,CAAA;AAEX;;ACnDO,SAASE,oBAAoBA,GAAG;EACrC,oBACEP,cAAA,CAACC,sBA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CAAC,CAAA;AAEX;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
import OperationHeader from './OperationHeader';
|
|
3
|
+
import MessageExamples from './MessageExamples';
|
|
4
|
+
|
|
5
|
+
export function AvailableOperations({ operations }) {
|
|
6
|
+
if (!operations || operations.length === 0) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<Text newLines={2}>### Available Operations</Text>
|
|
12
|
+
{operations.map((operation) => (
|
|
13
|
+
<Text newLines={2}>
|
|
14
|
+
<OperationHeader operation={operation} />
|
|
15
|
+
<MessageExamples operation={operation} />
|
|
16
|
+
</Text>
|
|
17
|
+
))}
|
|
18
|
+
</>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
import { Constructor } from './Constructor';
|
|
3
|
+
import { Connect } from './Connect';
|
|
4
|
+
import { RegisterErrorHandler } from './RegisterErrorHandler';
|
|
5
|
+
import { HandleMessage } from './HandleMessage';
|
|
6
|
+
import { SendOperation } from './SendOperation';
|
|
7
|
+
import { CloseConnection, RegisterMessageHandler } from '@asyncapi/generator-components';
|
|
8
|
+
import { ModuleExport } from './ModuleExport';
|
|
9
|
+
|
|
10
|
+
export function ClientClass({ clientName, serverUrl, title, sendOperations}) {
|
|
11
|
+
return (
|
|
12
|
+
<Text>
|
|
13
|
+
<Text newLines={2}>
|
|
14
|
+
{`class ${clientName} {`}
|
|
15
|
+
</Text>
|
|
16
|
+
<Constructor serverUrl={serverUrl} />
|
|
17
|
+
<Connect title={title} />
|
|
18
|
+
<RegisterMessageHandler
|
|
19
|
+
language="javascript"
|
|
20
|
+
methodParams={['handler']}
|
|
21
|
+
/>
|
|
22
|
+
<RegisterErrorHandler />
|
|
23
|
+
<HandleMessage />
|
|
24
|
+
<SendOperation sendOperations={sendOperations} clientName={clientName} />
|
|
25
|
+
<CloseConnection language="javascript" />
|
|
26
|
+
<Text>
|
|
27
|
+
{'}'}
|
|
28
|
+
</Text>
|
|
29
|
+
<ModuleExport clientName={clientName} />
|
|
30
|
+
</Text>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
export function Connect({ title }) {
|
|
4
|
+
return (
|
|
5
|
+
<Text newLines={2} indent={2}>
|
|
6
|
+
{
|
|
7
|
+
`// Method to establish a WebSocket connection
|
|
8
|
+
connect() {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
this.websocket = new WebSocket(this.url);
|
|
11
|
+
|
|
12
|
+
// On successful connection
|
|
13
|
+
this.websocket.onopen = () => {
|
|
14
|
+
console.log('Connected to ${title} server');
|
|
15
|
+
resolve();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// On receiving a message
|
|
19
|
+
this.websocket.onmessage = (event) => {
|
|
20
|
+
if (this.messageHandlers.length > 0) {
|
|
21
|
+
// Call custom message handlers
|
|
22
|
+
this.messageHandlers.forEach(handler => {
|
|
23
|
+
if (typeof handler === 'function') {
|
|
24
|
+
this.handleMessage(event.data, handler);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
// Default message logging
|
|
29
|
+
console.log('Message received:', event.data);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// On error first call custom error handlers, then default error behavior
|
|
34
|
+
this.websocket.onerror = (error) => {
|
|
35
|
+
if (this.errorHandlers.length > 0) {
|
|
36
|
+
// Call custom error handlers
|
|
37
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
38
|
+
} else {
|
|
39
|
+
// Default error behavior
|
|
40
|
+
console.error('WebSocket Error:', error);
|
|
41
|
+
}
|
|
42
|
+
reject(error);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// On connection close
|
|
46
|
+
this.websocket.onclose = () => {
|
|
47
|
+
console.log('Disconnected from ${title} server');
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}`
|
|
51
|
+
}
|
|
52
|
+
</Text>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
export function Constructor({ serverUrl }) {
|
|
4
|
+
return (
|
|
5
|
+
<Text indent={2}>
|
|
6
|
+
{
|
|
7
|
+
`/*
|
|
8
|
+
* Constructor to initialize the WebSocket client
|
|
9
|
+
* @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.
|
|
10
|
+
*/
|
|
11
|
+
constructor(url) {
|
|
12
|
+
this.url = url || '${serverUrl}';
|
|
13
|
+
this.websocket = null;
|
|
14
|
+
this.messageHandlers = [];
|
|
15
|
+
this.errorHandlers = [];
|
|
16
|
+
}
|
|
17
|
+
`
|
|
18
|
+
}
|
|
19
|
+
</Text>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
export function HandleMessage() {
|
|
4
|
+
return (
|
|
5
|
+
<Text newLines={2} indent={2}>
|
|
6
|
+
{
|
|
7
|
+
`// Method to handle message with callback
|
|
8
|
+
handleMessage(message, cb) {
|
|
9
|
+
if (cb) cb(message);
|
|
10
|
+
}`
|
|
11
|
+
}
|
|
12
|
+
</Text>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getMessageExamples, getOperationMessages } from '@asyncapi/generator-helpers';
|
|
2
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
3
|
+
|
|
4
|
+
export default function MessageExamples({operation}) {
|
|
5
|
+
const operationId = operation.id();
|
|
6
|
+
const messageExamples = [];
|
|
7
|
+
const messages = getOperationMessages(operation) || [];
|
|
8
|
+
|
|
9
|
+
messages.forEach((message) => {
|
|
10
|
+
const examples = getMessageExamples(message) || [];
|
|
11
|
+
examples.forEach((example) => {
|
|
12
|
+
const payload = example.payload();
|
|
13
|
+
messageExamples.push(`\n\n**Example:**\n\`\`\`javascript\nclient.${operationId}(${JSON.stringify(payload, null, 2)});\n\`\`\``);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return (
|
|
17
|
+
<Text>
|
|
18
|
+
{messageExamples.map(example => (
|
|
19
|
+
<Text>
|
|
20
|
+
{example}
|
|
21
|
+
</Text>
|
|
22
|
+
))}
|
|
23
|
+
</Text>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
export default function OperationHeader({operation}) {
|
|
4
|
+
const operationId = operation.id();
|
|
5
|
+
return (
|
|
6
|
+
<Text>
|
|
7
|
+
{`#### \`${operationId}(payload)\`
|
|
8
|
+
${operation.hasSummary() ? operation.summary() : ''}
|
|
9
|
+
${operation.hasDescription() ? `\n${operation.description()}` : ''}`}
|
|
10
|
+
</Text>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
export function RegisterErrorHandler() {
|
|
4
|
+
return (
|
|
5
|
+
<Text newLines={2} indent={2}>
|
|
6
|
+
{
|
|
7
|
+
`// Method to register custom error handlers
|
|
8
|
+
registerErrorHandler(handler) {
|
|
9
|
+
if (typeof handler === 'function') {
|
|
10
|
+
this.errorHandlers.push(handler);
|
|
11
|
+
} else {
|
|
12
|
+
console.warn('Error handler must be a function');
|
|
13
|
+
}
|
|
14
|
+
}`
|
|
15
|
+
}
|
|
16
|
+
</Text>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
+
|
|
3
|
+
export function SendOperation({ sendOperations, clientName }) {
|
|
4
|
+
if (!sendOperations || sendOperations.length === 0) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
{sendOperations.map((operation) => (
|
|
11
|
+
<Text newLines={2} indent={2}>
|
|
12
|
+
{`
|
|
13
|
+
/**
|
|
14
|
+
* Sends a ${operation.id()} message over the WebSocket connection.
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} message - The message payload to send. Should match the schema defined in the AsyncAPI document.
|
|
17
|
+
* @param {WebSocket} [socket] - The WebSocket connection to use. If not provided, the client's own connection will be used.
|
|
18
|
+
* @throws {TypeError} If message cannot be stringified to JSON
|
|
19
|
+
* @throws {Error} If WebSocket connection is not in OPEN state
|
|
20
|
+
*/
|
|
21
|
+
static ${operation.id()}(message, socket) {
|
|
22
|
+
try {
|
|
23
|
+
socket.send(JSON.stringify(message));
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Error sending ${operation.id()} message:', error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Instance method version of ${operation.id()} that uses the client's own WebSocket connection.
|
|
30
|
+
* @param {Object} message - The message payload to send
|
|
31
|
+
* @throws {Error} If WebSocket connection is not established
|
|
32
|
+
*/
|
|
33
|
+
${operation.id()}(message){
|
|
34
|
+
if(!this.websocket){
|
|
35
|
+
throw new Error('WebSocket connection not established. Call connect() first.');
|
|
36
|
+
}
|
|
37
|
+
${clientName}.${operation.id()}(message, this.websocket);
|
|
38
|
+
}
|
|
39
|
+
`}
|
|
40
|
+
</Text>
|
|
41
|
+
))}
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const WSClient = require('./test/temp/snapshotTestResult/custom_client_hoppscotch/client.js');
|
|
2
|
+
// Example usage
|
|
3
|
+
const wsClient = new WSClient();
|
|
4
|
+
|
|
5
|
+
// Example of how custom message handler that operates on incoming messages can look like
|
|
6
|
+
function myHandler(message) {
|
|
7
|
+
console.log('====================');
|
|
8
|
+
console.log('Just proving I got the message in myHandler:', message);
|
|
9
|
+
console.log('====================');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Example of custom error handler
|
|
13
|
+
function myErrorHandler(error) {
|
|
14
|
+
console.error('Errors from Websocket:', error.message);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
wsClient.registerMessageHandler(myHandler);
|
|
19
|
+
wsClient.registerErrorHandler(myErrorHandler);
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await wsClient.connect();
|
|
23
|
+
|
|
24
|
+
// Loop to send messages every 5 seconds
|
|
25
|
+
const interval = 5000; // 5 seconds
|
|
26
|
+
const message = 'Hello, Echo!';
|
|
27
|
+
|
|
28
|
+
while (true) {
|
|
29
|
+
try {
|
|
30
|
+
await wsClient.sendEchoMessage(message);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error('Error while sending message:', error);
|
|
33
|
+
}
|
|
34
|
+
// Wait for the interval before sending the next message
|
|
35
|
+
await new Promise(resolve => setTimeout(resolve, interval));
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error('Failed to connect to WebSocket:', error.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "core-template-client-websocket-javascript",
|
|
3
|
+
"private": true,
|
|
4
|
+
"description": "This is a template generating JavaScript websocket client",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "jest --coverage",
|
|
7
|
+
"test:update": "npm run test -- -u",
|
|
8
|
+
"lint": "eslint --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore .",
|
|
9
|
+
"lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore ."
|
|
10
|
+
},
|
|
11
|
+
"author": "Lukasz Gornicki <lpgornicki@gmail.com>",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@asyncapi/generator-react-sdk": "*",
|
|
15
|
+
"@asyncapi/generator-helpers": "1.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@asyncapi/parser": "^3.0.14",
|
|
19
|
+
"@babel/cli": "^7.25.9",
|
|
20
|
+
"@babel/core": "^7.26.0",
|
|
21
|
+
"@babel/preset-env": "^7.26.0",
|
|
22
|
+
"@babel/preset-react": "^7.25.9",
|
|
23
|
+
"jest-esm-transformer": "^1.0.0",
|
|
24
|
+
"eslint": "^6.8.0",
|
|
25
|
+
"eslint-plugin-jest": "^23.8.2",
|
|
26
|
+
"eslint-plugin-react": "^7.34.1",
|
|
27
|
+
"eslint-plugin-sonarjs": "^0.5.0"
|
|
28
|
+
},
|
|
29
|
+
"jest": {
|
|
30
|
+
"moduleFileExtensions": [
|
|
31
|
+
"js",
|
|
32
|
+
"json",
|
|
33
|
+
"jsx"
|
|
34
|
+
],
|
|
35
|
+
"transform": {
|
|
36
|
+
"^.+\\.jsx?$": "babel-jest"
|
|
37
|
+
},
|
|
38
|
+
"moduleNameMapper": {
|
|
39
|
+
"^nimma/legacy$": "<rootDir>/../../../../../node_modules/nimma/dist/legacy/cjs/index.js",
|
|
40
|
+
"^nimma/(.*)": "<rootDir>/../../../../../node_modules/nimma/dist/cjs/$1"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"babel": {
|
|
44
|
+
"presets": [
|
|
45
|
+
"@babel/preset-env",
|
|
46
|
+
[
|
|
47
|
+
"@babel/preset-react",
|
|
48
|
+
{
|
|
49
|
+
"runtime": "automatic"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|