@adaas/a-utils 0.1.28 → 0.1.30
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/LICENSE +1 -1
- package/dist/index.cjs +18 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +402 -21
- package/dist/index.d.ts +402 -21
- package/dist/index.mjs +18 -28
- package/dist/index.mjs.map +1 -1
- package/examples/A-Logger-examples.ts +101 -24
- package/package.json +5 -5
- package/src/index.ts +16 -0
- package/src/lib/A-Logger/A-Logger.component.ts +385 -70
- package/src/lib/A-Logger/A-Logger.constants.ts +13 -0
- package/src/lib/A-Logger/A-Logger.types.ts +12 -1
- package/src/lib/A-Logger/README.md +116 -12
- package/src/lib/A-Memory/A-Memory.component.ts +0 -3
- package/src/lib/A-Route/A-Route.entity.ts +136 -0
- package/src/lib/A-Route/A-Route.types.ts +1 -0
- package/src/lib/A-Signal/A-Signal.constants.ts +10 -0
- package/src/lib/A-Signal/A-Signal.error.ts +0 -0
- package/src/lib/A-Signal/A-Signal.types.ts +47 -0
- package/src/lib/A-Signal/components/A-SignalBus.component.ts +103 -0
- package/src/lib/A-Signal/context/A-SignalConfig.context.ts +81 -0
- package/src/lib/A-Signal/context/A-SignalState.context.ts +197 -0
- package/src/lib/A-Signal/entities/A-Signal.entity.ts +42 -0
- package/src/lib/A-Signal/entities/A-SignalVector.entity.ts +83 -0
- package/src/lib/A-StateMachine/A-StateMachine.component.ts +2 -1
- package/tests/A-Logger.test.ts +90 -5
- package/tests/A-Route.test.ts +34 -0
- package/tests/A-Signal.test.ts +66 -0
- package/examples/config.ts +0 -33
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This file demonstrates various usage patterns and features of the A_Logger component.
|
|
5
5
|
* These examples show the logging capabilities without complex dependency injection.
|
|
6
|
+
*
|
|
7
|
+
* New Features Demonstrated:
|
|
8
|
+
* - Terminal width detection and automatic text wrapping
|
|
9
|
+
* - Enhanced color palette with A_LoggerColorName enum support
|
|
10
|
+
* - Responsive formatting for different terminal sizes
|
|
11
|
+
* - Browser console compatibility
|
|
6
12
|
*/
|
|
7
13
|
|
|
8
14
|
import { A_Scope, A_Error } from "@adaas/a-concept";
|
|
9
15
|
import { A_Logger } from "../src/lib/A-Logger/A-Logger.component";
|
|
16
|
+
import { A_LoggerColorName } from "../src/lib/A-Logger/A-Logger.types";
|
|
10
17
|
|
|
11
18
|
// =============================================
|
|
12
19
|
// Basic Logging Examples
|
|
@@ -21,10 +28,11 @@ function basicLogging() {
|
|
|
21
28
|
const scope = new A_Scope({ name: 'API-Service' });
|
|
22
29
|
const logger = new A_Logger(scope);
|
|
23
30
|
|
|
24
|
-
// Different log types
|
|
25
|
-
logger.
|
|
26
|
-
logger.
|
|
27
|
-
logger.
|
|
31
|
+
// Different log types with color enum support
|
|
32
|
+
logger.info('Logger initialized successfully');
|
|
33
|
+
logger.info('green', 'This is a success message');
|
|
34
|
+
logger.info('brightBlue', 'This is a bright blue info message');
|
|
35
|
+
logger.debug('gray', 'This is a debug message (may not show depending on log level)');
|
|
28
36
|
logger.warning('This is a warning message');
|
|
29
37
|
logger.error('This is an error message');
|
|
30
38
|
}
|
|
@@ -130,7 +138,7 @@ function errorLogging() {
|
|
|
130
138
|
}
|
|
131
139
|
|
|
132
140
|
/**
|
|
133
|
-
* Example 5:
|
|
141
|
+
* Example 5: Color Demonstration with A_LoggerColorName Enum
|
|
134
142
|
*/
|
|
135
143
|
function colorDemo() {
|
|
136
144
|
console.log('\n=== Example 5: Color Demonstration ===\n');
|
|
@@ -138,16 +146,78 @@ function colorDemo() {
|
|
|
138
146
|
const scope = new A_Scope({ name: 'ColorDemo' });
|
|
139
147
|
const logger = new A_Logger(scope);
|
|
140
148
|
|
|
141
|
-
//
|
|
142
|
-
const
|
|
149
|
+
// Basic colors
|
|
150
|
+
const basicColors: A_LoggerColorName[] = ['green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan'];
|
|
151
|
+
console.log('Basic Colors:');
|
|
152
|
+
basicColors.forEach(color => {
|
|
153
|
+
logger.info(color, `This is a ${color} colored message`);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Extended color palette
|
|
157
|
+
const extendedColors: A_LoggerColorName[] = [
|
|
158
|
+
'brightBlue', 'brightCyan', 'brightMagenta',
|
|
159
|
+
'indigo', 'violet', 'purple', 'lavender',
|
|
160
|
+
'skyBlue', 'steelBlue', 'slateBlue', 'deepBlue',
|
|
161
|
+
'lightBlue', 'periwinkle', 'cornflower', 'powder'
|
|
162
|
+
];
|
|
163
|
+
console.log('\nExtended Color Palette:');
|
|
164
|
+
extendedColors.forEach(color => {
|
|
165
|
+
logger.info(color, `Extended color: ${color}`);
|
|
166
|
+
});
|
|
143
167
|
|
|
144
|
-
|
|
145
|
-
|
|
168
|
+
// Grayscale colors
|
|
169
|
+
const grayscaleColors: A_LoggerColorName[] = ['darkGray', 'lightGray', 'charcoal', 'silver', 'smoke', 'slate'];
|
|
170
|
+
console.log('\nGrayscale Colors:');
|
|
171
|
+
grayscaleColors.forEach(color => {
|
|
172
|
+
logger.info(color, `Grayscale: ${color}`);
|
|
146
173
|
});
|
|
147
174
|
}
|
|
148
175
|
|
|
149
176
|
/**
|
|
150
|
-
* Example 6:
|
|
177
|
+
* Example 6: Terminal Width and Text Wrapping Demonstration
|
|
178
|
+
*/
|
|
179
|
+
function terminalWidthDemo() {
|
|
180
|
+
console.log('\n=== Example 6: Terminal Width Demonstration ===\n');
|
|
181
|
+
|
|
182
|
+
const scope = new A_Scope({ name: 'TerminalWidth' });
|
|
183
|
+
const logger = new A_Logger(scope);
|
|
184
|
+
|
|
185
|
+
// Long single line that will wrap
|
|
186
|
+
logger.info('cyan', 'This is a very long message that demonstrates automatic text wrapping based on terminal width detection. The logger automatically detects your terminal width and wraps text appropriately to ensure readable output without manual line breaks. This feature works in both Node.js terminal environments and browser consoles with appropriate defaults.');
|
|
187
|
+
|
|
188
|
+
// Multiple long arguments
|
|
189
|
+
logger.info('purple',
|
|
190
|
+
'First argument with considerable length to demonstrate wrapping behavior across multiple arguments.',
|
|
191
|
+
'Second argument that is also quite long and will be properly formatted with consistent indentation.',
|
|
192
|
+
'Third argument to show how multiple wrapped arguments maintain visual hierarchy.'
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Object with long values
|
|
196
|
+
const configObject = {
|
|
197
|
+
databaseConnectionString: 'postgresql://user:password@localhost:5432/mydatabase?ssl=true&connection_timeout=30000&pool_min=5&pool_max=20',
|
|
198
|
+
apiEndpoint: 'https://api.example.com/v2/users/profiles/detailed-information-endpoint-with-very-long-path-name',
|
|
199
|
+
description: 'This is a configuration object with very long string values that will demonstrate how the logger handles wrapping within JSON formatted output',
|
|
200
|
+
features: {
|
|
201
|
+
enableAutoWrapping: true,
|
|
202
|
+
terminalWidthDetection: 'automatic',
|
|
203
|
+
fallbackWidth: 80,
|
|
204
|
+
browserConsoleWidth: 120
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
logger.info('brightMagenta', 'Configuration loaded:', configObject);
|
|
209
|
+
|
|
210
|
+
// Show current terminal info
|
|
211
|
+
logger.info('steelBlue', 'Terminal environment info:', {
|
|
212
|
+
environment: process?.stdout?.isTTY ? 'TTY Terminal' : 'Non-TTY Environment',
|
|
213
|
+
columns: process?.stdout?.columns || 'Not Available',
|
|
214
|
+
rows: process?.stdout?.rows || 'Not Available',
|
|
215
|
+
platform: process?.platform || 'Browser'
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Example 7: Performance Logging Simulation
|
|
151
221
|
*/
|
|
152
222
|
async function performanceLogging() {
|
|
153
223
|
console.log('\n=== Example 6: Performance Logging ===\n');
|
|
@@ -166,7 +236,7 @@ async function performanceLogging() {
|
|
|
166
236
|
const duration = Date.now() - startTime;
|
|
167
237
|
const status = duration < 100 ? 'green' : duration < 150 ? 'yellow' : 'red';
|
|
168
238
|
|
|
169
|
-
logger.
|
|
239
|
+
logger.info(status as A_LoggerColorName, `${operation} completed:`, {
|
|
170
240
|
operation,
|
|
171
241
|
duration: `${duration}ms`,
|
|
172
242
|
status: duration < 100 ? 'fast' : duration < 150 ? 'normal' : 'slow',
|
|
@@ -176,10 +246,10 @@ async function performanceLogging() {
|
|
|
176
246
|
}
|
|
177
247
|
|
|
178
248
|
/**
|
|
179
|
-
* Example
|
|
249
|
+
* Example 8: Real-world Service Logging
|
|
180
250
|
*/
|
|
181
251
|
async function serviceLogging() {
|
|
182
|
-
console.log('\n=== Example
|
|
252
|
+
console.log('\n=== Example 8: Service Logging Simulation ===\n');
|
|
183
253
|
|
|
184
254
|
// Create different service loggers
|
|
185
255
|
const services = {
|
|
@@ -192,25 +262,25 @@ async function serviceLogging() {
|
|
|
192
262
|
// Simulate user registration flow
|
|
193
263
|
const userId = 'user-' + Math.random().toString(36).substr(2, 9);
|
|
194
264
|
|
|
195
|
-
services.api.
|
|
265
|
+
services.api.info('brightBlue', 'Registration request received:', {
|
|
196
266
|
endpoint: '/api/auth/register',
|
|
197
267
|
userId,
|
|
198
268
|
timestamp: new Date().toISOString()
|
|
199
269
|
});
|
|
200
270
|
|
|
201
|
-
services.auth.
|
|
271
|
+
services.auth.info('indigo', 'Validating user credentials...');
|
|
202
272
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
203
|
-
services.auth.
|
|
273
|
+
services.auth.info('green', 'Credentials validated successfully');
|
|
204
274
|
|
|
205
|
-
services.db.
|
|
275
|
+
services.db.info('violet', 'Creating user record...');
|
|
206
276
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
207
|
-
services.db.
|
|
277
|
+
services.db.info('green', 'User record created:', { userId, table: 'users' });
|
|
208
278
|
|
|
209
|
-
services.cache.
|
|
279
|
+
services.cache.info('cornflower', 'Caching user session...');
|
|
210
280
|
await new Promise(resolve => setTimeout(resolve, 30));
|
|
211
|
-
services.cache.
|
|
281
|
+
services.cache.info('green', 'Session cached:', { userId, ttl: 3600 });
|
|
212
282
|
|
|
213
|
-
services.api.
|
|
283
|
+
services.api.info('green', 'Registration completed successfully:', {
|
|
214
284
|
userId,
|
|
215
285
|
totalTime: '180ms',
|
|
216
286
|
status: 'success'
|
|
@@ -218,10 +288,10 @@ async function serviceLogging() {
|
|
|
218
288
|
}
|
|
219
289
|
|
|
220
290
|
/**
|
|
221
|
-
* Example
|
|
291
|
+
* Example 9: Complex Object Logging with Enhanced Formatting
|
|
222
292
|
*/
|
|
223
293
|
function complexObjectLogging() {
|
|
224
|
-
console.log('\n=== Example
|
|
294
|
+
console.log('\n=== Example 9: Complex Object Logging ===\n');
|
|
225
295
|
|
|
226
296
|
const scope = new A_Scope({ name: 'ComplexLogger' });
|
|
227
297
|
const logger = new A_Logger(scope);
|
|
@@ -258,7 +328,12 @@ function complexObjectLogging() {
|
|
|
258
328
|
}
|
|
259
329
|
};
|
|
260
330
|
|
|
261
|
-
logger.
|
|
331
|
+
logger.info('deepBlue', 'API Request Complete:', complexObject);
|
|
332
|
+
|
|
333
|
+
// Demonstrate terminal width with a very long single-line log
|
|
334
|
+
const longMessage = 'This demonstrates how the logger handles extremely long single messages that exceed normal terminal width. The message will be automatically wrapped while maintaining proper indentation and visual hierarchy. This feature ensures readability across different terminal sizes and environments, from narrow mobile terminals to wide desktop displays.';
|
|
335
|
+
|
|
336
|
+
logger.info('lavender', 'Long message demonstration:', longMessage);
|
|
262
337
|
}
|
|
263
338
|
|
|
264
339
|
// =============================================
|
|
@@ -278,6 +353,7 @@ async function runAllExamples() {
|
|
|
278
353
|
objectLogging();
|
|
279
354
|
errorLogging();
|
|
280
355
|
colorDemo();
|
|
356
|
+
terminalWidthDemo();
|
|
281
357
|
await performanceLogging();
|
|
282
358
|
await serviceLogging();
|
|
283
359
|
complexObjectLogging();
|
|
@@ -296,6 +372,7 @@ export {
|
|
|
296
372
|
objectLogging,
|
|
297
373
|
errorLogging,
|
|
298
374
|
colorDemo,
|
|
375
|
+
terminalWidthDemo,
|
|
299
376
|
performanceLogging,
|
|
300
377
|
serviceLogging,
|
|
301
378
|
complexObjectLogging,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"scripts": {
|
|
70
70
|
"test": "jest ",
|
|
71
71
|
"start": "nodemon ./tests/log.ts",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
72
|
+
"example:A-Config": "nodemon ./examples/config.ts",
|
|
73
|
+
"example:A-Logger": "nodemon ./examples/A-Logger-examples.ts",
|
|
74
|
+
"example:A-Command": "nodemon ./examples/A-Command-examples.ts",
|
|
75
75
|
"release": "npm run test && npm run build && git add . && git commit -m \"new version created :: $(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g')\" && npm version patch && npm publish --access public",
|
|
76
76
|
"preversion": "echo test",
|
|
77
77
|
"version": "echo git add .",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"build": "tsup --config tsup.config.ts"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@adaas/a-concept": "^0.1.
|
|
83
|
+
"@adaas/a-concept": "^0.1.53"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/chai": "^4.3.14",
|
package/src/index.ts
CHANGED
|
@@ -84,6 +84,22 @@ export * from './lib/A-Service/A-Service.constants';
|
|
|
84
84
|
export { A_Polyfill } from './lib/A-Polyfill/A-Polyfill.component';
|
|
85
85
|
export * from './lib/A-Polyfill/A-Polyfill.types';
|
|
86
86
|
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// A-Route Components
|
|
89
|
+
// ============================================================================
|
|
90
|
+
export { A_Route } from './lib/A-Route/A-Route.entity';
|
|
91
|
+
// export * from './lib/A-Route/A-Route.types';
|
|
92
|
+
|
|
93
|
+
// ============================================================================
|
|
94
|
+
// A-Signal Components
|
|
95
|
+
// ============================================================================
|
|
96
|
+
export { A_Signal } from './lib/A-Signal/entities/A-Signal.entity';
|
|
97
|
+
export { A_SignalVector } from './lib/A-Signal/entities/A-SignalVector.entity';
|
|
98
|
+
export { A_SignalBus } from './lib/A-Signal/components/A-SignalBus.component';
|
|
99
|
+
export { A_SignalConfig } from './lib/A-Signal/context/A-SignalConfig.context';
|
|
100
|
+
export { A_SignalState } from './lib/A-Signal/context/A-SignalState.context';
|
|
101
|
+
export * from './lib/A-Signal/A-Signal.types';
|
|
102
|
+
export * from './lib/A-Signal/A-Signal.constants';
|
|
87
103
|
|
|
88
104
|
// ============================================================================
|
|
89
105
|
// A-Schedule Components
|