@qodalis/cli-server-logs 1.0.8 → 2.0.0-beta.2

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/umd/index.js DELETED
@@ -1,228 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@qodalis/cli-core'), require('@angular/core'), require('@microsoft/signalr')) :
3
- typeof define === 'function' && define.amd ? define(['@qodalis/cli-core', '@angular/core', '@microsoft/signalr'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.cliCore, global.ngCore, global.signalR));
5
- })(this, (function (cliCore, core, signalR) { 'use strict';
6
-
7
- function _interopNamespaceDefault(e) {
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var signalR__namespace = /*#__PURE__*/_interopNamespaceDefault(signalR);
25
-
26
- /******************************************************************************
27
- Copyright (c) Microsoft Corporation.
28
-
29
- Permission to use, copy, modify, and/or distribute this software for any
30
- purpose with or without fee is hereby granted.
31
-
32
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
33
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
34
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
35
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
36
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38
- PERFORMANCE OF THIS SOFTWARE.
39
- ***************************************************************************** */
40
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
41
-
42
-
43
- function __decorate(decorators, target, key, desc) {
44
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
45
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
46
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
- return c > 3 && r && Object.defineProperty(target, key, r), r;
48
- }
49
-
50
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
51
- var e = new Error(message);
52
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
53
- };
54
-
55
- // Automatically generated during build
56
- const LIBRARY_VERSION = '1.0.8';
57
-
58
- const levels = ['verbose', 'debug', 'information', 'warning', 'error', 'fatal'];
59
- let CliLogsCommandProcessor = class CliLogsCommandProcessor {
60
- constructor() {
61
- this.command = 'server-logs';
62
- this.description = 'Show live logs';
63
- this.processors = [];
64
- this.metadata = {
65
- requireServer: true,
66
- icon: '📜',
67
- requiredCoreVersion: '0.0.16',
68
- requiredCliVersion: '1.0.37',
69
- };
70
- this.parameters = [
71
- {
72
- name: 'pattern',
73
- type: 'string',
74
- description: 'The regex pattern to search for in the logs',
75
- required: false,
76
- validator: (value) => {
77
- const isValid = this.isValidRegex(value);
78
- return {
79
- valid: isValid,
80
- message: isValid
81
- ? undefined
82
- : 'Invalid regex pattern provided',
83
- };
84
- },
85
- },
86
- {
87
- name: 'level',
88
- type: 'string',
89
- description: 'The log level to filter by, e.g. ' + levels.join(', '),
90
- required: false,
91
- validator: (value) => {
92
- const isValid = levels.includes(value);
93
- return {
94
- valid: isValid,
95
- message: isValid
96
- ? undefined
97
- : 'Invalid log level provided, must be one of: ' +
98
- levels.join(', '),
99
- };
100
- },
101
- },
102
- {
103
- name: 'server',
104
- type: 'string',
105
- description: 'The server to connect to, e.g. "http://localhost:5000"',
106
- required: false,
107
- },
108
- {
109
- name: 'hub',
110
- type: 'string',
111
- description: 'The hub to connect to, e.g. "loghub" (default) or "loghub2"',
112
- required: false,
113
- },
114
- {
115
- name: 'file',
116
- type: 'boolean',
117
- description: 'Export logs to a file',
118
- required: false,
119
- },
120
- ];
121
- this.author = cliCore.DefaultLibraryAuthor;
122
- this.version = LIBRARY_VERSION;
123
- this.processors?.push({
124
- command: 'live',
125
- description: this.description,
126
- parameters: this.parameters,
127
- processCommand: this.processCommand.bind(this),
128
- writeDescription: this.writeDescription.bind(this),
129
- });
130
- }
131
- async processCommand(command, context) {
132
- let qs = '?';
133
- const args = this.excludeKeys(command.args, ['server', 'hub', 'file']);
134
- if (Object.keys(args).length > 0) {
135
- qs += cliCore.toQueryString(args);
136
- }
137
- const hub = command.args['hub'] || 'loghub';
138
- let server = command.args['server'] || '';
139
- server = server.replace(/\/+$/, '');
140
- const url = `${server}/${hub}${qs}`;
141
- console.log('Connecting to:', url);
142
- this.hubConnection = new signalR__namespace.HubConnectionBuilder()
143
- .withUrl(url)
144
- .build();
145
- const buffer = [];
146
- await this.hubConnection
147
- .start()
148
- .then(() => {
149
- console.log('SignalR connection started');
150
- context.writer.writeWarning('Connected to live logs');
151
- if (qs.length) {
152
- Object.keys(args).forEach((key) => {
153
- context.writer.writeWarning(`Filtering logs by: ${key}=${command.args[key]}`);
154
- });
155
- }
156
- let firstLog = true;
157
- let index = 0;
158
- this.hubConnection.on('log', (log) => {
159
- if (firstLog) {
160
- context.writer.writeln();
161
- }
162
- buffer.push(log);
163
- context.writer.writeln(`\x1b[33m${++index}\x1b[0m. ` +
164
- (command.args['pattern']
165
- ? cliCore.highlightTextWithBg(log, new RegExp(command.args['pattern'], 'g'))
166
- : log));
167
- firstLog = false;
168
- });
169
- const subscription = context.onAbort.subscribe(() => {
170
- this.hubConnection.stop();
171
- context.writer.writeWarning('Disconnected from live logs');
172
- if (command.args['file']) {
173
- const filename = `logs-${new Date().toISOString()}.txt`;
174
- context.writer.writeToFile(filename, buffer.join('\n'));
175
- }
176
- subscription.unsubscribe();
177
- });
178
- })
179
- .catch((err) => {
180
- console.error('Error starting SignalR connection:', err);
181
- context.writer.writeError('Failed to connect to live logs');
182
- context.writer.writeError(err?.toString());
183
- });
184
- }
185
- writeDescription(context) {
186
- const { writer } = context;
187
- writer.writeln('Stream live server logs via SignalR');
188
- writer.writeln();
189
- writer.writeln('📋 Usage:');
190
- writer.writeln(` ${writer.wrapInColor('server-logs', cliCore.CliForegroundColor.Cyan)} Start streaming`);
191
- writer.writeln(` ${writer.wrapInColor('server-logs --level=error', cliCore.CliForegroundColor.Cyan)} Filter by level`);
192
- writer.writeln(` ${writer.wrapInColor('server-logs --pattern="Exception"', cliCore.CliForegroundColor.Cyan)} Filter by regex`);
193
- writer.writeln(` ${writer.wrapInColor('server-logs --server=http://localhost:5000', cliCore.CliForegroundColor.Cyan)} Custom server`);
194
- writer.writeln();
195
- writer.writeln(`⚙️ Options:`);
196
- writer.writeln(` ${writer.wrapInColor('--level', cliCore.CliForegroundColor.Yellow)} Log level: verbose, debug, information, warning, error, fatal`);
197
- writer.writeln(` ${writer.wrapInColor('--pattern', cliCore.CliForegroundColor.Yellow)} Regex pattern to highlight matches`);
198
- writer.writeln(` ${writer.wrapInColor('--server', cliCore.CliForegroundColor.Yellow)} Server URL to connect to`);
199
- writer.writeln(` ${writer.wrapInColor('--hub', cliCore.CliForegroundColor.Yellow)} Hub name (default: loghub)`);
200
- writer.writeln(` ${writer.wrapInColor('--file', cliCore.CliForegroundColor.Yellow)} Export logs to a file on disconnect`);
201
- writer.writeln();
202
- writer.writeln(`💡 Press ${writer.wrapInColor('Ctrl+C', cliCore.CliForegroundColor.Yellow)} to stop streaming`);
203
- }
204
- excludeKeys(record, keysToExclude) {
205
- return Object.fromEntries(Object.entries(record).filter(([key]) => !keysToExclude.includes(key)));
206
- }
207
- isValidRegex(pattern) {
208
- try {
209
- new RegExp(pattern);
210
- return true;
211
- }
212
- catch (e) {
213
- return false;
214
- }
215
- }
216
- };
217
- CliLogsCommandProcessor = __decorate([
218
- core.Injectable({
219
- providedIn: 'root',
220
- })
221
- ], CliLogsCommandProcessor);
222
-
223
- cliCore.bootUmdModule({
224
- name: '@qodalis/cli-server-logs',
225
- processors: [new CliLogsCommandProcessor()],
226
- });
227
-
228
- }));