Skip to content

Commit 375ba47

Browse files
feat: minor version change (#9)
1 parent b518b78 commit 375ba47

17 files changed

+1011
-193
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
<h1 align="center">TypeScript/Node.js NATS client wrapper</h1>
3+
<p align="center">
4+
<em>This is a generated TypeScript/Node.js NATS client for the application - Rust public API.</em>
5+
</p>
6+
7+
**We highly recommend you do not modify this client in any way since it is build for you to re-generate it when your AsyncAPI document changes.**
8+
9+
test
10+
11+
You can find the general information about the different aspects of this library by checking [the documentation folder](./docs/general.md).
12+
13+
An [API document](./API.md) have also been generated which contains all the possible configurations and usages this client supports.
14+
15+
## Example
16+
```ts
17+
import * as GeneratedClient from "./nats-client";
18+
const natsClient = new GeneratedClient.NatsAsyncApiClient();
19+
natsClient.connect(...).catch((e) => {});
20+
```
21+
22+
23+

configs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"template_last_version": "0.5.15",
3-
"document_last_version": "0.1.0"
2+
"template_last_version": "0.5.21",
3+
"document_last_version": "0.4.0"
44
}

package-lock.json

Lines changed: 224 additions & 183 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import ChatMessage from '../models/ChatMessage';
2+
import * as Nats from 'nats';
3+
import {
4+
ErrorCode,
5+
NatsTypescriptTemplateError
6+
} from '../NatsTypescriptTemplateError';
7+
/**
8+
* Module which wraps functionality for the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted` channel
9+
* @module v0RustServersServerIdEventsPlayerSteamIdChatted
10+
*/
11+
/**
12+
* Internal functionality to setup subscription on the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted` channel
13+
*
14+
* @param onDataCallback to call when messages are received
15+
* @param nc to subscribe with
16+
* @param codec used to convert messages
17+
* @param server_id parameter to use in topic
18+
* @param steam_id parameter to use in topic
19+
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
20+
*/
21+
export function subscribe(
22+
onDataCallback: (
23+
err ? : NatsTypescriptTemplateError,
24+
msg ? : ChatMessage, server_id ? : string, steam_id ? : string) => void,
25+
nc: Nats.NatsConnection,
26+
codec: Nats.Codec < any > , server_id: string, steam_id: string,
27+
options ? : Nats.SubscriptionOptions
28+
): Promise < Nats.Subscription > {
29+
return new Promise(async (resolve, reject) => {
30+
let subscribeOptions: Nats.SubscriptionOptions = {
31+
...options
32+
};
33+
try {
34+
let subscription = nc.subscribe(`v0.rust.servers.${server_id}.events.player.${steam_id}.chatted`, subscribeOptions);
35+
(async () => {
36+
for await (const msg of subscription) {
37+
const unmodifiedChannel = `v0.rust.servers.{server_id}.events.player.{steam_id}.chatted`;
38+
let channel = msg.subject;
39+
const serverIdSplit = unmodifiedChannel.split("{server_id}");
40+
const steamIdSplit = serverIdSplit[1].split("{steam_id}");
41+
const splits = [
42+
serverIdSplit[0],
43+
steamIdSplit[0],
44+
steamIdSplit[1]
45+
];
46+
channel = channel.substring(splits[0].length);
47+
const serverIdEnd = channel.indexOf(splits[1]);
48+
const serverIdParam = "" + channel.substring(0, serverIdEnd);
49+
channel = channel.substring(serverIdEnd + splits[1].length);
50+
const steamIdEnd = channel.indexOf(splits[2]);
51+
const steamIdParam = "" + channel.substring(0, steamIdEnd);
52+
let receivedData: any = codec.decode(msg.data);
53+
onDataCallback(undefined, ChatMessage.unmarshal(receivedData), serverIdParam, steamIdParam);
54+
}
55+
console.log("subscription closed");
56+
})();
57+
resolve(subscription);
58+
} catch (e: any) {
59+
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.INTERNAL_NATS_TS_ERROR, e));
60+
}
61+
})
62+
}

