@alagoni97/cli 0.72.1
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/LICENSE +201 -0
- package/README.md +336 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.mjs +3 -0
- package/bin/run.cmd +3 -0
- package/bin/run.mjs +4 -0
- package/dist/LoggingInterface.d.ts +123 -0
- package/dist/LoggingInterface.js +300 -0
- package/dist/PersistedConfig.d.ts +46 -0
- package/dist/PersistedConfig.js +94 -0
- package/dist/browser/adapters/output.d.ts +69 -0
- package/dist/browser/adapters/output.js +91 -0
- package/dist/browser/config.d.ts +18 -0
- package/dist/browser/config.js +59 -0
- package/dist/browser/generate.d.ts +20 -0
- package/dist/browser/generate.js +129 -0
- package/dist/browser/index.d.ts +17 -0
- package/dist/browser/index.js +26 -0
- package/dist/browser/parser.d.ts +9 -0
- package/dist/browser/parser.js +61 -0
- package/dist/browser/shims/asyncapi-parser.d.ts +30 -0
- package/dist/browser/shims/asyncapi-parser.js +52 -0
- package/dist/browser/shims/fs.d.ts +190 -0
- package/dist/browser/shims/fs.js +188 -0
- package/dist/browser/shims/json-schema-ref-parser.d.ts +73 -0
- package/dist/browser/shims/json-schema-ref-parser.js +246 -0
- package/dist/browser/shims/swagger-parser.d.ts +20 -0
- package/dist/browser/shims/swagger-parser.js +40 -0
- package/dist/codegen/configurationSchemaBuilder.d.ts +15 -0
- package/dist/codegen/configurationSchemaBuilder.js +48 -0
- package/dist/codegen/configurations.d.ts +29 -0
- package/dist/codegen/configurations.js +260 -0
- package/dist/codegen/detection.d.ts +19 -0
- package/dist/codegen/detection.js +174 -0
- package/dist/codegen/errors.d.ts +111 -0
- package/dist/codegen/errors.js +352 -0
- package/dist/codegen/generators/generic/custom.d.ts +75 -0
- package/dist/codegen/generators/generic/custom.js +66 -0
- package/dist/codegen/generators/index.d.ts +14 -0
- package/dist/codegen/generators/index.js +42 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.js +131 -0
- package/dist/codegen/generators/typescript/channels/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/index.js +142 -0
- package/dist/codegen/generators/typescript/channels/openapi.d.ts +9 -0
- package/dist/codegen/generators/typescript/channels/openapi.js +168 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.js +106 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.js +102 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.js +133 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.js +144 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.js +132 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.d.ts +14 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.js +800 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.js +96 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.d.ts +48 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.js +491 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.js +127 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.js +108 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.js +154 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.js +58 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.js +113 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.js +99 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.js +186 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.js +90 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.js +142 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.js +143 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.js +89 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.js +146 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.d.ts +35 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.js +120 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.js +152 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.js +64 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.js +115 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.js +151 -0
- package/dist/codegen/generators/typescript/channels/types.d.ts +181 -0
- package/dist/codegen/generators/typescript/channels/types.js +131 -0
- package/dist/codegen/generators/typescript/channels/utils.d.ts +64 -0
- package/dist/codegen/generators/typescript/channels/utils.js +163 -0
- package/dist/codegen/generators/typescript/client/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/client/index.js +61 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.js +53 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.js +90 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.js +83 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.js +54 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.js +82 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.d.ts +2 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.js +182 -0
- package/dist/codegen/generators/typescript/client/types.d.ts +49 -0
- package/dist/codegen/generators/typescript/client/types.js +37 -0
- package/dist/codegen/generators/typescript/headers.d.ts +54 -0
- package/dist/codegen/generators/typescript/headers.js +138 -0
- package/dist/codegen/generators/typescript/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/index.js +38 -0
- package/dist/codegen/generators/typescript/models.d.ts +21761 -0
- package/dist/codegen/generators/typescript/models.js +64 -0
- package/dist/codegen/generators/typescript/parameters.d.ts +37 -0
- package/dist/codegen/generators/typescript/parameters.js +101 -0
- package/dist/codegen/generators/typescript/payloads.d.ts +73 -0
- package/dist/codegen/generators/typescript/payloads.js +250 -0
- package/dist/codegen/generators/typescript/types.d.ts +34 -0
- package/dist/codegen/generators/typescript/types.js +70 -0
- package/dist/codegen/generators/typescript/utils.d.ts +38 -0
- package/dist/codegen/generators/typescript/utils.js +195 -0
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +38 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.js +41 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.d.ts +14 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.js +120 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.d.ts +16 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.js +124 -0
- package/dist/codegen/inputs/asyncapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/asyncapi/generators/types.js +61 -0
- package/dist/codegen/inputs/asyncapi/index.d.ts +1 -0
- package/dist/codegen/inputs/asyncapi/index.js +7 -0
- package/dist/codegen/inputs/asyncapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/asyncapi/parser.js +90 -0
- package/dist/codegen/inputs/index.d.ts +3 -0
- package/dist/codegen/inputs/index.js +19 -0
- package/dist/codegen/inputs/jsonschema/generators/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/generators/index.js +5 -0
- package/dist/codegen/inputs/jsonschema/generators/models.d.ts +7 -0
- package/dist/codegen/inputs/jsonschema/generators/models.js +26 -0
- package/dist/codegen/inputs/jsonschema/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/index.js +7 -0
- package/dist/codegen/inputs/jsonschema/parser.d.ts +31 -0
- package/dist/codegen/inputs/jsonschema/parser.js +128 -0
- package/dist/codegen/inputs/openapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/headers.js +101 -0
- package/dist/codegen/inputs/openapi/generators/parameters.d.ts +10 -0
- package/dist/codegen/inputs/openapi/generators/parameters.js +852 -0
- package/dist/codegen/inputs/openapi/generators/payloads.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/payloads.js +231 -0
- package/dist/codegen/inputs/openapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/openapi/generators/types.js +86 -0
- package/dist/codegen/inputs/openapi/index.d.ts +2 -0
- package/dist/codegen/inputs/openapi/index.js +8 -0
- package/dist/codegen/inputs/openapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/openapi/parser.js +115 -0
- package/dist/codegen/inputs/openapi/security.d.ts +56 -0
- package/dist/codegen/inputs/openapi/security.js +193 -0
- package/dist/codegen/modelina/index.d.ts +2 -0
- package/dist/codegen/modelina/index.js +20 -0
- package/dist/codegen/modelina/presets/index.d.ts +3 -0
- package/dist/codegen/modelina/presets/index.js +14 -0
- package/dist/codegen/modelina/presets/primitives.d.ts +34 -0
- package/dist/codegen/modelina/presets/primitives.js +211 -0
- package/dist/codegen/modelina/presets/union.d.ts +33 -0
- package/dist/codegen/modelina/presets/union.js +197 -0
- package/dist/codegen/modelina/presets/validation.d.ts +66 -0
- package/dist/codegen/modelina/presets/validation.js +183 -0
- package/dist/codegen/modelina/types.d.ts +61845 -0
- package/dist/codegen/modelina/types.js +412 -0
- package/dist/codegen/output/filesystem.d.ts +30 -0
- package/dist/codegen/output/filesystem.js +61 -0
- package/dist/codegen/output/index.d.ts +16 -0
- package/dist/codegen/output/index.js +57 -0
- package/dist/codegen/output/memory.d.ts +54 -0
- package/dist/codegen/output/memory.js +81 -0
- package/dist/codegen/output/modelina.d.ts +30 -0
- package/dist/codegen/output/modelina.js +30 -0
- package/dist/codegen/output/types.d.ts +47 -0
- package/dist/codegen/output/types.js +6 -0
- package/dist/codegen/renderer.d.ts +13 -0
- package/dist/codegen/renderer.js +309 -0
- package/dist/codegen/schemaPostProcess.d.ts +25 -0
- package/dist/codegen/schemaPostProcess.js +38 -0
- package/dist/codegen/types.d.ts +285187 -0
- package/dist/codegen/types.js +177 -0
- package/dist/codegen/utils.d.ts +126 -0
- package/dist/codegen/utils.js +373 -0
- package/dist/commands/base.d.ts +18 -0
- package/dist/commands/base.js +59 -0
- package/dist/commands/generate.d.ts +46 -0
- package/dist/commands/generate.js +305 -0
- package/dist/commands/init.d.ts +55 -0
- package/dist/commands/init.js +544 -0
- package/dist/commands/telemetry.d.ts +25 -0
- package/dist/commands/telemetry.js +115 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +35 -0
- package/dist/telemetry/anonymize.d.ts +19 -0
- package/dist/telemetry/anonymize.js +73 -0
- package/dist/telemetry/collector.d.ts +26 -0
- package/dist/telemetry/collector.js +57 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +97 -0
- package/dist/telemetry/events.d.ts +72 -0
- package/dist/telemetry/events.js +5 -0
- package/dist/telemetry/index.d.ts +46 -0
- package/dist/telemetry/index.js +91 -0
- package/dist/telemetry/notice.d.ts +8 -0
- package/dist/telemetry/notice.js +50 -0
- package/dist/telemetry/sender.d.ts +14 -0
- package/dist/telemetry/sender.js +125 -0
- package/dist/utils/gitignore.d.ts +66 -0
- package/dist/utils/gitignore.js +111 -0
- package/dist/utils/inputSource.d.ts +3 -0
- package/dist/utils/inputSource.js +26 -0
- package/dist/utils/refResolvers.d.ts +29 -0
- package/dist/utils/refResolvers.js +83 -0
- package/dist/utils/remoteFetch.d.ts +18 -0
- package/dist/utils/remoteFetch.js +64 -0
- package/oclif.manifest.json +510 -0
- package/package.json +155 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderWebSocketSubscribe = void 0;
|
|
4
|
+
/* eslint-disable sonarjs/no-nested-template-literals */
|
|
5
|
+
/* eslint-disable sonarjs/no-duplicate-string */
|
|
6
|
+
const __1 = require("../..");
|
|
7
|
+
const utils_1 = require("../../../utils");
|
|
8
|
+
const utils_2 = require("../../utils");
|
|
9
|
+
function renderWebSocketSubscribe({ topic, messageType, messageModule, channelParameters, subName = (0, utils_1.pascalCase)(topic), functionName = `subscribeTo${subName}`, description, deprecated }) {
|
|
10
|
+
let messageUnmarshalling = `${messageType}.unmarshal(receivedData)`;
|
|
11
|
+
if (messageModule) {
|
|
12
|
+
messageUnmarshalling = `${messageModule}.unmarshal(receivedData)`;
|
|
13
|
+
}
|
|
14
|
+
messageType = messageModule ? `${messageModule}.${messageType}` : messageType;
|
|
15
|
+
const callbackParameters = [
|
|
16
|
+
'err?: Error',
|
|
17
|
+
`msg?: ${messageType}`,
|
|
18
|
+
...(channelParameters ? [`parameters?: ${channelParameters.type}`] : []),
|
|
19
|
+
'ws?: WebSocket.WebSocket'
|
|
20
|
+
];
|
|
21
|
+
const callbackArguments = [
|
|
22
|
+
'err: undefined',
|
|
23
|
+
'msg: parsedMessage',
|
|
24
|
+
...(channelParameters ? ['parameters'] : []),
|
|
25
|
+
'ws'
|
|
26
|
+
];
|
|
27
|
+
const errorCallbackArguments = [
|
|
28
|
+
'err: new Error(`Failed to parse message: ${error.message}`)',
|
|
29
|
+
'msg: undefined',
|
|
30
|
+
...(channelParameters ? ['parameters'] : []),
|
|
31
|
+
'ws'
|
|
32
|
+
];
|
|
33
|
+
const functionParameters = [
|
|
34
|
+
{
|
|
35
|
+
parameter: `onDataCallback`,
|
|
36
|
+
parameterType: `onDataCallback: (params: {${callbackParameters.join(', ')}}) => void`,
|
|
37
|
+
jsDoc: ' * @param onDataCallback callback when messages are received'
|
|
38
|
+
},
|
|
39
|
+
...(channelParameters
|
|
40
|
+
? [
|
|
41
|
+
{
|
|
42
|
+
parameter: `parameters`,
|
|
43
|
+
parameterType: `parameters: ${channelParameters.type}`,
|
|
44
|
+
jsDoc: ' * @param parameters for URL path substitution'
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
: []),
|
|
48
|
+
{
|
|
49
|
+
parameter: 'ws',
|
|
50
|
+
parameterType: 'ws: WebSocket.WebSocket',
|
|
51
|
+
jsDoc: ' * @param ws the WebSocket connection (assumed to be already connected)'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
parameter: 'skipMessageValidation = false',
|
|
55
|
+
parameterType: 'skipMessageValidation?: boolean',
|
|
56
|
+
jsDoc: ' * @param skipMessageValidation turn off runtime validation of incoming messages'
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
const jsDoc = (0, utils_2.renderChannelJSDoc)({
|
|
60
|
+
description,
|
|
61
|
+
deprecated,
|
|
62
|
+
fallbackDescription: `WebSocket client-side function to subscribe to messages from \`${topic}\``,
|
|
63
|
+
parameters: functionParameters.map((param) => ({
|
|
64
|
+
jsDoc: param.jsDoc
|
|
65
|
+
}))
|
|
66
|
+
});
|
|
67
|
+
const code = `${jsDoc}
|
|
68
|
+
function ${functionName}({
|
|
69
|
+
${functionParameters.map((param) => param.parameter).join(',\n ')}
|
|
70
|
+
}: {
|
|
71
|
+
${functionParameters.map((param) => param.parameterType).join(',\n ')}
|
|
72
|
+
}): void {
|
|
73
|
+
try {
|
|
74
|
+
// Check if WebSocket is open
|
|
75
|
+
if (ws.readyState !== WebSocket.WebSocket.OPEN) {
|
|
76
|
+
onDataCallback({
|
|
77
|
+
err: new Error('WebSocket is not open'),
|
|
78
|
+
msg: undefined,${channelParameters ? '\n parameters,' : ''}
|
|
79
|
+
ws
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const validator = ${messageModule ? `${messageModule}.createValidator()` : `${messageType}.createValidator()`};
|
|
85
|
+
|
|
86
|
+
ws.on('message', (data: WebSocket.RawData) => {
|
|
87
|
+
try {
|
|
88
|
+
const receivedData = data.toString();
|
|
89
|
+
const parsedMessage = ${messageUnmarshalling};
|
|
90
|
+
|
|
91
|
+
// Validate message if validation is enabled
|
|
92
|
+
if (!skipMessageValidation) {
|
|
93
|
+
const messageToValidate = ${messageModule ? `${messageModule}.marshal(parsedMessage)` : `parsedMessage.marshal()`};
|
|
94
|
+
const {valid, errors} = ${messageModule ? `${messageModule}.validate({data: messageToValidate, ajvValidatorFunction: validator})` : `${messageType}.validate({data: messageToValidate, ajvValidatorFunction: validator})`};
|
|
95
|
+
if (!valid) {
|
|
96
|
+
onDataCallback({
|
|
97
|
+
err: new Error(\`Invalid message payload received; \${JSON.stringify({cause: errors})}\`),
|
|
98
|
+
msg: undefined,${channelParameters ? '\n parameters,' : ''}
|
|
99
|
+
ws
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
onDataCallback({
|
|
106
|
+
${callbackArguments.join(',\n ')}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
} catch (error: any) {
|
|
110
|
+
onDataCallback({
|
|
111
|
+
${errorCallbackArguments.join(',\n ')}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
ws.on('error', (error: Error) => {
|
|
117
|
+
onDataCallback({
|
|
118
|
+
err: new Error(\`WebSocket error: \${error.message}\`),
|
|
119
|
+
msg: undefined,${channelParameters ? '\n parameters,' : ''}
|
|
120
|
+
ws
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
ws.on('close', (code: number, reason: Buffer) => {
|
|
125
|
+
// Only report as error if it's not a normal closure (1000) or going away (1001)
|
|
126
|
+
if (code !== 1000 && code !== 1001 && code !== 1005) { // 1005 is no status received
|
|
127
|
+
onDataCallback({
|
|
128
|
+
err: new Error(\`WebSocket closed unexpectedly: \${code} \${reason.toString()}\`),
|
|
129
|
+
msg: undefined,${channelParameters ? '\n parameters,' : ''}
|
|
130
|
+
ws
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
} catch (error: any) {
|
|
136
|
+
onDataCallback({
|
|
137
|
+
err: new Error(\`Failed to set up WebSocket subscription: \${error.message}\`),
|
|
138
|
+
msg: undefined,${channelParameters ? '\n parameters,' : ''}
|
|
139
|
+
ws
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}`;
|
|
143
|
+
return {
|
|
144
|
+
messageType,
|
|
145
|
+
code,
|
|
146
|
+
functionName,
|
|
147
|
+
dependencies: [`import * as WebSocket from 'ws';`],
|
|
148
|
+
functionType: __1.ChannelFunctionTypes.WEBSOCKET_SUBSCRIBE
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
exports.renderWebSocketSubscribe = renderWebSocketSubscribe;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { GenericCodegenContext } from '../../../types';
|
|
3
|
+
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
|
|
4
|
+
import { TypeScriptPayloadRenderType } from '../payloads';
|
|
5
|
+
import { TypeScriptParameterRenderType } from '../parameters';
|
|
6
|
+
import { ConstrainedObjectModel } from '@asyncapi/modelina';
|
|
7
|
+
import { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
8
|
+
import { SecuritySchemeOptions } from '../../../inputs/openapi/security';
|
|
9
|
+
export { SecuritySchemeOptions };
|
|
10
|
+
export declare enum ChannelFunctionTypes {
|
|
11
|
+
NATS_JETSTREAM_PUBLISH = "nats_jetstream_publish",
|
|
12
|
+
NATS_JETSTREAM_PULL_SUBSCRIBE = "nats_jetstream_pull_subscribe",
|
|
13
|
+
NATS_JETSTREAM_PUSH_SUBSCRIBE = "nats_jetstream_push_subscribe",
|
|
14
|
+
NATS_SUBSCRIBE = "nats_subscribe",
|
|
15
|
+
NATS_PUBLISH = "nats_publish",
|
|
16
|
+
NATS_REQUEST = "nats_request",
|
|
17
|
+
NATS_REPLY = "nats_reply",
|
|
18
|
+
MQTT_PUBLISH = "mqtt_publish",
|
|
19
|
+
MQTT_SUBSCRIBE = "mqtt_subscribe",
|
|
20
|
+
KAFKA_PUBLISH = "kafka_publish",
|
|
21
|
+
KAFKA_SUBSCRIBE = "kafka_subscribe",
|
|
22
|
+
AMQP_QUEUE_PUBLISH = "amqp_queue_publish",
|
|
23
|
+
AMQP_QUEUE_SUBSCRIBE = "amqp_queue_subscribe",
|
|
24
|
+
AMQP_EXCHANGE_PUBLISH = "amqp_exchange_publish",
|
|
25
|
+
HTTP_CLIENT = "http_client",
|
|
26
|
+
EVENT_SOURCE_FETCH = "event_source_fetch",
|
|
27
|
+
EVENT_SOURCE_EXPRESS = "event_source_express",
|
|
28
|
+
WEBSOCKET_PUBLISH = "websocket_publish",
|
|
29
|
+
WEBSOCKET_SUBSCRIBE = "websocket_subscribe",
|
|
30
|
+
WEBSOCKET_REGISTER = "websocket_register"
|
|
31
|
+
}
|
|
32
|
+
export declare const sendingFunctionTypes: ChannelFunctionTypes[];
|
|
33
|
+
export declare const receivingFunctionTypes: ChannelFunctionTypes[];
|
|
34
|
+
export declare const zodTypescriptChannelsGenerator: z.ZodObject<{
|
|
35
|
+
id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
36
|
+
dependencies: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
37
|
+
preset: z.ZodDefault<z.ZodLiteral<"channels">>;
|
|
38
|
+
outputPath: z.ZodDefault<z.ZodString>;
|
|
39
|
+
protocols: z.ZodDefault<z.ZodArray<z.ZodEnum<["nats", "kafka", "mqtt", "amqp", "event_source", "http_client", "websocket"]>, "many">>;
|
|
40
|
+
parameterGeneratorId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
41
|
+
payloadGeneratorId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
42
|
+
headerGeneratorId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
43
|
+
asyncapiReverseOperations: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
44
|
+
asyncapiGenerateForOperations: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
45
|
+
functionTypeMapping: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof ChannelFunctionTypes>, "many">>>>>;
|
|
46
|
+
kafkaTopicSeparator: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
47
|
+
eventSourceDependency: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
48
|
+
language: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"typescript">>>;
|
|
49
|
+
importExtension: z.ZodOptional<z.ZodEnum<[".ts", ".js", "none"]>>;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
preset: "channels";
|
|
52
|
+
id: string;
|
|
53
|
+
dependencies: string[];
|
|
54
|
+
language: "typescript";
|
|
55
|
+
outputPath: string;
|
|
56
|
+
protocols: ("http_client" | "nats" | "kafka" | "mqtt" | "amqp" | "event_source" | "websocket")[];
|
|
57
|
+
parameterGeneratorId: string;
|
|
58
|
+
payloadGeneratorId: string;
|
|
59
|
+
headerGeneratorId: string;
|
|
60
|
+
asyncapiReverseOperations: boolean;
|
|
61
|
+
asyncapiGenerateForOperations: boolean;
|
|
62
|
+
functionTypeMapping: Record<string, ChannelFunctionTypes[] | undefined>;
|
|
63
|
+
kafkaTopicSeparator: string;
|
|
64
|
+
eventSourceDependency: string;
|
|
65
|
+
importExtension?: ".ts" | ".js" | "none" | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
preset?: "channels" | undefined;
|
|
68
|
+
id?: string | undefined;
|
|
69
|
+
dependencies?: string[] | undefined;
|
|
70
|
+
language?: "typescript" | undefined;
|
|
71
|
+
outputPath?: string | undefined;
|
|
72
|
+
protocols?: ("http_client" | "nats" | "kafka" | "mqtt" | "amqp" | "event_source" | "websocket")[] | undefined;
|
|
73
|
+
parameterGeneratorId?: string | undefined;
|
|
74
|
+
payloadGeneratorId?: string | undefined;
|
|
75
|
+
headerGeneratorId?: string | undefined;
|
|
76
|
+
asyncapiReverseOperations?: boolean | undefined;
|
|
77
|
+
asyncapiGenerateForOperations?: boolean | undefined;
|
|
78
|
+
functionTypeMapping?: Record<string, ChannelFunctionTypes[] | undefined> | undefined;
|
|
79
|
+
kafkaTopicSeparator?: string | undefined;
|
|
80
|
+
eventSourceDependency?: string | undefined;
|
|
81
|
+
importExtension?: ".ts" | ".js" | "none" | undefined;
|
|
82
|
+
}>;
|
|
83
|
+
export type TypeScriptChannelsGenerator = z.input<typeof zodTypescriptChannelsGenerator>;
|
|
84
|
+
export type TypeScriptChannelsGeneratorInternal = z.infer<typeof zodTypescriptChannelsGenerator>;
|
|
85
|
+
export declare const defaultTypeScriptChannelsGenerator: TypeScriptChannelsGeneratorInternal;
|
|
86
|
+
export interface TypeScriptChannelsContext extends GenericCodegenContext {
|
|
87
|
+
inputType: 'asyncapi' | 'openapi';
|
|
88
|
+
asyncapiDocument?: AsyncAPIDocumentInterface;
|
|
89
|
+
openapiDocument?: OpenAPIV3.Document | OpenAPIV2.Document | OpenAPIV3_1.Document;
|
|
90
|
+
generator: TypeScriptChannelsGeneratorInternal;
|
|
91
|
+
}
|
|
92
|
+
export interface TypeScriptChannelsGeneratorContext extends TypeScriptChannelsContext {
|
|
93
|
+
payloads: TypeScriptPayloadRenderType;
|
|
94
|
+
parameter: ConstrainedObjectModel | undefined;
|
|
95
|
+
headers: ConstrainedObjectModel | undefined;
|
|
96
|
+
topic: string;
|
|
97
|
+
subName: string;
|
|
98
|
+
}
|
|
99
|
+
export type TypeScriptChannelRenderedFunctionType = {
|
|
100
|
+
functionType: ChannelFunctionTypes;
|
|
101
|
+
functionName: string;
|
|
102
|
+
messageType: string;
|
|
103
|
+
replyType?: string;
|
|
104
|
+
parameterType?: string;
|
|
105
|
+
};
|
|
106
|
+
export interface TypeScriptChannelRenderType {
|
|
107
|
+
payloadRender: TypeScriptPayloadRenderType;
|
|
108
|
+
parameterRender: TypeScriptParameterRenderType;
|
|
109
|
+
generator: TypeScriptChannelsGeneratorInternal;
|
|
110
|
+
/**
|
|
111
|
+
* All the rendered functions based on type.
|
|
112
|
+
*/
|
|
113
|
+
renderedFunctions: Record<string, TypeScriptChannelRenderedFunctionType[]>;
|
|
114
|
+
/**
|
|
115
|
+
* The generated index file content (imports and re-exports of protocol modules).
|
|
116
|
+
*/
|
|
117
|
+
result: string;
|
|
118
|
+
/**
|
|
119
|
+
* The generated protocol file contents, keyed by protocol name.
|
|
120
|
+
* E.g., { nats: "export function publish...", kafka: "export function produce..." }
|
|
121
|
+
* Useful for testing/snapshot verification of generated protocol code.
|
|
122
|
+
*/
|
|
123
|
+
protocolFiles: Record<string, string>;
|
|
124
|
+
/**
|
|
125
|
+
* Generated files with path and content.
|
|
126
|
+
*/
|
|
127
|
+
files: import('../../../types').GeneratedFile[];
|
|
128
|
+
}
|
|
129
|
+
export interface RenderRegularParameters<T = any> {
|
|
130
|
+
topic: string;
|
|
131
|
+
messageType: string;
|
|
132
|
+
messageModule?: string;
|
|
133
|
+
channelParameters: ConstrainedObjectModel | undefined;
|
|
134
|
+
channelHeaders: ConstrainedObjectModel | undefined;
|
|
135
|
+
subName?: string;
|
|
136
|
+
functionName?: string;
|
|
137
|
+
payloadGenerator: TypeScriptPayloadRenderType;
|
|
138
|
+
additionalProperties?: T;
|
|
139
|
+
/** Operation description from API specification for JSDoc generation */
|
|
140
|
+
description?: string;
|
|
141
|
+
/** Whether the operation is marked as deprecated in the API specification */
|
|
142
|
+
deprecated?: boolean;
|
|
143
|
+
}
|
|
144
|
+
export interface RenderRequestReplyParameters {
|
|
145
|
+
requestTopic: string;
|
|
146
|
+
requestMessageType: string;
|
|
147
|
+
requestMessageModule: string | undefined;
|
|
148
|
+
replyMessageType: string;
|
|
149
|
+
replyMessageModule: string | undefined;
|
|
150
|
+
channelParameters: ConstrainedObjectModel | undefined;
|
|
151
|
+
channelHeaders: ConstrainedObjectModel | undefined;
|
|
152
|
+
subName?: string;
|
|
153
|
+
functionName?: string;
|
|
154
|
+
payloadGenerator: TypeScriptPayloadRenderType;
|
|
155
|
+
/** Operation description from API specification for JSDoc generation */
|
|
156
|
+
description?: string;
|
|
157
|
+
/** Whether the operation is marked as deprecated in the API specification */
|
|
158
|
+
deprecated?: boolean;
|
|
159
|
+
}
|
|
160
|
+
export interface RenderHttpParameters {
|
|
161
|
+
requestTopic: string;
|
|
162
|
+
requestMessageType?: string;
|
|
163
|
+
servers?: string[];
|
|
164
|
+
requestMessageModule: string | undefined;
|
|
165
|
+
replyMessageType: string;
|
|
166
|
+
replyMessageModule: string | undefined;
|
|
167
|
+
channelParameters: ConstrainedObjectModel | undefined;
|
|
168
|
+
subName?: string;
|
|
169
|
+
functionName?: string;
|
|
170
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
171
|
+
/**
|
|
172
|
+
* Whether the reply payload includes status code-based unmarshalling.
|
|
173
|
+
* When true, use unmarshalByStatusCode(json, statusCode) instead of unmarshal(json).
|
|
174
|
+
*/
|
|
175
|
+
includesStatusCodes?: boolean;
|
|
176
|
+
/** Operation description from API specification for JSDoc generation */
|
|
177
|
+
description?: string;
|
|
178
|
+
/** Whether the operation is marked as deprecated in the API specification */
|
|
179
|
+
deprecated?: boolean;
|
|
180
|
+
}
|
|
181
|
+
export type SupportedProtocols = 'nats' | 'kafka' | 'mqtt' | 'amqp' | 'event_source' | 'http_client' | 'websocket';
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultTypeScriptChannelsGenerator = exports.zodTypescriptChannelsGenerator = exports.receivingFunctionTypes = exports.sendingFunctionTypes = exports.ChannelFunctionTypes = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
var ChannelFunctionTypes;
|
|
7
|
+
(function (ChannelFunctionTypes) {
|
|
8
|
+
ChannelFunctionTypes["NATS_JETSTREAM_PUBLISH"] = "nats_jetstream_publish";
|
|
9
|
+
ChannelFunctionTypes["NATS_JETSTREAM_PULL_SUBSCRIBE"] = "nats_jetstream_pull_subscribe";
|
|
10
|
+
ChannelFunctionTypes["NATS_JETSTREAM_PUSH_SUBSCRIBE"] = "nats_jetstream_push_subscribe";
|
|
11
|
+
ChannelFunctionTypes["NATS_SUBSCRIBE"] = "nats_subscribe";
|
|
12
|
+
ChannelFunctionTypes["NATS_PUBLISH"] = "nats_publish";
|
|
13
|
+
ChannelFunctionTypes["NATS_REQUEST"] = "nats_request";
|
|
14
|
+
ChannelFunctionTypes["NATS_REPLY"] = "nats_reply";
|
|
15
|
+
ChannelFunctionTypes["MQTT_PUBLISH"] = "mqtt_publish";
|
|
16
|
+
ChannelFunctionTypes["MQTT_SUBSCRIBE"] = "mqtt_subscribe";
|
|
17
|
+
ChannelFunctionTypes["KAFKA_PUBLISH"] = "kafka_publish";
|
|
18
|
+
ChannelFunctionTypes["KAFKA_SUBSCRIBE"] = "kafka_subscribe";
|
|
19
|
+
ChannelFunctionTypes["AMQP_QUEUE_PUBLISH"] = "amqp_queue_publish";
|
|
20
|
+
ChannelFunctionTypes["AMQP_QUEUE_SUBSCRIBE"] = "amqp_queue_subscribe";
|
|
21
|
+
ChannelFunctionTypes["AMQP_EXCHANGE_PUBLISH"] = "amqp_exchange_publish";
|
|
22
|
+
ChannelFunctionTypes["HTTP_CLIENT"] = "http_client";
|
|
23
|
+
ChannelFunctionTypes["EVENT_SOURCE_FETCH"] = "event_source_fetch";
|
|
24
|
+
ChannelFunctionTypes["EVENT_SOURCE_EXPRESS"] = "event_source_express";
|
|
25
|
+
ChannelFunctionTypes["WEBSOCKET_PUBLISH"] = "websocket_publish";
|
|
26
|
+
ChannelFunctionTypes["WEBSOCKET_SUBSCRIBE"] = "websocket_subscribe";
|
|
27
|
+
ChannelFunctionTypes["WEBSOCKET_REGISTER"] = "websocket_register";
|
|
28
|
+
})(ChannelFunctionTypes || (exports.ChannelFunctionTypes = ChannelFunctionTypes = {}));
|
|
29
|
+
exports.sendingFunctionTypes = [
|
|
30
|
+
ChannelFunctionTypes.NATS_JETSTREAM_PUBLISH,
|
|
31
|
+
ChannelFunctionTypes.NATS_PUBLISH,
|
|
32
|
+
ChannelFunctionTypes.NATS_REQUEST,
|
|
33
|
+
ChannelFunctionTypes.MQTT_PUBLISH,
|
|
34
|
+
ChannelFunctionTypes.KAFKA_PUBLISH,
|
|
35
|
+
ChannelFunctionTypes.AMQP_EXCHANGE_PUBLISH,
|
|
36
|
+
ChannelFunctionTypes.AMQP_QUEUE_PUBLISH,
|
|
37
|
+
ChannelFunctionTypes.EVENT_SOURCE_EXPRESS,
|
|
38
|
+
ChannelFunctionTypes.HTTP_CLIENT,
|
|
39
|
+
ChannelFunctionTypes.WEBSOCKET_PUBLISH,
|
|
40
|
+
ChannelFunctionTypes.WEBSOCKET_REGISTER
|
|
41
|
+
];
|
|
42
|
+
exports.receivingFunctionTypes = [
|
|
43
|
+
ChannelFunctionTypes.NATS_JETSTREAM_PULL_SUBSCRIBE,
|
|
44
|
+
ChannelFunctionTypes.NATS_JETSTREAM_PUSH_SUBSCRIBE,
|
|
45
|
+
ChannelFunctionTypes.NATS_REPLY,
|
|
46
|
+
ChannelFunctionTypes.NATS_SUBSCRIBE,
|
|
47
|
+
ChannelFunctionTypes.MQTT_SUBSCRIBE,
|
|
48
|
+
ChannelFunctionTypes.KAFKA_SUBSCRIBE,
|
|
49
|
+
ChannelFunctionTypes.EVENT_SOURCE_FETCH,
|
|
50
|
+
ChannelFunctionTypes.AMQP_QUEUE_SUBSCRIBE,
|
|
51
|
+
ChannelFunctionTypes.WEBSOCKET_SUBSCRIBE
|
|
52
|
+
];
|
|
53
|
+
exports.zodTypescriptChannelsGenerator = zod_1.z.object({
|
|
54
|
+
id: zod_1.z
|
|
55
|
+
.string()
|
|
56
|
+
.optional()
|
|
57
|
+
.default('channels-typescript')
|
|
58
|
+
.describe('Unique identifier for this generator instance. Used by other generators to reference this one as a dependency. [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
59
|
+
dependencies: zod_1.z
|
|
60
|
+
.array(zod_1.z.string())
|
|
61
|
+
.optional()
|
|
62
|
+
.default([
|
|
63
|
+
'parameters-typescript',
|
|
64
|
+
'payloads-typescript',
|
|
65
|
+
'headers-typescript'
|
|
66
|
+
])
|
|
67
|
+
.describe('The list of other generator IDs that this generator depends on. The channels generator depends on the parameters, payloads, and headers generators by default. [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
68
|
+
preset: zod_1.z
|
|
69
|
+
.literal('channels')
|
|
70
|
+
.default('channels')
|
|
71
|
+
.describe('Generates protocol-specific publish/subscribe/request/reply functions for each channel or operation. [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
72
|
+
outputPath: zod_1.z
|
|
73
|
+
.string()
|
|
74
|
+
.default('src/__gen__/channels')
|
|
75
|
+
.describe('The directory path where the generated channel functions will be written. [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
76
|
+
protocols: zod_1.z
|
|
77
|
+
.array(zod_1.z.enum([
|
|
78
|
+
'nats',
|
|
79
|
+
'kafka',
|
|
80
|
+
'mqtt',
|
|
81
|
+
'amqp',
|
|
82
|
+
'event_source',
|
|
83
|
+
'http_client',
|
|
84
|
+
'websocket'
|
|
85
|
+
]))
|
|
86
|
+
.default([])
|
|
87
|
+
.describe('The protocols to generate channel functions for. Each protocol produces typed publish/subscribe/request/reply functions tailored to that messaging system. [Read more about supported protocols here](https://the-codegen-project.org/docs/getting-started/protocols)'),
|
|
88
|
+
parameterGeneratorId: zod_1.z
|
|
89
|
+
.string()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe('When multiple TypeScript parameter generators are configured, specify which one this channels generator should depend on. Defaults to "parameters-typescript". [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)')
|
|
92
|
+
.default('parameters-typescript'),
|
|
93
|
+
payloadGeneratorId: zod_1.z
|
|
94
|
+
.string()
|
|
95
|
+
.optional()
|
|
96
|
+
.describe('When multiple TypeScript payload generators are configured, specify which one this channels generator should depend on. Defaults to "payloads-typescript". [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)')
|
|
97
|
+
.default('payloads-typescript'),
|
|
98
|
+
headerGeneratorId: zod_1.z
|
|
99
|
+
.string()
|
|
100
|
+
.optional()
|
|
101
|
+
.describe('When multiple TypeScript header generators are configured, specify which one this channels generator should depend on. Defaults to "headers-typescript". [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)')
|
|
102
|
+
.default('headers-typescript'),
|
|
103
|
+
asyncapiReverseOperations: zod_1.z
|
|
104
|
+
.boolean()
|
|
105
|
+
.optional()
|
|
106
|
+
.default(false)
|
|
107
|
+
.describe('When true, AsyncAPI operations are generated with their action reversed (a "send" operation becomes "receive" and vice versa). Often used to generate the opposite side of an API for testing. [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
108
|
+
asyncapiGenerateForOperations: zod_1.z
|
|
109
|
+
.boolean()
|
|
110
|
+
.optional()
|
|
111
|
+
.default(true)
|
|
112
|
+
.describe('When true (default), only the operations defined in the AsyncAPI document are generated and their declared action is enforced. When false, more generic channel functions are generated regardless of the operation action. [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
113
|
+
functionTypeMapping: zod_1.z
|
|
114
|
+
.record(zod_1.z.array(zod_1.z.nativeEnum(ChannelFunctionTypes)).optional())
|
|
115
|
+
.optional()
|
|
116
|
+
.default({})
|
|
117
|
+
.describe('Used with AsyncAPI input to map a channel ID to the specific channel function types that should be rendered for it (e.g. "nats_publish", "kafka_subscribe"). [Read more about the channels generator here](https://the-codegen-project.org/docs/generators/channels)'),
|
|
118
|
+
kafkaTopicSeparator: zod_1.z
|
|
119
|
+
.string()
|
|
120
|
+
.optional()
|
|
121
|
+
.default('.')
|
|
122
|
+
.describe('The separator used when converting AsyncAPI channel addresses into Kafka topic names. For example, with the default ".", an address like "my/resource/path" becomes "my.resource.path". [Read more about the Kafka protocol here](https://the-codegen-project.org/docs/protocols/kafka)'),
|
|
123
|
+
eventSourceDependency: zod_1.z
|
|
124
|
+
.string()
|
|
125
|
+
.optional()
|
|
126
|
+
.default('@microsoft/fetch-event-source')
|
|
127
|
+
.describe('The npm package used as the EventSource (Server-Sent Events) client implementation. Override this when you need a fork or alternative because @microsoft/fetch-event-source is out of date in some areas. [Read more about the EventSource protocol here](https://the-codegen-project.org/docs/protocols/eventsource)'),
|
|
128
|
+
language: zod_1.z.literal('typescript').optional().default('typescript'),
|
|
129
|
+
importExtension: utils_1.zodImportExtension.describe('File extension appended to relative import paths in generated channel code. Use ".ts" for moduleResolution: "node16"/"nodenext", ".js" for compiled ESM output, or "none" (default) for bundlers. Overrides the global importExtension. [Read more about import extensions here](https://the-codegen-project.org/docs/configurations)')
|
|
130
|
+
});
|
|
131
|
+
exports.defaultTypeScriptChannelsGenerator = exports.zodTypescriptChannelsGenerator.parse({});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OutputModel } from '@asyncapi/modelina';
|
|
2
|
+
import { ChannelPayload } from '../../../types';
|
|
3
|
+
import { ImportExtension } from '../../../utils';
|
|
4
|
+
import { TypeScriptPayloadRenderType } from '../payloads';
|
|
5
|
+
import { TypeScriptParameterRenderType } from '../parameters';
|
|
6
|
+
import { TypeScriptHeadersRenderType } from '../headers';
|
|
7
|
+
import { TypeScriptChannelsContext } from './types';
|
|
8
|
+
export declare function addPayloadsToDependencies(models: ChannelPayload[], payloadGenerator: {
|
|
9
|
+
outputPath: string;
|
|
10
|
+
}, currentGenerator: {
|
|
11
|
+
outputPath: string;
|
|
12
|
+
}, dependencies: string[], importExtension?: ImportExtension): void;
|
|
13
|
+
export declare function addPayloadsToExports(models: ChannelPayload[], dependencies: string[]): void;
|
|
14
|
+
export declare function addParametersToDependencies(parameters: Record<string, OutputModel | undefined>, parameterGenerator: {
|
|
15
|
+
outputPath: string;
|
|
16
|
+
}, currentGenerator: {
|
|
17
|
+
outputPath: string;
|
|
18
|
+
}, dependencies: string[], importExtension?: ImportExtension): void;
|
|
19
|
+
export declare function addParametersToExports(parameters: Record<string, OutputModel | undefined>, dependencies: string[]): void;
|
|
20
|
+
export declare function addHeadersToDependencies(headers: Record<string, OutputModel | undefined>, headerGenerator: {
|
|
21
|
+
outputPath: string;
|
|
22
|
+
}, currentGenerator: {
|
|
23
|
+
outputPath: string;
|
|
24
|
+
}, dependencies: string[], importExtension?: ImportExtension): void;
|
|
25
|
+
export declare function getMessageTypeAndModule(payload: ChannelPayload): {
|
|
26
|
+
messageType: undefined;
|
|
27
|
+
messageModule: undefined;
|
|
28
|
+
includesStatusCodes: boolean;
|
|
29
|
+
} | {
|
|
30
|
+
messageType: string;
|
|
31
|
+
messageModule: string | undefined;
|
|
32
|
+
includesStatusCodes: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare function getValidationFunctions({ includeValidation, messageModule, messageType, onValidationFail }: {
|
|
35
|
+
includeValidation: boolean;
|
|
36
|
+
messageModule?: string;
|
|
37
|
+
messageType: string;
|
|
38
|
+
onValidationFail: string;
|
|
39
|
+
}): {
|
|
40
|
+
potentialValidatorCreation: string;
|
|
41
|
+
potentialValidationFunction: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Collects all payload, parameter, and header imports for a specific protocol's dependencies.
|
|
45
|
+
* This should be called once per protocol to add the necessary imports.
|
|
46
|
+
*/
|
|
47
|
+
export declare function collectProtocolDependencies(payloads: TypeScriptPayloadRenderType, parameters: TypeScriptParameterRenderType, headers: TypeScriptHeadersRenderType | undefined, context: TypeScriptChannelsContext, protocolDeps: string[], importExtension?: ImportExtension): void;
|
|
48
|
+
/**
|
|
49
|
+
* Escapes special characters in description for JSDoc.
|
|
50
|
+
* Handles closing comment markers and formats multi-line descriptions.
|
|
51
|
+
*/
|
|
52
|
+
export declare function escapeJSDocDescription(description: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Renders JSDoc block for channel functions.
|
|
55
|
+
* Uses operation description from API spec when available, falls back to generic text.
|
|
56
|
+
*/
|
|
57
|
+
export declare function renderChannelJSDoc(params: {
|
|
58
|
+
description?: string;
|
|
59
|
+
deprecated?: boolean;
|
|
60
|
+
fallbackDescription: string;
|
|
61
|
+
parameters?: Array<{
|
|
62
|
+
jsDoc: string;
|
|
63
|
+
}>;
|
|
64
|
+
}): string;
|