Skip to content

Commit

Permalink
feat: minor version change (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jul 5, 2022
1 parent b518b78 commit 375ba47
Show file tree
Hide file tree
Showing 17 changed files with 1,011 additions and 193 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<h1 align="center">TypeScript/Node.js NATS client wrapper</h1>
<p align="center">
<em>This is a generated TypeScript/Node.js NATS client for the application - Rust public API.</em>
</p>

**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.**

test

You can find the general information about the different aspects of this library by checking [the documentation folder](./docs/general.md).

An [API document](./API.md) have also been generated which contains all the possible configurations and usages this client supports.

## Example
```ts
import * as GeneratedClient from "./nats-client";
const natsClient = new GeneratedClient.NatsAsyncApiClient();
natsClient.connect(...).catch((e) => {});
```



4 changes: 2 additions & 2 deletions configs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"template_last_version": "0.5.15",
"document_last_version": "0.1.0"
"template_last_version": "0.5.21",
"document_last_version": "0.4.0"
}
407 changes: 224 additions & 183 deletions package-lock.json

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions src/channels/V0RustServersServerIdEventsPlayerSteamIdChatted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import ChatMessage from '../models/ChatMessage';
import * as Nats from 'nats';
import {
ErrorCode,
NatsTypescriptTemplateError
} from '../NatsTypescriptTemplateError';
/**
* Module which wraps functionality for the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted` channel
* @module v0RustServersServerIdEventsPlayerSteamIdChatted
*/
/**
* Internal functionality to setup subscription on the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted` channel
*
* @param onDataCallback to call when messages are received
* @param nc to subscribe with
* @param codec used to convert messages
* @param server_id parameter to use in topic
* @param steam_id parameter to use in topic
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
*/
export function subscribe(
onDataCallback: (
err ? : NatsTypescriptTemplateError,
msg ? : ChatMessage, server_id ? : string, steam_id ? : string) => void,
nc: Nats.NatsConnection,
codec: Nats.Codec < any > , server_id: string, steam_id: string,
options ? : Nats.SubscriptionOptions
): Promise < Nats.Subscription > {
return new Promise(async (resolve, reject) => {
let subscribeOptions: Nats.SubscriptionOptions = {
...options
};
try {
let subscription = nc.subscribe(`v0.rust.servers.${server_id}.events.player.${steam_id}.chatted`, subscribeOptions);
(async () => {
for await (const msg of subscription) {
const unmodifiedChannel = `v0.rust.servers.{server_id}.events.player.{steam_id}.chatted`;
let channel = msg.subject;
const serverIdSplit = unmodifiedChannel.split("{server_id}");
const steamIdSplit = serverIdSplit[1].split("{steam_id}");
const splits = [
serverIdSplit[0],
steamIdSplit[0],
steamIdSplit[1]
];
channel = channel.substring(splits[0].length);
const serverIdEnd = channel.indexOf(splits[1]);
const serverIdParam = "" + channel.substring(0, serverIdEnd);
channel = channel.substring(serverIdEnd + splits[1].length);
const steamIdEnd = channel.indexOf(splits[2]);
const steamIdParam = "" + channel.substring(0, steamIdEnd);
let receivedData: any = codec.decode(msg.data);
onDataCallback(undefined, ChatMessage.unmarshal(receivedData), serverIdParam, steamIdParam);
}
console.log("subscription closed");
})();
resolve(subscription);
} catch (e: any) {
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.INTERNAL_NATS_TS_ERROR, e));
}
})
}
6 changes: 4 additions & 2 deletions src/channels/V0RustServersServerIdEventsStarted.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ServerStarted from '../models/ServerStarted';
import * as Nats from 'nats';
import {
ErrorCode,
Expand All @@ -19,7 +20,7 @@ import {
export function subscribe(
onDataCallback: (
err ? : NatsTypescriptTemplateError,
msg ? : null, server_id ? : string) => void,
msg ? : ServerStarted, server_id ? : string) => void,
nc: Nats.NatsConnection,
codec: Nats.Codec < any > , server_id: string,
options ? : Nats.SubscriptionOptions
Expand All @@ -42,7 +43,8 @@ export function subscribe(
channel = channel.substring(splits[0].length);
const serverIdEnd = channel.indexOf(splits[1]);
const serverIdParam = "" + channel.substring(0, serverIdEnd);
onDataCallback(undefined, null, serverIdParam);
let receivedData: any = codec.decode(msg.data);
onDataCallback(undefined, ServerStarted.unmarshal(receivedData), serverIdParam);
}
console.log("subscription closed");
})();
Expand Down
56 changes: 56 additions & 0 deletions src/channels/V0RustServersServerIdEventsStopped.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import ServerStopped from '../models/ServerStopped';
import * as Nats from 'nats';
import {
ErrorCode,
NatsTypescriptTemplateError
} from '../NatsTypescriptTemplateError';
/**
* Module which wraps functionality for the `v0/rust/servers/{server_id}/events/stopped` channel
* @module v0RustServersServerIdEventsStopped
*/
/**
* Internal functionality to setup subscription on the `v0/rust/servers/{server_id}/events/stopped` channel
*
* @param onDataCallback to call when messages are received
* @param nc to subscribe with
* @param codec used to convert messages
* @param server_id parameter to use in topic
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
*/
export function subscribe(
onDataCallback: (
err ? : NatsTypescriptTemplateError,
msg ? : ServerStopped, server_id ? : string) => void,
nc: Nats.NatsConnection,
codec: Nats.Codec < any > , server_id: string,
options ? : Nats.SubscriptionOptions
): Promise < Nats.Subscription > {
return new Promise(async (resolve, reject) => {
let subscribeOptions: Nats.SubscriptionOptions = {
...options
};
try {
let subscription = nc.subscribe(`v0.rust.servers.${server_id}.events.stopped`, subscribeOptions);
(async () => {
for await (const msg of subscription) {
const unmodifiedChannel = `v0.rust.servers.{server_id}.events.stopped`;
let channel = msg.subject;
const serverIdSplit = unmodifiedChannel.split("{server_id}");
const splits = [
serverIdSplit[0],
serverIdSplit[1]
];
channel = channel.substring(splits[0].length);
const serverIdEnd = channel.indexOf(splits[1]);
const serverIdParam = "" + channel.substring(0, serverIdEnd);
let receivedData: any = codec.decode(msg.data);
onDataCallback(undefined, ServerStopped.unmarshal(receivedData), serverIdParam);
}
console.log("subscription closed");
})();
resolve(subscription);
} catch (e: any) {
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.INTERNAL_NATS_TS_ERROR, e));
}
})
}
99 changes: 98 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,29 @@ import {
} from './NatsTypescriptTemplateError';
import * as Nats from 'nats';
import * as v0RustServersServerIdEventsStartedChannel from "./channels/V0RustServersServerIdEventsStarted";
import * as v0RustServersServerIdEventsStoppedChannel from "./channels/V0RustServersServerIdEventsStopped";
import * as v0RustServersServerIdEventsPlayerSteamIdChattedChannel from "./channels/V0RustServersServerIdEventsPlayerSteamIdChatted";
import ServerStarted from "./models/ServerStarted";
import ServerStopped from "./models/ServerStopped";
import ChatMessage from "./models/ChatMessage";
export {
v0RustServersServerIdEventsStartedChannel
};
export {
v0RustServersServerIdEventsStoppedChannel
};
export {
v0RustServersServerIdEventsPlayerSteamIdChattedChannel
};
export {
ServerStarted
};
export {
ServerStopped
};
export {
ChatMessage
};
export {
ErrorCode,
NatsTypescriptTemplateError
Expand Down Expand Up @@ -124,7 +144,7 @@ export class NatsAsyncApiClient {
public subscribeToV0RustServersServerIdEventsStarted(
onDataCallback: (
err ? : NatsTypescriptTemplateError,
msg ? : null, server_id ? : string) => void, server_id: string,
msg ? : ServerStarted, server_id ? : string) => void, server_id: string,
flush ? : boolean,
options ? : Nats.SubscriptionOptions
): Promise < Nats.Subscription > {
Expand All @@ -149,4 +169,81 @@ export class NatsAsyncApiClient {
}
});
}
/**
* Subscribe to the `v0/rust/servers/{server_id}/events/stopped`
*
* Channel for the API to process for when a server has stopped
*
* @param onDataCallback to call when messages are received
* @param server_id parameter to use in topic
* @param flush ensure client is force flushed after subscribing
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
*/
public subscribeToV0RustServersServerIdEventsStopped(
onDataCallback: (
err ? : NatsTypescriptTemplateError,
msg ? : ServerStopped, server_id ? : string) => void, server_id: string,
flush ? : boolean,
options ? : Nats.SubscriptionOptions
): Promise < Nats.Subscription > {
return new Promise(async (resolve, reject) => {
if (!this.isClosed() && this.nc !== undefined && this.codec !== undefined) {
try {
const sub = await v0RustServersServerIdEventsStoppedChannel.subscribe(
onDataCallback,
this.nc,
this.codec, server_id,
options
);
if (flush) {
await this.nc.flush();
}
resolve(sub);
} catch (e: any) {
reject(e);
}
} else {
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.NOT_CONNECTED));
}
});
}
/**
* Subscribe to the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted`
*
* Event for when a player used the chat
*
* @param onDataCallback to call when messages are received
* @param server_id parameter to use in topic
* @param steam_id parameter to use in topic
* @param flush ensure client is force flushed after subscribing
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified
*/
public subscribeToV0RustServersServerIdEventsPlayerSteamIdChatted(
onDataCallback: (
err ? : NatsTypescriptTemplateError,
msg ? : ChatMessage, server_id ? : string, steam_id ? : string) => void, server_id: string, steam_id: string,
flush ? : boolean,
options ? : Nats.SubscriptionOptions
): Promise < Nats.Subscription > {
return new Promise(async (resolve, reject) => {
if (!this.isClosed() && this.nc !== undefined && this.codec !== undefined) {
try {
const sub = await v0RustServersServerIdEventsPlayerSteamIdChattedChannel.subscribe(
onDataCallback,
this.nc,
this.codec, server_id, steam_id,
options
);
if (flush) {
await this.nc.flush();
}
resolve(sub);
} catch (e: any) {
reject(e);
}
} else {
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.NOT_CONNECTED));
}
});
}
}
Loading

0 comments on commit 375ba47

Please sign in to comment.