@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.
Files changed (34) hide show
  1. package/README.md +92 -18
  2. package/dist/index.d.mts +335 -71
  3. package/dist/index.d.ts +335 -71
  4. package/dist/index.js +491 -210
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +489 -210
  7. package/dist/index.mjs.map +1 -1
  8. package/examples/{channel-examples.ts → A-Channel-examples.ts} +15 -15
  9. package/examples/{command-examples.ts → A-Command-examples.ts} +47 -45
  10. package/examples/A-Logger-examples.ts +308 -0
  11. package/examples/config.ts +1 -1
  12. package/package.json +26 -7
  13. package/src/index.ts +3 -1
  14. package/src/lib/A-Channel/A-Channel.component.ts +84 -17
  15. package/src/lib/A-Channel/A-Channel.error.ts +5 -5
  16. package/src/lib/A-Channel/A-ChannelRequest.context.ts +1 -1
  17. package/src/lib/A-Channel/README.md +24 -24
  18. package/src/lib/A-Command/A-Command.constants.ts +49 -13
  19. package/src/lib/A-Command/A-Command.entity.ts +21 -15
  20. package/src/lib/A-Command/A-Command.types.ts +2 -35
  21. package/src/lib/A-Config/A-Config.container.ts +3 -3
  22. package/src/lib/A-Config/components/ConfigReader.component.ts +4 -6
  23. package/src/lib/A-Logger/A-Logger.component.ts +369 -130
  24. package/src/lib/A-Logger/A-Logger.constants.ts +69 -0
  25. package/src/lib/A-Logger/A-Logger.env.ts +27 -0
  26. package/src/lib/A-Logger/A-Logger.types.ts +3 -0
  27. package/src/lib/A-Logger/README.md +383 -0
  28. package/src/lib/A-Manifest/A-Manifest.types.ts +1 -2
  29. package/src/lib/A-Memory/A-Memory.context.ts +1 -1
  30. package/tests/A-Channel.test.ts +14 -14
  31. package/tests/A-Command.test.ts +26 -26
  32. package/tests/A-Logger.test.ts +520 -0
  33. package/tests/A-Memory.test.ts +5 -5
  34. 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
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
6
+ ![Node.js](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white)
7
+ ![Jest](https://img.shields.io/badge/Jest-323330?style=for-the-badge&logo=Jest&logoColor=white)
8
+ ![npm](https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white)
9
+
10
+ ![License](https://img.shields.io/badge/license-ISC-blue.svg)
11
+ ![Version](https://img.shields.io/npm/v/@adaas/a-utils)
12
+ ![Downloads](https://img.shields.io/npm/dm/@adaas/a-utils)
13
+ ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
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.7 | v0.1.7 | [@adaas/a-utils](https://npm.com) |
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(A_ChannelRequestContext) context: A_ChannelRequestContext
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 comprehensive logging system with color support, scope awareness, and configurable output formatting.
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
- name: 'MyApp',
237
- components: [A_Logger]
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
- const logger = scope.resolve(A_Logger);
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
- logger.log('Hello World');
243
- logger.error('Something went wrong');
244
- logger.warning('This is a warning');
245
- logger.success('Operation completed');
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
- - Colored console output
250
- - Scope-aware logging
251
- - Multiple log levels (log, error, warning, success)
252
- - Integration with A-Config for configuration
253
- - Formatted output with timestamps and scope information
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