@ioka-technologies/asyncapi-ts-client-template 0.0.25 → 0.0.26
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
2
|
import { File } from '@asyncapi/generator-react-sdk';
|
|
3
|
-
import { generateTypeScriptModels } from
|
|
3
|
+
import { generateTypeScriptModels } from "../../dist/common/index.js";
|
|
4
4
|
|
|
5
5
|
export default function ({ asyncapi, params }) {
|
|
6
6
|
// Generate models using the common helper
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import { File } from '@asyncapi/generator-react-sdk';
|
|
3
|
+
import { generateTypeScriptModels } from '../../../common/src/index.js';
|
|
4
|
+
|
|
5
|
+
export default function ({ asyncapi, params }) {
|
|
6
|
+
// Generate models using the common helper
|
|
7
|
+
const models = generateTypeScriptModels(asyncapi, {
|
|
8
|
+
includeMessageTypes: true // TypeScript client includes message type constants
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<File name="models.ts">
|
|
13
|
+
{`// Generated TypeScript models from AsyncAPI specification
|
|
14
|
+
|
|
15
|
+
${models.generateComponentSchemas()}
|
|
16
|
+
${models.generateMessageSchemas()}
|
|
17
|
+
${models.generateMessageTypes()}
|
|
18
|
+
`}
|
|
19
|
+
</File>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -17,14 +17,15 @@ import { generateAuthHeaders, generateAuthQueryParams, hasAuthCredentials, AuthE
|
|
|
17
17
|
import { createRetryManager, getRetryConfig } from '../retry';
|
|
18
18
|
|
|
19
19
|
// Environment-aware WebSocket implementation
|
|
20
|
-
const getWebSocketImpl = ():
|
|
20
|
+
const getWebSocketImpl = async (): Promise<any> => {
|
|
21
21
|
if (typeof window !== 'undefined' && window.WebSocket) {
|
|
22
22
|
// Browser environment - use native WebSocket
|
|
23
23
|
return window.WebSocket;
|
|
24
24
|
} else if (typeof global !== 'undefined') {
|
|
25
|
-
// Node.js environment - try to
|
|
25
|
+
// Node.js environment - try to import ws
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
const { default: WebSocket } = await import('ws');
|
|
28
|
+
return WebSocket;
|
|
28
29
|
} catch (error) {
|
|
29
30
|
throw new Error('WebSocket implementation not available. In Node.js, please install the "ws" package: npm install ws');
|
|
30
31
|
}
|
|
@@ -47,7 +48,7 @@ type WebSocketLike = {
|
|
|
47
48
|
|
|
48
49
|
export class WebSocketTransport implements Transport {
|
|
49
50
|
private ws: WebSocketLike | null = null;
|
|
50
|
-
private WebSocketImpl:
|
|
51
|
+
private WebSocketImpl: any;
|
|
51
52
|
private config: TransportConfig;
|
|
52
53
|
private responseHandlers: Map<string, ResponseHandler> = new Map();
|
|
53
54
|
private subscriptions: Map<string, Set<EnvelopeCallback>> = new Map();
|
|
@@ -59,10 +60,14 @@ export class WebSocketTransport implements Transport {
|
|
|
59
60
|
|
|
60
61
|
constructor(config: TransportConfig) {
|
|
61
62
|
this.config = config;
|
|
62
|
-
|
|
63
|
+
// WebSocketImpl will be set during connect()
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
async connect(): Promise<void> {
|
|
67
|
+
if (!this.WebSocketImpl) {
|
|
68
|
+
this.WebSocketImpl = await getWebSocketImpl();
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
return new Promise((resolve, reject) => {
|
|
67
72
|
try {
|
|
68
73
|
this.ws = new this.WebSocketImpl(this.config.url) as WebSocketLike;
|