@asyncapi/generator 3.2.2 → 3.2.3
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 +8 -0
- package/lib/logMessages.js +19 -0
- package/lib/parser.js +36 -16
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/ClientClass.js +7 -3
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/ClientClass.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/template/client.dart.js +10 -20
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/template/client.dart.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/ClientClass.js +7 -4
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/template/client.dart.js +2 -1
- package/lib/utils.js +1 -0
- package/package.json +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/SendEchoMessage.js +0 -27
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/__transpiled/components/SendEchoMessage.js.map +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/SendEchoMessage.js +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @asyncapi/generator
|
|
2
2
|
|
|
3
|
+
## 3.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 69c2fa1: The `mapBaseUrlToFolder` resolver now rejects `$ref`s that resolve outside the configured base folder. Previously a reference such as `https://schema.example.com/crm/../../../etc/passwd` was passed through unnormalized, letting a malicious AsyncAPI document read files outside the mapped folder (path traversal). References that escape the base folder are now blocked with an explicit error.
|
|
8
|
+
|
|
9
|
+
This only affects references that start with the mapped base URL and then use `../` to climb out of the mapped folder (e.g. `https://schema.example.com/crm/../shared/common.json` reaching a sibling folder). If you relied on this to reference files outside the mapped folder, map a higher-level base instead — e.g. map `https://schema.example.com/` to `./schemas/` and reference `https://schema.example.com/shared/common.json` directly — so the resolved paths stay within the mapped folder.
|
|
10
|
+
|
|
3
11
|
## 3.2.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/lib/logMessages.js
CHANGED
|
@@ -54,6 +54,22 @@ function compileEnabled(dir, output_dir) {
|
|
|
54
54
|
return `Transpilation of files ${dir} into ${output_dir} started.`;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
function mappedRefOutsideBaseFolder(ref, mappingKey) {
|
|
58
|
+
// Why: never interpolate the resolved host filesystem path here — it leaks the internal
|
|
59
|
+
// directory layout. Reference the configured mapping key (the mapped base url) instead.
|
|
60
|
+
return `Reference "${ref}" resolves to a location outside the mapped base folder "${mappingKey}" and was blocked to prevent path traversal.`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function mappedRefSymlinkOutsideBaseFolder(ref, mappingKey) {
|
|
64
|
+
// Why: same no-path-leak rule as above. This message is specific to the symlink branch so the
|
|
65
|
+
// user is told the escape happened through a symbolic link rather than `../` traversal.
|
|
66
|
+
return `Reference "${ref}" resolves a symbolic link that points outside the mapped base folder "${mappingKey}" and was blocked to prevent path traversal.`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function errorOpeningFile(filePath) {
|
|
70
|
+
return `Error opening file "${filePath}"`;
|
|
71
|
+
}
|
|
72
|
+
|
|
57
73
|
function fetchSpecError(link, status, statusText) {
|
|
58
74
|
return `Failed to fetch AsyncAPI document from ${link}: HTTP ${status}${statusText}`;
|
|
59
75
|
}
|
|
@@ -74,5 +90,8 @@ module.exports = {
|
|
|
74
90
|
conditionalFilesMatched,
|
|
75
91
|
compileEnabled,
|
|
76
92
|
skipOverwrite,
|
|
93
|
+
mappedRefOutsideBaseFolder,
|
|
94
|
+
mappedRefSymlinkOutsideBaseFolder,
|
|
95
|
+
errorOpeningFile,
|
|
77
96
|
fetchSpecError
|
|
78
97
|
};
|
package/lib/parser.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const utils = require('./utils');
|
|
3
|
+
const logMessages = require('./logMessages');
|
|
2
4
|
const { convertToOldAPI } = require('@asyncapi/parser');
|
|
3
5
|
const { ConvertDocumentParserAPIVersion, NewParser } = require('@asyncapi/multi-parser');
|
|
4
6
|
|
|
@@ -100,22 +102,40 @@ function getMapBaseUrlToFolderResolvers({ url: baseUrl, folder: baseDir }) {
|
|
|
100
102
|
const resolver = {
|
|
101
103
|
order: 1,
|
|
102
104
|
canRead: true,
|
|
103
|
-
read(uri) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
reject(`Error opening file "${localpath}"`);
|
|
105
|
+
async read(uri) {
|
|
106
|
+
const uriStr = uri.toString();
|
|
107
|
+
const localpath = uriStr.replace(baseUrl, baseDir);
|
|
108
|
+
// Why: a $ref under the mapped baseUrl can contain `../` segments that the parser passes
|
|
109
|
+
// through unnormalized, letting the resolved file path escape baseDir (path traversal).
|
|
110
|
+
// Only guard refs that actually fall under baseUrl so unrelated http(s) refs keep their behavior.
|
|
111
|
+
if (uriStr.startsWith(baseUrl)) {
|
|
112
|
+
const resolvedBase = path.resolve(baseDir);
|
|
113
|
+
const resolvedTarget = path.resolve(localpath);
|
|
114
|
+
// Lexical containment runs first: it rejects `../` traversal even when the target file
|
|
115
|
+
// does not exist (realpath below would throw ENOENT before we could report it).
|
|
116
|
+
if (resolvedTarget !== resolvedBase && !resolvedTarget.startsWith(resolvedBase + path.sep)) {
|
|
117
|
+
throw new Error(logMessages.mappedRefOutsideBaseFolder(uriStr, baseUrl));
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
+
// Why: path.resolve is purely lexical and ignores symlinks, so a symlink inside baseDir
|
|
120
|
+
// pointing elsewhere would pass the check above yet read a file outside baseDir.
|
|
121
|
+
// Canonicalize with realpath to close that gap. realpath needs the path to exist; a
|
|
122
|
+
// missing target is already proven contained lexically, so ENOENT is safe to ignore.
|
|
123
|
+
const realBase = await utils.realpath(resolvedBase);
|
|
124
|
+
const realTarget = await utils.realpath(resolvedTarget).catch((err) => {
|
|
125
|
+
if (err.code === 'ENOENT') return null;
|
|
126
|
+
throw err;
|
|
127
|
+
});
|
|
128
|
+
if (realTarget !== null && realTarget !== realBase && !realTarget.startsWith(realBase + path.sep)) {
|
|
129
|
+
// Why: reaching here means the lexical check above passed but canonicalization still
|
|
130
|
+
// escaped baseDir — that can only happen via a symlink, so report it as such.
|
|
131
|
+
throw new Error(logMessages.mappedRefSymlinkOutsideBaseFolder(uriStr, baseUrl));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return (await utils.readFile(localpath)).toString();
|
|
136
|
+
} catch (err) {
|
|
137
|
+
throw new Error(logMessages.errorOpeningFile(localpath));
|
|
138
|
+
}
|
|
119
139
|
}
|
|
120
140
|
};
|
|
121
141
|
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
require('source-map-support/register');
|
|
6
6
|
var generatorReactSdk = require('@asyncapi/generator-react-sdk');
|
|
7
7
|
var Constructor = require('./Constructor.js');
|
|
8
|
-
var SendEchoMessage = require('./SendEchoMessage.js');
|
|
9
8
|
var generatorComponents = require('@asyncapi/generator-components');
|
|
10
9
|
var ClientFields = require('./ClientFields.js');
|
|
11
10
|
var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/react/cjs/react-jsx-runtime.production.min.js');
|
|
@@ -13,7 +12,8 @@ var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/rea
|
|
|
13
12
|
function ClientClass({
|
|
14
13
|
clientName,
|
|
15
14
|
serverUrl,
|
|
16
|
-
title
|
|
15
|
+
title,
|
|
16
|
+
sendOperations
|
|
17
17
|
}) {
|
|
18
18
|
return /*#__PURE__*/jsxRuntime.jsxs(generatorReactSdk.Text, {
|
|
19
19
|
children: [/*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
@@ -37,7 +37,11 @@ function ClientClass({
|
|
|
37
37
|
methodParams: ['dynamic message', 'void Function(String) cb']
|
|
38
38
|
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.HandleError, {
|
|
39
39
|
language: "dart"
|
|
40
|
-
}), /*#__PURE__*/jsxRuntime.jsx(
|
|
40
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.SendOperations, {
|
|
41
|
+
language: "dart",
|
|
42
|
+
sendOperations: sendOperations,
|
|
43
|
+
clientName: clientName
|
|
44
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.CloseConnection, {
|
|
41
45
|
language: "dart"
|
|
42
46
|
}), /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
43
47
|
children: '}'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientClass.js","sources":["../../../../../../../../packages/templates/clients/websocket/dart/components/ClientClass.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport {
|
|
1
|
+
{"version":3,"file":"ClientClass.js","sources":["../../../../../../../../packages/templates/clients/websocket/dart/components/ClientClass.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage, HandleError } from '@asyncapi/generator-components';\nimport { ClientFields } from './ClientFields';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations }) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <ClientFields />\n <Constructor clientName={clientName} serverUrl={serverUrl} />\n <Connect language=\"dart\" title={title} />\n <RegisterMessageHandler \n language=\"dart\" \n methodParams={['void Function(String) handler']}\n />\n <RegisterErrorHandler\n language=\"dart\"\n methodParams={['void Function(Object) handler']}\n />\n <HandleMessage\n language=\"dart\" \n methodName=\"_handleMessage\"\n methodParams={['dynamic message', 'void Function(String) cb']}\n />\n <HandleError language=\"dart\" />\n <SendOperations\n language=\"dart\"\n sendOperations={sendOperations}\n clientName={clientName}\n />\n <CloseConnection language=\"dart\" />\n <Text>\n {'}'}\n </Text>\n </Text>\n );\n}\n"],"names":["ClientClass","clientName","serverUrl","title","sendOperations","_jsxs","Text","children","_jsx","newLines","ClientFields","Constructor","Connect","language","RegisterMessageHandler","methodParams","RegisterErrorHandler","HandleMessage","methodName","HandleError","SendOperations","CloseConnection"],"mappings":";;;;;;;;;;;AAKO,SAASA,WAAWA,CAAC;EAAEC,UAAU;EAAEC,SAAS;EAAEC,KAAK;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;EAC5E,oBACEC,eAAA,CAACC,sBAAI,EAAA;IAAAC,QAAA,EAAA,cACHC,cAAA,CAACF,sBAAI,EAAA;AAACG,MAAAA,QAAQ,EAAE,CAAE;MAAAF,QAAA,EACf,SAASN,UAAU,CAAA,EAAA,CAAA;KAChB,CAAC,eACPO,cAAA,CAACE,yBAAY,IAAE,CAAC,eAChBF,cAAA,CAACG,uBAAW,EAAA;AAACV,MAAAA,UAAU,EAAEA,UAAW;AAACC,MAAAA,SAAS,EAAEA,SAAAA;AAAU,KAAE,CAAC,eAC7DM,cAAA,CAACI,2BAAO,EAAA;AAACC,MAAAA,QAAQ,EAAC,MAAM;AAACV,MAAAA,KAAK,EAAEA,KAAAA;AAAM,KAAE,CAAC,eACzCK,cAAA,CAACM,0CAAsB,EAAA;AACrBD,MAAAA,QAAQ,EAAC,MAAM;MACfE,YAAY,EAAE,CAAC,+BAA+B,CAAA;AAAE,KACjD,CAAC,eACFP,cAAA,CAACQ,wCAAoB,EAAA;AACnBH,MAAAA,QAAQ,EAAC,MAAM;MACfE,YAAY,EAAE,CAAC,+BAA+B,CAAA;AAAE,KACjD,CAAC,eACFP,cAAA,CAACS,iCAAa,EAAA;AACZJ,MAAAA,QAAQ,EAAC,MAAM;AACfK,MAAAA,UAAU,EAAC,gBAAgB;AAC3BH,MAAAA,YAAY,EAAE,CAAC,iBAAiB,EAAE,0BAA0B,CAAA;AAAE,KAC/D,CAAC,eACFP,cAAA,CAACW,+BAAW,EAAA;AAACN,MAAAA,QAAQ,EAAC,MAAA;AAAM,KAAE,CAAC,eAC/BL,cAAA,CAACY,kCAAc,EAAA;AACbP,MAAAA,QAAQ,EAAC,MAAM;AACfT,MAAAA,cAAc,EAAEA,cAAe;AAC/BH,MAAAA,UAAU,EAAEA,UAAAA;AAAW,KACxB,CAAC,eACFO,cAAA,CAACa,mCAAe,EAAA;AAACR,MAAAA,QAAQ,EAAC,MAAA;AAAM,KAAE,CAAC,eACnCL,cAAA,CAACF,sBAAI,EAAA;AAAAC,MAAAA,QAAA,EACF,GAAA;AAAG,KACA,CAAC,CAAA;AAAA,GACH,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -23,23 +23,6 @@ ${clientName}({String? url})
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function SendEchoMessage() {
|
|
27
|
-
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
28
|
-
newLines: 2,
|
|
29
|
-
indent: 2,
|
|
30
|
-
children: `/// Method to send an echo message to the server
|
|
31
|
-
void sendEchoMessage(dynamic message) {
|
|
32
|
-
if (_channel == null) {
|
|
33
|
-
print('Error: WebSocket is not connected.');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
final payload = message is String ? message : jsonEncode(message);
|
|
37
|
-
_channel!.sink.add(payload);
|
|
38
|
-
print('Sent message to echo server: $payload');
|
|
39
|
-
}`
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
26
|
function ClientFields() {
|
|
44
27
|
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
45
28
|
indent: 2,
|
|
@@ -54,7 +37,8 @@ final List<void Function(Object)> _errorHandlers = [];`
|
|
|
54
37
|
function ClientClass({
|
|
55
38
|
clientName,
|
|
56
39
|
serverUrl,
|
|
57
|
-
title
|
|
40
|
+
title,
|
|
41
|
+
sendOperations
|
|
58
42
|
}) {
|
|
59
43
|
return /*#__PURE__*/jsxRuntime.jsxs(generatorReactSdk.Text, {
|
|
60
44
|
children: [/*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
@@ -78,7 +62,11 @@ function ClientClass({
|
|
|
78
62
|
methodParams: ['dynamic message', 'void Function(String) cb']
|
|
79
63
|
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.HandleError, {
|
|
80
64
|
language: "dart"
|
|
81
|
-
}), /*#__PURE__*/jsxRuntime.jsx(
|
|
65
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.SendOperations, {
|
|
66
|
+
language: "dart",
|
|
67
|
+
sendOperations: sendOperations,
|
|
68
|
+
clientName: clientName
|
|
69
|
+
}), /*#__PURE__*/jsxRuntime.jsx(generatorComponents.CloseConnection, {
|
|
82
70
|
language: "dart"
|
|
83
71
|
}), /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
84
72
|
children: '}'
|
|
@@ -95,6 +83,7 @@ function client_dart ({
|
|
|
95
83
|
const title = generatorHelpers.getTitle(asyncapi);
|
|
96
84
|
const clientName = generatorHelpers.getClientName(asyncapi, params.appendClientSuffix, params.customClientName);
|
|
97
85
|
const serverUrl = generatorHelpers.getServerUrl(server);
|
|
86
|
+
const sendOperations = asyncapi.operations().filterBySend();
|
|
98
87
|
return (
|
|
99
88
|
/*#__PURE__*/
|
|
100
89
|
// The clientFileName default values can be found and modified under the package.json
|
|
@@ -109,7 +98,8 @@ function client_dart ({
|
|
|
109
98
|
}), /*#__PURE__*/jsxRuntime.jsx(ClientClass, {
|
|
110
99
|
clientName: clientName,
|
|
111
100
|
serverUrl: serverUrl,
|
|
112
|
-
title: title
|
|
101
|
+
title: title,
|
|
102
|
+
sendOperations: sendOperations
|
|
113
103
|
})]
|
|
114
104
|
})
|
|
115
105
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.dart.js","sources":["../../../../../../../../packages/templates/clients/websocket/dart/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/dart/components/
|
|
1
|
+
{"version":3,"file":"client.dart.js","sources":["../../../../../../../../packages/templates/clients/websocket/dart/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/dart/components/ClientFields.js","../../../../../../../../packages/templates/clients/websocket/dart/components/ClientClass.js","../../../../../../../../packages/templates/clients/websocket/dart/template/client.dart.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Constructor({ clientName, serverUrl }) {\n return (\n <Text newLines={2} indent={2}>\n {\n `\n/// Constructor to initialize the WebSocket client\n/// \n/// [url] - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.\n${clientName}({String? url})\n : _url = url ?? '${serverUrl}';\n`}\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function ClientFields() {\n return (\n <Text indent={2} newLines={2}>\n {`final String _url;\nWebSocketChannel? _channel;\nfinal List<void Function(String)> _messageHandlers = [];\nfinal List<void Function(Object)> _errorHandlers = [];`}\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage, HandleError } from '@asyncapi/generator-components';\nimport { ClientFields } from './ClientFields';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations }) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <ClientFields />\n <Constructor clientName={clientName} serverUrl={serverUrl} />\n <Connect language=\"dart\" title={title} />\n <RegisterMessageHandler \n language=\"dart\" \n methodParams={['void Function(String) handler']}\n />\n <RegisterErrorHandler\n language=\"dart\"\n methodParams={['void Function(Object) handler']}\n />\n <HandleMessage\n language=\"dart\" \n methodName=\"_handleMessage\"\n methodParams={['dynamic message', 'void Function(String) cb']}\n />\n <HandleError language=\"dart\" />\n <SendOperations\n language=\"dart\"\n sendOperations={sendOperations}\n clientName={clientName}\n />\n <CloseConnection language=\"dart\" />\n <Text>\n {'}'}\n </Text>\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 // The clientFileName default values can be found and modified under the package.json\n <File name={params.clientFileName}>\n <FileHeaderInfo\n info={info}\n server={server}\n language=\"dart\"\n />\n <DependencyProvider language=\"dart\" />\n <ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />\n </File>\n );\n}\n"],"names":["Constructor","clientName","serverUrl","_jsx","Text","newLines","indent","children","ClientFields","ClientClass","title","sendOperations","_jsxs","Connect","language","RegisterMessageHandler","methodParams","RegisterErrorHandler","HandleMessage","methodName","HandleError","SendOperations","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;EAAEC,UAAU;AAAEC,EAAAA,SAAAA;AAAU,CAAC,EAAE;EACrD,oBACEC,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,QAAQ,EAAE,CAAE;AAACC,IAA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AA;MAACC,IAAI,EAAEd,MAAM,CAACe,cAAe;MAAAhC,QAAA,EAAA,cAChCJ,cAAA,CAACqC,kCAAc,EAAA;AACbZ,QAAAA,IAAI,EAAEA,IAAK;AACXH,QAAAA,MAAM,EAAEA,MAAO;AACfX,QAAAA,QAAQ,EAAC,MAAA;AAAM,OAChB,CAAC,eACFX,cAAA,CAACsC,sCAAkB,EAAA;AAAC3B,QAAAA,QAAQ,EAAC,MAAA;AAAM,OAAE,CAAC,eACtCX,cAAA,CAACM,WAAW,EAAA;AAACR,QAAAA,UAAU,EAAEA,UAAW;AAACC,QAAAA,SAAS,EAAEA,SAAU;AAACQ,QAAAA,KAAK,EAAEA,KAAM;AAACC,QAAAA,cAAc,EAAEA,cAAAA;AAAe,OAAE,CAAC,CAAA;KACvG,CAAA;AAAC,IAAA;AAEX;;;;"}
|
package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/components/ClientClass.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
2
|
import { Constructor } from './Constructor';
|
|
3
|
-
import {
|
|
4
|
-
import { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, Connect, HandleMessage, HandleError } from '@asyncapi/generator-components';
|
|
3
|
+
import { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage, HandleError } from '@asyncapi/generator-components';
|
|
5
4
|
import { ClientFields } from './ClientFields';
|
|
6
5
|
|
|
7
|
-
export function ClientClass({ clientName, serverUrl, title }) {
|
|
6
|
+
export function ClientClass({ clientName, serverUrl, title, sendOperations }) {
|
|
8
7
|
return (
|
|
9
8
|
<Text>
|
|
10
9
|
<Text newLines={2}>
|
|
@@ -27,7 +26,11 @@ export function ClientClass({ clientName, serverUrl, title }) {
|
|
|
27
26
|
methodParams={['dynamic message', 'void Function(String) cb']}
|
|
28
27
|
/>
|
|
29
28
|
<HandleError language="dart" />
|
|
30
|
-
<
|
|
29
|
+
<SendOperations
|
|
30
|
+
language="dart"
|
|
31
|
+
sendOperations={sendOperations}
|
|
32
|
+
clientName={clientName}
|
|
33
|
+
/>
|
|
31
34
|
<CloseConnection language="dart" />
|
|
32
35
|
<Text>
|
|
33
36
|
{'}'}
|
package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/template/client.dart.js
CHANGED
|
@@ -9,6 +9,7 @@ export default function ({ asyncapi, params }) {
|
|
|
9
9
|
const title = getTitle(asyncapi);
|
|
10
10
|
const clientName = getClientName(asyncapi, params.appendClientSuffix, params.customClientName);
|
|
11
11
|
const serverUrl = getServerUrl(server);
|
|
12
|
+
const sendOperations = asyncapi.operations().filterBySend();
|
|
12
13
|
return (
|
|
13
14
|
// The clientFileName default values can be found and modified under the package.json
|
|
14
15
|
<File name={params.clientFileName}>
|
|
@@ -18,7 +19,7 @@ export default function ({ asyncapi, params }) {
|
|
|
18
19
|
language="dart"
|
|
19
20
|
/>
|
|
20
21
|
<DependencyProvider language="dart" />
|
|
21
|
-
<ClientClass clientName={clientName} serverUrl={serverUrl} title={title} />
|
|
22
|
+
<ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />
|
|
22
23
|
</File>
|
|
23
24
|
);
|
|
24
25
|
}
|
package/lib/utils.js
CHANGED
|
@@ -17,6 +17,7 @@ const utils = module.exports;
|
|
|
17
17
|
utils.lstat = util.promisify(fs.lstat);
|
|
18
18
|
utils.readlink = util.promisify(fs.readlink);
|
|
19
19
|
utils.readFile = util.promisify(fs.readFile);
|
|
20
|
+
utils.realpath = util.promisify(fs.realpath);
|
|
20
21
|
utils.writeFile = util.promisify(fs.writeFile);
|
|
21
22
|
utils.copyFile = util.promisify(fs.copyFile);
|
|
22
23
|
utils.readDir = util.promisify(fs.readdir);
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
require('source-map-support/register');
|
|
6
|
-
var generatorReactSdk = require('@asyncapi/generator-react-sdk');
|
|
7
|
-
var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/react/cjs/react-jsx-runtime.production.min.js');
|
|
8
|
-
|
|
9
|
-
function SendEchoMessage() {
|
|
10
|
-
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
11
|
-
newLines: 2,
|
|
12
|
-
indent: 2,
|
|
13
|
-
children: `/// Method to send an echo message to the server
|
|
14
|
-
void sendEchoMessage(dynamic message) {
|
|
15
|
-
if (_channel == null) {
|
|
16
|
-
print('Error: WebSocket is not connected.');
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
final payload = message is String ? message : jsonEncode(message);
|
|
20
|
-
_channel!.sink.add(payload);
|
|
21
|
-
print('Sent message to echo server: $payload');
|
|
22
|
-
}`
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.SendEchoMessage = SendEchoMessage;
|
|
27
|
-
//# sourceMappingURL=SendEchoMessage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SendEchoMessage.js","sources":["../../../../../../../../packages/templates/clients/websocket/dart/components/SendEchoMessage.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function SendEchoMessage() {\n return (\n <Text newLines={2} indent={2}>\n {\n `/// Method to send an echo message to the server\nvoid sendEchoMessage(dynamic message) {\n if (_channel == null) {\n print('Error: WebSocket is not connected.');\n return;\n }\n final payload = message is String ? message : jsonEncode(message);\n _channel!.sink.add(payload);\n print('Sent message to echo server: $payload');\n}`\n }\n </Text>\n );\n}\n"],"names":["SendEchoMessage","_jsx","Text","newLines","indent","children"],"mappings":";;;;;;;;AAEO,SAASA,eAAeA,GAAG;EAChC,oBACEC,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,QAAQ,EAAE,CAAE;AAACC,IAAAA,MAAM,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAEzB,CAAA;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAA,CAAA;AAAE,GAEQ,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Text } from '@asyncapi/generator-react-sdk';
|
|
2
|
-
|
|
3
|
-
export function SendEchoMessage() {
|
|
4
|
-
return (
|
|
5
|
-
<Text newLines={2} indent={2}>
|
|
6
|
-
{
|
|
7
|
-
`/// Method to send an echo message to the server
|
|
8
|
-
void sendEchoMessage(dynamic message) {
|
|
9
|
-
if (_channel == null) {
|
|
10
|
-
print('Error: WebSocket is not connected.');
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
final payload = message is String ? message : jsonEncode(message);
|
|
14
|
-
_channel!.sink.add(payload);
|
|
15
|
-
print('Sent message to echo server: $payload');
|
|
16
|
-
}`
|
|
17
|
-
}
|
|
18
|
-
</Text>
|
|
19
|
-
);
|
|
20
|
-
}
|