forge-sql-orm 2.1.11 → 2.1.12

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.
@@ -1,45 +1,45 @@
1
- import {getHttpResponse, TriggerResponse} from "./index";
2
- import {slowQueryPerHours} from "../utils/sqlUtils";
3
- import {ForgeSqlOperation} from "../core/ForgeSQLQueryBuilder";
1
+ import { getHttpResponse, TriggerResponse } from "./index";
2
+ import { slowQueryPerHours } from "../utils/sqlUtils";
3
+ import { ForgeSqlOperation } from "../core/ForgeSQLQueryBuilder";
4
4
 
5
5
  /**
6
6
  * Scheduler trigger for analyzing slow queries from the last specified number of hours.
7
- *
7
+ *
8
8
  * This trigger analyzes slow queries from TiDB's slow query log system table and provides
9
9
  * detailed performance information including SQL query text, memory usage, execution time,
10
10
  * and execution plans. It's designed to be used as a scheduled trigger in Atlassian Forge
11
11
  * to monitor query performance over time.
12
- *
12
+ *
13
13
  * The function queries the slow query system table to find queries executed within the
14
14
  * specified time window and logs detailed performance information to the console. Results
15
15
  * are limited to the top 50 slow queries to prevent excessive output.
16
- *
16
+ *
17
17
  * @param forgeSQLORM - The ForgeSQL operation instance for database access
18
18
  * @param options - Configuration options for the slow query analysis
19
19
  * @param options.hours - Number of hours to look back for slow queries (default: 1)
20
20
  * @param options.timeout - Timeout in milliseconds for the query execution (default: 2000ms)
21
- *
21
+ *
22
22
  * @returns Promise<TriggerResponse<string>> - HTTP response with JSON stringified query results or error message
23
- *
23
+ *
24
24
  * @example
25
25
  * ```typescript
26
26
  * import ForgeSQL, { slowQuerySchedulerTrigger } from "forge-sql-orm";
27
- *
27
+ *
28
28
  * const forgeSQL = new ForgeSQL();
29
- *
29
+ *
30
30
  * // Basic usage with default options (1 hour, 2000ms timeout)
31
31
  * export const slowQueryTrigger = () =>
32
32
  * slowQuerySchedulerTrigger(forgeSQL, { hours: 1, timeout: 2000 });
33
- *
33
+ *
34
34
  * // Analyze slow queries from the last 6 hours with extended timeout
35
35
  * export const sixHourSlowQueryTrigger = () =>
36
36
  * slowQuerySchedulerTrigger(forgeSQL, { hours: 6, timeout: 5000 });
37
- *
37
+ *
38
38
  * // Analyze slow queries from the last 24 hours
39
39
  * export const dailySlowQueryTrigger = () =>
40
40
  * slowQuerySchedulerTrigger(forgeSQL, { hours: 24, timeout: 3000 });
41
41
  * ```
42
- *
42
+ *
43
43
  * @example
44
44
  * ```yaml
45
45
  * # manifest.yml configuration
@@ -47,36 +47,43 @@ import {ForgeSqlOperation} from "../core/ForgeSQLQueryBuilder";
47
47
  * - key: slow-query-trigger
48
48
  * function: slowQueryTrigger
49
49
  * interval: hour
50
- *
50
+ *
51
51
  * function:
52
52
  * - key: slowQueryTrigger
53
53
  * handler: index.slowQueryTrigger
54
54
  * ```
55
- *
55
+ *
56
56
  * @remarks
57
57
  * - Results are automatically logged to the Forge Developer Console via `console.warn()`
58
58
  * - The function returns up to 50 slow queries to prevent excessive logging
59
59
  * - Transient timeouts are usually fine; repeated timeouts indicate the diagnostic query itself is slow
60
60
  * - This trigger is best used with hourly intervals to catch slow queries in a timely manner
61
61
  * - Error responses return HTTP 500 with error details
62
- *
62
+ *
63
63
  * @see {@link slowQueryPerHours} - The underlying function that performs the actual query analysis
64
64
  */
65
- export async function slowQuerySchedulerTrigger(forgeSQLORM: ForgeSqlOperation, options: {
66
- hours: number,
67
- timeout: number
68
- }): Promise<TriggerResponse<string>> {
69
- try {
70
- return getHttpResponse<string>(200, JSON.stringify(await slowQueryPerHours(forgeSQLORM, options?.hours ?? 1, options?.timeout ?? 3000)));
71
- } catch (error: any) {
72
- const errorMessage =
73
- error?.debug?.sqlMessage ??
74
- error?.debug?.message ??
75
- error.message ??
76
- "Unknown error occurred";
77
- // eslint-disable-next-line no-console
78
- console.error(errorMessage);
79
- return getHttpResponse<string>(500, errorMessage);
80
- }
65
+ export async function slowQuerySchedulerTrigger(
66
+ forgeSQLORM: ForgeSqlOperation,
67
+ options: {
68
+ hours: number;
69
+ timeout: number;
70
+ },
71
+ ): Promise<TriggerResponse<string>> {
72
+ try {
73
+ return getHttpResponse<string>(
74
+ 200,
75
+ JSON.stringify(
76
+ await slowQueryPerHours(forgeSQLORM, options?.hours ?? 1, options?.timeout ?? 3000),
77
+ ),
78
+ );
79
+ } catch (error: any) {
80
+ const errorMessage =
81
+ error?.debug?.sqlMessage ??
82
+ error?.debug?.message ??
83
+ error.message ??
84
+ "Unknown error occurred";
85
+ // eslint-disable-next-line no-console
86
+ console.error(errorMessage);
87
+ return getHttpResponse<string>(500, errorMessage);
88
+ }
81
89
  }
82
-