@adaas/a-utils 0.1.14 → 0.1.16
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/README.md +92 -18
- package/dist/index.d.mts +335 -71
- package/dist/index.d.ts +335 -71
- package/dist/index.js +491 -210
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +489 -210
- package/dist/index.mjs.map +1 -1
- package/examples/{channel-examples.ts → A-Channel-examples.ts} +15 -15
- package/examples/{command-examples.ts → A-Command-examples.ts} +47 -45
- package/examples/A-Logger-examples.ts +308 -0
- package/examples/config.ts +1 -1
- package/package.json +26 -7
- package/src/index.ts +3 -1
- package/src/lib/A-Channel/A-Channel.component.ts +84 -17
- package/src/lib/A-Channel/A-Channel.error.ts +5 -5
- package/src/lib/A-Channel/A-ChannelRequest.context.ts +1 -1
- package/src/lib/A-Channel/README.md +24 -24
- package/src/lib/A-Command/A-Command.constants.ts +49 -13
- package/src/lib/A-Command/A-Command.entity.ts +21 -15
- package/src/lib/A-Command/A-Command.types.ts +2 -35
- package/src/lib/A-Config/A-Config.container.ts +3 -3
- package/src/lib/A-Config/components/ConfigReader.component.ts +4 -6
- package/src/lib/A-Logger/A-Logger.component.ts +369 -130
- package/src/lib/A-Logger/A-Logger.constants.ts +69 -0
- package/src/lib/A-Logger/A-Logger.env.ts +27 -0
- package/src/lib/A-Logger/A-Logger.types.ts +3 -0
- package/src/lib/A-Logger/README.md +383 -0
- package/src/lib/A-Manifest/A-Manifest.types.ts +1 -2
- package/src/lib/A-Memory/A-Memory.context.ts +1 -1
- package/tests/A-Channel.test.ts +14 -14
- package/tests/A-Command.test.ts +26 -26
- package/tests/A-Logger.test.ts +520 -0
- package/tests/A-Memory.test.ts +5 -5
- package/tests/A-Polyfill.test.ts +3 -2
package/README.md
CHANGED
|
@@ -2,13 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
# A-Utils SDK
|
|
4
4
|
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
|
|
5
15
|
This package is a set of common utilities that can be used across projects related or not related to ADAAS Ecosystem.
|
|
6
16
|
In this package it is possible to find useful features to work with structures, objects, types, commands, configuration management, logging, scheduling, and more.
|
|
7
17
|
|
|
8
18
|
|
|
9
19
|
| LTS | Latest | npm |
|
|
10
20
|
|---------------|----------|---------------------------|
|
|
11
|
-
| v0.1.
|
|
21
|
+
| v0.1.14 | v0.1.14 | [@adaas/a-utils](https://www.npmjs.com/package/@adaas/a-utils) |
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## ✨ Key Features
|
|
25
|
+
|
|
26
|
+
🚀 **Communication Channels** - Structured messaging with lifecycle management
|
|
27
|
+
⚡ **Command Pattern** - Event-driven command execution with serialization
|
|
28
|
+
🔧 **Configuration Management** - Multi-source config with type safety
|
|
29
|
+
📝 **Smart Logging** - Scope-aware logging with color support
|
|
30
|
+
🛡️ **Access Control** - Regex-based permission management
|
|
31
|
+
💾 **Memory Management** - Type-safe intermediate value storage
|
|
32
|
+
📅 **Task Scheduling** - Promise-based scheduling with cancellation
|
|
33
|
+
🔌 **Polyfills** - Cross-environment compatibility
|
|
34
|
+
🏗️ **Component Architecture** - Extensible dependency injection system
|
|
12
35
|
|
|
13
36
|
|
|
14
37
|
<!-- TABLE OF CONTENTS -->
|
|
@@ -16,6 +39,7 @@ In this package it is possible to find useful features to work with structures,
|
|
|
16
39
|
|
|
17
40
|
- [About the Project](#overview)
|
|
18
41
|
- [Installation](#installation)
|
|
42
|
+
- [Key Features](#-key-features)
|
|
19
43
|
- [Components](#components)
|
|
20
44
|
- [A-Channel](#a-channel)
|
|
21
45
|
- [A-Command](#a-command)
|
|
@@ -69,7 +93,7 @@ class HttpChannel extends A_Channel {}
|
|
|
69
93
|
class HttpProcessor extends A_Component {
|
|
70
94
|
@A_Feature.Extend({ scope: [HttpChannel] })
|
|
71
95
|
async [A_ChannelFeatures.onRequest](
|
|
72
|
-
@A_Inject(
|
|
96
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
73
97
|
) {
|
|
74
98
|
const response = await fetch(context.params.url);
|
|
75
99
|
(context as any)._result = await response.json();
|
|
@@ -225,32 +249,82 @@ const configLoader = new A_ConfigLoader();
|
|
|
225
249
|
|
|
226
250
|
### A-Logger
|
|
227
251
|
|
|
228
|
-
A
|
|
252
|
+
A sophisticated logging component with advanced formatting, scope-based organization, and configurable output levels for ADAAS applications.
|
|
229
253
|
|
|
230
254
|
**Basic Usage:**
|
|
231
255
|
```typescript
|
|
232
256
|
import { A_Logger } from '@adaas/a-utils';
|
|
233
257
|
import { A_Scope } from '@adaas/a-concept';
|
|
234
258
|
|
|
235
|
-
const scope = new A_Scope({
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
259
|
+
const scope = new A_Scope({ name: 'MyService' });
|
|
260
|
+
const logger = new A_Logger(scope);
|
|
261
|
+
|
|
262
|
+
// Basic logging with colors
|
|
263
|
+
logger.log('Application started');
|
|
264
|
+
logger.log('green', 'Operation successful');
|
|
265
|
+
logger.warning('Resource usage high');
|
|
266
|
+
logger.error('Database connection failed');
|
|
267
|
+
|
|
268
|
+
// Object logging with formatting
|
|
269
|
+
const user = { id: 1, name: 'John', active: true };
|
|
270
|
+
logger.log('blue', 'User data:', user);
|
|
271
|
+
|
|
272
|
+
// Multi-argument logging
|
|
273
|
+
logger.log('green',
|
|
274
|
+
'Processing complete:',
|
|
275
|
+
'Records:', 150,
|
|
276
|
+
'Errors:', 2,
|
|
277
|
+
'Success rate:', '98.7%'
|
|
278
|
+
);
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Advanced Features:**
|
|
282
|
+
```typescript
|
|
283
|
+
// Error handling with context
|
|
284
|
+
try {
|
|
285
|
+
throw new Error('Database timeout');
|
|
286
|
+
} catch (error) {
|
|
287
|
+
logger.error('Operation failed:', error, 'Context:', {
|
|
288
|
+
userId: '123',
|
|
289
|
+
operation: 'update'
|
|
290
|
+
});
|
|
291
|
+
}
|
|
239
292
|
|
|
240
|
-
|
|
293
|
+
// Log level filtering (via A_LOGGER_LEVEL env var)
|
|
294
|
+
// Levels: debug, info, warn, error, all
|
|
295
|
+
process.env.A_LOGGER_LEVEL = 'warn'; // Only warnings and errors
|
|
241
296
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
297
|
+
// Scope alignment - all messages align consistently
|
|
298
|
+
const services = [
|
|
299
|
+
new A_Logger(new A_Scope({ name: 'API' })),
|
|
300
|
+
new A_Logger(new A_Scope({ name: 'DatabaseConnectionPool' })),
|
|
301
|
+
new A_Logger(new A_Scope({ name: 'Auth' }))
|
|
302
|
+
];
|
|
246
303
|
```
|
|
247
304
|
|
|
248
|
-
**Features:**
|
|
249
|
-
-
|
|
250
|
-
-
|
|
251
|
-
-
|
|
252
|
-
-
|
|
253
|
-
-
|
|
305
|
+
**Key Features:**
|
|
306
|
+
- ✅ **Scope-based Formatting** - Consistent message alignment regardless of scope name length
|
|
307
|
+
- ✅ **9 Terminal Colors** - green, blue, red, yellow, gray, magenta, cyan, white, pink
|
|
308
|
+
- ✅ **Object Pretty-printing** - JSON formatting with proper indentation
|
|
309
|
+
- ✅ **Error Handling** - Special formatting for A_Error and standard Error objects
|
|
310
|
+
- ✅ **Log Level Filtering** - Configurable filtering (debug, info, warn, error, all)
|
|
311
|
+
- ✅ **Performance Optimized** - Efficient handling of large objects and rapid logging
|
|
312
|
+
- ✅ **Multi-line Support** - Proper alignment for complex multi-argument logs
|
|
313
|
+
- ✅ **Timestamp Integration** - High-precision timestamps (MM:SS:mmm format)
|
|
314
|
+
|
|
315
|
+
**Output Examples:**
|
|
316
|
+
```
|
|
317
|
+
[API ] |15:42:123| Operation successful
|
|
318
|
+
[DatabaseConnectionPool] |15:42:124| Connection established
|
|
319
|
+
[Auth ] |15:42:125| User authenticated: {"id":1,"name":"John"}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Log Levels:**
|
|
323
|
+
- `debug` - Shows all messages
|
|
324
|
+
- `info` - Shows info, warning, and error messages
|
|
325
|
+
- `warn` - Shows warning and error messages only
|
|
326
|
+
- `error` - Shows error messages only
|
|
327
|
+
- `all` - Shows all messages (default)
|
|
254
328
|
|
|
255
329
|
---
|
|
256
330
|
|