Skip to content

Commit fbad17c

Browse files
authored
[DOC] added JSDoc so that the API for the client can be generated and made available (#333)
[ADD] added models for configuring StreamConfig.republish
1 parent 70358b3 commit fbad17c

File tree

6 files changed

+1722
-71
lines changed

6 files changed

+1722
-71
lines changed

nats-base-client/codec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@ import { ErrorCode, NatsError } from "./error.ts";
1717
import { TD, TE } from "./encoders.ts";
1818

1919
export interface Codec<T> {
20+
/**
21+
* Encode T to an Uint8Array suitable for including in a message payload.
22+
* @param d
23+
*/
2024
encode(d: T): Uint8Array;
25+
26+
/**
27+
* Decode an Uint8Array from a message payload into a T
28+
* @param a
29+
*/
2130
decode(a: Uint8Array): T;
2231
}
2332

33+
/**
34+
* Returns a {@link Codec} for encoding strings to a message payload
35+
* and decoding message payloads into strings.
36+
* @constructor
37+
*/
2438
export function StringCodec(): Codec<string> {
2539
return {
2640
encode(d: string): Uint8Array {
@@ -32,6 +46,13 @@ export function StringCodec(): Codec<string> {
3246
};
3347
}
3448

49+
/**
50+
* Returns a {@link Codec} for encoding JavaScript object to JSON and
51+
* serialize them to an Uint8Array, and conversely, from an
52+
* Uint8Array to JSON to a JavaScript Object.
53+
* @param reviver
54+
* @constructor
55+
*/
3556
export function JSONCodec<T = unknown>(
3657
reviver?: (this: unknown, key: string, value: unknown) => unknown,
3758
): Codec<T> {

nats-base-client/jsmdirect_api.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ export class DirectMsgImpl implements DirectMsg {
6565
}
6666

6767
get subject(): string {
68-
return this.header.get(DirectMsgHeaders.JsSubject);
68+
return this.header.get(DirectMsgHeaders.Subject);
6969
}
7070

7171
get seq(): number {
72-
const v = this.header.get(DirectMsgHeaders.JsSequence);
72+
const v = this.header.get(DirectMsgHeaders.Sequence);
7373
return typeof v === "string" ? parseInt(v) : 0;
7474
}
7575

7676
get time(): Date {
77-
return new Date(this.header.get(DirectMsgHeaders.JsTimeStamp));
77+
return new Date(this.header.get(DirectMsgHeaders.TimeStamp));
7878
}
7979

8080
get stream(): string {
81-
return this.header.get(DirectMsgHeaders.JsStream);
81+
return this.header.get(DirectMsgHeaders.Stream);
8282
}
8383
}

nats-base-client/jsutil.ts

+16
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,26 @@ export function defaultConsumer(
5757
}, opts);
5858
}
5959

60+
/**
61+
* Converts the specified millis into Nanos
62+
* @param millis
63+
*/
6064
export function nanos(millis: number): Nanos {
6165
return millis * 1000000;
6266
}
6367

68+
/**
69+
* Convert the specified Nanos into millis
70+
* @param ns
71+
*/
6472
export function millis(ns: Nanos) {
6573
return Math.floor(ns / 1000000);
6674
}
6775

76+
/**
77+
* Returns true if the message is a flow control message
78+
* @param msg
79+
*/
6880
export function isFlowControlMsg(msg: Msg): boolean {
6981
if (msg.data.length > 0) {
7082
return false;
@@ -76,6 +88,10 @@ export function isFlowControlMsg(msg: Msg): boolean {
7688
return h.code >= 100 && h.code < 200;
7789
}
7890

91+
/**
92+
* Returns true if the message is a heart beat message
93+
* @param msg
94+
*/
7995
export function isHeartbeatMsg(msg: Msg): boolean {
8096
return isFlowControlMsg(msg) && msg.headers?.description === "Idle Heartbeat";
8197
}

0 commit comments

Comments
 (0)