@vedmalex/statemachine 1.0.0-beta.1
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 +21 -0
- package/README.md +75 -0
- package/dist/index.cjs +3989 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +3943 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
- package/types/adapters.d.ts +30 -0
- package/types/config_validator.d.ts +76 -0
- package/types/error_handling.d.ts +124 -0
- package/types/index.d.ts +77 -0
- package/types/lite.d.ts +6 -0
- package/types/logger.d.ts +74 -0
- package/types/monitoring.d.ts +239 -0
- package/types/presets.d.ts +27 -0
- package/types/scheduler.d.ts +65 -0
- package/types/security.d.ts +145 -0
- package/types/state_machine.d.ts +227 -0
- package/types/types.d.ts +250 -0
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vedmalex/statemachine",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "Hierarchical state machine for TypeScript with monitoring, validation, and persistence (lite-only DI-free surface).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"state-machine",
|
|
7
|
+
"statemachine",
|
|
8
|
+
"hierarchical",
|
|
9
|
+
"lite",
|
|
10
|
+
"wasm-friendly"
|
|
11
|
+
],
|
|
12
|
+
"author": "vedmalex (Vedanta-krit das)",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"homepage": "https://github.com/vedmalex/statemachine#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/vedmalex/statemachine.git",
|
|
18
|
+
"directory": "packages/statemachine"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/vedmalex/statemachine/issues"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./types/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./types/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"types",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"clean": "rm -rf dist types coverage tsconfig.tsbuildinfo",
|
|
46
|
+
"build": "npm run clean && tsup && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
47
|
+
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"test:coverage": "vitest run --coverage",
|
|
51
|
+
"test:cjs-smoke": "node test/cjs-smoke/smoke.cjs",
|
|
52
|
+
"test:deno-smoke": "deno run -A test/deno-smoke.ts",
|
|
53
|
+
"test:browser": "playwright test",
|
|
54
|
+
"knip": "knip --no-progress",
|
|
55
|
+
"api:check": "api-extractor run --local --verbose",
|
|
56
|
+
"prepublishOnly": "npm run build && node test/verify-dist.cjs"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {},
|
|
59
|
+
"peerDependencies": {},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@changesets/cli": "^2.31.0",
|
|
62
|
+
"@microsoft/api-extractor": "^7.58.7",
|
|
63
|
+
"@playwright/test": "^1.59.1",
|
|
64
|
+
"@types/bun": "^1.2.16",
|
|
65
|
+
"@types/node": "^25.6.0",
|
|
66
|
+
"@vitest/coverage-istanbul": "^4.1.5",
|
|
67
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
68
|
+
"knip": "^6.11.0",
|
|
69
|
+
"tsup": "^8.5.1",
|
|
70
|
+
"typedoc": "^0.28.19",
|
|
71
|
+
"typescript": "^5.6.0",
|
|
72
|
+
"vitest": "^4.1.5"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Adapter, StatePersistenceAdapter } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for a minimal state machine that can be updated from the adapter
|
|
4
|
+
*/
|
|
5
|
+
interface ISyncableStateMachine {
|
|
6
|
+
restoreState(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* BroadcastChannelAdapter wraps any other adapter and synchronizes state across browser tabs/windows
|
|
10
|
+
*/
|
|
11
|
+
export declare class BroadcastChannelAdapter<T extends object> implements Adapter<T>, StatePersistenceAdapter {
|
|
12
|
+
adaptee: T;
|
|
13
|
+
private inner;
|
|
14
|
+
private channel;
|
|
15
|
+
private sm?;
|
|
16
|
+
constructor(inner: Adapter<T> & Partial<StatePersistenceAdapter>, channelName: string);
|
|
17
|
+
/**
|
|
18
|
+
* Bind a state machine instance to this adapter for automatic updates
|
|
19
|
+
*/
|
|
20
|
+
bindStateMachine(sm: ISyncableStateMachine): void;
|
|
21
|
+
get(property: keyof T): T[keyof T];
|
|
22
|
+
set(property: keyof T, value: T[keyof T]): void;
|
|
23
|
+
save(state?: any): Promise<void>;
|
|
24
|
+
restore(): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Close the underlying BroadcastChannel
|
|
27
|
+
*/
|
|
28
|
+
destroy(): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration validation module for StateMachine library
|
|
3
|
+
* Validates StateMachine configurations to prevent runtime errors
|
|
4
|
+
*/
|
|
5
|
+
import type { StateMachineConfig } from './types';
|
|
6
|
+
export interface ValidationResult {
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
errors: ValidationError[];
|
|
9
|
+
warnings: ValidationWarning[];
|
|
10
|
+
}
|
|
11
|
+
export interface ValidationError {
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
severity: 'error' | 'warning';
|
|
15
|
+
path: string;
|
|
16
|
+
details?: Record<string, any>;
|
|
17
|
+
suggestion?: string;
|
|
18
|
+
documentationUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ValidationWarning extends ValidationError {
|
|
21
|
+
severity: 'warning';
|
|
22
|
+
}
|
|
23
|
+
interface ValidationContext {
|
|
24
|
+
addError(code: string, message: string, path: string, suggestion?: string): void;
|
|
25
|
+
addWarning(code: string, message: string, path: string, suggestion?: string): void;
|
|
26
|
+
}
|
|
27
|
+
type CustomRule<T extends object = any> = {
|
|
28
|
+
id: string;
|
|
29
|
+
validate: (config: StateMachineConfig<T>, context: ValidationContext) => void;
|
|
30
|
+
};
|
|
31
|
+
export interface ValidationConfig {
|
|
32
|
+
strictMode: boolean;
|
|
33
|
+
allowEmptyStates: boolean;
|
|
34
|
+
allowEmptyEvents: boolean;
|
|
35
|
+
maxStateDepth: number;
|
|
36
|
+
maxStatesCount: number;
|
|
37
|
+
maxEventsCount: number;
|
|
38
|
+
requireInitialState: boolean;
|
|
39
|
+
validateTransitionPaths: boolean;
|
|
40
|
+
validateActionReferences: boolean;
|
|
41
|
+
customRules?: CustomRule[];
|
|
42
|
+
}
|
|
43
|
+
export declare const DEFAULT_VALIDATION_CONFIG: ValidationConfig;
|
|
44
|
+
export declare class ConfigValidator {
|
|
45
|
+
private config;
|
|
46
|
+
private errors;
|
|
47
|
+
private warnings;
|
|
48
|
+
constructor(config?: Partial<ValidationConfig>);
|
|
49
|
+
/**
|
|
50
|
+
* Validates a complete StateMachine configuration
|
|
51
|
+
*/
|
|
52
|
+
validate<T extends object>(smConfig: StateMachineConfig<T>): ValidationResult;
|
|
53
|
+
/**
|
|
54
|
+
* Runs custom validation rules
|
|
55
|
+
*/
|
|
56
|
+
private runCustomRules;
|
|
57
|
+
private validateBasicStructure;
|
|
58
|
+
private validateStates;
|
|
59
|
+
private validateState;
|
|
60
|
+
private validateEvents;
|
|
61
|
+
private validateEvent;
|
|
62
|
+
private validateTransition;
|
|
63
|
+
private validateStatePath;
|
|
64
|
+
private isValidStatePath;
|
|
65
|
+
private validateInitialState;
|
|
66
|
+
private validateCrossReferences;
|
|
67
|
+
private collectStateNames;
|
|
68
|
+
private validatePerformanceConstraints;
|
|
69
|
+
private countStates;
|
|
70
|
+
private addError;
|
|
71
|
+
private addWarning;
|
|
72
|
+
}
|
|
73
|
+
export declare function validateConfig<T extends object>(config: StateMachineConfig<T>, validationConfig?: Partial<ValidationConfig>): ValidationResult;
|
|
74
|
+
export declare function validateConfigStrict<T extends object>(config: StateMachineConfig<T>): ValidationResult;
|
|
75
|
+
export declare function isValidConfig<T extends object>(config: StateMachineConfig<T>): boolean;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced error handling module for StateMachine library
|
|
3
|
+
* Provides comprehensive error context, recovery strategies, and error analytics
|
|
4
|
+
*/
|
|
5
|
+
import { type ErrorContext, StateMachineError } from './types';
|
|
6
|
+
export interface ExtendedErrorContext extends ErrorContext {
|
|
7
|
+
timestamp: number;
|
|
8
|
+
machineId?: string;
|
|
9
|
+
currentStateHistory?: string[];
|
|
10
|
+
attemptedTransition?: {
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
event: string;
|
|
14
|
+
};
|
|
15
|
+
stackTrace?: string | undefined;
|
|
16
|
+
userAgent?: string | undefined;
|
|
17
|
+
sessionId?: string | undefined;
|
|
18
|
+
additionalData?: Record<string, any> | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare const ErrorSeverity: {
|
|
21
|
+
readonly LOW: "low";
|
|
22
|
+
readonly MEDIUM: "medium";
|
|
23
|
+
readonly HIGH: "high";
|
|
24
|
+
readonly CRITICAL: "critical";
|
|
25
|
+
};
|
|
26
|
+
export type ErrorSeverity = (typeof ErrorSeverity)[keyof typeof ErrorSeverity];
|
|
27
|
+
export declare const ErrorCategory: {
|
|
28
|
+
readonly VALIDATION: "validation";
|
|
29
|
+
readonly TRANSITION: "transition";
|
|
30
|
+
readonly ACTION: "action";
|
|
31
|
+
readonly SERIALIZATION: "serialization";
|
|
32
|
+
readonly CONFIGURATION: "configuration";
|
|
33
|
+
readonly SECURITY: "security";
|
|
34
|
+
readonly PERFORMANCE: "performance";
|
|
35
|
+
readonly NETWORK: "network";
|
|
36
|
+
readonly UNKNOWN: "unknown";
|
|
37
|
+
};
|
|
38
|
+
export type ErrorCategory = (typeof ErrorCategory)[keyof typeof ErrorCategory];
|
|
39
|
+
export declare class EnhancedStateMachineError extends StateMachineError {
|
|
40
|
+
readonly severity: ErrorSeverity;
|
|
41
|
+
readonly category: ErrorCategory;
|
|
42
|
+
readonly extendedContext: ExtendedErrorContext;
|
|
43
|
+
readonly recoverable: boolean;
|
|
44
|
+
readonly errorCode: string;
|
|
45
|
+
constructor(message: string, context: ErrorContext, options?: {
|
|
46
|
+
severity?: ErrorSeverity;
|
|
47
|
+
category?: ErrorCategory;
|
|
48
|
+
recoverable?: boolean;
|
|
49
|
+
errorCode?: string;
|
|
50
|
+
additionalData?: Record<string, any>;
|
|
51
|
+
cause?: Error;
|
|
52
|
+
});
|
|
53
|
+
private generateErrorCode;
|
|
54
|
+
toJSON(): Record<string, any>;
|
|
55
|
+
}
|
|
56
|
+
export interface ErrorRecoveryStrategy {
|
|
57
|
+
name: string;
|
|
58
|
+
canRecover(error: EnhancedStateMachineError): boolean;
|
|
59
|
+
recover(error: EnhancedStateMachineError, context: any): Promise<boolean>;
|
|
60
|
+
}
|
|
61
|
+
export declare class RetryRecoveryStrategy implements ErrorRecoveryStrategy {
|
|
62
|
+
name: string;
|
|
63
|
+
private maxRetries;
|
|
64
|
+
private retryDelay;
|
|
65
|
+
constructor(maxRetries?: number, retryDelay?: number);
|
|
66
|
+
canRecover(error: EnhancedStateMachineError): boolean;
|
|
67
|
+
recover(error: EnhancedStateMachineError, context: any): Promise<boolean>;
|
|
68
|
+
}
|
|
69
|
+
export declare class FallbackStateRecoveryStrategy implements ErrorRecoveryStrategy {
|
|
70
|
+
name: string;
|
|
71
|
+
private fallbackState;
|
|
72
|
+
constructor(fallbackState?: string);
|
|
73
|
+
canRecover(error: EnhancedStateMachineError): boolean;
|
|
74
|
+
recover(error: EnhancedStateMachineError, context: any): Promise<boolean>;
|
|
75
|
+
}
|
|
76
|
+
export declare class ErrorAnalytics {
|
|
77
|
+
private errors;
|
|
78
|
+
private maxStoredErrors;
|
|
79
|
+
constructor(maxStoredErrors?: number);
|
|
80
|
+
recordError(error: EnhancedStateMachineError): void;
|
|
81
|
+
getErrorStats(): {
|
|
82
|
+
total: number;
|
|
83
|
+
bySeverity: Record<ErrorSeverity, number>;
|
|
84
|
+
byCategory: Record<ErrorCategory, number>;
|
|
85
|
+
recentErrors: number;
|
|
86
|
+
errorRate: number;
|
|
87
|
+
};
|
|
88
|
+
getTopErrors(limit?: number): Array<{
|
|
89
|
+
errorCode: string;
|
|
90
|
+
message: string;
|
|
91
|
+
count: number;
|
|
92
|
+
lastOccurrence: number;
|
|
93
|
+
severity: ErrorSeverity;
|
|
94
|
+
category: ErrorCategory;
|
|
95
|
+
}>;
|
|
96
|
+
clearErrors(): void;
|
|
97
|
+
}
|
|
98
|
+
export declare class ErrorHandler {
|
|
99
|
+
private recoveryStrategies;
|
|
100
|
+
private analytics;
|
|
101
|
+
private enabled;
|
|
102
|
+
constructor();
|
|
103
|
+
addRecoveryStrategy(strategy: ErrorRecoveryStrategy): void;
|
|
104
|
+
removeRecoveryStrategy(strategyName: string): void;
|
|
105
|
+
handleError(error: Error | EnhancedStateMachineError, context?: any): Promise<boolean>;
|
|
106
|
+
private convertToEnhancedError;
|
|
107
|
+
getAnalytics(): ErrorAnalytics;
|
|
108
|
+
enable(): void;
|
|
109
|
+
disable(): void;
|
|
110
|
+
isEnabled(): boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @internal — default factory for StateMachine.errorHandler injection slot.
|
|
114
|
+
* Returns a new ErrorHandler instance (NOT a singleton).
|
|
115
|
+
* Constructor at line 343 is public (verified).
|
|
116
|
+
*/
|
|
117
|
+
export declare function createDefaultErrorHandler(): import('./types').IErrorHandler;
|
|
118
|
+
export declare function createEnhancedError(message: string, context: ErrorContext, options?: {
|
|
119
|
+
severity?: ErrorSeverity;
|
|
120
|
+
category?: ErrorCategory;
|
|
121
|
+
recoverable?: boolean;
|
|
122
|
+
additionalData?: Record<string, any>;
|
|
123
|
+
}): EnhancedStateMachineError;
|
|
124
|
+
export declare function isRecoverableError(error: Error): boolean;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* @vedmalex/statemachine — hierarchical state machine for TypeScript.
|
|
5
|
+
*
|
|
6
|
+
* @unstable — full surface defaults to @unstable per the package's STABILITY policy.
|
|
7
|
+
* Per-symbol @stable tags below mark firm exports for the 1.0.0-beta.x consumer contract.
|
|
8
|
+
*
|
|
9
|
+
* @see README.md for usage and stability policy.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @stable — primary factory; the canonical consumer entry point.
|
|
13
|
+
* @category Stable
|
|
14
|
+
*/
|
|
15
|
+
export { createMachine } from './lite';
|
|
16
|
+
/**
|
|
17
|
+
* @stable — class form for advanced consumers needing direct instance access.
|
|
18
|
+
* @category Stable
|
|
19
|
+
*/
|
|
20
|
+
export { StateMachine } from './state_machine';
|
|
21
|
+
/**
|
|
22
|
+
* @stable — top-level machine configuration interface.
|
|
23
|
+
* @category Stable
|
|
24
|
+
*/
|
|
25
|
+
export type { StateMachineConfig } from './types';
|
|
26
|
+
/**
|
|
27
|
+
* @stable — transition descriptor used in events.
|
|
28
|
+
* @category Stable
|
|
29
|
+
*/
|
|
30
|
+
export type { Transition } from './types';
|
|
31
|
+
/**
|
|
32
|
+
* @stable — state node shape; consumed by States<T> map.
|
|
33
|
+
* @category Stable
|
|
34
|
+
*/
|
|
35
|
+
export type { State } from './types';
|
|
36
|
+
/**
|
|
37
|
+
* @category Unstable
|
|
38
|
+
*/
|
|
39
|
+
export type { States, Events, Event, Adapter, StateMachineOptions, RegionsConfig, StateInvocation, StateName, EventName, RegionName, EventAction, ErrorHandler, ActionOrString, ErrorHandlerOrString, RegionStateName, NestedStateName, DeepNestedStateName, StatePaths, SimpleStateName, MethodsOf, PropertiesOf, KeysOf, ExtractAdaptee, ErrorContext, } from './types';
|
|
40
|
+
export { MemoryAdapter, LocalStorageAdapter, SessionStorageAdapter, ServerAdapter, StateMachineError, isAdapter, } from './types';
|
|
41
|
+
export { createEnhancedError, EnhancedStateMachineError, ErrorAnalytics, ErrorCategory, type ErrorCategory as ErrorCategoryType, ErrorHandler as EnhancedErrorHandler, type ErrorRecoveryStrategy, ErrorSeverity, type ErrorSeverity as ErrorSeverityType, type ExtendedErrorContext, FallbackStateRecoveryStrategy, isRecoverableError, RetryRecoveryStrategy, } from './error_handling';
|
|
42
|
+
export { validateConfig, validateConfigStrict, isValidConfig, type ValidationResult, type ValidationError, type ValidationWarning, } from './config_validator';
|
|
43
|
+
/**
|
|
44
|
+
* @category Unstable
|
|
45
|
+
* @unstable — observability injection contract; implement to collect per-machine metrics.
|
|
46
|
+
*/
|
|
47
|
+
export type { IMonitor } from './types';
|
|
48
|
+
/**
|
|
49
|
+
* @category Unstable
|
|
50
|
+
* @unstable — timer scheduling injection contract; implement for WASM/host portability.
|
|
51
|
+
*/
|
|
52
|
+
export type { ITimerScheduler } from './types';
|
|
53
|
+
/**
|
|
54
|
+
* @category Unstable
|
|
55
|
+
* @unstable — error-handler injection contract; implement to replace built-in recovery.
|
|
56
|
+
*/
|
|
57
|
+
export type { IErrorHandler } from './types';
|
|
58
|
+
/**
|
|
59
|
+
* @category Unstable
|
|
60
|
+
* @unstable — logging injection contract; implement to route logs to host logging stack.
|
|
61
|
+
*/
|
|
62
|
+
export type { ILogger } from './types';
|
|
63
|
+
/**
|
|
64
|
+
* @category Unstable
|
|
65
|
+
* @unstable — persistence adapter contract; implement to save/restore machine state.
|
|
66
|
+
*/
|
|
67
|
+
export type { StatePersistenceAdapter } from './types';
|
|
68
|
+
/**
|
|
69
|
+
* @category Unstable
|
|
70
|
+
* @unstable — transition observability context passed to IMonitor.recordTransition.
|
|
71
|
+
*/
|
|
72
|
+
export type { TransitionContext } from './types';
|
|
73
|
+
/**
|
|
74
|
+
* @category Unstable
|
|
75
|
+
* @unstable — aggregate observability snapshot returned by IMonitor.getMetrics.
|
|
76
|
+
*/
|
|
77
|
+
export type { MonitorMetricsSnapshot } from './types';
|
package/types/lite.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StateMachine } from './state_machine';
|
|
2
|
+
import { type Adapter, type StateMachineConfig, type StateMachineOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Public factory for @vedmalex/statemachine. DI-free; the only factory in this package.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createMachine<T extends object>(config: StateMachineConfig<T>, owner?: T | Adapter<T>, options?: StateMachineOptions): StateMachine<T, any>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Professional logging system for StateMachine library
|
|
3
|
+
* Replaces console.log/console.error with configurable, structured logging
|
|
4
|
+
*/
|
|
5
|
+
export declare const LogLevel: {
|
|
6
|
+
readonly DEBUG: 0;
|
|
7
|
+
readonly INFO: 1;
|
|
8
|
+
readonly WARN: 2;
|
|
9
|
+
readonly ERROR: 3;
|
|
10
|
+
readonly FATAL: 4;
|
|
11
|
+
readonly OFF: 5;
|
|
12
|
+
};
|
|
13
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
14
|
+
interface LogEntry {
|
|
15
|
+
timestamp: number;
|
|
16
|
+
level: LogLevel;
|
|
17
|
+
message: string;
|
|
18
|
+
context?: Record<string, any>;
|
|
19
|
+
error?: Error;
|
|
20
|
+
source: string;
|
|
21
|
+
}
|
|
22
|
+
interface LoggerConfig {
|
|
23
|
+
level: LogLevel;
|
|
24
|
+
enableConsole: boolean;
|
|
25
|
+
enableStructuredLogging: boolean;
|
|
26
|
+
timestampFormat: 'iso' | 'unix' | 'relative';
|
|
27
|
+
includeStackTrace: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare const DEFAULT_LOGGER_CONFIG: LoggerConfig;
|
|
30
|
+
interface LogAppender {
|
|
31
|
+
append(entry: LogEntry): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class ConsoleAppender implements LogAppender {
|
|
34
|
+
private config;
|
|
35
|
+
constructor(config: LoggerConfig);
|
|
36
|
+
append(entry: LogEntry): void;
|
|
37
|
+
private formatTimestamp;
|
|
38
|
+
}
|
|
39
|
+
export declare class MemoryAppender implements LogAppender {
|
|
40
|
+
private entries;
|
|
41
|
+
append(entry: LogEntry): void;
|
|
42
|
+
getEntries(): LogEntry[];
|
|
43
|
+
clear(): void;
|
|
44
|
+
getEntriesByLevel(level: LogLevel): LogEntry[];
|
|
45
|
+
}
|
|
46
|
+
export declare class Logger {
|
|
47
|
+
private config;
|
|
48
|
+
private appenders;
|
|
49
|
+
private source;
|
|
50
|
+
constructor(source: string, config?: Partial<LoggerConfig>);
|
|
51
|
+
addAppender(appender: LogAppender): void;
|
|
52
|
+
removeAppender(appender: LogAppender): void;
|
|
53
|
+
updateConfig(config: Partial<LoggerConfig>): void;
|
|
54
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
55
|
+
private log;
|
|
56
|
+
debug(message: string, context?: Record<string, any>): void;
|
|
57
|
+
info(message: string, context?: Record<string, any>): void;
|
|
58
|
+
warn(message: string, context?: Record<string, any>): void;
|
|
59
|
+
error(message: string, context?: Record<string, any>, error?: Error): void;
|
|
60
|
+
fatal(message: string, context?: Record<string, any>, error?: Error): void;
|
|
61
|
+
child(childSource: string, _additionalContext?: Record<string, any>): Logger;
|
|
62
|
+
}
|
|
63
|
+
export declare class LoggerFactory {
|
|
64
|
+
private static defaultConfig;
|
|
65
|
+
private static loggers;
|
|
66
|
+
static setDefaultConfig(config: Partial<LoggerConfig>): void;
|
|
67
|
+
static getLogger(source: string, config?: Partial<LoggerConfig>): Logger;
|
|
68
|
+
static clearLoggers(): void;
|
|
69
|
+
}
|
|
70
|
+
export declare const getLogger: typeof LoggerFactory.getLogger;
|
|
71
|
+
export declare const setDefaultLogLevel: (level: LogLevel) => void;
|
|
72
|
+
export declare const stateMachineLogger: Logger;
|
|
73
|
+
export declare const securityLogger: Logger;
|
|
74
|
+
export {};
|