src/channels/V0RustServersServerIdEventsStarted.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ServerStarted from '../models/ServerStarted';
12
import * as Nats from 'nats';
23
import {
34
ErrorCode,
@@ -19,7 +20,7 @@ import {
1920
export function subscribe(
2021
onDataCallback: (
2122
err ? : NatsTypescriptTemplateError,
22-
msg ? : null, server_id ? : string) => void,
23+
msg ? : ServerStarted, server_id ? : string) => void,
2324
nc: Nats.NatsConnection,
2425
codec: Nats.Codec < any > , server_id: string,
2526
options ? : Nats.SubscriptionOptions
@@ -42,7 +43,8 @@ export function subscribe(
4243
channel = channel.substring(splits[0].length);
4344
const serverIdEnd = channel.indexOf(splits[1]);
4445
const serverIdParam = "" + channel.substring(0, serverIdEnd);
45-
onDataCallback(undefined, null, serverIdParam);
46+
let receivedData: any = codec.decode(msg.data);
47+
onDataCallback(undefined, ServerStarted.unmarshal(receivedData), serverIdParam);
4648
}
4749
console.log("subscription closed");
4850
})();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import ServerStopped from '../models/ServerStopped';
2+
import * as Nats from 'nats';
3+
import {
4+
ErrorCode,
5+
NatsTypescriptTemplateError
6+
} from '../NatsTypescriptTemplateError';
7+
/**
8+
* Module which wraps functionality for the `v0/rust/servers/{server_id}/events/stopped` channel
9+
* @module v0RustServersServerIdEventsStopped
10+
*/
11+
/**
12+
* Internal functionality to setup subscription on the `v0/rust/servers/{server_id}/events/stopped` channel
13+
*
14+
* @param onDataCallback to call when messages are received
15+
* @param nc to subscribe with
16+
* @param codec used to convert messages
17+
* @param server_id parameter to use in topic
18+
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
19+
*/
20+
export function subscribe(
21+
onDataCallback: (
22+
err ? : NatsTypescriptTemplateError,
23+
msg ? : ServerStopped, server_id ? : string) => void,
24+
nc: Nats.NatsConnection,
25+
codec: Nats.Codec < any > , server_id: string,
26+
options ? : Nats.SubscriptionOptions
27+
): Promise < Nats.Subscription > {
28+
return new Promise(async (resolve, reject) => {
29+
let subscribeOptions: Nats.SubscriptionOptions = {
30+
...options
31+
};
32+
try {
33+
let subscription = nc.subscribe(`v0.rust.servers.${server_id}.events.stopped`, subscribeOptions);
34+
(async () => {
35+
for await (const msg of subscription) {
36+
const unmodifiedChannel = `v0.rust.servers.{server_id}.events.stopped`;
37+
let channel = msg.subject;
38+
const serverIdSplit = unmodifiedChannel.split("{server_id}");
39+
const splits = [
40+
serverIdSplit[0],
41+
serverIdSplit[1]
42+
];
43+
channel = channel.substring(splits[0].length);
44+
const serverIdEnd = channel.indexOf(splits[1]);
45+
const serverIdParam = "" + channel.substring(0, serverIdEnd);
46+
let receivedData: any = codec.decode(msg.data);
47+
onDataCallback(undefined, ServerStopped.unmarshal(receivedData), serverIdParam);
48+
}
49+
console.log("subscription closed");
50+
})();
51+
resolve(subscription);
52+
} catch (e: any) {
53+
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.INTERNAL_NATS_TS_ERROR, e));
54+
}
55+
})
56+
}

