@adaas/a-utils 0.1.29 → 0.1.31
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 +459 -21
- package/dist/index.d.ts +459 -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 +1 -4
- 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 +56 -0
- package/src/lib/A-Signal/components/A-SignalBus.component.ts +126 -0
- package/src/lib/A-Signal/context/A-SignalConfig.context.ts +83 -0
- package/src/lib/A-Signal/context/A-SignalState.context.ts +195 -0
- package/src/lib/A-Signal/entities/A-Signal.entity.ts +69 -0
- package/src/lib/A-Signal/entities/A-SignalVector.entity.ts +198 -0
- package/tests/A-Logger.test.ts +90 -5
- package/tests/A-Route.test.ts +34 -0
- package/tests/A-Signal.test.ts +133 -0
- package/examples/config.ts +0 -33
package/dist/index.d.ts
CHANGED
|
@@ -1045,6 +1045,13 @@ declare const A_LoggerEnvVariables: {
|
|
|
1045
1045
|
declare const A_LoggerEnvVariablesArray: readonly ["A_LOGGER_LEVEL", "A_LOGGER_DEFAULT_SCOPE_LENGTH", "A_LOGGER_DEFAULT_SCOPE_COLOR", "A_LOGGER_DEFAULT_LOG_COLOR"];
|
|
1046
1046
|
type A_LoggerEnvVariablesType = (typeof A_LoggerEnvVariables)[keyof typeof A_LoggerEnvVariables][];
|
|
1047
1047
|
|
|
1048
|
+
type A_LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'all';
|
|
1049
|
+
/**
|
|
1050
|
+
* Available color names for the logger
|
|
1051
|
+
* Can be used as first parameter in logging methods to specify message color
|
|
1052
|
+
*/
|
|
1053
|
+
type A_LoggerColorName = 'red' | 'yellow' | 'green' | 'blue' | 'cyan' | 'magenta' | 'gray' | 'brightBlue' | 'brightCyan' | 'brightMagenta' | 'darkGray' | 'lightGray' | 'indigo' | 'violet' | 'purple' | 'lavender' | 'skyBlue' | 'steelBlue' | 'slateBlue' | 'deepBlue' | 'lightBlue' | 'periwinkle' | 'cornflower' | 'powder' | 'charcoal' | 'silver' | 'smoke' | 'slate';
|
|
1054
|
+
|
|
1048
1055
|
/**
|
|
1049
1056
|
* A_Logger - Advanced Logging Component with Scope-based Output Formatting
|
|
1050
1057
|
*
|
|
@@ -1073,7 +1080,15 @@ type A_LoggerEnvVariablesType = (typeof A_LoggerEnvVariables)[keyof typeof A_Log
|
|
|
1073
1080
|
* doSomething() {
|
|
1074
1081
|
* this.logger.info('Processing started'); // Uses scope-name-based colors, always shows
|
|
1075
1082
|
* this.logger.debug('Debug information'); // Only shows when debug level enabled
|
|
1076
|
-
*
|
|
1083
|
+
*
|
|
1084
|
+
* // Color overload methods with enum support
|
|
1085
|
+
* this.logger.info('green', 'Success message'); // Green message, scope stays default
|
|
1086
|
+
* this.logger.debug('gray', 'Verbose debug info'); // Gray message for less important info
|
|
1087
|
+
* this.logger.info('brightBlue', 'Important notification');
|
|
1088
|
+
*
|
|
1089
|
+
* // Terminal width aware formatting - automatically wraps long lines
|
|
1090
|
+
* this.logger.info('This is a very long message that will be automatically wrapped to fit within the terminal width while maintaining proper indentation and formatting');
|
|
1091
|
+
*
|
|
1077
1092
|
* this.logger.warning('Something might be wrong');
|
|
1078
1093
|
* this.logger.error(new Error('Something failed'));
|
|
1079
1094
|
* }
|
|
@@ -1083,6 +1098,13 @@ type A_LoggerEnvVariablesType = (typeof A_LoggerEnvVariables)[keyof typeof A_Log
|
|
|
1083
1098
|
* const logger1 = new A_Logger(new A_Scope({name: 'UserService'})); // Gets consistent colors
|
|
1084
1099
|
* const logger2 = new A_Logger(new A_Scope({name: 'UserService'})); // Gets same colors as logger1
|
|
1085
1100
|
*
|
|
1101
|
+
* // Available color names (A_LoggerColorName enum):
|
|
1102
|
+
* // 'red', 'yellow', 'green', 'blue', 'cyan', 'magenta', 'gray',
|
|
1103
|
+
* // 'brightBlue', 'brightCyan', 'brightMagenta', 'darkGray', 'lightGray',
|
|
1104
|
+
* // 'indigo', 'violet', 'purple', 'lavender', 'skyBlue', 'steelBlue',
|
|
1105
|
+
* // 'slateBlue', 'deepBlue', 'lightBlue', 'periwinkle', 'cornflower',
|
|
1106
|
+
* // 'powder', 'charcoal', 'silver', 'smoke', 'slate'
|
|
1107
|
+
*
|
|
1086
1108
|
* // Configuration via environment variables or A_Config (overrides automatic selection)
|
|
1087
1109
|
* process.env.A_LOGGER_DEFAULT_SCOPE_COLOR = 'magenta';
|
|
1088
1110
|
* process.env.A_LOGGER_DEFAULT_LOG_COLOR = 'green';
|
|
@@ -1119,6 +1141,16 @@ declare class A_Logger extends A_Component {
|
|
|
1119
1141
|
* This color is used for the message body when logging without specifying a color
|
|
1120
1142
|
*/
|
|
1121
1143
|
private readonly DEFAULT_LOG_COLOR;
|
|
1144
|
+
/**
|
|
1145
|
+
* Current terminal width for responsive formatting
|
|
1146
|
+
* Automatically detected or falls back to default values
|
|
1147
|
+
*/
|
|
1148
|
+
private readonly TERMINAL_WIDTH;
|
|
1149
|
+
/**
|
|
1150
|
+
* Maximum content width based on terminal size
|
|
1151
|
+
* Used for word wrapping and line length calculations
|
|
1152
|
+
*/
|
|
1153
|
+
private readonly MAX_CONTENT_WIDTH;
|
|
1122
1154
|
/**
|
|
1123
1155
|
* Initialize A_Logger with dependency injection
|
|
1124
1156
|
* Colors are configured through A_Config or generated randomly if not provided
|
|
@@ -1151,6 +1183,34 @@ declare class A_Logger extends A_Component {
|
|
|
1151
1183
|
* @returns Object with scopeColor and logColor that work well together
|
|
1152
1184
|
*/
|
|
1153
1185
|
private generateComplementaryColorsFromScope;
|
|
1186
|
+
/**
|
|
1187
|
+
* Detect current terminal width based on environment
|
|
1188
|
+
*
|
|
1189
|
+
* Returns appropriate width for different environments:
|
|
1190
|
+
* - Node.js: Uses process.stdout.columns if available
|
|
1191
|
+
* - Browser: Returns browser default width
|
|
1192
|
+
* - Fallback: Returns default terminal width
|
|
1193
|
+
*
|
|
1194
|
+
* @returns Terminal width in characters
|
|
1195
|
+
*/
|
|
1196
|
+
private detectTerminalWidth;
|
|
1197
|
+
/**
|
|
1198
|
+
* Wrap text to fit within terminal width while preserving formatting
|
|
1199
|
+
*
|
|
1200
|
+
* @param text - Text to wrap
|
|
1201
|
+
* @param scopePadding - The scope padding string for alignment
|
|
1202
|
+
* @param isFirstLine - Whether this is the first line (affects available width calculation)
|
|
1203
|
+
* @returns Array of wrapped lines with proper indentation
|
|
1204
|
+
*/
|
|
1205
|
+
private wrapText;
|
|
1206
|
+
/**
|
|
1207
|
+
* Split a long word that doesn't fit on a single line
|
|
1208
|
+
*
|
|
1209
|
+
* @param word - Word to split
|
|
1210
|
+
* @param maxLength - Maximum length per chunk
|
|
1211
|
+
* @returns Array of word chunks
|
|
1212
|
+
*/
|
|
1213
|
+
private splitLongWord;
|
|
1154
1214
|
/**
|
|
1155
1215
|
* Get the formatted scope length for consistent message alignment
|
|
1156
1216
|
* Uses a standard length to ensure all messages align properly regardless of scope name
|
|
@@ -1176,20 +1236,28 @@ declare class A_Logger extends A_Component {
|
|
|
1176
1236
|
*
|
|
1177
1237
|
* @param messageColor - The color key to apply to the message content
|
|
1178
1238
|
* @param args - Variable arguments to format and display
|
|
1179
|
-
* @returns Array of formatted strings ready for console output
|
|
1239
|
+
* @returns Array of formatted strings and/or objects ready for console output
|
|
1180
1240
|
*/
|
|
1181
|
-
compile(messageColor: keyof typeof this.COLORS, ...args: any[]): Array<
|
|
1241
|
+
compile(messageColor: keyof typeof this.COLORS, ...args: any[]): Array<any>;
|
|
1182
1242
|
/**
|
|
1183
|
-
* Format an object for display with proper JSON indentation
|
|
1243
|
+
* Format an object for display with proper JSON indentation and terminal width awareness
|
|
1184
1244
|
*
|
|
1185
1245
|
* @param obj - The object to format
|
|
1186
1246
|
* @param shouldAddNewline - Whether to add a newline prefix
|
|
1187
1247
|
* @param scopePadding - The padding string for consistent alignment
|
|
1188
|
-
* @returns Formatted object string
|
|
1248
|
+
* @returns Formatted object string or the object itself for browser environments
|
|
1189
1249
|
*/
|
|
1190
1250
|
private formatObject;
|
|
1191
1251
|
/**
|
|
1192
|
-
*
|
|
1252
|
+
* Wrap a long JSON string value while preserving readability
|
|
1253
|
+
*
|
|
1254
|
+
* @param value - The string value to wrap
|
|
1255
|
+
* @param maxWidth - Maximum width for the value
|
|
1256
|
+
* @returns Wrapped string value
|
|
1257
|
+
*/
|
|
1258
|
+
private wrapJsonStringValue;
|
|
1259
|
+
/**
|
|
1260
|
+
* Format a string for display with proper indentation and terminal width wrapping
|
|
1193
1261
|
*
|
|
1194
1262
|
* @param str - The string to format
|
|
1195
1263
|
* @param shouldAddNewline - Whether to add a newline prefix
|
|
@@ -1222,7 +1290,7 @@ declare class A_Logger extends A_Component {
|
|
|
1222
1290
|
* Note: The scope color always remains the instance's default scope color,
|
|
1223
1291
|
* only the message content color changes when explicitly specified.
|
|
1224
1292
|
*
|
|
1225
|
-
* @param color - Optional color
|
|
1293
|
+
* @param color - Optional color name from A_LoggerColorName enum or the first message argument
|
|
1226
1294
|
* @param args - Additional arguments to log
|
|
1227
1295
|
*
|
|
1228
1296
|
* @example
|
|
@@ -1232,7 +1300,7 @@ declare class A_Logger extends A_Component {
|
|
|
1232
1300
|
* logger.debug('Processing user:', { id: 1, name: 'John' });
|
|
1233
1301
|
* ```
|
|
1234
1302
|
*/
|
|
1235
|
-
debug(color:
|
|
1303
|
+
debug(color: A_LoggerColorName, ...args: any[]): void;
|
|
1236
1304
|
debug(...args: any[]): void;
|
|
1237
1305
|
/**
|
|
1238
1306
|
* Info logging method with optional color specification
|
|
@@ -1245,7 +1313,7 @@ declare class A_Logger extends A_Component {
|
|
|
1245
1313
|
* Note: The scope color always remains the instance's default scope color,
|
|
1246
1314
|
* only the message content color changes when explicitly specified.
|
|
1247
1315
|
*
|
|
1248
|
-
* @param color - Optional color
|
|
1316
|
+
* @param color - Optional color name from A_LoggerColorName enum or the first message argument
|
|
1249
1317
|
* @param args - Additional arguments to log
|
|
1250
1318
|
*
|
|
1251
1319
|
* @example
|
|
@@ -1255,16 +1323,16 @@ declare class A_Logger extends A_Component {
|
|
|
1255
1323
|
* logger.info('Processing user:', { id: 1, name: 'John' });
|
|
1256
1324
|
* ```
|
|
1257
1325
|
*/
|
|
1258
|
-
info(color:
|
|
1326
|
+
info(color: A_LoggerColorName, ...args: any[]): void;
|
|
1259
1327
|
info(...args: any[]): void;
|
|
1260
1328
|
/**
|
|
1261
1329
|
* Legacy log method (kept for backward compatibility)
|
|
1262
1330
|
* @deprecated Use info() method instead
|
|
1263
1331
|
*
|
|
1264
|
-
* @param color - Optional color
|
|
1332
|
+
* @param color - Optional color name from A_LoggerColorName enum or the first message argument
|
|
1265
1333
|
* @param args - Additional arguments to log
|
|
1266
1334
|
*/
|
|
1267
|
-
log(color:
|
|
1335
|
+
log(color: A_LoggerColorName, ...args: any[]): void;
|
|
1268
1336
|
log(...args: any[]): void;
|
|
1269
1337
|
/**
|
|
1270
1338
|
* Log warning messages with yellow color coding
|
|
@@ -1307,21 +1375,32 @@ declare class A_Logger extends A_Component {
|
|
|
1307
1375
|
/**
|
|
1308
1376
|
* Format A_Error instances for inline display within compiled messages
|
|
1309
1377
|
*
|
|
1310
|
-
* Provides detailed formatting for A_Error objects
|
|
1311
|
-
* - Error code and
|
|
1312
|
-
* -
|
|
1313
|
-
* -
|
|
1378
|
+
* Provides detailed formatting for A_Error objects with:
|
|
1379
|
+
* - Error code, message, and description
|
|
1380
|
+
* - Original error information FIRST (better UX for debugging)
|
|
1381
|
+
* - Stack traces with terminal width awareness
|
|
1314
1382
|
* - Documentation links (if available)
|
|
1383
|
+
* - Consistent formatting with rest of logger
|
|
1315
1384
|
*
|
|
1316
1385
|
* @param error - The A_Error instance to format
|
|
1317
1386
|
* @returns Formatted string ready for display
|
|
1318
1387
|
*/
|
|
1319
1388
|
protected compile_A_Error(error: A_Error): string;
|
|
1389
|
+
/**
|
|
1390
|
+
* Format stack trace with proper terminal width wrapping and indentation
|
|
1391
|
+
*
|
|
1392
|
+
* @param stack - The stack trace string
|
|
1393
|
+
* @param baseIndent - Base indentation for continuation lines
|
|
1394
|
+
* @returns Array of formatted stack trace lines
|
|
1395
|
+
*/
|
|
1396
|
+
private formatStackTrace;
|
|
1320
1397
|
/**
|
|
1321
1398
|
* Format standard Error instances for inline display within compiled messages
|
|
1322
1399
|
*
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1400
|
+
* Provides clean, readable formatting for standard JavaScript errors with:
|
|
1401
|
+
* - Terminal width aware message wrapping
|
|
1402
|
+
* - Properly formatted stack traces
|
|
1403
|
+
* - Consistent indentation with rest of logger
|
|
1325
1404
|
*
|
|
1326
1405
|
* @param error - The Error instance to format
|
|
1327
1406
|
* @returns Formatted string ready for display
|
|
@@ -1954,8 +2033,6 @@ declare class FileConfigReader extends ConfigReader {
|
|
|
1954
2033
|
read<T extends string>(variables?: Array<T>): Promise<Record<T, any>>;
|
|
1955
2034
|
}
|
|
1956
2035
|
|
|
1957
|
-
type A_LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'all';
|
|
1958
|
-
|
|
1959
2036
|
/**
|
|
1960
2037
|
* A-Logger Constants
|
|
1961
2038
|
*
|
|
@@ -2036,6 +2113,18 @@ declare const A_LOGGER_FORMAT: {
|
|
|
2036
2113
|
readonly INDENT_BASE: 3;
|
|
2037
2114
|
readonly PIPE: "| ";
|
|
2038
2115
|
};
|
|
2116
|
+
/**
|
|
2117
|
+
* Environment variable keys
|
|
2118
|
+
*/
|
|
2119
|
+
/**
|
|
2120
|
+
* Terminal width configuration
|
|
2121
|
+
*/
|
|
2122
|
+
declare const A_LOGGER_TERMINAL: {
|
|
2123
|
+
readonly DEFAULT_WIDTH: 80;
|
|
2124
|
+
readonly MIN_WIDTH: 40;
|
|
2125
|
+
readonly MAX_LINE_LENGTH_RATIO: 0.8;
|
|
2126
|
+
readonly BROWSER_DEFAULT_WIDTH: 120;
|
|
2127
|
+
};
|
|
2039
2128
|
/**
|
|
2040
2129
|
* Environment variable keys
|
|
2041
2130
|
*/
|
|
@@ -2231,6 +2320,9 @@ declare class A_Memory<_StorageType extends Record<string, any> = Record<string,
|
|
|
2231
2320
|
[A_MemoryFeatures.onExpire](...args: any[]): Promise<void>;
|
|
2232
2321
|
[A_MemoryFeatures.onInit](context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2233
2322
|
[A_MemoryFeatures.onDestroy](context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2323
|
+
/**
|
|
2324
|
+
* Handles the 'get' operation for retrieving a value from memory
|
|
2325
|
+
*/
|
|
2234
2326
|
[A_MemoryFeatures.onGet](operation: A_MemoryOperationContext, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2235
2327
|
[A_MemoryFeatures.onHas](operation: A_MemoryOperationContext<boolean>, context: A_MemoryContext<_StorageType>, ...args: any[]): Promise<void>;
|
|
2236
2328
|
[A_MemoryFeatures.onSet](operation: A_MemoryOperationContext, context: A_MemoryContext<_StorageType>, scope: A_Scope, ...args: any[]): Promise<void>;
|
|
@@ -2343,6 +2435,352 @@ declare class A_Service extends A_Container {
|
|
|
2343
2435
|
protected [A_ServiceFeatures.onError](error: A_Error, logger?: A_Logger, ...args: any[]): Promise<void>;
|
|
2344
2436
|
}
|
|
2345
2437
|
|
|
2438
|
+
declare class A_Route<_TParams extends Record<string, any> = Record<string, any>, _TQuery extends Record<string, any> = Record<string, any>> extends A_Fragment {
|
|
2439
|
+
url: string;
|
|
2440
|
+
constructor(url: string | RegExp);
|
|
2441
|
+
/**
|
|
2442
|
+
* Returns path only without query and hash
|
|
2443
|
+
*/
|
|
2444
|
+
get path(): string;
|
|
2445
|
+
/**
|
|
2446
|
+
* Returns array of parameter names in the route path
|
|
2447
|
+
*/
|
|
2448
|
+
get params(): string[];
|
|
2449
|
+
/**
|
|
2450
|
+
* Returns protocol based on URL scheme
|
|
2451
|
+
*/
|
|
2452
|
+
get protocol(): string;
|
|
2453
|
+
extractParams(url: string): _TParams;
|
|
2454
|
+
extractQuery(url: string): _TQuery;
|
|
2455
|
+
toString(): string;
|
|
2456
|
+
toRegExp(): RegExp;
|
|
2457
|
+
toAFeatureExtension(extensionScope?: Array<string>): RegExp;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
type A_SignalConfig_Init = {
|
|
2461
|
+
/**
|
|
2462
|
+
* An array defining the structure of the signal vector.
|
|
2463
|
+
*
|
|
2464
|
+
* Each entry corresponds to a signal component constructor.
|
|
2465
|
+
*/
|
|
2466
|
+
structure?: Array<A_TYPES__Entity_Constructor<A_Signal>>;
|
|
2467
|
+
/**
|
|
2468
|
+
* A string representation of the structure for easier DI resolution.
|
|
2469
|
+
* Each signal's constructor name is used to form this string.
|
|
2470
|
+
* e.g. "['A_RouterWatcher', 'A_ScopeWatcher', 'A_LoggerWatcher']"
|
|
2471
|
+
* OR "A_RouterWatcher,A_ScopeWatcher,A_LoggerWatcher"
|
|
2472
|
+
*/
|
|
2473
|
+
stringStructure?: string;
|
|
2474
|
+
};
|
|
2475
|
+
type A_SignalVector_Init<_TSignals extends Array<A_Signal> = Array<A_Signal>, _TVectorStructure extends Array<A_TYPES__Entity_Constructor<_TSignals[number]>> = Array<A_TYPES__Entity_Constructor<_TSignals[number]>>> = {
|
|
2476
|
+
structure: _TVectorStructure;
|
|
2477
|
+
values: _TSignals;
|
|
2478
|
+
};
|
|
2479
|
+
type A_SignalVector_Serialized = A_TYPES__Entity_Serialized & {
|
|
2480
|
+
structure: string[];
|
|
2481
|
+
values: Array<Record<string, any>>;
|
|
2482
|
+
} & A_TYPES__Entity_Serialized;
|
|
2483
|
+
type A_Signal_Init<T extends Record<string, any> = Record<string, any>> = {
|
|
2484
|
+
/**
|
|
2485
|
+
* The signal name
|
|
2486
|
+
*/
|
|
2487
|
+
name?: string;
|
|
2488
|
+
/**
|
|
2489
|
+
* The signal data
|
|
2490
|
+
*/
|
|
2491
|
+
data: T;
|
|
2492
|
+
};
|
|
2493
|
+
type A_Signal_Serialized<T extends Record<string, any> = Record<string, any>> = {
|
|
2494
|
+
/**
|
|
2495
|
+
* The signal data
|
|
2496
|
+
*/
|
|
2497
|
+
data: T;
|
|
2498
|
+
} & A_TYPES__Entity_Serialized;
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* A Signal Entity is an individual signal instance that carries data.
|
|
2502
|
+
* Signals is a event types that uses for vectors of signals to be used for further processing.
|
|
2503
|
+
*
|
|
2504
|
+
* Comparing to standard events, signals should be used in case when the event impacts some "state"
|
|
2505
|
+
* and the state should be used instead of the event itself.
|
|
2506
|
+
*
|
|
2507
|
+
* For example, a signal can represent the current status of a user (online/offline/away),
|
|
2508
|
+
* while an event would represent a single action (user logged in/logged out).
|
|
2509
|
+
*
|
|
2510
|
+
* Signals are typically used in scenarios where the current state is more important than individual events,
|
|
2511
|
+
* such as monitoring systems, real-time dashboards, or stateful applications.
|
|
2512
|
+
*/
|
|
2513
|
+
declare class A_Signal<_TSignalDataType extends Record<string, any> = Record<string, any>> extends A_Entity<A_Signal_Init<_TSignalDataType>, A_Signal_Serialized<_TSignalDataType>> {
|
|
2514
|
+
data: _TSignalDataType;
|
|
2515
|
+
/**
|
|
2516
|
+
* Allows to define default data for the signal.
|
|
2517
|
+
*
|
|
2518
|
+
* If no data is provided during initialization, the default data will be used.
|
|
2519
|
+
*
|
|
2520
|
+
* @returns
|
|
2521
|
+
*/
|
|
2522
|
+
static default(): Promise<A_Signal | undefined>;
|
|
2523
|
+
fromJSON(serializedEntity: A_Signal_Serialized<_TSignalDataType>): void;
|
|
2524
|
+
fromNew(newEntity: A_Signal_Init<_TSignalDataType>): void;
|
|
2525
|
+
/**
|
|
2526
|
+
* Emits this signal within the provided scope.
|
|
2527
|
+
*
|
|
2528
|
+
* Scope is mandatory since signal itself should not be registered in the scope,
|
|
2529
|
+
* but should use particular scope context to use proper set of components
|
|
2530
|
+
*
|
|
2531
|
+
* @param scope
|
|
2532
|
+
*/
|
|
2533
|
+
emit(scope: A_Scope): Promise<void>;
|
|
2534
|
+
toJSON(): A_Signal_Serialized<_TSignalDataType>;
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
/**
|
|
2538
|
+
* A Signal Vector Entity is a collection of signals structured in a specific way.
|
|
2539
|
+
* It allows grouping multiple signals together for batch processing or transmission.
|
|
2540
|
+
*
|
|
2541
|
+
* Signal Vectors are useful in scenarios where multiple related signals need to be handled together,
|
|
2542
|
+
* as a state of the system or a snapshot of various parameters at a given time.
|
|
2543
|
+
*
|
|
2544
|
+
* @template TSignalsConstructors - Array of signal constructor types (e.g., [typeof MySignal, typeof CustomSignal])
|
|
2545
|
+
* @template TSignals - Array of signal instances derived from constructors
|
|
2546
|
+
*/
|
|
2547
|
+
declare class A_SignalVector<TSignals extends Array<A_Signal> = Array<A_Signal>, TSignalsConstructors extends Array<A_TYPES__Entity_Constructor<A_Signal>> = TSignals extends Array<infer U> ? U extends A_Signal ? A_TYPES__Entity_Constructor<U>[] : never : never> extends A_Entity<A_SignalVector_Init<TSignals[number][], TSignalsConstructors>, A_SignalVector_Serialized> {
|
|
2548
|
+
/**
|
|
2549
|
+
* The structure of the signal vector, defining the types of signals it contains.
|
|
2550
|
+
*
|
|
2551
|
+
* For example:
|
|
2552
|
+
* [UserSignInSignal, UserStatusSignal, UserActivitySignal]
|
|
2553
|
+
*
|
|
2554
|
+
* [!] if not provided, it will be derived from the signals values.
|
|
2555
|
+
*/
|
|
2556
|
+
protected _structure?: TSignalsConstructors;
|
|
2557
|
+
/**
|
|
2558
|
+
* It's actual vector Values of Signals like :
|
|
2559
|
+
* [UserActionSignal, UserMousePositionSignal, ExternalDependencySignal]
|
|
2560
|
+
*/
|
|
2561
|
+
protected _signals: TSignals[number][];
|
|
2562
|
+
fromNew(newEntity: A_SignalVector_Init<TSignals[number][], TSignalsConstructors>): void;
|
|
2563
|
+
/**
|
|
2564
|
+
* The structure of the signal vector, defining the types of signals it contains.
|
|
2565
|
+
*
|
|
2566
|
+
* For example:
|
|
2567
|
+
* [UserSignInSignal, UserStatusSignal, UserActivitySignal]
|
|
2568
|
+
*
|
|
2569
|
+
*/
|
|
2570
|
+
get structure(): TSignalsConstructors;
|
|
2571
|
+
get length(): number;
|
|
2572
|
+
/**
|
|
2573
|
+
* Checks if the vector contains a signal of the specified type.
|
|
2574
|
+
*
|
|
2575
|
+
* @param signal
|
|
2576
|
+
*/
|
|
2577
|
+
has(signal: A_Signal): boolean;
|
|
2578
|
+
has(signalConstructor: A_TYPES__Component_Constructor<A_Signal>): boolean;
|
|
2579
|
+
get(signal: A_Signal): Record<string, any> | undefined;
|
|
2580
|
+
get(signalConstructor: A_TYPES__Component_Constructor<A_Signal>): Record<string, any> | undefined;
|
|
2581
|
+
/**
|
|
2582
|
+
* Converts to Array of values of signals in the vector
|
|
2583
|
+
* Maintains the order specified in the structure/generic type
|
|
2584
|
+
*
|
|
2585
|
+
* @param structure - Optional structure to override the default ordering
|
|
2586
|
+
* @returns Array of signal instances in the specified order
|
|
2587
|
+
*/
|
|
2588
|
+
toVector<T extends Array<A_Signal> = TSignals>(structure?: {
|
|
2589
|
+
[K in keyof T]: T[K] extends A_Signal ? A_TYPES__Entity_Constructor<T[K]> : never;
|
|
2590
|
+
}): Promise<{
|
|
2591
|
+
[K in keyof T]: T[K];
|
|
2592
|
+
}>;
|
|
2593
|
+
/**
|
|
2594
|
+
* Converts to Array of data of signals in the vector
|
|
2595
|
+
* Maintains the order specified in the structure/generic type
|
|
2596
|
+
*
|
|
2597
|
+
* @param structure - Optional structure to override the default ordering
|
|
2598
|
+
* @returns Array of serialized signal data in the specified order
|
|
2599
|
+
*/
|
|
2600
|
+
toDataVector<T extends Array<A_Signal> = TSignals>(structure?: {
|
|
2601
|
+
[K in keyof T]: T[K] extends A_Signal ? A_TYPES__Entity_Constructor<T[K]> : never;
|
|
2602
|
+
}): Promise<{
|
|
2603
|
+
[K in keyof T]: T[K] extends A_Signal<infer D> ? D | undefined : never;
|
|
2604
|
+
}>;
|
|
2605
|
+
/**
|
|
2606
|
+
* Converts to Object with signal constructor names as keys and their corresponding data values
|
|
2607
|
+
* Uses the structure ordering to ensure consistent key ordering
|
|
2608
|
+
*
|
|
2609
|
+
* @returns Object with signal constructor names as keys and signal data as values
|
|
2610
|
+
*/
|
|
2611
|
+
toObject<T extends Array<A_Signal> = TSignals>(structure?: {
|
|
2612
|
+
[K in keyof T]: T[K] extends A_Signal ? A_TYPES__Entity_Constructor<T[K]> : never;
|
|
2613
|
+
}): Promise<{
|
|
2614
|
+
[key: string]: T[number] extends A_Signal<infer D> ? D | undefined : never;
|
|
2615
|
+
}>;
|
|
2616
|
+
/**
|
|
2617
|
+
* Serializes the Signal Vector to a JSON-compatible format.
|
|
2618
|
+
*
|
|
2619
|
+
*
|
|
2620
|
+
* @returns
|
|
2621
|
+
*/
|
|
2622
|
+
toJSON(): A_SignalVector_Serialized;
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
declare enum A_SignalFeatures {
|
|
2626
|
+
Emit = "_A_SignalFeatures_Emit"
|
|
2627
|
+
}
|
|
2628
|
+
declare enum A_SignalBusFeatures {
|
|
2629
|
+
Emit = "_A_SignalBusFeatures_Emit"
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
/**
|
|
2633
|
+
* A_SignalState manages the latest state of all signals within a given scope.
|
|
2634
|
+
*
|
|
2635
|
+
* This class maintains a mapping between signal constructors and their most recently emitted values,
|
|
2636
|
+
* providing a centralized state store for signal management within an application context.
|
|
2637
|
+
*
|
|
2638
|
+
* @template TSignalData - Union type of all possible signal data types that can be stored (must extend Record<string, any>)
|
|
2639
|
+
*
|
|
2640
|
+
* The generic ensures type safety by maintaining correspondence between:
|
|
2641
|
+
* - Signal constructor types and their data types
|
|
2642
|
+
* - Signal instances and their emitted value types
|
|
2643
|
+
* - Vector structure and the data it contains
|
|
2644
|
+
*/
|
|
2645
|
+
declare class A_SignalState<TSignalData extends Record<string, any> = Record<string, any>> extends A_Fragment {
|
|
2646
|
+
/**
|
|
2647
|
+
* Internal map storing the relationship between signal constructors and their latest values
|
|
2648
|
+
* Key: Signal constructor function
|
|
2649
|
+
* Value: Latest emitted data from that signal type
|
|
2650
|
+
*/
|
|
2651
|
+
protected _state: Map<A_TYPES__Component_Constructor<A_Signal>, A_Signal>;
|
|
2652
|
+
/**
|
|
2653
|
+
* Optional structure defining the ordered list of signal constructors
|
|
2654
|
+
* Used for vector operations and initialization
|
|
2655
|
+
*/
|
|
2656
|
+
protected _structure: Array<A_TYPES__Component_Constructor<A_Signal>>;
|
|
2657
|
+
/**
|
|
2658
|
+
* Gets the ordered structure of signal constructors
|
|
2659
|
+
* @returns Array of signal constructors in their defined order
|
|
2660
|
+
*/
|
|
2661
|
+
get structure(): Array<A_TYPES__Component_Constructor<A_Signal>>;
|
|
2662
|
+
/**
|
|
2663
|
+
* Creates a new A_SignalState instance
|
|
2664
|
+
*
|
|
2665
|
+
* @param structure - Optional array defining the ordered structure of signal constructors
|
|
2666
|
+
* This structure is used for vector operations and determines the order
|
|
2667
|
+
* in which signals are processed and serialized
|
|
2668
|
+
*/
|
|
2669
|
+
constructor(structure: A_TYPES__Component_Constructor<A_Signal>[]);
|
|
2670
|
+
/**
|
|
2671
|
+
* Sets the latest value for a specific signal type
|
|
2672
|
+
*
|
|
2673
|
+
* @param signal - The signal constructor to associate the value with
|
|
2674
|
+
* @param value - The data value emitted by the signal
|
|
2675
|
+
*/
|
|
2676
|
+
set(signal: A_Signal, value: A_Signal): void;
|
|
2677
|
+
set(signal: A_Signal): void;
|
|
2678
|
+
set(signal: A_TYPES__Component_Constructor<A_Signal>, value: A_Signal): void;
|
|
2679
|
+
/**
|
|
2680
|
+
* Retrieves the latest value for a specific signal type
|
|
2681
|
+
*
|
|
2682
|
+
* @param signal - The signal constructor to get the value for
|
|
2683
|
+
* @returns The latest data value or undefined if no value has been set
|
|
2684
|
+
*/
|
|
2685
|
+
get(signal: A_Signal): A_Signal | undefined;
|
|
2686
|
+
get(signal: A_TYPES__Component_Constructor<A_Signal>): A_Signal | undefined;
|
|
2687
|
+
/**
|
|
2688
|
+
* Checks if a signal type has been registered in the state
|
|
2689
|
+
*
|
|
2690
|
+
* @param signal - The signal constructor to check for
|
|
2691
|
+
* @returns True if the signal type exists in the state map
|
|
2692
|
+
*/
|
|
2693
|
+
has(signal: A_Signal): boolean;
|
|
2694
|
+
has(signal: A_TYPES__Component_Constructor<A_Signal>): boolean;
|
|
2695
|
+
/**
|
|
2696
|
+
* Removes a signal type and its associated value from the state
|
|
2697
|
+
*
|
|
2698
|
+
* @param signal - The signal constructor to remove
|
|
2699
|
+
* @returns True if the signal was successfully deleted, false if it didn't exist
|
|
2700
|
+
*/
|
|
2701
|
+
delete(signal: A_Signal): boolean;
|
|
2702
|
+
delete(signal: A_TYPES__Component_Constructor<A_Signal>): boolean;
|
|
2703
|
+
/**
|
|
2704
|
+
* Converts the current state to a vector (ordered array) format
|
|
2705
|
+
*
|
|
2706
|
+
* The order is determined by the structure array provided during construction.
|
|
2707
|
+
* Each position in the vector corresponds to a specific signal type's latest value.
|
|
2708
|
+
*
|
|
2709
|
+
* @returns Array of signal values in the order defined by the structure
|
|
2710
|
+
* @throws Error if structure is not defined or if any signal value is undefined
|
|
2711
|
+
*/
|
|
2712
|
+
toVector(): A_SignalVector;
|
|
2713
|
+
/**
|
|
2714
|
+
* Converts the current state to an object with signal constructor names as keys
|
|
2715
|
+
*
|
|
2716
|
+
* This provides a more readable representation of the state where each signal
|
|
2717
|
+
* type is identified by its constructor name.
|
|
2718
|
+
*
|
|
2719
|
+
* @returns Object mapping signal constructor names to their latest values
|
|
2720
|
+
* @throws Error if any signal value is undefined
|
|
2721
|
+
*/
|
|
2722
|
+
toObject(): Record<string, A_Signal>;
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
/**
|
|
2726
|
+
* This component should dictate a structure of the vector for all signals within a given scope.
|
|
2727
|
+
* so if there're multiple signals it should say what type at what position should be expected.
|
|
2728
|
+
*
|
|
2729
|
+
* e.g. [A_RouterWatcher, A_ScopeWatcher, A_LoggerWatcher]
|
|
2730
|
+
* This structure then should be used for any further processing of signals within the scope.
|
|
2731
|
+
*/
|
|
2732
|
+
declare class A_SignalConfig extends A_Fragment {
|
|
2733
|
+
protected _structure?: Array<A_TYPES__Entity_Constructor<A_Signal>>;
|
|
2734
|
+
protected _config: A_SignalConfig_Init;
|
|
2735
|
+
protected _ready?: Promise<void>;
|
|
2736
|
+
get structure(): Array<A_TYPES__Entity_Constructor<A_Signal>>;
|
|
2737
|
+
/**
|
|
2738
|
+
* Uses for synchronization to ensure the config is initialized.
|
|
2739
|
+
*
|
|
2740
|
+
* @returns True if the configuration has been initialized.
|
|
2741
|
+
*/
|
|
2742
|
+
get ready(): Promise<void> | undefined;
|
|
2743
|
+
constructor(params: A_SignalConfig_Init);
|
|
2744
|
+
/**
|
|
2745
|
+
* Initializes the signal configuration if not already initialized.
|
|
2746
|
+
*
|
|
2747
|
+
* @returns
|
|
2748
|
+
*/
|
|
2749
|
+
initialize(): Promise<void>;
|
|
2750
|
+
/**
|
|
2751
|
+
* Initializes the signal configuration by processing the provided structure or string representation.
|
|
2752
|
+
* This method sets up the internal structure of signal constructors based on the configuration.
|
|
2753
|
+
*/
|
|
2754
|
+
protected _initialize(): Promise<void>;
|
|
2755
|
+
}
|
|
2756
|
+
|
|
2757
|
+
/**
|
|
2758
|
+
* This component should listen for all available signal watchers components in this and all parent scopes.
|
|
2759
|
+
* When a signal is emitted, it should forward the signal to all registered watchers.
|
|
2760
|
+
*
|
|
2761
|
+
* A_SignalBus should always return the same vector structure of the signals, and that's why it should store the state of the latest behavior.
|
|
2762
|
+
* For example if there are 3 watchers registered, the bus should always return a vector of 3 elements, based on the A_SignalConfig structure.
|
|
2763
|
+
*
|
|
2764
|
+
*
|
|
2765
|
+
* The component itself is stateless and all methods uses only parameters (context) is provided with.
|
|
2766
|
+
*/
|
|
2767
|
+
declare class A_SignalBus extends A_Component {
|
|
2768
|
+
/**
|
|
2769
|
+
* This methods extends A-Signal Emit feature to handle signal emission within the bus.
|
|
2770
|
+
*
|
|
2771
|
+
* It updates the signal state and emits the updated signal vector.
|
|
2772
|
+
*
|
|
2773
|
+
* @param signal
|
|
2774
|
+
* @param globalConfig
|
|
2775
|
+
* @param logger
|
|
2776
|
+
* @param state
|
|
2777
|
+
* @param config
|
|
2778
|
+
* @returns
|
|
2779
|
+
*/
|
|
2780
|
+
[A_SignalFeatures.Emit](signal: A_Signal, globalConfig?: A_Config<['A_SIGNAL_VECTOR_STRUCTURE']>, logger?: A_Logger, state?: A_SignalState, config?: A_SignalConfig): Promise<void>;
|
|
2781
|
+
getState(): void;
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2346
2784
|
type A_UTILS_TYPES__ScheduleObjectConfig = {
|
|
2347
2785
|
/**
|
|
2348
2786
|
* If the timeout is cleared, should the promise resolve or reject?
|
|
@@ -2456,4 +2894,4 @@ declare class A_StateMachineError extends A_Error {
|
|
|
2456
2894
|
static readonly TransitionError = "A-StateMachine Transition Error";
|
|
2457
2895
|
}
|
|
2458
2896
|
|
|
2459
|
-
export { A_CONSTANTS__CONFIG_ENV_VARIABLES, A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY, A_Channel, A_ChannelError, A_ChannelFeatures, A_ChannelRequest, A_ChannelRequestStatuses, A_Command, A_CommandError, A_CommandEvent, type A_CommandEvents, A_CommandFeatures, A_CommandTransitions, type A_Command_ExecutionContext, A_Command_Status, A_Config, A_ConfigError, A_ConfigLoader, A_Deferred, A_ExecutionContext, A_LOGGER_ANSI, A_LOGGER_COLORS, A_LOGGER_DEFAULT_LEVEL, A_LOGGER_DEFAULT_SCOPE_LENGTH, A_LOGGER_ENV_KEYS, A_LOGGER_FORMAT, A_LOGGER_SAFE_RANDOM_COLORS, A_LOGGER_TIME_FORMAT, A_Logger, A_LoggerEnvVariables, A_LoggerEnvVariablesArray, type A_LoggerEnvVariablesType, type A_LoggerLevel, A_Manifest, A_ManifestChecker, A_ManifestError, A_Memory, A_MemoryContext, type A_MemoryContextMeta, A_MemoryError, A_MemoryFeatures, type A_MemoryOperationContext, type A_MemoryOperationContextMeta, type A_MemoryOperations, type A_Memory_Storage, A_OperationContext, type A_Operation_Serialized, type A_Operation_Storage, A_Polyfill, A_Schedule, A_ScheduleObject, A_Service, A_ServiceFeatures, A_StateMachine, A_StateMachineError, A_StateMachineFeatures, A_StateMachineTransition, type A_StateMachineTransitionParams, type A_StateMachineTransitionStorage, type A_TYPES__Command_Constructor, type A_TYPES__Command_Init, type A_TYPES__Command_Listener, type A_TYPES__Command_Serialized, type A_TYPES__ConfigContainerConstructor, type A_TYPES__ConfigENVVariables, A_TYPES__ConfigFeature, type A_UTILS_TYPES__ManifestQuery, type A_UTILS_TYPES__ManifestRule, type A_UTILS_TYPES__Manifest_AllowedComponents, type A_UTILS_TYPES__Manifest_ComponentLevelConfig, type A_UTILS_TYPES__Manifest_Init, type A_UTILS_TYPES__Manifest_MethodLevelConfig, type A_UTILS_TYPES__Manifest_Rules, type A_UTILS_TYPES__ScheduleObjectCallback, type A_UTILS_TYPES__ScheduleObjectConfig, ConfigReader, ENVConfigReader, FileConfigReader, type IbufferInterface, type IcryptoInterface, type Ifspolyfill, type IhttpInterface, type IhttpsInterface, type IpathInterface, type IprocessInterface, type IurlInterface };
|
|
2897
|
+
export { A_CONSTANTS__CONFIG_ENV_VARIABLES, A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY, A_Channel, A_ChannelError, A_ChannelFeatures, A_ChannelRequest, A_ChannelRequestStatuses, A_Command, A_CommandError, A_CommandEvent, type A_CommandEvents, A_CommandFeatures, A_CommandTransitions, type A_Command_ExecutionContext, A_Command_Status, A_Config, A_ConfigError, A_ConfigLoader, A_Deferred, A_ExecutionContext, A_LOGGER_ANSI, A_LOGGER_COLORS, A_LOGGER_DEFAULT_LEVEL, A_LOGGER_DEFAULT_SCOPE_LENGTH, A_LOGGER_ENV_KEYS, A_LOGGER_FORMAT, A_LOGGER_SAFE_RANDOM_COLORS, A_LOGGER_TERMINAL, A_LOGGER_TIME_FORMAT, A_Logger, type A_LoggerColorName, A_LoggerEnvVariables, A_LoggerEnvVariablesArray, type A_LoggerEnvVariablesType, type A_LoggerLevel, A_Manifest, A_ManifestChecker, A_ManifestError, A_Memory, A_MemoryContext, type A_MemoryContextMeta, A_MemoryError, A_MemoryFeatures, type A_MemoryOperationContext, type A_MemoryOperationContextMeta, type A_MemoryOperations, type A_Memory_Storage, A_OperationContext, type A_Operation_Serialized, type A_Operation_Storage, A_Polyfill, A_Route, A_Schedule, A_ScheduleObject, A_Service, A_ServiceFeatures, A_Signal, A_SignalBus, A_SignalBusFeatures, A_SignalConfig, type A_SignalConfig_Init, A_SignalFeatures, A_SignalState, A_SignalVector, type A_SignalVector_Init, type A_SignalVector_Serialized, type A_Signal_Init, type A_Signal_Serialized, A_StateMachine, A_StateMachineError, A_StateMachineFeatures, A_StateMachineTransition, type A_StateMachineTransitionParams, type A_StateMachineTransitionStorage, type A_TYPES__Command_Constructor, type A_TYPES__Command_Init, type A_TYPES__Command_Listener, type A_TYPES__Command_Serialized, type A_TYPES__ConfigContainerConstructor, type A_TYPES__ConfigENVVariables, A_TYPES__ConfigFeature, type A_UTILS_TYPES__ManifestQuery, type A_UTILS_TYPES__ManifestRule, type A_UTILS_TYPES__Manifest_AllowedComponents, type A_UTILS_TYPES__Manifest_ComponentLevelConfig, type A_UTILS_TYPES__Manifest_Init, type A_UTILS_TYPES__Manifest_MethodLevelConfig, type A_UTILS_TYPES__Manifest_Rules, type A_UTILS_TYPES__ScheduleObjectCallback, type A_UTILS_TYPES__ScheduleObjectConfig, ConfigReader, ENVConfigReader, FileConfigReader, type IbufferInterface, type IcryptoInterface, type Ifspolyfill, type IhttpInterface, type IhttpsInterface, type IpathInterface, type IprocessInterface, type IurlInterface };
|