Skip to content

Commit 0237b83

Browse files
docs: #161 Document methods using tsdoc format (#274)
* add eslint tsdoc plugin * configured tsdoc eslint * configured tsdoc eslint * documented public methods raygun.batch.ts * documented lib/raygun.breadcrumbs.express.ts * document methods in lib/raygun.breadcrumbs.ts * documented lib/raygun.human.ts * documented lib/raygun.messageBuilder.ts * fix docs in lib/raygun.sync.transport.ts * fix docs lib/raygun.transport.ts * fix docs in lib/raygun.ts
1 parent 588fae6 commit 0237b83

11 files changed

+260
-36
lines changed

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import eslint from '@eslint/js';
44
import stylistic from '@stylistic/eslint-plugin';
55
import stylisticTs from '@stylistic/eslint-plugin-ts';
66
import tseslint from 'typescript-eslint';
7+
import tsdocPlugin from 'eslint-plugin-tsdoc';
78

89
export default tseslint.config(
910
// Basic eslint rules
@@ -15,6 +16,9 @@ export default tseslint.config(
1516
// Eslint rules for TS
1617
...tseslint.configs.recommended,
1718
{
19+
plugins: {
20+
['tsdoc']: tsdocPlugin,
21+
},
1822
languageOptions: {
1923
// Add node globals to ignore undefined
2024
globals: {
@@ -59,6 +63,8 @@ export default tseslint.config(
5963
"@stylistic/ts/no-extra-parens": ["off", 0],
6064
"@stylistic/ts/quote-props": ["off", 0],
6165
"@stylistic/ts/space-before-function-paren": ["off", 0],
66+
// Documentation format check
67+
"tsdoc/syntax": "warn"
6268
}
6369
}
6470
);

lib/raygun.batch.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class RaygunBatchTransport {
5050

5151
/**
5252
* Enqueues send request to batch processor.
53-
* @param options send options without callback
54-
* @return Promise with response or error if rejected
53+
* @param options - send options without callback
54+
* @returns Promise with response or error if rejected
5555
*/
5656
send(options: SendOptions): Promise<IncomingMessage> {
5757
const promise = this.onIncomingMessage(options.message);
@@ -63,6 +63,9 @@ export class RaygunBatchTransport {
6363
return promise;
6464
}
6565

66+
/**
67+
* Stops batch transport and clears timerId
68+
*/
6669
stopProcessing() {
6770
if (this.timerId) {
6871
debug("[raygun.batch.ts] Batch transport - stopping");

lib/raygun.breadcrumbs.express.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const debug = require("debug")("raygun");
66

77
/**
88
* Parses an ExpressJS Request and adds it to the breadcrumbs store
9-
* @param request
9+
* @param request - ExpressJS request object
1010
*/
1111
export function addRequestBreadcrumb(request: Request) {
1212
const crumbs = getBreadcrumbs();

lib/raygun.breadcrumbs.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ function getCallsite(): SourceFile | null {
5757
return callsite;
5858
}
5959

60+
/**
61+
* Adds Breadcrumb to current scope
62+
* @param breadcrumb - either String message or BreadcrumbMessage object
63+
* @param type - defaults to manual, values as defined in Breadcrumb type
64+
*/
6065
export function addBreadcrumb(
6166
breadcrumb: string | BreadcrumbMessage,
6267
type: Breadcrumb["type"] = "manual",
@@ -98,6 +103,10 @@ export function addBreadcrumb(
98103
crumbs.push(internalCrumb);
99104
}
100105

106+
/**
107+
* Obtain list of Breadcrumbs in current scope
108+
* @returns List of Breadcrumbs or null if no local storage
109+
*/
101110
export function getBreadcrumbs(): Breadcrumb[] | null {
102111
if (!asyncLocalStorage) {
103112
return null;
@@ -117,6 +126,11 @@ export function getBreadcrumbs(): Breadcrumb[] | null {
117126
return newStore;
118127
}
119128

129+
/**
130+
* Run synchronous function in Breadcrumb scope
131+
* @param f - function to run
132+
* @param store - optional Breadcrumb scope store
133+
*/
120134
export function runWithBreadcrumbs(f: () => void, store: Breadcrumb[] = []) {
121135
if (!asyncLocalStorage) {
122136
f();
@@ -127,6 +141,11 @@ export function runWithBreadcrumbs(f: () => void, store: Breadcrumb[] = []) {
127141
asyncLocalStorage.run(store, f);
128142
}
129143

144+
/**
145+
* Run asynchronous function returning a Promise in Breadcrumb scope
146+
* @param f - asynchronous function to run
147+
* @param store - optional Breadcrumb scope store
148+
*/
130149
export function runWithBreadcrumbsAsync<T>(
131150
f: () => Promise<T>,
132151
store: Breadcrumb[] = [],
@@ -139,6 +158,9 @@ export function runWithBreadcrumbsAsync<T>(
139158
return asyncLocalStorage.run(store, f);
140159
}
141160

161+
/**
162+
* Clear the stored Breadcrumbs in current scope
163+
*/
142164
export function clear() {
143165
if (!asyncLocalStorage) {
144166
return;

lib/raygun.human.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ const symbolEqual = "=";
99
* - Maximum one level deep
1010
*
1111
* Example:
12-
* - Object "{ name: "Test" }" becomes string "name=Test" as all is the top level
13-
* - Object "{ one: { name: "Test" }}" becomes string "one={name=Test}" as one level deep is explored
14-
* - Object "{ one: { two: { name: "Test" }}}" becomes string "one={two=...}" as the max level deep is reached
12+
* - Object `{ name: "Test" }` becomes string `name=Test` as all is the top level
13+
* - Object `{ one: { name: "Test" }}` becomes string `one={name=Test}` as one level deep is explored
14+
* - Object `{ one: { two: { name: "Test" }}}` becomes string `one={two=...}` as the max level deep is reached
1515
*
16-
* @param obj input object to stringify
17-
* @param level level of recursion, should start at 0
16+
* @param obj - input object to stringify
17+
* @param level - level of recursion, should start at 0
18+
* @returns a formatted String
1819
*/
1920
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2021
export function humanString(obj: any, level: number = 0): string {

lib/raygun.messageBuilder.ts

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ const packageDetails = require("../package.json");
3737
/**
3838
* Filter properties in obj according to provided filters.
3939
* Also removes any recursive self-referencing object.
40-
* @param obj object to apply filter
41-
* @param filters list of keys to filter
42-
* @param explored Set that contains already explored nodes, used internally
40+
* @param obj - object to apply filter
41+
* @param filters - list of keys to filter
42+
* @param explored - Set that contains already explored nodes, used internally
43+
* @returns object after applying the filters
4344
*/
4445
function filterKeys(
4546
obj: object,
@@ -70,6 +71,12 @@ function filterKeys(
7071
return _obj;
7172
}
7273

74+
/**
75+
* Extract stacktrace from provided Error
76+
* @param error - error to process
77+
* @param options - builder options
78+
* @returns created stack trace
79+
*/
7380
function getStackTrace(
7481
error: Error,
7582
options: MessageBuilderOptions,
@@ -98,6 +105,12 @@ function getStackTrace(
98105
return stack;
99106
}
100107

108+
/**
109+
* Created an error payload to send
110+
* @param error - error to process
111+
* @param options - builder options
112+
* @returns created error
113+
*/
101114
function buildError(
102115
error: IndexableError,
103116
options: MessageBuilderOptions,
@@ -153,6 +166,10 @@ export class RaygunMessageBuilder {
153166
return this.message as Message;
154167
}
155168

169+
/**
170+
* Add error details to builder
171+
* @param error - error to add
172+
*/
156173
// eslint-disable-next-line @typescript-eslint/no-explicit-any
157174
setErrorDetails(error: Error | string | any) {
158175
if (
@@ -181,6 +198,9 @@ export class RaygunMessageBuilder {
181198
return this;
182199
}
183200

201+
/**
202+
* Set environment details from OS to builder
203+
*/
184204
setEnvironmentDetails() {
185205
const environment: Environment = {
186206
osVersion: `${os.type()} ${os.platform()} ${os.release()}`,
@@ -203,23 +223,39 @@ export class RaygunMessageBuilder {
203223
return this;
204224
}
205225

226+
/**
227+
* Set machine name to builder
228+
* @param machineName - the machine name, if not provided reads from OS
229+
*/
206230
setMachineName(machineName?: string) {
207231
this.message.details.machineName = machineName || os.hostname();
208232
return this;
209233
}
210234

235+
/**
236+
* Set custom data to builder
237+
* @param customData - optional CustomData object
238+
*/
211239
setUserCustomData(customData?: CustomData) {
212240
this.message.details.userCustomData = customData;
213241
return this;
214242
}
215243

244+
/**
245+
* Set tags to builder
246+
* @param tags - List of Tags
247+
*/
216248
setTags(tags: Tag[]) {
217249
if (Array.isArray(tags)) {
218250
this.message.details.tags = tags;
219251
}
220252
return this;
221253
}
222254

255+
/**
256+
* Set Request to builder
257+
* @param request - optional request object
258+
*/
223259
setRequestDetails(request: RequestParams | undefined) {
224260
if (request) {
225261
const host = "hostname" in request ? request.hostname : request.host;
@@ -237,6 +273,10 @@ export class RaygunMessageBuilder {
237273
return this;
238274
}
239275

276+
/**
277+
* Set user info to builder
278+
* @param user - either a function or a UserMessageData object
279+
*/
240280
setUser(user: (() => UserMessageData) | UserMessageData | undefined) {
241281
if (!user) {
242282
return this;
@@ -258,6 +298,10 @@ export class RaygunMessageBuilder {
258298
return this;
259299
}
260300

301+
/**
302+
* Set application version to builder
303+
* @param version - version as String
304+
*/
261305
setVersion(version: string) {
262306
this.message.details.version = version;
263307
return this;
@@ -286,6 +330,10 @@ export class RaygunMessageBuilder {
286330
return data;
287331
}
288332

333+
/**
334+
* Set list of breadcrumbs to builder
335+
* @param breadcrumbs - optional list of breadcrumbs
336+
*/
289337
setBreadcrumbs(breadcrumbs: Breadcrumb[] | null) {
290338
debug(
291339
`[raygun.messageBuilder.ts] Added breadcrumbs: ${breadcrumbs?.length || 0}`,

lib/raygun.sync.transport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function syncRequest(httpOptions: SendOptions) {
2525
* Spawns a synchronous send request.
2626
* Errors are not returned and callback is ignored.
2727
* Only used to report uncaught exceptions.
28-
* @param options
28+
* @param options - Send options
2929
*/
3030
export function send(options: SendOptions) {
3131
try {

lib/raygun.transport.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export function sendBatch(options: SendOptions): Promise<IncomingMessage> {
2525
/**
2626
* Transport implementation that sends error to Raygun.
2727
* Errors are reported back via callback.
28-
* @param options without callback
29-
* @param path service endpoint
30-
* @return Promise with IncomingMessage or rejected with Error
28+
* @param options - without callback
29+
* @param path - service endpoint
30+
* @returns Promise with IncomingMessage or rejected with Error
3131
*/
3232
export function send(
3333
options: SendOptions,

0 commit comments

Comments
 (0)