src/index.ts

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,29 @@ import {
55
} from './NatsTypescriptTemplateError';
66
import * as Nats from 'nats';
77
import * as v0RustServersServerIdEventsStartedChannel from "./channels/V0RustServersServerIdEventsStarted";
8+
import * as v0RustServersServerIdEventsStoppedChannel from "./channels/V0RustServersServerIdEventsStopped";
9+
import * as v0RustServersServerIdEventsPlayerSteamIdChattedChannel from "./channels/V0RustServersServerIdEventsPlayerSteamIdChatted";
10+
import ServerStarted from "./models/ServerStarted";
11+
import ServerStopped from "./models/ServerStopped";
12+
import ChatMessage from "./models/ChatMessage";
813
export {
914
v0RustServersServerIdEventsStartedChannel
1015
};
16+
export {
17+
v0RustServersServerIdEventsStoppedChannel
18+
};
19+
export {
20+
v0RustServersServerIdEventsPlayerSteamIdChattedChannel
21+
};
22+
export {
23+
ServerStarted
24+
};
25+
export {
26+
ServerStopped
27+
};
28+
export {
29+
ChatMessage
30+
};
1131
export {
1232
ErrorCode,
1333
NatsTypescriptTemplateError
@@ -124,7 +144,7 @@ export class NatsAsyncApiClient {
124144
public subscribeToV0RustServersServerIdEventsStarted(
125145
onDataCallback: (
126146
err ? : NatsTypescriptTemplateError,
127-
msg ? : null, server_id ? : string) => void, server_id: string,
147+
msg ? : ServerStarted, server_id ? : string) => void, server_id: string,
128148
flush ? : boolean,
129149
options ? : Nats.SubscriptionOptions
130150
): Promise < Nats.Subscription > {
@@ -149,4 +169,81 @@ export class NatsAsyncApiClient {
149169
}
150170
});
151171
}
172+
/**
173+
* Subscribe to the `v0/rust/servers/{server_id}/events/stopped`
174+
*
175+
* Channel for the API to process for when a server has stopped
176+
*
177+
* @param onDataCallback to call when messages are received
178+
* @param server_id parameter to use in topic
179+
* @param flush ensure client is force flushed after subscribing
180+
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
181+
*/
182+
public subscribeToV0RustServersServerIdEventsStopped(
183+
onDataCallback: (
184+
err ? : NatsTypescriptTemplateError,
185+
msg ? : ServerStopped, server_id ? : string) => void, server_id: string,
186+
flush ? : boolean,
187+
options ? : Nats.SubscriptionOptions
188+
): Promise < Nats.Subscription > {
189+
return new Promise(async (resolve, reject) => {
190+
if (!this.isClosed() && this.nc !== undefined && this.codec !== undefined) {
191+
try {
192+
const sub = await v0RustServersServerIdEventsStoppedChannel.subscribe(
193+
onDataCallback,
194+
this.nc,
195+
this.codec, server_id,
196+
options
197+
);
198+
if (flush) {
199+
await this.nc.flush();
200+
}
201+
resolve(sub);
202+
} catch (e: any) {
203+
reject(e);
204+
}
205+
} else {
206+
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.NOT_CONNECTED));
207+
}
208+
});
209+
}
210+
/**
211+
* Subscribe to the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted`
212+
*
213+
* Event for when a player used the chat
214+
*
215+
* @param onDataCallback to call when messages are received
216+
* @param server_id parameter to use in topic
217+
* @param steam_id parameter to use in topic
218+
* @param flush ensure client is force flushed after subscribing
219+
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
220+
*/
221+
public subscribeToV0RustServersServerIdEventsPlayerSteamIdChatted(
222+
onDataCallback: (
223+
err ? : NatsTypescriptTemplateError,
224+
msg ? : ChatMessage, server_id ? : string, steam_id ? : string) => void, server_id: string, steam_id: string,
225+
flush ? : boolean,
226+
options ? : Nats.SubscriptionOptions
227+
): Promise < Nats.Subscription > {
228+
return new Promise(async (resolve, reject) => {
229+
if (!this.isClosed() && this.nc !== undefined && this.codec !== undefined) {
230+
try {
231+
const sub = await v0RustServersServerIdEventsPlayerSteamIdChattedChannel.subscribe(
232+
onDataCallback,
233+
this.nc,
234+
this.codec, server_id, steam_id,
235+
options
236+
);
237+
if (flush) {
238+
await this.nc.flush();
239+
}
240+
resolve(sub);
241+
} catch (e: any) {
242+
reject(e);
243+
}
244+
} else {
245+
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.NOT_CONNECTED));
246+
}
247+
});
248+
}
152249
}

0 commit comments

Comments
 (0)