@gravito/spectrum 3.0.0 → 3.0.1
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.
- package/dist/index.d.cts +102 -2
- package/dist/index.d.ts +102 -2
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3,34 +3,76 @@ import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
|
3
3
|
/**
|
|
4
4
|
* @gravito/spectrum - Types
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Represents a detailed snapshot of an HTTP request processed by the application.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
* @since 3.0.0
|
|
11
|
+
*/
|
|
6
12
|
interface CapturedRequest {
|
|
13
|
+
/** Unique execution ID. */
|
|
7
14
|
id: string;
|
|
15
|
+
/** HTTP Method (GET, POST, etc.). */
|
|
8
16
|
method: string;
|
|
17
|
+
/** URL Path. */
|
|
9
18
|
path: string;
|
|
19
|
+
/** Full URL. */
|
|
10
20
|
url: string;
|
|
21
|
+
/** HTTP response status code. */
|
|
11
22
|
status: number;
|
|
23
|
+
/** Processing duration in milliseconds. */
|
|
12
24
|
duration: number;
|
|
25
|
+
/** Epoch timestamp of when the request started. */
|
|
13
26
|
startTime: number;
|
|
27
|
+
/** Client IP address. */
|
|
14
28
|
ip: string;
|
|
29
|
+
/** Client user agent string. */
|
|
15
30
|
userAgent?: string;
|
|
31
|
+
/** Incoming request headers. */
|
|
16
32
|
requestHeaders: Record<string, string>;
|
|
33
|
+
/** Outgoing response headers. */
|
|
17
34
|
responseHeaders: Record<string, string>;
|
|
35
|
+
/** Parsed request body (if captured). */
|
|
18
36
|
requestBody?: any;
|
|
37
|
+
/** Parsed response body (if captured). */
|
|
19
38
|
responseBody?: any;
|
|
20
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a log entry captured during application execution.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @since 3.0.0
|
|
45
|
+
*/
|
|
21
46
|
interface CapturedLog {
|
|
47
|
+
/** Unique log entry ID. */
|
|
22
48
|
id: string;
|
|
49
|
+
/** Log severity level. */
|
|
23
50
|
level: 'debug' | 'info' | 'warn' | 'error';
|
|
51
|
+
/** The primary log message text. */
|
|
24
52
|
message: string;
|
|
53
|
+
/** Additional arguments passed to the logger. */
|
|
25
54
|
args: any[];
|
|
55
|
+
/** Epoch timestamp when the log was generated. */
|
|
26
56
|
timestamp: number;
|
|
27
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Represents a database query captured during application execution.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
* @since 3.0.0
|
|
63
|
+
*/
|
|
28
64
|
interface CapturedQuery {
|
|
65
|
+
/** Unique query execution ID. */
|
|
29
66
|
id: string;
|
|
67
|
+
/** The name of the database connection used. */
|
|
30
68
|
connection: string;
|
|
69
|
+
/** The raw or prepared SQL statement. */
|
|
31
70
|
sql: string;
|
|
71
|
+
/** Prepared statement bindings/parameters. */
|
|
32
72
|
bindings: any[];
|
|
73
|
+
/** Query execution duration in milliseconds. */
|
|
33
74
|
duration: number;
|
|
75
|
+
/** Epoch timestamp when the query was executed. */
|
|
34
76
|
timestamp: number;
|
|
35
77
|
}
|
|
36
78
|
|
|
@@ -38,6 +80,15 @@ interface CapturedQuery {
|
|
|
38
80
|
* @gravito/spectrum - Storage Contract
|
|
39
81
|
*/
|
|
40
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Interface for Spectrum storage backends.
|
|
85
|
+
*
|
|
86
|
+
* Implement this interface to provide custom storage for captured telemetry
|
|
87
|
+
* data (requests, logs, queries).
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
* @since 3.0.0
|
|
91
|
+
*/
|
|
41
92
|
interface SpectrumStorage {
|
|
42
93
|
/**
|
|
43
94
|
* Initialize storage driver
|
|
@@ -85,17 +136,30 @@ interface SpectrumStorage {
|
|
|
85
136
|
* @gravito/spectrum - SpectrumOrbit
|
|
86
137
|
*/
|
|
87
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Configuration options for the Spectrum observability orbit.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
* @since 3.0.0
|
|
144
|
+
*/
|
|
88
145
|
interface SpectrumConfig {
|
|
146
|
+
/** The URL path where the dashboard UI will be served. @default '/gravito/spectrum' */
|
|
89
147
|
path?: string;
|
|
148
|
+
/** Maximum number of records to keep in memory/disk per category. @default 100 */
|
|
90
149
|
maxItems?: number;
|
|
150
|
+
/** Whether the spectrum capture is enabled. @default true */
|
|
91
151
|
enabled?: boolean;
|
|
152
|
+
/** Custom storage backend for captured data. Defaults to MemoryStorage. */
|
|
92
153
|
storage?: SpectrumStorage;
|
|
93
154
|
/**
|
|
94
|
-
* Authorization gate
|
|
155
|
+
* Authorization gate for accessing the dashboard and its API.
|
|
156
|
+
* Return true to allow access, false to block.
|
|
95
157
|
*/
|
|
96
158
|
gate?: (c: GravitoContext) => boolean | Promise<boolean>;
|
|
97
159
|
/**
|
|
98
|
-
*
|
|
160
|
+
* Probability sample rate (0.0 to 1.0).
|
|
161
|
+
* 1.0 captures everything, 0.0 captures nothing.
|
|
162
|
+
* @default 1.0
|
|
99
163
|
*/
|
|
100
164
|
sampleRate?: number;
|
|
101
165
|
}
|
|
@@ -111,6 +175,26 @@ interface SpectrumOrbitDeps {
|
|
|
111
175
|
};
|
|
112
176
|
} | null>;
|
|
113
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* SpectrumOrbit is the official observability and debug dashboard for Gravito.
|
|
180
|
+
*
|
|
181
|
+
* It automatically captures HTTP requests, application logs, and database queries,
|
|
182
|
+
* providing a real-time view of your application's internals. It includes a
|
|
183
|
+
* built-in web dashboard for exploring and replaying captured data.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { SpectrumOrbit } from '@gravito/spectrum';
|
|
188
|
+
*
|
|
189
|
+
* const spectrum = new SpectrumOrbit({
|
|
190
|
+
* gate: (ctx) => ctx.get('auth')?.user?.isAdmin
|
|
191
|
+
* });
|
|
192
|
+
* core.addOrbit(spectrum);
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @public
|
|
196
|
+
* @since 3.0.0
|
|
197
|
+
*/
|
|
114
198
|
declare class SpectrumOrbit implements GravitoOrbit {
|
|
115
199
|
static instance: SpectrumOrbit | undefined;
|
|
116
200
|
readonly name = "spectrum";
|
|
@@ -135,9 +219,25 @@ declare class SpectrumOrbit implements GravitoOrbit {
|
|
|
135
219
|
* Persistent storage using JSONL files.
|
|
136
220
|
*/
|
|
137
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Configuration for the `FileStorage` backend.
|
|
224
|
+
*
|
|
225
|
+
* @public
|
|
226
|
+
* @since 3.0.0
|
|
227
|
+
*/
|
|
138
228
|
interface FileStorageConfig {
|
|
229
|
+
/** The directory where captured telemetry data will be stored as JSONL files. */
|
|
139
230
|
directory: string;
|
|
140
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* FileStorage persists Spectrum telemetry data to the local file system.
|
|
234
|
+
*
|
|
235
|
+
* It uses newline-delimited JSON (JSONL) files for efficient appends and
|
|
236
|
+
* maintains an in-memory cache for fast dashboard retrieval.
|
|
237
|
+
*
|
|
238
|
+
* @public
|
|
239
|
+
* @since 3.0.0
|
|
240
|
+
*/
|
|
141
241
|
declare class FileStorage implements SpectrumStorage {
|
|
142
242
|
private config;
|
|
143
243
|
private requestsPath;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,34 +3,76 @@ import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
|
3
3
|
/**
|
|
4
4
|
* @gravito/spectrum - Types
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Represents a detailed snapshot of an HTTP request processed by the application.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
* @since 3.0.0
|
|
11
|
+
*/
|
|
6
12
|
interface CapturedRequest {
|
|
13
|
+
/** Unique execution ID. */
|
|
7
14
|
id: string;
|
|
15
|
+
/** HTTP Method (GET, POST, etc.). */
|
|
8
16
|
method: string;
|
|
17
|
+
/** URL Path. */
|
|
9
18
|
path: string;
|
|
19
|
+
/** Full URL. */
|
|
10
20
|
url: string;
|
|
21
|
+
/** HTTP response status code. */
|
|
11
22
|
status: number;
|
|
23
|
+
/** Processing duration in milliseconds. */
|
|
12
24
|
duration: number;
|
|
25
|
+
/** Epoch timestamp of when the request started. */
|
|
13
26
|
startTime: number;
|
|
27
|
+
/** Client IP address. */
|
|
14
28
|
ip: string;
|
|
29
|
+
/** Client user agent string. */
|
|
15
30
|
userAgent?: string;
|
|
31
|
+
/** Incoming request headers. */
|
|
16
32
|
requestHeaders: Record<string, string>;
|
|
33
|
+
/** Outgoing response headers. */
|
|
17
34
|
responseHeaders: Record<string, string>;
|
|
35
|
+
/** Parsed request body (if captured). */
|
|
18
36
|
requestBody?: any;
|
|
37
|
+
/** Parsed response body (if captured). */
|
|
19
38
|
responseBody?: any;
|
|
20
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a log entry captured during application execution.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @since 3.0.0
|
|
45
|
+
*/
|
|
21
46
|
interface CapturedLog {
|
|
47
|
+
/** Unique log entry ID. */
|
|
22
48
|
id: string;
|
|
49
|
+
/** Log severity level. */
|
|
23
50
|
level: 'debug' | 'info' | 'warn' | 'error';
|
|
51
|
+
/** The primary log message text. */
|
|
24
52
|
message: string;
|
|
53
|
+
/** Additional arguments passed to the logger. */
|
|
25
54
|
args: any[];
|
|
55
|
+
/** Epoch timestamp when the log was generated. */
|
|
26
56
|
timestamp: number;
|
|
27
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Represents a database query captured during application execution.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
* @since 3.0.0
|
|
63
|
+
*/
|
|
28
64
|
interface CapturedQuery {
|
|
65
|
+
/** Unique query execution ID. */
|
|
29
66
|
id: string;
|
|
67
|
+
/** The name of the database connection used. */
|
|
30
68
|
connection: string;
|
|
69
|
+
/** The raw or prepared SQL statement. */
|
|
31
70
|
sql: string;
|
|
71
|
+
/** Prepared statement bindings/parameters. */
|
|
32
72
|
bindings: any[];
|
|
73
|
+
/** Query execution duration in milliseconds. */
|
|
33
74
|
duration: number;
|
|
75
|
+
/** Epoch timestamp when the query was executed. */
|
|
34
76
|
timestamp: number;
|
|
35
77
|
}
|
|
36
78
|
|
|
@@ -38,6 +80,15 @@ interface CapturedQuery {
|
|
|
38
80
|
* @gravito/spectrum - Storage Contract
|
|
39
81
|
*/
|
|
40
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Interface for Spectrum storage backends.
|
|
85
|
+
*
|
|
86
|
+
* Implement this interface to provide custom storage for captured telemetry
|
|
87
|
+
* data (requests, logs, queries).
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
* @since 3.0.0
|
|
91
|
+
*/
|
|
41
92
|
interface SpectrumStorage {
|
|
42
93
|
/**
|
|
43
94
|
* Initialize storage driver
|
|
@@ -85,17 +136,30 @@ interface SpectrumStorage {
|
|
|
85
136
|
* @gravito/spectrum - SpectrumOrbit
|
|
86
137
|
*/
|
|
87
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Configuration options for the Spectrum observability orbit.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
* @since 3.0.0
|
|
144
|
+
*/
|
|
88
145
|
interface SpectrumConfig {
|
|
146
|
+
/** The URL path where the dashboard UI will be served. @default '/gravito/spectrum' */
|
|
89
147
|
path?: string;
|
|
148
|
+
/** Maximum number of records to keep in memory/disk per category. @default 100 */
|
|
90
149
|
maxItems?: number;
|
|
150
|
+
/** Whether the spectrum capture is enabled. @default true */
|
|
91
151
|
enabled?: boolean;
|
|
152
|
+
/** Custom storage backend for captured data. Defaults to MemoryStorage. */
|
|
92
153
|
storage?: SpectrumStorage;
|
|
93
154
|
/**
|
|
94
|
-
* Authorization gate
|
|
155
|
+
* Authorization gate for accessing the dashboard and its API.
|
|
156
|
+
* Return true to allow access, false to block.
|
|
95
157
|
*/
|
|
96
158
|
gate?: (c: GravitoContext) => boolean | Promise<boolean>;
|
|
97
159
|
/**
|
|
98
|
-
*
|
|
160
|
+
* Probability sample rate (0.0 to 1.0).
|
|
161
|
+
* 1.0 captures everything, 0.0 captures nothing.
|
|
162
|
+
* @default 1.0
|
|
99
163
|
*/
|
|
100
164
|
sampleRate?: number;
|
|
101
165
|
}
|
|
@@ -111,6 +175,26 @@ interface SpectrumOrbitDeps {
|
|
|
111
175
|
};
|
|
112
176
|
} | null>;
|
|
113
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* SpectrumOrbit is the official observability and debug dashboard for Gravito.
|
|
180
|
+
*
|
|
181
|
+
* It automatically captures HTTP requests, application logs, and database queries,
|
|
182
|
+
* providing a real-time view of your application's internals. It includes a
|
|
183
|
+
* built-in web dashboard for exploring and replaying captured data.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { SpectrumOrbit } from '@gravito/spectrum';
|
|
188
|
+
*
|
|
189
|
+
* const spectrum = new SpectrumOrbit({
|
|
190
|
+
* gate: (ctx) => ctx.get('auth')?.user?.isAdmin
|
|
191
|
+
* });
|
|
192
|
+
* core.addOrbit(spectrum);
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @public
|
|
196
|
+
* @since 3.0.0
|
|
197
|
+
*/
|
|
114
198
|
declare class SpectrumOrbit implements GravitoOrbit {
|
|
115
199
|
static instance: SpectrumOrbit | undefined;
|
|
116
200
|
readonly name = "spectrum";
|
|
@@ -135,9 +219,25 @@ declare class SpectrumOrbit implements GravitoOrbit {
|
|
|
135
219
|
* Persistent storage using JSONL files.
|
|
136
220
|
*/
|
|
137
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Configuration for the `FileStorage` backend.
|
|
224
|
+
*
|
|
225
|
+
* @public
|
|
226
|
+
* @since 3.0.0
|
|
227
|
+
*/
|
|
138
228
|
interface FileStorageConfig {
|
|
229
|
+
/** The directory where captured telemetry data will be stored as JSONL files. */
|
|
139
230
|
directory: string;
|
|
140
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* FileStorage persists Spectrum telemetry data to the local file system.
|
|
234
|
+
*
|
|
235
|
+
* It uses newline-delimited JSON (JSONL) files for efficient appends and
|
|
236
|
+
* maintains an in-memory cache for fast dashboard retrieval.
|
|
237
|
+
*
|
|
238
|
+
* @public
|
|
239
|
+
* @since 3.0.0
|
|
240
|
+
*/
|
|
141
241
|
declare class FileStorage implements SpectrumStorage {
|
|
142
242
|
private config;
|
|
143
243
|
private requestsPath;
|