@antelopejs/interface-core 0.0.2
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 +190 -0
- package/dist/antelope.test.d.ts +2 -0
- package/dist/antelope.test.js +12 -0
- package/dist/antelope.test.js.map +1 -0
- package/dist/config.d.ts +74 -0
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -0
- package/dist/decorators.d.ts +206 -0
- package/dist/decorators.js +199 -0
- package/dist/decorators.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +140 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +19 -0
- package/dist/internal.js +26 -0
- package/dist/internal.js.map +1 -0
- package/dist/logging/index.d.ts +139 -0
- package/dist/logging/index.js +174 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/listener.d.ts +26 -0
- package/dist/logging/listener.js +12 -0
- package/dist/logging/listener.js.map +1 -0
- package/dist/modules.d.ts +165 -0
- package/dist/modules.js +145 -0
- package/dist/modules.js.map +1 -0
- package/dist/proxies.d.ts +135 -0
- package/dist/proxies.js +272 -0
- package/dist/proxies.js.map +1 -0
- package/dist/tests/modules.test.d.ts +1 -0
- package/dist/tests/modules.test.js +27 -0
- package/dist/tests/modules.test.js.map +1 -0
- package/dist/tests/stub-mode.test.d.ts +1 -0
- package/dist/tests/stub-mode.test.js +57 -0
- package/dist/tests/stub-mode.test.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Logging = void 0;
|
|
7
|
+
const listener_1 = __importDefault(require("./listener"));
|
|
8
|
+
/**
|
|
9
|
+
* Provides a structured logging system with multiple severity levels and channels.
|
|
10
|
+
*
|
|
11
|
+
* The Logging namespace offers standardized functions for logging at different severity levels
|
|
12
|
+
* through a unified interface. It supports multiple channels for categorizing logs and
|
|
13
|
+
* uses an event-based system for log collection and processing.
|
|
14
|
+
*/
|
|
15
|
+
var Logging;
|
|
16
|
+
(function (Logging) {
|
|
17
|
+
/**
|
|
18
|
+
* Log severity levels in descending order of importance.
|
|
19
|
+
* Higher numerical values indicate higher severity.
|
|
20
|
+
*/
|
|
21
|
+
let Level;
|
|
22
|
+
(function (Level) {
|
|
23
|
+
/** Critical errors that may cause application failure */
|
|
24
|
+
Level[Level["ERROR"] = 40] = "ERROR";
|
|
25
|
+
/** Important issues that don't prevent application functioning */
|
|
26
|
+
Level[Level["WARN"] = 30] = "WARN";
|
|
27
|
+
/** General application information and status updates */
|
|
28
|
+
Level[Level["INFO"] = 20] = "INFO";
|
|
29
|
+
/** Detailed information useful for debugging */
|
|
30
|
+
Level[Level["DEBUG"] = 10] = "DEBUG";
|
|
31
|
+
/** Highly detailed tracing information */
|
|
32
|
+
Level[Level["TRACE"] = 0] = "TRACE";
|
|
33
|
+
/** Messages without prefix for direct display */
|
|
34
|
+
Level[Level["NO_PREFIX"] = -1] = "NO_PREFIX";
|
|
35
|
+
})(Level = Logging.Level || (Logging.Level = {}));
|
|
36
|
+
class Channel {
|
|
37
|
+
channel;
|
|
38
|
+
constructor(channel) {
|
|
39
|
+
this.channel = channel;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Write arguments to the log channel at the ERROR level.
|
|
43
|
+
*
|
|
44
|
+
* Use for critical errors that may cause application failure or require immediate attention.
|
|
45
|
+
*
|
|
46
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
47
|
+
*/
|
|
48
|
+
Error(...args) {
|
|
49
|
+
Write(Level.ERROR, this.channel, ...args);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Write arguments to the log channel at the WARN level.
|
|
53
|
+
*
|
|
54
|
+
* Use for important issues that don't prevent the application from functioning
|
|
55
|
+
* but should be addressed.
|
|
56
|
+
*
|
|
57
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
58
|
+
*/
|
|
59
|
+
Warn(...args) {
|
|
60
|
+
Write(Level.WARN, this.channel, ...args);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Write arguments to the log channel at the INFO level.
|
|
64
|
+
*
|
|
65
|
+
* Use for general application information and status updates that are useful
|
|
66
|
+
* for understanding the normal operation of the system.
|
|
67
|
+
*
|
|
68
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
69
|
+
*/
|
|
70
|
+
Info(...args) {
|
|
71
|
+
Write(Level.INFO, this.channel, ...args);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Write arguments to the log channel at the DEBUG level.
|
|
75
|
+
*
|
|
76
|
+
* Use for detailed information useful for debugging and troubleshooting issues.
|
|
77
|
+
*
|
|
78
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
79
|
+
*/
|
|
80
|
+
Debug(...args) {
|
|
81
|
+
Write(Level.DEBUG, this.channel, ...args);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Write arguments to the log channel at the TRACE level.
|
|
85
|
+
*
|
|
86
|
+
* Use for highly detailed tracing information, typically only enabled during
|
|
87
|
+
* intensive debugging sessions.
|
|
88
|
+
*
|
|
89
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
90
|
+
*/
|
|
91
|
+
Trace(...args) {
|
|
92
|
+
Write(Level.TRACE, this.channel, ...args);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Write arguments to the log channel at the given severity level.
|
|
96
|
+
*
|
|
97
|
+
* This is the core logging function that all other logging functions ultimately call.
|
|
98
|
+
* It emits an event with the log entry that can be captured by registered listeners.
|
|
99
|
+
*
|
|
100
|
+
* @param levelId - Severity level of the log entry (use values from the Level enum)
|
|
101
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
102
|
+
*/
|
|
103
|
+
Write(levelId, ...args) {
|
|
104
|
+
Write(levelId, this.channel, ...args);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
Logging.Channel = Channel;
|
|
108
|
+
const MainChannel = new Channel("main");
|
|
109
|
+
/**
|
|
110
|
+
* Write arguments to the main log channel at the ERROR level.
|
|
111
|
+
*
|
|
112
|
+
* Use for critical errors that may cause application failure or require immediate attention.
|
|
113
|
+
*
|
|
114
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
115
|
+
*/
|
|
116
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: public logging API exposes Error as a level name.
|
|
117
|
+
Logging.Error = MainChannel.Error.bind(MainChannel);
|
|
118
|
+
/**
|
|
119
|
+
* Write arguments to the main log channel at the WARN level.
|
|
120
|
+
*
|
|
121
|
+
* Use for important issues that don't prevent the application from functioning
|
|
122
|
+
* but should be addressed.
|
|
123
|
+
*
|
|
124
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
125
|
+
*/
|
|
126
|
+
Logging.Warn = MainChannel.Warn.bind(MainChannel);
|
|
127
|
+
/**
|
|
128
|
+
* Write arguments to the main log channel at the INFO level.
|
|
129
|
+
*
|
|
130
|
+
* Use for general application information and status updates that are useful
|
|
131
|
+
* for understanding the normal operation of the system.
|
|
132
|
+
*
|
|
133
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
134
|
+
*/
|
|
135
|
+
Logging.Info = MainChannel.Info.bind(MainChannel);
|
|
136
|
+
/**
|
|
137
|
+
* Write arguments to the main log channel at the DEBUG level.
|
|
138
|
+
*
|
|
139
|
+
* Use for detailed information useful for debugging and troubleshooting issues.
|
|
140
|
+
*
|
|
141
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
142
|
+
*/
|
|
143
|
+
Logging.Debug = MainChannel.Debug.bind(MainChannel);
|
|
144
|
+
/**
|
|
145
|
+
* Write arguments to the main log channel at the TRACE level.
|
|
146
|
+
*
|
|
147
|
+
* Use for highly detailed tracing information, typically only enabled during
|
|
148
|
+
* intensive debugging sessions.
|
|
149
|
+
*
|
|
150
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
151
|
+
*/
|
|
152
|
+
Logging.Trace = MainChannel.Trace.bind(MainChannel);
|
|
153
|
+
/**
|
|
154
|
+
* Write arguments to the specified log channel at the given severity level.
|
|
155
|
+
*
|
|
156
|
+
* This is the core logging function that all other logging functions ultimately call.
|
|
157
|
+
* It emits an event with the log entry that can be captured by registered listeners.
|
|
158
|
+
*
|
|
159
|
+
* @param levelId - Severity level of the log entry (use values from the Level enum)
|
|
160
|
+
* @param channel - Name of the channel to log to, useful for categorizing logs
|
|
161
|
+
* @param args - Values to log, which can be of any type and will be serialized appropriately
|
|
162
|
+
*/
|
|
163
|
+
function Write(levelId, channel, ...args) {
|
|
164
|
+
listener_1.default.emit({
|
|
165
|
+
time: Date.now(),
|
|
166
|
+
channel,
|
|
167
|
+
levelId,
|
|
168
|
+
args,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
Logging.Write = Write;
|
|
172
|
+
})(Logging || (exports.Logging = Logging = {}));
|
|
173
|
+
exports.default = Logging;
|
|
174
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logging/index.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAElC;;;;;;GAMG;AACH,IAAiB,OAAO,CA4KvB;AA5KD,WAAiB,OAAO;IACtB;;;OAGG;IACH,IAAY,KAaX;IAbD,WAAY,KAAK;QACf,yDAAyD;QACzD,oCAAU,CAAA;QACV,kEAAkE;QAClE,kCAAS,CAAA;QACT,yDAAyD;QACzD,kCAAS,CAAA;QACT,gDAAgD;QAChD,oCAAU,CAAA;QACV,0CAA0C;QAC1C,mCAAS,CAAA;QACT,iDAAiD;QACjD,4CAAc,CAAA;IAChB,CAAC,EAbW,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AC,CAAC;IAEzD;;;;;;;OAOG;IACU,YAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvD;;;;;;;OAOG;IACU,YAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvD;;;;;;OAMG;IACU,aAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEzD;;;;;;;OAOG;IACU,aAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEzD;;;;;;;;;OASG;IACH,SAAgB,KAAK,CACnB,OAAe,EACf,OAAe,EACf,GAAG,IAAW;QAEd,kBAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;YAChB,OAAO;YACP,OAAO;YACP,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAXe,aAAK,QAWpB,CAAA;AACH,CAAC,EA5KgB,OAAO,uBAAP,OAAO,QA4KvB;AACD,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventProxy } from "../proxies";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a structured log entry in the Antelopejs logging system.
|
|
4
|
+
*
|
|
5
|
+
* Log entries contain all necessary metadata about a logging event, including
|
|
6
|
+
* timestamp, severity level, channel, and the actual content being logged.
|
|
7
|
+
*/
|
|
8
|
+
export interface Log {
|
|
9
|
+
/** Timestamp when the log was created (milliseconds since epoch) */
|
|
10
|
+
time: number;
|
|
11
|
+
/** The channel/category this log belongs to (e.g., 'main', 'database', 'network') */
|
|
12
|
+
channel: string;
|
|
13
|
+
/** Numeric severity level (higher values indicate higher severity, see Logging.Level enum) */
|
|
14
|
+
levelId: number;
|
|
15
|
+
/** The actual content of the log entry, can be any serializable values */
|
|
16
|
+
args: any[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Event proxy for log entry listeners.
|
|
20
|
+
*
|
|
21
|
+
* This EventProxy allows parts of the application to subscribe to log events
|
|
22
|
+
* and process them as needed (e.g., write to console, file, or send to a logging service).
|
|
23
|
+
* Provides module-aware event handler management with automatic cleanup.
|
|
24
|
+
*/
|
|
25
|
+
declare const _default: EventProxy<(log: Log) => void>;
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const proxies_1 = require("../proxies");
|
|
4
|
+
/**
|
|
5
|
+
* Event proxy for log entry listeners.
|
|
6
|
+
*
|
|
7
|
+
* This EventProxy allows parts of the application to subscribe to log events
|
|
8
|
+
* and process them as needed (e.g., write to console, file, or send to a logging service).
|
|
9
|
+
* Provides module-aware event handler management with automatic cleanup.
|
|
10
|
+
*/
|
|
11
|
+
exports.default = new proxies_1.EventProxy();
|
|
12
|
+
//# sourceMappingURL=listener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/logging/listener.ts"],"names":[],"mappings":";;AAAA,wCAAwC;AAsBxC;;;;;;GAMG;AACH,kBAAe,IAAI,oBAAU,EAAsB,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { EventProxy } from ".";
|
|
2
|
+
/**
|
|
3
|
+
* Contains events related to module lifecycle management.
|
|
4
|
+
*
|
|
5
|
+
* These events allow subscribers to be notified when modules change state,
|
|
6
|
+
* enabling coordinated actions during module transitions.
|
|
7
|
+
*/
|
|
8
|
+
export declare namespace Events {
|
|
9
|
+
/**
|
|
10
|
+
* Event triggers when a module is constructed.
|
|
11
|
+
*
|
|
12
|
+
* Fires after the module's code has been loaded and a module instance has been created,
|
|
13
|
+
* but before the module is started.
|
|
14
|
+
*
|
|
15
|
+
* @param module Module ID
|
|
16
|
+
*/
|
|
17
|
+
const ModuleConstructed: EventProxy<(module: string) => void>;
|
|
18
|
+
/**
|
|
19
|
+
* Event triggers when a module is started.
|
|
20
|
+
*
|
|
21
|
+
* Fires after the module's start method has been called and completed successfully.
|
|
22
|
+
* At this point, the module is fully operational and available for use.
|
|
23
|
+
*
|
|
24
|
+
* @param module Module ID
|
|
25
|
+
*/
|
|
26
|
+
const ModuleStarted: EventProxy<(module: string) => void>;
|
|
27
|
+
/**
|
|
28
|
+
* Event triggers when a module is stopped.
|
|
29
|
+
*
|
|
30
|
+
* Fires after the module's stop method has been called and completed successfully.
|
|
31
|
+
* The module still exists but is no longer active or providing services.
|
|
32
|
+
*
|
|
33
|
+
* @param module Module ID
|
|
34
|
+
*/
|
|
35
|
+
const ModuleStopped: EventProxy<(module: string) => void>;
|
|
36
|
+
/**
|
|
37
|
+
* Event triggers when a module is destroyed.
|
|
38
|
+
*
|
|
39
|
+
* Fires after the module instance has been destroyed and all its resources
|
|
40
|
+
* have been released. The module's code may still be loaded, but the instance is gone.
|
|
41
|
+
*
|
|
42
|
+
* @param module Module ID
|
|
43
|
+
*/
|
|
44
|
+
const ModuleDestroyed: EventProxy<(module: string) => void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for defining a module to be loaded into the system.
|
|
48
|
+
*
|
|
49
|
+
* Contains all necessary information to locate, load, and configure a module.
|
|
50
|
+
*/
|
|
51
|
+
export interface ModuleDefinition {
|
|
52
|
+
/**
|
|
53
|
+
* Source location and type information for the module.
|
|
54
|
+
* The type field indicates the loading mechanism to use (e.g., 'file', 'npm').
|
|
55
|
+
* Additional fields depend on the source type.
|
|
56
|
+
*/
|
|
57
|
+
source: {
|
|
58
|
+
type: string;
|
|
59
|
+
} & Record<string, any>;
|
|
60
|
+
/**
|
|
61
|
+
* Optional configuration data passed to the module during initialization.
|
|
62
|
+
* The structure depends on what the specific module expects.
|
|
63
|
+
*/
|
|
64
|
+
config?: unknown;
|
|
65
|
+
/**
|
|
66
|
+
* Optional mapping of import paths to alternative paths.
|
|
67
|
+
* Can be used to redirect imports to different modules than requested.
|
|
68
|
+
*/
|
|
69
|
+
importOverrides?: Record<string, string[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Optional list of exports that should not be exposed by this module.
|
|
72
|
+
* Can be used to restrict what functionality a module provides.
|
|
73
|
+
*/
|
|
74
|
+
disabledExports?: string[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Complete information about a loaded module in the system.
|
|
78
|
+
*
|
|
79
|
+
* Extends ModuleDefinition with runtime information about the module's state and location.
|
|
80
|
+
*/
|
|
81
|
+
export type ModuleInfo = Required<ModuleDefinition> & {
|
|
82
|
+
/**
|
|
83
|
+
* Current lifecycle status of the module.
|
|
84
|
+
* - 'loaded': Module code has been loaded but not constructed
|
|
85
|
+
* - 'constructed': Module instance exists but is not started
|
|
86
|
+
* - 'active': Module is fully started and running
|
|
87
|
+
* - 'unknown': Module status cannot be determined
|
|
88
|
+
*/
|
|
89
|
+
status: "loaded" | "constructed" | "active" | "unknown";
|
|
90
|
+
/**
|
|
91
|
+
* File system path where the module is located.
|
|
92
|
+
*/
|
|
93
|
+
localPath: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* List all loaded modules.
|
|
97
|
+
*
|
|
98
|
+
* Retrieves the identifiers of all modules currently loaded in the system,
|
|
99
|
+
* regardless of their status.
|
|
100
|
+
*
|
|
101
|
+
* @returns Array of module IDs
|
|
102
|
+
*/
|
|
103
|
+
export declare const ListModules: () => Promise<string[]>;
|
|
104
|
+
/**
|
|
105
|
+
* Retrieve the configuration and status information of a loaded module.
|
|
106
|
+
*
|
|
107
|
+
* Provides comprehensive information about a specific module, including its
|
|
108
|
+
* configuration, status, and location.
|
|
109
|
+
*
|
|
110
|
+
* @param module The module ID to get information for
|
|
111
|
+
* @returns Complete module information object
|
|
112
|
+
*/
|
|
113
|
+
export declare const GetModuleInfo: (module: string) => Promise<ModuleInfo>;
|
|
114
|
+
/**
|
|
115
|
+
* Load a new module with the given ID and configuration.
|
|
116
|
+
*
|
|
117
|
+
* Loads the module code and optionally constructs and starts the module.
|
|
118
|
+
* If the module is already loaded, this may update its configuration.
|
|
119
|
+
*
|
|
120
|
+
* @param module Unique identifier for the module
|
|
121
|
+
* @param configuration Module configuration including source information
|
|
122
|
+
* @param autostart Whether to automatically start the module after loading (default: false)
|
|
123
|
+
*/
|
|
124
|
+
export declare const LoadModule: (module: string, configuration: ModuleDefinition, autostart?: boolean | undefined) => Promise<string[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Start a loaded but inactive module.
|
|
127
|
+
*
|
|
128
|
+
* Transitions a module from 'loaded' or 'constructed' state to 'active'.
|
|
129
|
+
* Has no effect if the module is already active.
|
|
130
|
+
*
|
|
131
|
+
* @param module The module ID to start
|
|
132
|
+
* @throws Error if the module is not loaded or cannot be started
|
|
133
|
+
*/
|
|
134
|
+
export declare const StartModule: (module: string) => Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Stop an active module.
|
|
137
|
+
*
|
|
138
|
+
* Transitions a module from 'active' state to 'constructed'.
|
|
139
|
+
* Has no effect if the module is not active.
|
|
140
|
+
*
|
|
141
|
+
* @param module The module ID to stop
|
|
142
|
+
* @throws Error if the module is not loaded or cannot be stopped
|
|
143
|
+
*/
|
|
144
|
+
export declare const StopModule: (module: string) => Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Destroy a stopped module.
|
|
147
|
+
*
|
|
148
|
+
* Releases all resources associated with the module instance.
|
|
149
|
+
* The module remains loaded but transitions to 'loaded' state from 'constructed'.
|
|
150
|
+
*
|
|
151
|
+
* @param module The module ID to destroy
|
|
152
|
+
* @throws Error if the module is active or not loaded
|
|
153
|
+
*/
|
|
154
|
+
export declare const DestroyModule: (module: string) => Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Unload a module and retrigger its source mechanism.
|
|
157
|
+
*
|
|
158
|
+
* First stops and destroys the module if needed, then unloads the module code
|
|
159
|
+
* and reloads it from the source. Useful for updating modules without restarting
|
|
160
|
+
* the entire application.
|
|
161
|
+
*
|
|
162
|
+
* @param module The module ID to reload
|
|
163
|
+
* @throws Error if the module cannot be reloaded
|
|
164
|
+
*/
|
|
165
|
+
export declare const ReloadModule: (module: string) => Promise<void>;
|
package/dist/modules.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReloadModule = exports.DestroyModule = exports.StopModule = exports.StartModule = exports.LoadModule = exports.GetModuleInfo = exports.ListModules = exports.Events = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const internal_1 = require("./internal");
|
|
6
|
+
/**
|
|
7
|
+
* Contains events related to module lifecycle management.
|
|
8
|
+
*
|
|
9
|
+
* These events allow subscribers to be notified when modules change state,
|
|
10
|
+
* enabling coordinated actions during module transitions.
|
|
11
|
+
*/
|
|
12
|
+
var Events;
|
|
13
|
+
(function (Events) {
|
|
14
|
+
/**
|
|
15
|
+
* Event triggers when a module is constructed.
|
|
16
|
+
*
|
|
17
|
+
* Fires after the module's code has been loaded and a module instance has been created,
|
|
18
|
+
* but before the module is started.
|
|
19
|
+
*
|
|
20
|
+
* @param module Module ID
|
|
21
|
+
*/
|
|
22
|
+
Events.ModuleConstructed = new _1.EventProxy();
|
|
23
|
+
/**
|
|
24
|
+
* Event triggers when a module is started.
|
|
25
|
+
*
|
|
26
|
+
* Fires after the module's start method has been called and completed successfully.
|
|
27
|
+
* At this point, the module is fully operational and available for use.
|
|
28
|
+
*
|
|
29
|
+
* @param module Module ID
|
|
30
|
+
*/
|
|
31
|
+
Events.ModuleStarted = new _1.EventProxy();
|
|
32
|
+
/**
|
|
33
|
+
* Event triggers when a module is stopped.
|
|
34
|
+
*
|
|
35
|
+
* Fires after the module's stop method has been called and completed successfully.
|
|
36
|
+
* The module still exists but is no longer active or providing services.
|
|
37
|
+
*
|
|
38
|
+
* @param module Module ID
|
|
39
|
+
*/
|
|
40
|
+
Events.ModuleStopped = new _1.EventProxy();
|
|
41
|
+
/**
|
|
42
|
+
* Event triggers when a module is destroyed.
|
|
43
|
+
*
|
|
44
|
+
* Fires after the module instance has been destroyed and all its resources
|
|
45
|
+
* have been released. The module's code may still be loaded, but the instance is gone.
|
|
46
|
+
*
|
|
47
|
+
* @param module Module ID
|
|
48
|
+
*/
|
|
49
|
+
Events.ModuleDestroyed = new _1.EventProxy();
|
|
50
|
+
})(Events || (exports.Events = Events = {}));
|
|
51
|
+
// Using the Events namespace from modules.ts instead of the lowercase events
|
|
52
|
+
Events.ModuleDestroyed.register((module) => {
|
|
53
|
+
if (internal_1.internal.knownAsync.has(module)) {
|
|
54
|
+
for (const proxy of internal_1.internal.knownAsync.get(module) ?? []) {
|
|
55
|
+
proxy.detach();
|
|
56
|
+
}
|
|
57
|
+
internal_1.internal.knownAsync.delete(module);
|
|
58
|
+
}
|
|
59
|
+
if (internal_1.internal.knownRegisters.has(module)) {
|
|
60
|
+
for (const proxy of internal_1.internal.knownRegisters.get(module) ?? []) {
|
|
61
|
+
proxy.detach();
|
|
62
|
+
}
|
|
63
|
+
internal_1.internal.knownRegisters.delete(module);
|
|
64
|
+
}
|
|
65
|
+
for (const [, proxies] of internal_1.internal.knownRegisters) {
|
|
66
|
+
for (const proxy of proxies) {
|
|
67
|
+
proxy.unregisterModule(module);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const proxy of internal_1.internal.knownEvents) {
|
|
71
|
+
proxy.unregisterModule(module);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* List all loaded modules.
|
|
76
|
+
*
|
|
77
|
+
* Retrieves the identifiers of all modules currently loaded in the system,
|
|
78
|
+
* regardless of their status.
|
|
79
|
+
*
|
|
80
|
+
* @returns Array of module IDs
|
|
81
|
+
*/
|
|
82
|
+
exports.ListModules = (0, _1.InterfaceFunction)();
|
|
83
|
+
/**
|
|
84
|
+
* Retrieve the configuration and status information of a loaded module.
|
|
85
|
+
*
|
|
86
|
+
* Provides comprehensive information about a specific module, including its
|
|
87
|
+
* configuration, status, and location.
|
|
88
|
+
*
|
|
89
|
+
* @param module The module ID to get information for
|
|
90
|
+
* @returns Complete module information object
|
|
91
|
+
*/
|
|
92
|
+
exports.GetModuleInfo = (0, _1.InterfaceFunction)();
|
|
93
|
+
/**
|
|
94
|
+
* Load a new module with the given ID and configuration.
|
|
95
|
+
*
|
|
96
|
+
* Loads the module code and optionally constructs and starts the module.
|
|
97
|
+
* If the module is already loaded, this may update its configuration.
|
|
98
|
+
*
|
|
99
|
+
* @param module Unique identifier for the module
|
|
100
|
+
* @param configuration Module configuration including source information
|
|
101
|
+
* @param autostart Whether to automatically start the module after loading (default: false)
|
|
102
|
+
*/
|
|
103
|
+
exports.LoadModule = (0, _1.InterfaceFunction)();
|
|
104
|
+
/**
|
|
105
|
+
* Start a loaded but inactive module.
|
|
106
|
+
*
|
|
107
|
+
* Transitions a module from 'loaded' or 'constructed' state to 'active'.
|
|
108
|
+
* Has no effect if the module is already active.
|
|
109
|
+
*
|
|
110
|
+
* @param module The module ID to start
|
|
111
|
+
* @throws Error if the module is not loaded or cannot be started
|
|
112
|
+
*/
|
|
113
|
+
exports.StartModule = (0, _1.InterfaceFunction)();
|
|
114
|
+
/**
|
|
115
|
+
* Stop an active module.
|
|
116
|
+
*
|
|
117
|
+
* Transitions a module from 'active' state to 'constructed'.
|
|
118
|
+
* Has no effect if the module is not active.
|
|
119
|
+
*
|
|
120
|
+
* @param module The module ID to stop
|
|
121
|
+
* @throws Error if the module is not loaded or cannot be stopped
|
|
122
|
+
*/
|
|
123
|
+
exports.StopModule = (0, _1.InterfaceFunction)();
|
|
124
|
+
/**
|
|
125
|
+
* Destroy a stopped module.
|
|
126
|
+
*
|
|
127
|
+
* Releases all resources associated with the module instance.
|
|
128
|
+
* The module remains loaded but transitions to 'loaded' state from 'constructed'.
|
|
129
|
+
*
|
|
130
|
+
* @param module The module ID to destroy
|
|
131
|
+
* @throws Error if the module is active or not loaded
|
|
132
|
+
*/
|
|
133
|
+
exports.DestroyModule = (0, _1.InterfaceFunction)();
|
|
134
|
+
/**
|
|
135
|
+
* Unload a module and retrigger its source mechanism.
|
|
136
|
+
*
|
|
137
|
+
* First stops and destroys the module if needed, then unloads the module code
|
|
138
|
+
* and reloads it from the source. Useful for updating modules without restarting
|
|
139
|
+
* the entire application.
|
|
140
|
+
*
|
|
141
|
+
* @param module The module ID to reload
|
|
142
|
+
* @throws Error if the module cannot be reloaded
|
|
143
|
+
*/
|
|
144
|
+
exports.ReloadModule = (0, _1.InterfaceFunction)();
|
|
145
|
+
//# sourceMappingURL=modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":";;;AAAA,wBAAkD;AAClD,yCAAsC;AAEtC;;;;;GAKG;AACH,IAAiB,MAAM,CAwCtB;AAxCD,WAAiB,MAAM;IACrB;;;;;;;OAOG;IACU,wBAAiB,GAAG,IAAI,aAAU,EAA4B,CAAC;IAE5E;;;;;;;OAOG;IACU,oBAAa,GAAG,IAAI,aAAU,EAA4B,CAAC;IAExE;;;;;;;OAOG;IACU,oBAAa,GAAG,IAAI,aAAU,EAA4B,CAAC;IAExE;;;;;;;OAOG;IACU,sBAAe,GAAG,IAAI,aAAU,EAA4B,CAAC;AAC5E,CAAC,EAxCgB,MAAM,sBAAN,MAAM,QAwCtB;AAED,6EAA6E;AAC7E,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE;IACzC,IAAI,mBAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,KAAK,MAAM,KAAK,IAAI,mBAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1D,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,CAAC;QACD,mBAAQ,CAAC,UAAU,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1
|
+
type Func<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
2
|
+
/**
|
|
3
|
+
* Proxy for an asynchronous function.
|
|
4
|
+
*
|
|
5
|
+
* Queues up calls while unattached, automatically unattaches when the source module is unloaded.
|
|
6
|
+
* Provides a mechanism for delayed execution and module-aware function binding.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AsyncProxy<T extends Func = Func, R = Awaited<ReturnType<T>>> {
|
|
9
|
+
private callback?;
|
|
10
|
+
private queue;
|
|
11
|
+
/**
|
|
12
|
+
* Attaches a callback to the proxy
|
|
13
|
+
*
|
|
14
|
+
* Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
|
|
15
|
+
* When attached, any queued calls will be executed immediately.
|
|
16
|
+
*
|
|
17
|
+
* @param callback Function to attach
|
|
18
|
+
* @param manualDetach Don't detach automatically when module is unloaded
|
|
19
|
+
*/
|
|
20
|
+
onCall(callback: T, manualDetach?: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* Manually detach the callback on this proxy.
|
|
23
|
+
*/
|
|
24
|
+
detach(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Call the function attached to this proxy.
|
|
27
|
+
*
|
|
28
|
+
* If a callback has not been attached yet, the call is queued up for later.
|
|
29
|
+
*/
|
|
30
|
+
call(...args: Parameters<T>): Promise<R>;
|
|
31
|
+
}
|
|
32
|
+
type RegisterFunction = (id: any, ...args: any[]) => void;
|
|
33
|
+
type RID<T> = T extends (id: infer P, ...args: any[]) => void ? P : never;
|
|
34
|
+
type RArgs<T> = T extends (id: any, ...args: infer P) => void ? P : never;
|
|
35
|
+
/**
|
|
36
|
+
* Proxy for a pair of register/unregister functions.
|
|
37
|
+
*
|
|
38
|
+
* Manages registration of handlers and ensures proper cleanup when modules are unloaded.
|
|
39
|
+
* This allows for module-aware event registration with automatic cleanup.
|
|
40
|
+
*/
|
|
41
|
+
export declare class RegisteringProxy<T extends RegisterFunction = RegisterFunction> {
|
|
42
|
+
private registerCallback?;
|
|
43
|
+
private unregisterCallback?;
|
|
44
|
+
private registered;
|
|
45
|
+
/**
|
|
46
|
+
* Attaches a register callback to the proxy
|
|
47
|
+
*
|
|
48
|
+
* Automatically detached if the module calling this function gets unloaded and manualDetach is not set to true.
|
|
49
|
+
*
|
|
50
|
+
* @param callback Function to attach as the register callback
|
|
51
|
+
* @param manualDetach Don't detach automatically
|
|
52
|
+
*/
|
|
53
|
+
onRegister(callback: T, manualDetach?: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Attaches an unregister callback to the proxy
|
|
56
|
+
*
|
|
57
|
+
* Detached at the same time as the register callback.
|
|
58
|
+
*
|
|
59
|
+
* @param callback Function to attach as the unregister callback
|
|
60
|
+
*/
|
|
61
|
+
onUnregister(callback: (id: RID<T>) => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* Manually detach the callbacks on this proxy.
|
|
64
|
+
*/
|
|
65
|
+
detach(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Call the register callback attached to this proxy.
|
|
68
|
+
*
|
|
69
|
+
* If a callback has not been attached yet, the call is queued up for later.
|
|
70
|
+
*
|
|
71
|
+
* @param id Unique identifier used to unregister
|
|
72
|
+
* @param args Extra arguments
|
|
73
|
+
*/
|
|
74
|
+
register(id: RID<T>, ...args: RArgs<T>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Call the unregister callback attached to this proxy.
|
|
77
|
+
*
|
|
78
|
+
* @param id Unique identifier to unregister
|
|
79
|
+
*/
|
|
80
|
+
unregister(id: RID<T>): void;
|
|
81
|
+
/**
|
|
82
|
+
* Unregister all entries created by the given module
|
|
83
|
+
* @internal
|
|
84
|
+
*
|
|
85
|
+
* @param mod Module ID
|
|
86
|
+
*/
|
|
87
|
+
unregisterModule(mod: string): void;
|
|
88
|
+
}
|
|
89
|
+
type EventFunction = (...args: any[]) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Event handler list that automatically removes handlers from unloaded modules.
|
|
92
|
+
*
|
|
93
|
+
* Provides a module-aware event system that cleans up event handlers when modules are unloaded,
|
|
94
|
+
* preventing memory leaks and ensuring proper modularity.
|
|
95
|
+
*/
|
|
96
|
+
export declare class EventProxy<T extends EventFunction = EventFunction> {
|
|
97
|
+
private registered;
|
|
98
|
+
constructor();
|
|
99
|
+
/**
|
|
100
|
+
* Call all the event handlers with the specified arguments.
|
|
101
|
+
*
|
|
102
|
+
* @param args Arguments
|
|
103
|
+
*/
|
|
104
|
+
emit(...args: Parameters<T>): void;
|
|
105
|
+
/**
|
|
106
|
+
* Register a new handler for this event.
|
|
107
|
+
*
|
|
108
|
+
* @param func Handler
|
|
109
|
+
*/
|
|
110
|
+
register(func: T): void;
|
|
111
|
+
/**
|
|
112
|
+
* Unregister a handler on this event.
|
|
113
|
+
*
|
|
114
|
+
* @param fn The handler that was passed to {@link register}
|
|
115
|
+
*/
|
|
116
|
+
unregister(fn: T): void;
|
|
117
|
+
/**
|
|
118
|
+
* Unregister all handlers created by the given module.
|
|
119
|
+
* @internal
|
|
120
|
+
*
|
|
121
|
+
* @param mod Module ID
|
|
122
|
+
*/
|
|
123
|
+
unregisterModule(mod: string): void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gets the responsible module for the current execution context.
|
|
127
|
+
*
|
|
128
|
+
* Determines which module is responsible for the current code execution by analyzing the call stack.
|
|
129
|
+
* This is used for automatic proxy detachment and event handler cleanup.
|
|
130
|
+
*
|
|
131
|
+
* @param startFrame The starting frame in the stack trace to analyze
|
|
132
|
+
* @returns The module ID or undefined if no module is found
|
|
133
|
+
*/
|
|
134
|
+
export declare function GetResponsibleModule(startFrame?: number): string | undefined;
|
|
135
|
+
export {};
|