@context-action/core 0.0.2 → 0.0.3
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/dist/index.cjs +267 -12
- package/dist/index.d.cts +203 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +203 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -71,7 +71,7 @@ var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+
|
|
|
71
71
|
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js
|
|
72
72
|
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
73
73
|
var toPropertyKey = require_toPropertyKey();
|
|
74
|
-
function _defineProperty$
|
|
74
|
+
function _defineProperty$2(e, r, t) {
|
|
75
75
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
76
76
|
value: t,
|
|
77
77
|
enumerable: !0,
|
|
@@ -79,68 +79,311 @@ var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project
|
|
|
79
79
|
writable: !0
|
|
80
80
|
}) : e[r] = t, e;
|
|
81
81
|
}
|
|
82
|
-
module.exports = _defineProperty$
|
|
82
|
+
module.exports = _defineProperty$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
83
83
|
} });
|
|
84
84
|
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/logger.ts
|
|
87
|
+
var import_defineProperty$1 = __toESM(require_defineProperty(), 1);
|
|
88
|
+
/**
|
|
89
|
+
* Log levels in order of severity (lowest to highest)
|
|
90
|
+
*/
|
|
91
|
+
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
92
|
+
LogLevel$1[LogLevel$1["TRACE"] = 0] = "TRACE";
|
|
93
|
+
LogLevel$1[LogLevel$1["DEBUG"] = 1] = "DEBUG";
|
|
94
|
+
LogLevel$1[LogLevel$1["INFO"] = 2] = "INFO";
|
|
95
|
+
LogLevel$1[LogLevel$1["WARN"] = 3] = "WARN";
|
|
96
|
+
LogLevel$1[LogLevel$1["ERROR"] = 4] = "ERROR";
|
|
97
|
+
LogLevel$1[LogLevel$1["FATAL"] = 5] = "FATAL";
|
|
98
|
+
return LogLevel$1;
|
|
99
|
+
}({});
|
|
100
|
+
/**
|
|
101
|
+
* Default console logger implementation
|
|
102
|
+
*/
|
|
103
|
+
var ConsoleLogger = class {
|
|
104
|
+
constructor(level = LogLevel.ERROR) {
|
|
105
|
+
this.level = level;
|
|
106
|
+
}
|
|
107
|
+
shouldLog(level) {
|
|
108
|
+
return level >= this.level;
|
|
109
|
+
}
|
|
110
|
+
formatMessage(level, message) {
|
|
111
|
+
return `[${level.toUpperCase()}] ${message}`;
|
|
112
|
+
}
|
|
113
|
+
trace(message, ...args) {
|
|
114
|
+
if (this.shouldLog(LogLevel.TRACE)) console.trace(this.formatMessage("trace", message), ...args);
|
|
115
|
+
}
|
|
116
|
+
debug(message, ...args) {
|
|
117
|
+
if (this.shouldLog(LogLevel.DEBUG)) console.debug(this.formatMessage("debug", message), ...args);
|
|
118
|
+
}
|
|
119
|
+
info(message, ...args) {
|
|
120
|
+
if (this.shouldLog(LogLevel.INFO)) console.info(this.formatMessage("info", message), ...args);
|
|
121
|
+
}
|
|
122
|
+
warn(message, ...args) {
|
|
123
|
+
if (this.shouldLog(LogLevel.WARN)) console.warn(this.formatMessage("warn", message), ...args);
|
|
124
|
+
}
|
|
125
|
+
error(message, ...args) {
|
|
126
|
+
if (this.shouldLog(LogLevel.ERROR)) console.error(this.formatMessage("error", message), ...args);
|
|
127
|
+
}
|
|
128
|
+
fatal(message, ...args) {
|
|
129
|
+
if (this.shouldLog(LogLevel.FATAL)) console.error(this.formatMessage("fatal", message), ...args);
|
|
130
|
+
}
|
|
131
|
+
setLevel(level) {
|
|
132
|
+
this.level = level;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Parse log level from string
|
|
137
|
+
*/
|
|
138
|
+
function parseLogLevel(level) {
|
|
139
|
+
const upperLevel = level.toUpperCase();
|
|
140
|
+
switch (upperLevel) {
|
|
141
|
+
case "TRACE": return LogLevel.TRACE;
|
|
142
|
+
case "DEBUG": return LogLevel.DEBUG;
|
|
143
|
+
case "INFO": return LogLevel.INFO;
|
|
144
|
+
case "WARN": return LogLevel.WARN;
|
|
145
|
+
case "ERROR": return LogLevel.ERROR;
|
|
146
|
+
case "FATAL": return LogLevel.FATAL;
|
|
147
|
+
default: return LogLevel.ERROR;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get log level from environment variable or default to ERROR
|
|
152
|
+
*/
|
|
153
|
+
function getLogLevelFromEnv() {
|
|
154
|
+
if (typeof process !== "undefined" && process.env) {
|
|
155
|
+
const envLevel = process.env.LOG_LEVEL || process.env.ACTION_LOG_LEVEL;
|
|
156
|
+
if (envLevel) return parseLogLevel(envLevel);
|
|
157
|
+
}
|
|
158
|
+
return LogLevel.TRACE;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Extract trace ID from payload if it exists
|
|
162
|
+
*/
|
|
163
|
+
function extractTraceIdFromPayload(payload) {
|
|
164
|
+
if (payload && typeof payload === "object") return payload._traceId || payload.traceId || payload.trace_id;
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Extract session ID from payload if it exists
|
|
169
|
+
*/
|
|
170
|
+
function extractSessionIdFromPayload(payload) {
|
|
171
|
+
if (payload && typeof payload === "object") return payload._sessionId || payload.sessionId || payload.session_id;
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create OTEL context from payload
|
|
176
|
+
*/
|
|
177
|
+
function createOtelContextFromPayload(payload) {
|
|
178
|
+
return {
|
|
179
|
+
traceId: extractTraceIdFromPayload(payload),
|
|
180
|
+
sessionId: extractSessionIdFromPayload(payload),
|
|
181
|
+
metadata: payload
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* OpenTelemetry-aware console logger implementation
|
|
186
|
+
*/
|
|
187
|
+
var OtelConsoleLogger = class extends ConsoleLogger {
|
|
188
|
+
constructor(level = LogLevel.ERROR) {
|
|
189
|
+
super(level);
|
|
190
|
+
(0, import_defineProperty$1.default)(this, "context", {});
|
|
191
|
+
}
|
|
192
|
+
setContext(context) {
|
|
193
|
+
this.context = {
|
|
194
|
+
...this.context,
|
|
195
|
+
...context
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
getContext() {
|
|
199
|
+
return { ...this.context };
|
|
200
|
+
}
|
|
201
|
+
clearContext() {
|
|
202
|
+
this.context = {};
|
|
203
|
+
}
|
|
204
|
+
formatWithContext(level, message) {
|
|
205
|
+
const contextParts = [];
|
|
206
|
+
if (this.context.sessionId) contextParts.push(`session=${this.context.sessionId}`);
|
|
207
|
+
if (this.context.traceId) contextParts.push(`trace=${this.context.traceId}`);
|
|
208
|
+
if (this.context.spanId) contextParts.push(`span=${this.context.spanId}`);
|
|
209
|
+
const contextStr = contextParts.length > 0 ? ` [${contextParts.join(", ")}]` : "";
|
|
210
|
+
return `[${level.toUpperCase()}]${contextStr} ${message}`;
|
|
211
|
+
}
|
|
212
|
+
logWithContext(level, message, ...args) {
|
|
213
|
+
const levelName = LogLevel[level].toLowerCase();
|
|
214
|
+
const formattedMessage = this.formatWithContext(levelName, message);
|
|
215
|
+
switch (level) {
|
|
216
|
+
case LogLevel.TRACE:
|
|
217
|
+
if (this.shouldLog(LogLevel.TRACE)) console.trace(formattedMessage, ...args);
|
|
218
|
+
break;
|
|
219
|
+
case LogLevel.DEBUG:
|
|
220
|
+
if (this.shouldLog(LogLevel.DEBUG)) console.debug(formattedMessage, ...args);
|
|
221
|
+
break;
|
|
222
|
+
case LogLevel.INFO:
|
|
223
|
+
if (this.shouldLog(LogLevel.INFO)) console.info(formattedMessage, ...args);
|
|
224
|
+
break;
|
|
225
|
+
case LogLevel.WARN:
|
|
226
|
+
if (this.shouldLog(LogLevel.WARN)) console.warn(formattedMessage, ...args);
|
|
227
|
+
break;
|
|
228
|
+
case LogLevel.ERROR:
|
|
229
|
+
if (this.shouldLog(LogLevel.ERROR)) console.error(formattedMessage, ...args);
|
|
230
|
+
break;
|
|
231
|
+
case LogLevel.FATAL:
|
|
232
|
+
if (this.shouldLog(LogLevel.FATAL)) console.error(formattedMessage, ...args);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
trace(message, ...args) {
|
|
237
|
+
this.logWithContext(LogLevel.TRACE, message, ...args);
|
|
238
|
+
}
|
|
239
|
+
debug(message, ...args) {
|
|
240
|
+
this.logWithContext(LogLevel.DEBUG, message, ...args);
|
|
241
|
+
}
|
|
242
|
+
info(message, ...args) {
|
|
243
|
+
this.logWithContext(LogLevel.INFO, message, ...args);
|
|
244
|
+
}
|
|
245
|
+
warn(message, ...args) {
|
|
246
|
+
this.logWithContext(LogLevel.WARN, message, ...args);
|
|
247
|
+
}
|
|
248
|
+
error(message, ...args) {
|
|
249
|
+
this.logWithContext(LogLevel.ERROR, message, ...args);
|
|
250
|
+
}
|
|
251
|
+
fatal(message, ...args) {
|
|
252
|
+
this.logWithContext(LogLevel.FATAL, message, ...args);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
85
256
|
//#endregion
|
|
86
257
|
//#region src/ActionRegister.ts
|
|
87
258
|
var import_defineProperty = __toESM(require_defineProperty(), 1);
|
|
259
|
+
/**
|
|
260
|
+
* Core action pipeline management system
|
|
261
|
+
* @template T - Action payload map defining available actions and their payload types
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* interface AppActions extends ActionPayloadMap {
|
|
265
|
+
* increment: void;
|
|
266
|
+
* setCount: number;
|
|
267
|
+
* }
|
|
268
|
+
*
|
|
269
|
+
* const actionRegister = new ActionRegister<AppActions>();
|
|
270
|
+
*
|
|
271
|
+
* // Register handlers
|
|
272
|
+
* actionRegister.register('increment', () => console.log('Incremented'));
|
|
273
|
+
* actionRegister.register('setCount', (count) => console.log(`Count: ${count}`));
|
|
274
|
+
*
|
|
275
|
+
* // Dispatch actions
|
|
276
|
+
* await actionRegister.dispatch('increment');
|
|
277
|
+
* await actionRegister.dispatch('setCount', 42);
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
88
280
|
var ActionRegister = class {
|
|
89
|
-
constructor() {
|
|
281
|
+
constructor(config) {
|
|
90
282
|
(0, import_defineProperty.default)(this, "pipelines", /* @__PURE__ */ new Map());
|
|
91
283
|
(0, import_defineProperty.default)(this, "atomSetters", /* @__PURE__ */ new Map());
|
|
284
|
+
(0, import_defineProperty.default)(this, "handlerCounter", 0);
|
|
285
|
+
(0, import_defineProperty.default)(this, "logger", void 0);
|
|
286
|
+
const envLogLevel = getLogLevelFromEnv();
|
|
287
|
+
const configLogLevel = config?.logLevel ?? envLogLevel;
|
|
288
|
+
if (config?.logger) this.logger = config.logger;
|
|
289
|
+
else if (config?.useOtel) this.logger = new OtelConsoleLogger(configLogLevel);
|
|
290
|
+
else this.logger = new ConsoleLogger(configLogLevel);
|
|
291
|
+
if (config?.otelContext && this.logger instanceof OtelConsoleLogger) this.logger.setContext(config.otelContext);
|
|
292
|
+
this.logger.debug("ActionRegister initialized", {
|
|
293
|
+
logLevel: configLogLevel,
|
|
294
|
+
useOtel: config?.useOtel ?? false,
|
|
295
|
+
hasOtelContext: !!config?.otelContext
|
|
296
|
+
});
|
|
92
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Register a handler for an action in the pipeline
|
|
300
|
+
* @param action - The action name to handle
|
|
301
|
+
* @param handler - The handler function to execute
|
|
302
|
+
* @param config - Optional configuration for the handler
|
|
303
|
+
* @returns Unregister function to remove the handler
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const unregister = actionRegister.register('increment', () => {
|
|
307
|
+
* console.log('Incremented!');
|
|
308
|
+
* }, { priority: 10 });
|
|
309
|
+
*
|
|
310
|
+
* // Later, remove the handler
|
|
311
|
+
* unregister();
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
93
314
|
register(action, handler, config = {}) {
|
|
94
|
-
if (!this.pipelines.has(action))
|
|
315
|
+
if (!this.pipelines.has(action)) {
|
|
316
|
+
this.pipelines.set(action, /* @__PURE__ */ new Map());
|
|
317
|
+
this.logger.debug(`Created new pipeline for action: ${String(action)}`);
|
|
318
|
+
}
|
|
95
319
|
const pipeline = this.pipelines.get(action);
|
|
96
|
-
const handlerId = config.id || `handler_${
|
|
320
|
+
const handlerId = config.id || `handler_${++this.handlerCounter}`;
|
|
97
321
|
if (pipeline.has(handlerId)) {
|
|
98
|
-
|
|
322
|
+
this.logger.warn(`Handler with id ${handlerId} already exists for action: ${String(action)}`);
|
|
99
323
|
return () => {};
|
|
100
324
|
}
|
|
101
325
|
pipeline.set(handlerId, {
|
|
102
326
|
handler,
|
|
103
327
|
config
|
|
104
328
|
});
|
|
329
|
+
this.logger.debug(`Registered handler for action: ${String(action)}`, {
|
|
330
|
+
handlerId,
|
|
331
|
+
priority: config.priority ?? 0,
|
|
332
|
+
blocking: config.blocking ?? false
|
|
333
|
+
});
|
|
105
334
|
this.sortPipeline(action);
|
|
106
335
|
return () => {
|
|
107
336
|
pipeline.delete(handlerId);
|
|
337
|
+
this.logger.debug(`Unregistered handler: ${handlerId} for action: ${String(action)}`);
|
|
108
338
|
};
|
|
109
339
|
}
|
|
110
340
|
registerAtomSetter(name, setter) {
|
|
111
341
|
this.atomSetters.set(name, setter);
|
|
342
|
+
this.logger.debug(`Registered atom setter: ${name}`);
|
|
112
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Internal dispatch implementation
|
|
346
|
+
* @internal
|
|
347
|
+
*/
|
|
113
348
|
async dispatch(action, payload) {
|
|
114
349
|
const pipeline = this.pipelines.get(action);
|
|
350
|
+
if (this.logger instanceof OtelConsoleLogger && payload) {
|
|
351
|
+
const otelContext = createOtelContextFromPayload(payload);
|
|
352
|
+
if (otelContext.traceId || otelContext.sessionId) this.logger.setContext(otelContext);
|
|
353
|
+
}
|
|
354
|
+
this.logger.debug(`Dispatching action: ${String(action)}`, { payload });
|
|
115
355
|
if (!pipeline || pipeline.size === 0) {
|
|
116
|
-
|
|
356
|
+
this.logger.warn(`No handlers registered for action: ${String(action)}`);
|
|
117
357
|
return;
|
|
118
358
|
}
|
|
119
359
|
let modifiedPayload = payload;
|
|
120
360
|
const handlers = Array.from(pipeline.values());
|
|
361
|
+
let shouldContinue = true;
|
|
362
|
+
this.logger.trace(`Executing pipeline for action: ${String(action)}`, { handlerCount: handlers.length });
|
|
121
363
|
for (const { handler, config } of handlers) {
|
|
122
|
-
|
|
364
|
+
if (!shouldContinue) break;
|
|
123
365
|
const controller = {
|
|
124
366
|
next: () => {
|
|
125
367
|
shouldContinue = true;
|
|
126
368
|
},
|
|
127
369
|
abort: (reason) => {
|
|
128
370
|
shouldContinue = false;
|
|
129
|
-
|
|
371
|
+
this.logger.warn(`Pipeline aborted: ${reason}`);
|
|
130
372
|
},
|
|
131
373
|
modifyPayload: (modifier) => {
|
|
132
374
|
modifiedPayload = modifier(modifiedPayload);
|
|
375
|
+
this.logger.trace(`Payload modified for action: ${String(action)}`);
|
|
133
376
|
}
|
|
134
377
|
};
|
|
135
378
|
try {
|
|
136
379
|
if (config.blocking) await handler(modifiedPayload, controller);
|
|
137
380
|
else handler(modifiedPayload, controller);
|
|
138
|
-
if (!shouldContinue) break;
|
|
139
381
|
} catch (error) {
|
|
140
|
-
|
|
382
|
+
this.logger.error(`Error in pipeline handler for action: ${String(action)}`, error);
|
|
141
383
|
if (config.blocking) throw error;
|
|
142
384
|
}
|
|
143
385
|
}
|
|
386
|
+
this.logger.debug(`Completed dispatching action: ${String(action)}`);
|
|
144
387
|
}
|
|
145
388
|
sortPipeline(action) {
|
|
146
389
|
const pipeline = this.pipelines.get(action);
|
|
@@ -152,6 +395,10 @@ var ActionRegister = class {
|
|
|
152
395
|
});
|
|
153
396
|
pipeline.clear();
|
|
154
397
|
sorted.forEach(([id, data]) => pipeline.set(id, data));
|
|
398
|
+
this.logger.trace(`Sorted pipeline for action: ${String(action)}`, {
|
|
399
|
+
handlerCount: sorted.length,
|
|
400
|
+
priorities: sorted.map(([, data]) => data.config.priority ?? 0)
|
|
401
|
+
});
|
|
155
402
|
}
|
|
156
403
|
};
|
|
157
404
|
|
|
@@ -169,5 +416,13 @@ function isAction(action, type) {
|
|
|
169
416
|
|
|
170
417
|
//#endregion
|
|
171
418
|
exports.ActionRegister = ActionRegister;
|
|
419
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
420
|
+
exports.LogLevel = LogLevel;
|
|
421
|
+
exports.OtelConsoleLogger = OtelConsoleLogger;
|
|
172
422
|
exports.createAction = createAction;
|
|
173
|
-
exports.
|
|
423
|
+
exports.createOtelContextFromPayload = createOtelContextFromPayload;
|
|
424
|
+
exports.extractSessionIdFromPayload = extractSessionIdFromPayload;
|
|
425
|
+
exports.extractTraceIdFromPayload = extractTraceIdFromPayload;
|
|
426
|
+
exports.getLogLevelFromEnv = getLogLevelFromEnv;
|
|
427
|
+
exports.isAction = isAction;
|
|
428
|
+
exports.parseLogLevel = parseLogLevel;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,22 +1,224 @@
|
|
|
1
|
+
//#region src/logger.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Log levels in order of severity (lowest to highest)
|
|
4
|
+
*/
|
|
5
|
+
declare enum LogLevel {
|
|
6
|
+
TRACE = 0,
|
|
7
|
+
DEBUG = 1,
|
|
8
|
+
INFO = 2,
|
|
9
|
+
WARN = 3,
|
|
10
|
+
ERROR = 4,
|
|
11
|
+
FATAL = 5,
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Logger interface for custom logger implementations
|
|
15
|
+
*/
|
|
16
|
+
interface Logger {
|
|
17
|
+
trace(message: string, ...args: any[]): void;
|
|
18
|
+
debug(message: string, ...args: any[]): void;
|
|
19
|
+
info(message: string, ...args: any[]): void;
|
|
20
|
+
warn(message: string, ...args: any[]): void;
|
|
21
|
+
error(message: string, ...args: any[]): void;
|
|
22
|
+
fatal(message: string, ...args: any[]): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Default console logger implementation
|
|
26
|
+
*/
|
|
27
|
+
declare class ConsoleLogger implements Logger {
|
|
28
|
+
private level;
|
|
29
|
+
constructor(level?: LogLevel);
|
|
30
|
+
protected shouldLog(level: LogLevel): boolean;
|
|
31
|
+
private formatMessage;
|
|
32
|
+
trace(message: string, ...args: any[]): void;
|
|
33
|
+
debug(message: string, ...args: any[]): void;
|
|
34
|
+
info(message: string, ...args: any[]): void;
|
|
35
|
+
warn(message: string, ...args: any[]): void;
|
|
36
|
+
error(message: string, ...args: any[]): void;
|
|
37
|
+
fatal(message: string, ...args: any[]): void;
|
|
38
|
+
setLevel(level: LogLevel): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse log level from string
|
|
42
|
+
*/
|
|
43
|
+
declare function parseLogLevel(level: string): LogLevel;
|
|
44
|
+
/**
|
|
45
|
+
* Get log level from environment variable or default to ERROR
|
|
46
|
+
*/
|
|
47
|
+
declare function getLogLevelFromEnv(): LogLevel;
|
|
48
|
+
/**
|
|
49
|
+
* Extract trace ID from payload if it exists
|
|
50
|
+
*/
|
|
51
|
+
declare function extractTraceIdFromPayload(payload: any): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Extract session ID from payload if it exists
|
|
54
|
+
*/
|
|
55
|
+
declare function extractSessionIdFromPayload(payload: any): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Create OTEL context from payload
|
|
58
|
+
*/
|
|
59
|
+
declare function createOtelContextFromPayload(payload: any): OtelContext;
|
|
60
|
+
/**
|
|
61
|
+
* OpenTelemetry context interface for tracing
|
|
62
|
+
*/
|
|
63
|
+
interface OtelContext {
|
|
64
|
+
/** Session ID for tracking user sessions */
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
/** Trace ID for distributed tracing */
|
|
67
|
+
traceId?: string;
|
|
68
|
+
/** Span ID for current operation */
|
|
69
|
+
spanId?: string;
|
|
70
|
+
/** Parent span ID for operation hierarchy */
|
|
71
|
+
parentSpanId?: string;
|
|
72
|
+
/** Additional context metadata */
|
|
73
|
+
metadata?: Record<string, any>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Extended logger interface with OpenTelemetry support
|
|
77
|
+
*/
|
|
78
|
+
interface OtelLogger extends Logger {
|
|
79
|
+
/** Set OpenTelemetry context */
|
|
80
|
+
setContext(context: OtelContext): void;
|
|
81
|
+
/** Get current OpenTelemetry context */
|
|
82
|
+
getContext(): OtelContext;
|
|
83
|
+
/** Clear OpenTelemetry context */
|
|
84
|
+
clearContext(): void;
|
|
85
|
+
/** Log with OpenTelemetry context */
|
|
86
|
+
logWithContext(level: LogLevel, message: string, ...args: any[]): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* OpenTelemetry-aware console logger implementation
|
|
90
|
+
*/
|
|
91
|
+
declare class OtelConsoleLogger extends ConsoleLogger implements OtelLogger {
|
|
92
|
+
private context;
|
|
93
|
+
constructor(level?: LogLevel);
|
|
94
|
+
setContext(context: OtelContext): void;
|
|
95
|
+
getContext(): OtelContext;
|
|
96
|
+
clearContext(): void;
|
|
97
|
+
private formatWithContext;
|
|
98
|
+
logWithContext(level: LogLevel, message: string, ...args: any[]): void;
|
|
99
|
+
trace(message: string, ...args: any[]): void;
|
|
100
|
+
debug(message: string, ...args: any[]): void;
|
|
101
|
+
info(message: string, ...args: any[]): void;
|
|
102
|
+
warn(message: string, ...args: any[]): void;
|
|
103
|
+
error(message: string, ...args: any[]): void;
|
|
104
|
+
fatal(message: string, ...args: any[]): void;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
107
|
+
//#endregion
|
|
1
108
|
//#region src/ActionRegister.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* Controller object provided to action handlers for pipeline management
|
|
111
|
+
* @template T - The type of the payload being processed
|
|
112
|
+
*/
|
|
2
113
|
type PipelineController<T = any> = {
|
|
114
|
+
/** Continue to the next handler in the pipeline */
|
|
3
115
|
next: () => void;
|
|
116
|
+
/** Abort the pipeline execution with an optional reason */
|
|
4
117
|
abort: (reason?: string) => void;
|
|
118
|
+
/** Modify the payload that will be passed to subsequent handlers */
|
|
5
119
|
modifyPayload: (modifier: (payload: T) => T) => void;
|
|
6
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* Action handler function that processes actions in the pipeline
|
|
123
|
+
* @template T - The type of the payload
|
|
124
|
+
* @param payload - The data passed to the handler
|
|
125
|
+
* @param controller - Pipeline controller for flow management
|
|
126
|
+
* @returns void or Promise<void> for async handlers
|
|
127
|
+
*/
|
|
7
128
|
type ActionHandler<T = any> = (payload: T, controller: PipelineController<T>) => void | Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Configuration options for action handlers
|
|
131
|
+
*/
|
|
8
132
|
type HandlerConfig = {
|
|
133
|
+
/** Priority level (higher numbers execute first). Default: 0 */
|
|
9
134
|
priority?: number;
|
|
135
|
+
/** Unique identifier for the handler. Auto-generated if not provided */
|
|
10
136
|
id?: string;
|
|
137
|
+
/** Whether to wait for async handlers to complete. Default: false */
|
|
11
138
|
blocking?: boolean;
|
|
12
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Base interface for defining action payload mappings
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* interface MyActions extends ActionPayloadMap {
|
|
145
|
+
* increment: void;
|
|
146
|
+
* setCount: number;
|
|
147
|
+
* updateUser: { id: string; name: string };
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
13
151
|
interface ActionPayloadMap {}
|
|
152
|
+
/**
|
|
153
|
+
* Configuration options for ActionRegister
|
|
154
|
+
*/
|
|
155
|
+
interface ActionRegisterConfig {
|
|
156
|
+
/** Custom logger implementation. Defaults to ConsoleLogger */
|
|
157
|
+
logger?: Logger;
|
|
158
|
+
/** Log level for the logger. Defaults to ERROR if not provided */
|
|
159
|
+
logLevel?: LogLevel;
|
|
160
|
+
/** OpenTelemetry context for tracing */
|
|
161
|
+
otelContext?: OtelContext;
|
|
162
|
+
/** Whether to use OTEL-aware logger. Defaults to false */
|
|
163
|
+
useOtel?: boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Core action pipeline management system
|
|
167
|
+
* @template T - Action payload map defining available actions and their payload types
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* interface AppActions extends ActionPayloadMap {
|
|
171
|
+
* increment: void;
|
|
172
|
+
* setCount: number;
|
|
173
|
+
* }
|
|
174
|
+
*
|
|
175
|
+
* const actionRegister = new ActionRegister<AppActions>();
|
|
176
|
+
*
|
|
177
|
+
* // Register handlers
|
|
178
|
+
* actionRegister.register('increment', () => console.log('Incremented'));
|
|
179
|
+
* actionRegister.register('setCount', (count) => console.log(`Count: ${count}`));
|
|
180
|
+
*
|
|
181
|
+
* // Dispatch actions
|
|
182
|
+
* await actionRegister.dispatch('increment');
|
|
183
|
+
* await actionRegister.dispatch('setCount', 42);
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
14
186
|
declare class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {
|
|
15
187
|
private pipelines;
|
|
16
188
|
private atomSetters;
|
|
189
|
+
private handlerCounter;
|
|
190
|
+
readonly logger: Logger;
|
|
191
|
+
constructor(config?: ActionRegisterConfig);
|
|
192
|
+
/**
|
|
193
|
+
* Register a handler for an action in the pipeline
|
|
194
|
+
* @param action - The action name to handle
|
|
195
|
+
* @param handler - The handler function to execute
|
|
196
|
+
* @param config - Optional configuration for the handler
|
|
197
|
+
* @returns Unregister function to remove the handler
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const unregister = actionRegister.register('increment', () => {
|
|
201
|
+
* console.log('Incremented!');
|
|
202
|
+
* }, { priority: 10 });
|
|
203
|
+
*
|
|
204
|
+
* // Later, remove the handler
|
|
205
|
+
* unregister();
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
17
208
|
register<K extends keyof T>(action: K, handler: ActionHandler<T[K]>, config?: HandlerConfig): () => void;
|
|
18
209
|
registerAtomSetter(name: string, setter: Function): void;
|
|
210
|
+
/**
|
|
211
|
+
* Dispatch an action through the pipeline (for actions without payload)
|
|
212
|
+
* @param action - The action to dispatch
|
|
213
|
+
* @returns Promise that resolves when all handlers complete
|
|
214
|
+
*/
|
|
19
215
|
dispatch<K extends keyof T>(action: T[K] extends void ? K : never): Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* Dispatch an action through the pipeline (for actions with payload)
|
|
218
|
+
* @param action - The action to dispatch
|
|
219
|
+
* @param payload - The payload data to pass to handlers
|
|
220
|
+
* @returns Promise that resolves when all handlers complete
|
|
221
|
+
*/
|
|
20
222
|
dispatch<K extends keyof T>(action: K, payload: T[K]): Promise<void>;
|
|
21
223
|
private sortPipeline;
|
|
22
224
|
}
|
|
@@ -38,5 +240,5 @@ declare function isAction<T extends Record<string, any>, K extends keyof T>(acti
|
|
|
38
240
|
//# sourceMappingURL=types.d.ts.map
|
|
39
241
|
|
|
40
242
|
//#endregion
|
|
41
|
-
export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionType, BaseActionPayloadMap, HandlerConfig, PipelineController, createAction, isAction };
|
|
243
|
+
export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionRegisterConfig, ActionType, BaseActionPayloadMap, ConsoleLogger, HandlerConfig, LogLevel, Logger, OtelConsoleLogger, OtelContext, OtelLogger, PipelineController, createAction, createOtelContextFromPayload, extractSessionIdFromPayload, extractTraceIdFromPayload, getLogLevelFromEnv, isAction, parseLogLevel };
|
|
42
244
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/logger.ts","../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;AAGA;AAYA;AAYa,aAxBD,QAAA;EAwBe,KAAA,GAAA,CAAA;EAAA,KACE,GAAA,CAAA;EAAyB,IAEzB,GAAA,CAAA;EAAQ,IA4CnB,GAAA,CAAA;EAAQ,KA/CY,GAAA,CAAA;EAAM,KAAA,GAAA,CAAA;AAuD5C;AAuBA;AAaA;AAUA;AAUgB,UA3HC,MAAA,CA2HD;EAWC,KAAA,CAAA,OAAA,EAAW,MAAA,EAAA,GAUf,IAAM,EAAA,GAAA,EAAA,CAAA,EAAA,IAAA;EAMF,KAAA,CAAA,OAAW,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,GAAA,EAAA,CAAA,EAAA,IAAA;EAAA,IAAA,CAAA,OAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,GAAA,EAAA,CAAA,EAAA,IAAA;EAAA,IAEN,CAAA,OAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,GAAA,EAAA,CAAA,EAAA,IAAA;EAAW,KAEjB,CAAA,OAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,GAAA,EAAA,CAAA,EAAA,IAAA;EAAW,KAIH,CAAA,OAAA,EAAA,MAAA,EAAA,GAAA,IAAA,EAAA,GAAA,EAAA,CAAA,EAAA,IAAA;;AARkB;AAc1C;;AAGqB,cA3JR,aAAA,YAAyB,MA2JjB,CAAA;EAAyB,QAIxB,KAAA;EAAW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AAuBgB,iBE/EA,QF+EkB,CAAA,UE/EC,MF+EW,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,ME/E0B,CF+E1B,CAAA,CAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EE7EtC,CF6EsC,CAAA,EAAA,MAAA,IAAA;EAa9B,IAAA,EEzFK,CFyFL;EAUA,OAAA,EEnGiB,CFmGjB,CEnGmB,CFmGnB,CAAA;AAUhB,CAAA;AAWA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,224 @@
|
|
|
1
|
+
//#region src/logger.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Log levels in order of severity (lowest to highest)
|
|
4
|
+
*/
|
|
5
|
+
declare enum LogLevel {
|
|
6
|
+
TRACE = 0,
|
|
7
|
+
DEBUG = 1,
|
|
8
|
+
INFO = 2,
|
|
9
|
+
WARN = 3,
|
|
10
|
+
ERROR = 4,
|
|
11
|
+
FATAL = 5,
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Logger interface for custom logger implementations
|
|
15
|
+
*/
|
|
16
|
+
interface Logger {
|
|
17
|
+
trace(message: string, ...args: any[]): void;
|
|
18
|
+
debug(message: string, ...args: any[]): void;
|
|
19
|
+
info(message: string, ...args: any[]): void;
|
|
20
|
+
warn(message: string, ...args: any[]): void;
|
|
21
|
+
error(message: string, ...args: any[]): void;
|
|
22
|
+
fatal(message: string, ...args: any[]): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Default console logger implementation
|
|
26
|
+
*/
|
|
27
|
+
declare class ConsoleLogger implements Logger {
|
|
28
|
+
private level;
|
|
29
|
+
constructor(level?: LogLevel);
|
|
30
|
+
protected shouldLog(level: LogLevel): boolean;
|
|
31
|
+
private formatMessage;
|
|
32
|
+
trace(message: string, ...args: any[]): void;
|
|
33
|
+
debug(message: string, ...args: any[]): void;
|
|
34
|
+
info(message: string, ...args: any[]): void;
|
|
35
|
+
warn(message: string, ...args: any[]): void;
|
|
36
|
+
error(message: string, ...args: any[]): void;
|
|
37
|
+
fatal(message: string, ...args: any[]): void;
|
|
38
|
+
setLevel(level: LogLevel): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse log level from string
|
|
42
|
+
*/
|
|
43
|
+
declare function parseLogLevel(level: string): LogLevel;
|
|
44
|
+
/**
|
|
45
|
+
* Get log level from environment variable or default to ERROR
|
|
46
|
+
*/
|
|
47
|
+
declare function getLogLevelFromEnv(): LogLevel;
|
|
48
|
+
/**
|
|
49
|
+
* Extract trace ID from payload if it exists
|
|
50
|
+
*/
|
|
51
|
+
declare function extractTraceIdFromPayload(payload: any): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Extract session ID from payload if it exists
|
|
54
|
+
*/
|
|
55
|
+
declare function extractSessionIdFromPayload(payload: any): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Create OTEL context from payload
|
|
58
|
+
*/
|
|
59
|
+
declare function createOtelContextFromPayload(payload: any): OtelContext;
|
|
60
|
+
/**
|
|
61
|
+
* OpenTelemetry context interface for tracing
|
|
62
|
+
*/
|
|
63
|
+
interface OtelContext {
|
|
64
|
+
/** Session ID for tracking user sessions */
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
/** Trace ID for distributed tracing */
|
|
67
|
+
traceId?: string;
|
|
68
|
+
/** Span ID for current operation */
|
|
69
|
+
spanId?: string;
|
|
70
|
+
/** Parent span ID for operation hierarchy */
|
|
71
|
+
parentSpanId?: string;
|
|
72
|
+
/** Additional context metadata */
|
|
73
|
+
metadata?: Record<string, any>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Extended logger interface with OpenTelemetry support
|
|
77
|
+
*/
|
|
78
|
+
interface OtelLogger extends Logger {
|
|
79
|
+
/** Set OpenTelemetry context */
|
|
80
|
+
setContext(context: OtelContext): void;
|
|
81
|
+
/** Get current OpenTelemetry context */
|
|
82
|
+
getContext(): OtelContext;
|
|
83
|
+
/** Clear OpenTelemetry context */
|
|
84
|
+
clearContext(): void;
|
|
85
|
+
/** Log with OpenTelemetry context */
|
|
86
|
+
logWithContext(level: LogLevel, message: string, ...args: any[]): void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* OpenTelemetry-aware console logger implementation
|
|
90
|
+
*/
|
|
91
|
+
declare class OtelConsoleLogger extends ConsoleLogger implements OtelLogger {
|
|
92
|
+
private context;
|
|
93
|
+
constructor(level?: LogLevel);
|
|
94
|
+
setContext(context: OtelContext): void;
|
|
95
|
+
getContext(): OtelContext;
|
|
96
|
+
clearContext(): void;
|
|
97
|
+
private formatWithContext;
|
|
98
|
+
logWithContext(level: LogLevel, message: string, ...args: any[]): void;
|
|
99
|
+
trace(message: string, ...args: any[]): void;
|
|
100
|
+
debug(message: string, ...args: any[]): void;
|
|
101
|
+
info(message: string, ...args: any[]): void;
|
|
102
|
+
warn(message: string, ...args: any[]): void;
|
|
103
|
+
error(message: string, ...args: any[]): void;
|
|
104
|
+
fatal(message: string, ...args: any[]): void;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
107
|
+
//#endregion
|
|
1
108
|
//#region src/ActionRegister.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* Controller object provided to action handlers for pipeline management
|
|
111
|
+
* @template T - The type of the payload being processed
|
|
112
|
+
*/
|
|
2
113
|
type PipelineController<T = any> = {
|
|
114
|
+
/** Continue to the next handler in the pipeline */
|
|
3
115
|
next: () => void;
|
|
116
|
+
/** Abort the pipeline execution with an optional reason */
|
|
4
117
|
abort: (reason?: string) => void;
|
|
118
|
+
/** Modify the payload that will be passed to subsequent handlers */
|
|
5
119
|
modifyPayload: (modifier: (payload: T) => T) => void;
|
|
6
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* Action handler function that processes actions in the pipeline
|
|
123
|
+
* @template T - The type of the payload
|
|
124
|
+
* @param payload - The data passed to the handler
|
|
125
|
+
* @param controller - Pipeline controller for flow management
|
|
126
|
+
* @returns void or Promise<void> for async handlers
|
|
127
|
+
*/
|
|
7
128
|
type ActionHandler<T = any> = (payload: T, controller: PipelineController<T>) => void | Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Configuration options for action handlers
|
|
131
|
+
*/
|
|
8
132
|
type HandlerConfig = {
|
|
133
|
+
/** Priority level (higher numbers execute first). Default: 0 */
|
|
9
134
|
priority?: number;
|
|
135
|
+
/** Unique identifier for the handler. Auto-generated if not provided */
|
|
10
136
|
id?: string;
|
|
137
|
+
/** Whether to wait for async handlers to complete. Default: false */
|
|
11
138
|
blocking?: boolean;
|
|
12
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Base interface for defining action payload mappings
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* interface MyActions extends ActionPayloadMap {
|
|
145
|
+
* increment: void;
|
|
146
|
+
* setCount: number;
|
|
147
|
+
* updateUser: { id: string; name: string };
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
13
151
|
interface ActionPayloadMap {}
|
|
152
|
+
/**
|
|
153
|
+
* Configuration options for ActionRegister
|
|
154
|
+
*/
|
|
155
|
+
interface ActionRegisterConfig {
|
|
156
|
+
/** Custom logger implementation. Defaults to ConsoleLogger */
|
|
157
|
+
logger?: Logger;
|
|
158
|
+
/** Log level for the logger. Defaults to ERROR if not provided */
|
|
159
|
+
logLevel?: LogLevel;
|
|
160
|
+
/** OpenTelemetry context for tracing */
|
|
161
|
+
otelContext?: OtelContext;
|
|
162
|
+
/** Whether to use OTEL-aware logger. Defaults to false */
|
|
163
|
+
useOtel?: boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Core action pipeline management system
|
|
167
|
+
* @template T - Action payload map defining available actions and their payload types
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* interface AppActions extends ActionPayloadMap {
|
|
171
|
+
* increment: void;
|
|
172
|
+
* setCount: number;
|
|
173
|
+
* }
|
|
174
|
+
*
|
|
175
|
+
* const actionRegister = new ActionRegister<AppActions>();
|
|
176
|
+
*
|
|
177
|
+
* // Register handlers
|
|
178
|
+
* actionRegister.register('increment', () => console.log('Incremented'));
|
|
179
|
+
* actionRegister.register('setCount', (count) => console.log(`Count: ${count}`));
|
|
180
|
+
*
|
|
181
|
+
* // Dispatch actions
|
|
182
|
+
* await actionRegister.dispatch('increment');
|
|
183
|
+
* await actionRegister.dispatch('setCount', 42);
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
14
186
|
declare class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {
|
|
15
187
|
private pipelines;
|
|
16
188
|
private atomSetters;
|
|
189
|
+
private handlerCounter;
|
|
190
|
+
readonly logger: Logger;
|
|
191
|
+
constructor(config?: ActionRegisterConfig);
|
|
192
|
+
/**
|
|
193
|
+
* Register a handler for an action in the pipeline
|
|
194
|
+
* @param action - The action name to handle
|
|
195
|
+
* @param handler - The handler function to execute
|
|
196
|
+
* @param config - Optional configuration for the handler
|
|
197
|
+
* @returns Unregister function to remove the handler
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const unregister = actionRegister.register('increment', () => {
|
|
201
|
+
* console.log('Incremented!');
|
|
202
|
+
* }, { priority: 10 });
|
|
203
|
+
*
|
|
204
|
+
* // Later, remove the handler
|
|
205
|
+
* unregister();
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
17
208
|
register<K extends keyof T>(action: K, handler: ActionHandler<T[K]>, config?: HandlerConfig): () => void;
|
|
18
209
|
registerAtomSetter(name: string, setter: Function): void;
|
|
210
|
+
/**
|
|
211
|
+
* Dispatch an action through the pipeline (for actions without payload)
|
|
212
|
+
* @param action - The action to dispatch
|
|
213
|
+
* @returns Promise that resolves when all handlers complete
|
|
214
|
+
*/
|
|
19
215
|
dispatch<K extends keyof T>(action: T[K] extends void ? K : never): Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* Dispatch an action through the pipeline (for actions with payload)
|
|
218
|
+
* @param action - The action to dispatch
|
|
219
|
+
* @param payload - The payload data to pass to handlers
|
|
220
|
+
* @returns Promise that resolves when all handlers complete
|
|
221
|
+
*/
|
|
20
222
|
dispatch<K extends keyof T>(action: K, payload: T[K]): Promise<void>;
|
|
21
223
|
private sortPipeline;
|
|
22
224
|
}
|
|
@@ -38,5 +240,5 @@ declare function isAction<T extends Record<string, any>, K extends keyof T>(acti
|
|
|
38
240
|
//# sourceMappingURL=types.d.ts.map
|
|
39
241
|
|
|
40
242
|
//#endregion
|
|
41
|
-
export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionType, BaseActionPayloadMap, HandlerConfig, PipelineController, createAction, isAction };
|
|
243
|
+
export { ActionHandler, ActionHandlerMap, ActionPayload, ActionPayloadMap, ActionRegister, ActionRegisterConfig, ActionType, BaseActionPayloadMap, ConsoleLogger, HandlerConfig, LogLevel, Logger, OtelConsoleLogger, OtelContext, OtelLogger, PipelineController, createAction, createOtelContextFromPayload, extractSessionIdFromPayload, extractTraceIdFromPayload, getLogLevelFromEnv, isAction, parseLogLevel };
|
|
42
244
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/logger.ts","../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;AAGA;AAYA;AAYa,aAxBD,QAAA;EAwBe,KAAA,GAAA,CAAA;EAAA,KACE,GAAA,CAAA;EAAyB,IAEzB,GAAA,CAAA;EAAQ,IA4CnB,GAAA,CAAA;EAAQ,KA/CY,GAAA,CAAA;EAAM,KAAA,GAAA,CAAA;AAuD5C;AAuBA;AAaA;AAUA;AAUgB,UA3HC,MAAA,CA2HD;EAWC,KAAA,CAAA,OAA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,CAAA,UEnBf,MFmBe,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,MElBT,CFkBS,CAAA,GEjBvB,CFiBuB,CEjBrB,CFiBqB,CAAA;AAAA,KEdf,gBFce,CAAA,UEdY,MFcZ,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,GAAA,QACE,MEdf,CFce,IAAA,CAAA,OAAA,EEdA,CFcA,CEdE,CFcF,CAAA,EAAA,GAAA,IAAA,GEdgB,OFchB,CAAA,IAAA,CAAA,EAAyB;AA8CpC,iBExDF,YFwDE,CAAA,UExDqB,MFwDrB,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,MExD0D,CFwD1D,CAAA,CAAA,IAAA,EEvDV,CFuDU,EAAA,OAAA,EEtDP,CFsDO,CEtDL,CFsDK,CAAA,CAAA,EAAA;EAAQ,IA/CY,EEN3B,CFM2B;EAAM,OAAA,EENrB,CFMqB,CENnB,CFMmB,CAAA;AAuD5C,CAAA;AAuBgB,iBE/EA,QF+EkB,CAAA,UE/EC,MF+EW,CAAA,MAAA,EAAA,GAAA,CAAA,EAAA,UAAA,ME/E0B,CF+E1B,CAAA,CAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EE7EtC,CF6EsC,CAAA,EAAA,MAAA,IAAA;EAa9B,IAAA,EEzFK,CFyFL;EAUA,OAAA,EEnGiB,CFmGjB,CEnGmB,CFmGnB,CAAA;AAUhB,CAAA;AAWA"}
|
package/dist/index.js
CHANGED
|
@@ -70,7 +70,7 @@ var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+
|
|
|
70
70
|
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js
|
|
71
71
|
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
72
72
|
var toPropertyKey = require_toPropertyKey();
|
|
73
|
-
function _defineProperty$
|
|
73
|
+
function _defineProperty$2(e, r, t) {
|
|
74
74
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
75
75
|
value: t,
|
|
76
76
|
enumerable: !0,
|
|
@@ -78,68 +78,311 @@ var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project
|
|
|
78
78
|
writable: !0
|
|
79
79
|
}) : e[r] = t, e;
|
|
80
80
|
}
|
|
81
|
-
module.exports = _defineProperty$
|
|
81
|
+
module.exports = _defineProperty$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
82
82
|
} });
|
|
83
83
|
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/logger.ts
|
|
86
|
+
var import_defineProperty$1 = __toESM(require_defineProperty(), 1);
|
|
87
|
+
/**
|
|
88
|
+
* Log levels in order of severity (lowest to highest)
|
|
89
|
+
*/
|
|
90
|
+
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
91
|
+
LogLevel$1[LogLevel$1["TRACE"] = 0] = "TRACE";
|
|
92
|
+
LogLevel$1[LogLevel$1["DEBUG"] = 1] = "DEBUG";
|
|
93
|
+
LogLevel$1[LogLevel$1["INFO"] = 2] = "INFO";
|
|
94
|
+
LogLevel$1[LogLevel$1["WARN"] = 3] = "WARN";
|
|
95
|
+
LogLevel$1[LogLevel$1["ERROR"] = 4] = "ERROR";
|
|
96
|
+
LogLevel$1[LogLevel$1["FATAL"] = 5] = "FATAL";
|
|
97
|
+
return LogLevel$1;
|
|
98
|
+
}({});
|
|
99
|
+
/**
|
|
100
|
+
* Default console logger implementation
|
|
101
|
+
*/
|
|
102
|
+
var ConsoleLogger = class {
|
|
103
|
+
constructor(level = LogLevel.ERROR) {
|
|
104
|
+
this.level = level;
|
|
105
|
+
}
|
|
106
|
+
shouldLog(level) {
|
|
107
|
+
return level >= this.level;
|
|
108
|
+
}
|
|
109
|
+
formatMessage(level, message) {
|
|
110
|
+
return `[${level.toUpperCase()}] ${message}`;
|
|
111
|
+
}
|
|
112
|
+
trace(message, ...args) {
|
|
113
|
+
if (this.shouldLog(LogLevel.TRACE)) console.trace(this.formatMessage("trace", message), ...args);
|
|
114
|
+
}
|
|
115
|
+
debug(message, ...args) {
|
|
116
|
+
if (this.shouldLog(LogLevel.DEBUG)) console.debug(this.formatMessage("debug", message), ...args);
|
|
117
|
+
}
|
|
118
|
+
info(message, ...args) {
|
|
119
|
+
if (this.shouldLog(LogLevel.INFO)) console.info(this.formatMessage("info", message), ...args);
|
|
120
|
+
}
|
|
121
|
+
warn(message, ...args) {
|
|
122
|
+
if (this.shouldLog(LogLevel.WARN)) console.warn(this.formatMessage("warn", message), ...args);
|
|
123
|
+
}
|
|
124
|
+
error(message, ...args) {
|
|
125
|
+
if (this.shouldLog(LogLevel.ERROR)) console.error(this.formatMessage("error", message), ...args);
|
|
126
|
+
}
|
|
127
|
+
fatal(message, ...args) {
|
|
128
|
+
if (this.shouldLog(LogLevel.FATAL)) console.error(this.formatMessage("fatal", message), ...args);
|
|
129
|
+
}
|
|
130
|
+
setLevel(level) {
|
|
131
|
+
this.level = level;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Parse log level from string
|
|
136
|
+
*/
|
|
137
|
+
function parseLogLevel(level) {
|
|
138
|
+
const upperLevel = level.toUpperCase();
|
|
139
|
+
switch (upperLevel) {
|
|
140
|
+
case "TRACE": return LogLevel.TRACE;
|
|
141
|
+
case "DEBUG": return LogLevel.DEBUG;
|
|
142
|
+
case "INFO": return LogLevel.INFO;
|
|
143
|
+
case "WARN": return LogLevel.WARN;
|
|
144
|
+
case "ERROR": return LogLevel.ERROR;
|
|
145
|
+
case "FATAL": return LogLevel.FATAL;
|
|
146
|
+
default: return LogLevel.ERROR;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get log level from environment variable or default to ERROR
|
|
151
|
+
*/
|
|
152
|
+
function getLogLevelFromEnv() {
|
|
153
|
+
if (typeof process !== "undefined" && process.env) {
|
|
154
|
+
const envLevel = process.env.LOG_LEVEL || process.env.ACTION_LOG_LEVEL;
|
|
155
|
+
if (envLevel) return parseLogLevel(envLevel);
|
|
156
|
+
}
|
|
157
|
+
return LogLevel.TRACE;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Extract trace ID from payload if it exists
|
|
161
|
+
*/
|
|
162
|
+
function extractTraceIdFromPayload(payload) {
|
|
163
|
+
if (payload && typeof payload === "object") return payload._traceId || payload.traceId || payload.trace_id;
|
|
164
|
+
return void 0;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Extract session ID from payload if it exists
|
|
168
|
+
*/
|
|
169
|
+
function extractSessionIdFromPayload(payload) {
|
|
170
|
+
if (payload && typeof payload === "object") return payload._sessionId || payload.sessionId || payload.session_id;
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Create OTEL context from payload
|
|
175
|
+
*/
|
|
176
|
+
function createOtelContextFromPayload(payload) {
|
|
177
|
+
return {
|
|
178
|
+
traceId: extractTraceIdFromPayload(payload),
|
|
179
|
+
sessionId: extractSessionIdFromPayload(payload),
|
|
180
|
+
metadata: payload
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* OpenTelemetry-aware console logger implementation
|
|
185
|
+
*/
|
|
186
|
+
var OtelConsoleLogger = class extends ConsoleLogger {
|
|
187
|
+
constructor(level = LogLevel.ERROR) {
|
|
188
|
+
super(level);
|
|
189
|
+
(0, import_defineProperty$1.default)(this, "context", {});
|
|
190
|
+
}
|
|
191
|
+
setContext(context) {
|
|
192
|
+
this.context = {
|
|
193
|
+
...this.context,
|
|
194
|
+
...context
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
getContext() {
|
|
198
|
+
return { ...this.context };
|
|
199
|
+
}
|
|
200
|
+
clearContext() {
|
|
201
|
+
this.context = {};
|
|
202
|
+
}
|
|
203
|
+
formatWithContext(level, message) {
|
|
204
|
+
const contextParts = [];
|
|
205
|
+
if (this.context.sessionId) contextParts.push(`session=${this.context.sessionId}`);
|
|
206
|
+
if (this.context.traceId) contextParts.push(`trace=${this.context.traceId}`);
|
|
207
|
+
if (this.context.spanId) contextParts.push(`span=${this.context.spanId}`);
|
|
208
|
+
const contextStr = contextParts.length > 0 ? ` [${contextParts.join(", ")}]` : "";
|
|
209
|
+
return `[${level.toUpperCase()}]${contextStr} ${message}`;
|
|
210
|
+
}
|
|
211
|
+
logWithContext(level, message, ...args) {
|
|
212
|
+
const levelName = LogLevel[level].toLowerCase();
|
|
213
|
+
const formattedMessage = this.formatWithContext(levelName, message);
|
|
214
|
+
switch (level) {
|
|
215
|
+
case LogLevel.TRACE:
|
|
216
|
+
if (this.shouldLog(LogLevel.TRACE)) console.trace(formattedMessage, ...args);
|
|
217
|
+
break;
|
|
218
|
+
case LogLevel.DEBUG:
|
|
219
|
+
if (this.shouldLog(LogLevel.DEBUG)) console.debug(formattedMessage, ...args);
|
|
220
|
+
break;
|
|
221
|
+
case LogLevel.INFO:
|
|
222
|
+
if (this.shouldLog(LogLevel.INFO)) console.info(formattedMessage, ...args);
|
|
223
|
+
break;
|
|
224
|
+
case LogLevel.WARN:
|
|
225
|
+
if (this.shouldLog(LogLevel.WARN)) console.warn(formattedMessage, ...args);
|
|
226
|
+
break;
|
|
227
|
+
case LogLevel.ERROR:
|
|
228
|
+
if (this.shouldLog(LogLevel.ERROR)) console.error(formattedMessage, ...args);
|
|
229
|
+
break;
|
|
230
|
+
case LogLevel.FATAL:
|
|
231
|
+
if (this.shouldLog(LogLevel.FATAL)) console.error(formattedMessage, ...args);
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
trace(message, ...args) {
|
|
236
|
+
this.logWithContext(LogLevel.TRACE, message, ...args);
|
|
237
|
+
}
|
|
238
|
+
debug(message, ...args) {
|
|
239
|
+
this.logWithContext(LogLevel.DEBUG, message, ...args);
|
|
240
|
+
}
|
|
241
|
+
info(message, ...args) {
|
|
242
|
+
this.logWithContext(LogLevel.INFO, message, ...args);
|
|
243
|
+
}
|
|
244
|
+
warn(message, ...args) {
|
|
245
|
+
this.logWithContext(LogLevel.WARN, message, ...args);
|
|
246
|
+
}
|
|
247
|
+
error(message, ...args) {
|
|
248
|
+
this.logWithContext(LogLevel.ERROR, message, ...args);
|
|
249
|
+
}
|
|
250
|
+
fatal(message, ...args) {
|
|
251
|
+
this.logWithContext(LogLevel.FATAL, message, ...args);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
84
255
|
//#endregion
|
|
85
256
|
//#region src/ActionRegister.ts
|
|
86
257
|
var import_defineProperty = __toESM(require_defineProperty(), 1);
|
|
258
|
+
/**
|
|
259
|
+
* Core action pipeline management system
|
|
260
|
+
* @template T - Action payload map defining available actions and their payload types
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* interface AppActions extends ActionPayloadMap {
|
|
264
|
+
* increment: void;
|
|
265
|
+
* setCount: number;
|
|
266
|
+
* }
|
|
267
|
+
*
|
|
268
|
+
* const actionRegister = new ActionRegister<AppActions>();
|
|
269
|
+
*
|
|
270
|
+
* // Register handlers
|
|
271
|
+
* actionRegister.register('increment', () => console.log('Incremented'));
|
|
272
|
+
* actionRegister.register('setCount', (count) => console.log(`Count: ${count}`));
|
|
273
|
+
*
|
|
274
|
+
* // Dispatch actions
|
|
275
|
+
* await actionRegister.dispatch('increment');
|
|
276
|
+
* await actionRegister.dispatch('setCount', 42);
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
87
279
|
var ActionRegister = class {
|
|
88
|
-
constructor() {
|
|
280
|
+
constructor(config) {
|
|
89
281
|
(0, import_defineProperty.default)(this, "pipelines", /* @__PURE__ */ new Map());
|
|
90
282
|
(0, import_defineProperty.default)(this, "atomSetters", /* @__PURE__ */ new Map());
|
|
283
|
+
(0, import_defineProperty.default)(this, "handlerCounter", 0);
|
|
284
|
+
(0, import_defineProperty.default)(this, "logger", void 0);
|
|
285
|
+
const envLogLevel = getLogLevelFromEnv();
|
|
286
|
+
const configLogLevel = config?.logLevel ?? envLogLevel;
|
|
287
|
+
if (config?.logger) this.logger = config.logger;
|
|
288
|
+
else if (config?.useOtel) this.logger = new OtelConsoleLogger(configLogLevel);
|
|
289
|
+
else this.logger = new ConsoleLogger(configLogLevel);
|
|
290
|
+
if (config?.otelContext && this.logger instanceof OtelConsoleLogger) this.logger.setContext(config.otelContext);
|
|
291
|
+
this.logger.debug("ActionRegister initialized", {
|
|
292
|
+
logLevel: configLogLevel,
|
|
293
|
+
useOtel: config?.useOtel ?? false,
|
|
294
|
+
hasOtelContext: !!config?.otelContext
|
|
295
|
+
});
|
|
91
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Register a handler for an action in the pipeline
|
|
299
|
+
* @param action - The action name to handle
|
|
300
|
+
* @param handler - The handler function to execute
|
|
301
|
+
* @param config - Optional configuration for the handler
|
|
302
|
+
* @returns Unregister function to remove the handler
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const unregister = actionRegister.register('increment', () => {
|
|
306
|
+
* console.log('Incremented!');
|
|
307
|
+
* }, { priority: 10 });
|
|
308
|
+
*
|
|
309
|
+
* // Later, remove the handler
|
|
310
|
+
* unregister();
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
92
313
|
register(action, handler, config = {}) {
|
|
93
|
-
if (!this.pipelines.has(action))
|
|
314
|
+
if (!this.pipelines.has(action)) {
|
|
315
|
+
this.pipelines.set(action, /* @__PURE__ */ new Map());
|
|
316
|
+
this.logger.debug(`Created new pipeline for action: ${String(action)}`);
|
|
317
|
+
}
|
|
94
318
|
const pipeline = this.pipelines.get(action);
|
|
95
|
-
const handlerId = config.id || `handler_${
|
|
319
|
+
const handlerId = config.id || `handler_${++this.handlerCounter}`;
|
|
96
320
|
if (pipeline.has(handlerId)) {
|
|
97
|
-
|
|
321
|
+
this.logger.warn(`Handler with id ${handlerId} already exists for action: ${String(action)}`);
|
|
98
322
|
return () => {};
|
|
99
323
|
}
|
|
100
324
|
pipeline.set(handlerId, {
|
|
101
325
|
handler,
|
|
102
326
|
config
|
|
103
327
|
});
|
|
328
|
+
this.logger.debug(`Registered handler for action: ${String(action)}`, {
|
|
329
|
+
handlerId,
|
|
330
|
+
priority: config.priority ?? 0,
|
|
331
|
+
blocking: config.blocking ?? false
|
|
332
|
+
});
|
|
104
333
|
this.sortPipeline(action);
|
|
105
334
|
return () => {
|
|
106
335
|
pipeline.delete(handlerId);
|
|
336
|
+
this.logger.debug(`Unregistered handler: ${handlerId} for action: ${String(action)}`);
|
|
107
337
|
};
|
|
108
338
|
}
|
|
109
339
|
registerAtomSetter(name, setter) {
|
|
110
340
|
this.atomSetters.set(name, setter);
|
|
341
|
+
this.logger.debug(`Registered atom setter: ${name}`);
|
|
111
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Internal dispatch implementation
|
|
345
|
+
* @internal
|
|
346
|
+
*/
|
|
112
347
|
async dispatch(action, payload) {
|
|
113
348
|
const pipeline = this.pipelines.get(action);
|
|
349
|
+
if (this.logger instanceof OtelConsoleLogger && payload) {
|
|
350
|
+
const otelContext = createOtelContextFromPayload(payload);
|
|
351
|
+
if (otelContext.traceId || otelContext.sessionId) this.logger.setContext(otelContext);
|
|
352
|
+
}
|
|
353
|
+
this.logger.debug(`Dispatching action: ${String(action)}`, { payload });
|
|
114
354
|
if (!pipeline || pipeline.size === 0) {
|
|
115
|
-
|
|
355
|
+
this.logger.warn(`No handlers registered for action: ${String(action)}`);
|
|
116
356
|
return;
|
|
117
357
|
}
|
|
118
358
|
let modifiedPayload = payload;
|
|
119
359
|
const handlers = Array.from(pipeline.values());
|
|
360
|
+
let shouldContinue = true;
|
|
361
|
+
this.logger.trace(`Executing pipeline for action: ${String(action)}`, { handlerCount: handlers.length });
|
|
120
362
|
for (const { handler, config } of handlers) {
|
|
121
|
-
|
|
363
|
+
if (!shouldContinue) break;
|
|
122
364
|
const controller = {
|
|
123
365
|
next: () => {
|
|
124
366
|
shouldContinue = true;
|
|
125
367
|
},
|
|
126
368
|
abort: (reason) => {
|
|
127
369
|
shouldContinue = false;
|
|
128
|
-
|
|
370
|
+
this.logger.warn(`Pipeline aborted: ${reason}`);
|
|
129
371
|
},
|
|
130
372
|
modifyPayload: (modifier) => {
|
|
131
373
|
modifiedPayload = modifier(modifiedPayload);
|
|
374
|
+
this.logger.trace(`Payload modified for action: ${String(action)}`);
|
|
132
375
|
}
|
|
133
376
|
};
|
|
134
377
|
try {
|
|
135
378
|
if (config.blocking) await handler(modifiedPayload, controller);
|
|
136
379
|
else handler(modifiedPayload, controller);
|
|
137
|
-
if (!shouldContinue) break;
|
|
138
380
|
} catch (error) {
|
|
139
|
-
|
|
381
|
+
this.logger.error(`Error in pipeline handler for action: ${String(action)}`, error);
|
|
140
382
|
if (config.blocking) throw error;
|
|
141
383
|
}
|
|
142
384
|
}
|
|
385
|
+
this.logger.debug(`Completed dispatching action: ${String(action)}`);
|
|
143
386
|
}
|
|
144
387
|
sortPipeline(action) {
|
|
145
388
|
const pipeline = this.pipelines.get(action);
|
|
@@ -151,6 +394,10 @@ var ActionRegister = class {
|
|
|
151
394
|
});
|
|
152
395
|
pipeline.clear();
|
|
153
396
|
sorted.forEach(([id, data]) => pipeline.set(id, data));
|
|
397
|
+
this.logger.trace(`Sorted pipeline for action: ${String(action)}`, {
|
|
398
|
+
handlerCount: sorted.length,
|
|
399
|
+
priorities: sorted.map(([, data]) => data.config.priority ?? 0)
|
|
400
|
+
});
|
|
154
401
|
}
|
|
155
402
|
};
|
|
156
403
|
|
|
@@ -167,5 +414,5 @@ function isAction(action, type) {
|
|
|
167
414
|
}
|
|
168
415
|
|
|
169
416
|
//#endregion
|
|
170
|
-
export { ActionRegister, createAction, isAction };
|
|
417
|
+
export { ActionRegister, ConsoleLogger, LogLevel, OtelConsoleLogger, createAction, createOtelContextFromPayload, extractSessionIdFromPayload, extractTraceIdFromPayload, getLogLevelFromEnv, isAction, parseLogLevel };
|
|
171
418
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_typeof","o","_typeof","toPrimitive","toPropertyKey","_defineProperty","action: K","handler: ActionHandler<T[K]>","config: HandlerConfig","name: string","setter: Function","payload?: T[K]","controller: PipelineController<T[K]>","type: K","payload: T[K]","action: any"],"sources":["../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/typeof.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js","../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":["function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return module.exports = _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports, _typeof(o);\n}\nmodule.exports = _typeof, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nfunction toPrimitive(t, r) {\n if (\"object\" != _typeof(t) || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != _typeof(i)) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nmodule.exports = toPrimitive, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nvar toPrimitive = require(\"./toPrimitive.js\");\nfunction toPropertyKey(t) {\n var i = toPrimitive(t, \"string\");\n return \"symbol\" == _typeof(i) ? i : i + \"\";\n}\nmodule.exports = toPropertyKey, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var toPropertyKey = require(\"./toPropertyKey.js\");\nfunction _defineProperty(e, r, t) {\n return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {\n value: t,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }) : e[r] = t, e;\n}\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","// 타입 정의\nexport type PipelineController<T = any> = {\n next: () => void;\n abort: (reason?: string) => void;\n modifyPayload: (modifier: (payload: T) => T) => void;\n};\n\nexport type ActionHandler<T = any> = (\n payload: T,\n controller: PipelineController<T>\n) => void | Promise<void>;\n\nexport type HandlerConfig = {\n priority?: number;\n id?: string;\n blocking?: boolean;\n};\n\n// 선언적 타입 정의를 위한 인터페이스\nexport interface ActionPayloadMap {\n // 확장 가능한 구조\n // 'actionName': PayloadType;\n}\n\n// Action Register 클래스\nexport class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {\n private pipelines = new Map<keyof T, Map<string, {\n handler: ActionHandler<any>;\n config: HandlerConfig;\n }>>();\n \n private atomSetters = new Map<string, Function>();\n\n // 파이프라인에 핸들러 등록\n register<K extends keyof T>(\n action: K,\n handler: ActionHandler<T[K]>,\n config: HandlerConfig = {}\n ): () => void {\n if (!this.pipelines.has(action)) {\n this.pipelines.set(action, new Map());\n }\n \n const pipeline = this.pipelines.get(action)!;\n const handlerId = config.id || `handler_${Date.now()}_${Math.random()}`;\n \n // 중복 등록 방지\n if (pipeline.has(handlerId)) {\n console.warn(`Handler with id ${handlerId} already exists`);\n return () => {};\n }\n \n pipeline.set(handlerId, { handler, config });\n \n // 우선순위로 정렬\n this.sortPipeline(action);\n \n // unregister 함수 반환\n return () => {\n pipeline.delete(handlerId);\n };\n }\n\n // Atom setter 등록\n registerAtomSetter(name: string, setter: Function) {\n this.atomSetters.set(name, setter);\n }\n\n // 파이프라인 실행 - void 타입을 위한 오버로드\n async dispatch<K extends keyof T>(\n action: T[K] extends void ? K : never\n ): Promise<void>;\n async dispatch<K extends keyof T>(\n action: K,\n payload: T[K]\n ): Promise<void>;\n async dispatch<K extends keyof T>(\n action: K,\n payload?: T[K]\n ): Promise<void> {\n const pipeline = this.pipelines.get(action);\n \n if (!pipeline || pipeline.size === 0) {\n console.warn(`No handlers registered for action: ${String(action)}`);\n return;\n }\n \n let modifiedPayload = payload as T[K];\n const handlers = Array.from(pipeline.values());\n \n for (const { handler, config } of handlers) {\n let shouldContinue = true;\n \n const controller: PipelineController<T[K]> = {\n next: () => { shouldContinue = true; },\n abort: (reason) => {\n shouldContinue = false;\n console.log(`Pipeline aborted: ${reason}`);\n },\n modifyPayload: (modifier) => {\n modifiedPayload = modifier(modifiedPayload);\n }\n };\n \n try {\n if (config.blocking) {\n await handler(modifiedPayload, controller);\n } else {\n handler(modifiedPayload, controller);\n }\n \n if (!shouldContinue) break;\n } catch (error) {\n console.error(`Error in pipeline handler:`, error);\n if (config.blocking) throw error;\n }\n }\n }\n\n private sortPipeline<K extends keyof T>(action: K) {\n const pipeline = this.pipelines.get(action);\n if (!pipeline) return;\n \n const sorted = Array.from(pipeline.entries())\n .sort(([, a], [, b]) => {\n const priorityA = a.config.priority ?? 0;\n const priorityB = b.config.priority ?? 0;\n return priorityB - priorityA; // 높은 우선순위가 먼저\n });\n \n pipeline.clear();\n sorted.forEach(([id, data]) => pipeline.set(id, data));\n }\n}","// 기본 액션 타입 정의\nexport interface BaseActionPayloadMap {\n // 기본 액션들은 여기에 정의\n}\n\n// 액션 타입 추출 헬퍼\nexport type ActionType<T extends Record<string, any>> = keyof T;\nexport type ActionPayload<\n T extends Record<string, any>,\n K extends keyof T\n> = T[K];\n\n// 액션 핸들러 타입\nexport type ActionHandlerMap<T extends Record<string, any>> = {\n [K in keyof T]?: (payload: T[K]) => void | Promise<void>;\n};\n\n// 액션 생성 헬퍼\nexport function createAction<T extends Record<string, any>, K extends keyof T>(\n type: K,\n payload: T[K]\n): { type: K; payload: T[K] } {\n return { type, payload };\n}\n\n// 타입 가드\nexport function isAction<T extends Record<string, any>, K extends keyof T>(\n action: any,\n type: K\n): action is { type: K; payload: T[K] } {\n return action?.type === type;\n}"],"x_google_ignoreList":[0,1,2,3],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAA,SAASA,UAAQ,GAAG;AAClB;AAEA,SAAO,OAAO,UAAUA,YAAU,cAAc,OAAO,UAAU,YAAY,OAAO,OAAO,WAAW,SAAUC,KAAG;AACjH,UAAO,OAAOA;EACf,IAAG,SAAUA,KAAG;AACf,UAAOA,OAAK,cAAc,OAAO,UAAUA,IAAE,gBAAgB,UAAUA,QAAM,OAAO,YAAY,WAAW,OAAOA;EACnH,GAAE,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO,SAASD,UAAQ,EAAE;CAC5F;CACD,OAAO,UAAUA,WAAS,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO;;;;;;CCT/F,IAAIE,6BAAiC;CACrC,SAASC,cAAY,GAAG,GAAG;AACzB,MAAI,YAAYD,UAAQ,EAAE,IAAI,CAAC,EAAG,QAAO;EACzC,IAAI,IAAI,EAAE,OAAO;AACjB,MAAI,KAAK,MAAM,GAAG;GAChB,IAAI,IAAI,EAAE,KAAK,GAAG,KAAK,UAAU;AACjC,OAAI,YAAYA,UAAQ,EAAE,CAAE,QAAO;AACnC,SAAM,IAAI,UAAU;EACrB;AACD,UAAQ,aAAa,IAAI,SAAS,QAAQ,EAAE;CAC7C;CACD,OAAO,UAAUC,eAAa,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO;;;;;;CCXnG,IAAI,2BAAiC;CACrC,IAAI;CACJ,SAASC,gBAAc,GAAG;EACxB,IAAI,IAAI,YAAY,GA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zB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_typeof","o","_typeof","toPrimitive","toPropertyKey","_defineProperty","level: LogLevel","level: string","message: string","payload: any","context: OtelContext","contextParts: string[]","config?: ActionRegisterConfig","action: K","handler: ActionHandler<T[K]>","config: HandlerConfig","name: string","setter: Function","payload?: T[K]","controller: PipelineController<T[K]>","type: K","payload: T[K]","action: any"],"sources":["../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/typeof.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js","../src/logger.ts","../src/ActionRegister.ts","../src/types.ts"],"sourcesContent":["function _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return module.exports = _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, module.exports.__esModule = true, module.exports[\"default\"] = module.exports, _typeof(o);\n}\nmodule.exports = _typeof, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nfunction toPrimitive(t, r) {\n if (\"object\" != _typeof(t) || !t) return t;\n var e = t[Symbol.toPrimitive];\n if (void 0 !== e) {\n var i = e.call(t, r || \"default\");\n if (\"object\" != _typeof(i)) return i;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (\"string\" === r ? String : Number)(t);\n}\nmodule.exports = toPrimitive, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var _typeof = require(\"./typeof.js\")[\"default\"];\nvar toPrimitive = require(\"./toPrimitive.js\");\nfunction toPropertyKey(t) {\n var i = toPrimitive(t, \"string\");\n return \"symbol\" == _typeof(i) ? i : i + \"\";\n}\nmodule.exports = toPropertyKey, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","var toPropertyKey = require(\"./toPropertyKey.js\");\nfunction _defineProperty(e, r, t) {\n return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {\n value: t,\n enumerable: !0,\n configurable: !0,\n writable: !0\n }) : e[r] = t, e;\n}\nmodule.exports = _defineProperty, module.exports.__esModule = true, module.exports[\"default\"] = module.exports;","/**\n * Log levels in order of severity (lowest to highest)\n */\nexport enum LogLevel {\n TRACE = 0,\n DEBUG = 1,\n INFO = 2,\n WARN = 3,\n ERROR = 4,\n FATAL = 5\n}\n\n/**\n * Logger interface for custom logger implementations\n */\nexport interface Logger {\n trace(message: string, ...args: any[]): void;\n debug(message: string, ...args: any[]): void;\n info(message: string, ...args: any[]): void;\n warn(message: string, ...args: any[]): void;\n error(message: string, ...args: any[]): void;\n fatal(message: string, ...args: any[]): void;\n}\n\n/**\n * Default console logger implementation\n */\nexport class ConsoleLogger implements Logger {\n constructor(private level: LogLevel = LogLevel.ERROR) {}\n\n protected shouldLog(level: LogLevel): boolean {\n return level >= this.level;\n }\n\n private formatMessage(level: string, message: string): string {\n return `[${level.toUpperCase()}] ${message}`;\n }\n\n trace(message: string, ...args: any[]): void {\n if (this.shouldLog(LogLevel.TRACE)) {\n console.trace(this.formatMessage('trace', message), ...args);\n }\n }\n\n debug(message: string, ...args: any[]): void {\n if (this.shouldLog(LogLevel.DEBUG)) {\n console.debug(this.formatMessage('debug', message), ...args);\n }\n }\n\n info(message: string, ...args: any[]): void {\n if (this.shouldLog(LogLevel.INFO)) {\n console.info(this.formatMessage('info', message), ...args);\n }\n }\n\n warn(message: string, ...args: any[]): void {\n if (this.shouldLog(LogLevel.WARN)) {\n console.warn(this.formatMessage('warn', message), ...args);\n }\n }\n\n error(message: string, ...args: any[]): void {\n if (this.shouldLog(LogLevel.ERROR)) {\n console.error(this.formatMessage('error', message), ...args);\n }\n }\n\n fatal(message: string, ...args: any[]): void {\n if (this.shouldLog(LogLevel.FATAL)) {\n console.error(this.formatMessage('fatal', message), ...args);\n }\n }\n\n setLevel(level: LogLevel): void {\n this.level = level;\n }\n}\n\n/**\n * Parse log level from string\n */\nexport function parseLogLevel(level: string): LogLevel {\n const upperLevel = level.toUpperCase();\n switch (upperLevel) {\n case 'TRACE':\n return LogLevel.TRACE;\n case 'DEBUG':\n return LogLevel.DEBUG;\n case 'INFO':\n return LogLevel.INFO;\n case 'WARN':\n return LogLevel.WARN;\n case 'ERROR':\n return LogLevel.ERROR;\n case 'FATAL':\n return LogLevel.FATAL;\n default:\n return LogLevel.ERROR;\n }\n}\n\n/**\n * Get log level from environment variable or default to ERROR\n */\nexport function getLogLevelFromEnv(): LogLevel {\n if (typeof process !== 'undefined' && process.env) {\n const envLevel = process.env.LOG_LEVEL || process.env.ACTION_LOG_LEVEL;\n if (envLevel) {\n return parseLogLevel(envLevel);\n }\n }\n return LogLevel.TRACE;\n}\n\n/**\n * Extract trace ID from payload if it exists\n */\nexport function extractTraceIdFromPayload(payload: any): string | undefined {\n if (payload && typeof payload === 'object') {\n return payload._traceId || payload.traceId || payload.trace_id;\n }\n return undefined;\n}\n\n/**\n * Extract session ID from payload if it exists\n */\nexport function extractSessionIdFromPayload(payload: any): string | undefined {\n if (payload && typeof payload === 'object') {\n return payload._sessionId || payload.sessionId || payload.session_id;\n }\n return undefined;\n}\n\n/**\n * Create OTEL context from payload\n */\nexport function createOtelContextFromPayload(payload: any): OtelContext {\n return {\n traceId: extractTraceIdFromPayload(payload),\n sessionId: extractSessionIdFromPayload(payload),\n metadata: payload\n };\n}\n\n/**\n * OpenTelemetry context interface for tracing\n */\nexport interface OtelContext {\n /** Session ID for tracking user sessions */\n sessionId?: string;\n /** Trace ID for distributed tracing */\n traceId?: string;\n /** Span ID for current operation */\n spanId?: string;\n /** Parent span ID for operation hierarchy */\n parentSpanId?: string;\n /** Additional context metadata */\n metadata?: Record<string, any>;\n}\n\n/**\n * Extended logger interface with OpenTelemetry support\n */\nexport interface OtelLogger extends Logger {\n /** Set OpenTelemetry context */\n setContext(context: OtelContext): void;\n /** Get current OpenTelemetry context */\n getContext(): OtelContext;\n /** Clear OpenTelemetry context */\n clearContext(): void;\n /** Log with OpenTelemetry context */\n logWithContext(level: LogLevel, message: string, ...args: any[]): void;\n}\n\n/**\n * OpenTelemetry-aware console logger implementation\n */\nexport class OtelConsoleLogger extends ConsoleLogger implements OtelLogger {\n private context: OtelContext = {};\n\n constructor(level: LogLevel = LogLevel.ERROR) {\n super(level);\n }\n\n setContext(context: OtelContext): void {\n this.context = { ...this.context, ...context };\n }\n\n getContext(): OtelContext {\n return { ...this.context };\n }\n\n clearContext(): void {\n this.context = {};\n }\n\n private formatWithContext(level: string, message: string): string {\n const contextParts: string[] = [];\n \n if (this.context.sessionId) {\n contextParts.push(`session=${this.context.sessionId}`);\n }\n if (this.context.traceId) {\n contextParts.push(`trace=${this.context.traceId}`);\n }\n if (this.context.spanId) {\n contextParts.push(`span=${this.context.spanId}`);\n }\n \n const contextStr = contextParts.length > 0 ? ` [${contextParts.join(', ')}]` : '';\n return `[${level.toUpperCase()}]${contextStr} ${message}`;\n }\n\n logWithContext(level: LogLevel, message: string, ...args: any[]): void {\n const levelName = LogLevel[level].toLowerCase();\n const formattedMessage = this.formatWithContext(levelName, message);\n \n switch (level) {\n case LogLevel.TRACE:\n if (this.shouldLog(LogLevel.TRACE)) {\n console.trace(formattedMessage, ...args);\n }\n break;\n case LogLevel.DEBUG:\n if (this.shouldLog(LogLevel.DEBUG)) {\n console.debug(formattedMessage, ...args);\n }\n break;\n case LogLevel.INFO:\n if (this.shouldLog(LogLevel.INFO)) {\n console.info(formattedMessage, ...args);\n }\n break;\n case LogLevel.WARN:\n if (this.shouldLog(LogLevel.WARN)) {\n console.warn(formattedMessage, ...args);\n }\n break;\n case LogLevel.ERROR:\n if (this.shouldLog(LogLevel.ERROR)) {\n console.error(formattedMessage, ...args);\n }\n break;\n case LogLevel.FATAL:\n if (this.shouldLog(LogLevel.FATAL)) {\n console.error(formattedMessage, ...args);\n }\n break;\n }\n }\n\n // Override base methods to include context\n trace(message: string, ...args: any[]): void {\n this.logWithContext(LogLevel.TRACE, message, ...args);\n }\n\n debug(message: string, ...args: any[]): void {\n this.logWithContext(LogLevel.DEBUG, message, ...args);\n }\n\n info(message: string, ...args: any[]): void {\n this.logWithContext(LogLevel.INFO, message, ...args);\n }\n\n warn(message: string, ...args: any[]): void {\n this.logWithContext(LogLevel.WARN, message, ...args);\n }\n\n error(message: string, ...args: any[]): void {\n this.logWithContext(LogLevel.ERROR, message, ...args);\n }\n\n fatal(message: string, ...args: any[]): void {\n this.logWithContext(LogLevel.FATAL, message, ...args);\n }\n}\n","import { Logger, LogLevel, ConsoleLogger, OtelConsoleLogger, OtelContext, getLogLevelFromEnv, createOtelContextFromPayload } from './logger';\n\n/**\n * Controller object provided to action handlers for pipeline management\n * @template T - The type of the payload being processed\n */\nexport type PipelineController<T = any> = {\n /** Continue to the next handler in the pipeline */\n next: () => void;\n /** Abort the pipeline execution with an optional reason */\n abort: (reason?: string) => void;\n /** Modify the payload that will be passed to subsequent handlers */\n modifyPayload: (modifier: (payload: T) => T) => void;\n};\n\n/**\n * Action handler function that processes actions in the pipeline\n * @template T - The type of the payload\n * @param payload - The data passed to the handler\n * @param controller - Pipeline controller for flow management\n * @returns void or Promise<void> for async handlers\n */\nexport type ActionHandler<T = any> = (\n payload: T,\n controller: PipelineController<T>\n) => void | Promise<void>;\n\n/**\n * Configuration options for action handlers\n */\nexport type HandlerConfig = {\n /** Priority level (higher numbers execute first). Default: 0 */\n priority?: number;\n /** Unique identifier for the handler. Auto-generated if not provided */\n id?: string;\n /** Whether to wait for async handlers to complete. Default: false */\n blocking?: boolean;\n};\n\n/**\n * Base interface for defining action payload mappings\n * @example\n * ```typescript\n * interface MyActions extends ActionPayloadMap {\n * increment: void;\n * setCount: number;\n * updateUser: { id: string; name: string };\n * }\n * ```\n */\nexport interface ActionPayloadMap {\n // Extensible structure for action definitions\n // 'actionName': PayloadType;\n}\n\n/**\n * Configuration options for ActionRegister\n */\nexport interface ActionRegisterConfig {\n /** Custom logger implementation. Defaults to ConsoleLogger */\n logger?: Logger;\n /** Log level for the logger. Defaults to ERROR if not provided */\n logLevel?: LogLevel;\n /** OpenTelemetry context for tracing */\n otelContext?: OtelContext;\n /** Whether to use OTEL-aware logger. Defaults to false */\n useOtel?: boolean;\n}\n\n/**\n * Core action pipeline management system\n * @template T - Action payload map defining available actions and their payload types\n * @example\n * ```typescript\n * interface AppActions extends ActionPayloadMap {\n * increment: void;\n * setCount: number;\n * }\n * \n * const actionRegister = new ActionRegister<AppActions>();\n * \n * // Register handlers\n * actionRegister.register('increment', () => console.log('Incremented'));\n * actionRegister.register('setCount', (count) => console.log(`Count: ${count}`));\n * \n * // Dispatch actions\n * await actionRegister.dispatch('increment');\n * await actionRegister.dispatch('setCount', 42);\n * ```\n */\nexport class ActionRegister<T extends ActionPayloadMap = ActionPayloadMap> {\n private pipelines = new Map<keyof T, Map<string, {\n handler: ActionHandler<any>;\n config: HandlerConfig;\n }>>();\n \n private atomSetters = new Map<string, Function>();\n private handlerCounter = 0;\n public readonly logger: Logger;\n\n constructor(config?: ActionRegisterConfig) {\n // 환경변수에서 로그 레벨 가져오기\n const envLogLevel = getLogLevelFromEnv();\n \n // 설정에서 로그 레벨 가져오기 (환경변수보다 우선)\n const configLogLevel = config?.logLevel ?? envLogLevel;\n \n // 커스텀 로거가 있으면 사용, OTEL 사용 설정이 있으면 OTEL 로거 사용, 없으면 기본 콘솔 로거 사용\n if (config?.logger) {\n this.logger = config.logger;\n } else if (config?.useOtel) {\n this.logger = new OtelConsoleLogger(configLogLevel);\n } else {\n this.logger = new ConsoleLogger(configLogLevel);\n }\n \n // OTEL 컨텍스트 설정\n if (config?.otelContext && this.logger instanceof OtelConsoleLogger) {\n this.logger.setContext(config.otelContext);\n }\n \n this.logger.debug('ActionRegister initialized', { \n logLevel: configLogLevel,\n useOtel: config?.useOtel ?? false,\n hasOtelContext: !!config?.otelContext\n });\n }\n\n /**\n * Register a handler for an action in the pipeline\n * @param action - The action name to handle\n * @param handler - The handler function to execute\n * @param config - Optional configuration for the handler\n * @returns Unregister function to remove the handler\n * @example\n * ```typescript\n * const unregister = actionRegister.register('increment', () => {\n * console.log('Incremented!');\n * }, { priority: 10 });\n * \n * // Later, remove the handler\n * unregister();\n * ```\n */\n register<K extends keyof T>(\n action: K,\n handler: ActionHandler<T[K]>,\n config: HandlerConfig = {}\n ): () => void {\n if (!this.pipelines.has(action)) {\n this.pipelines.set(action, new Map());\n this.logger.debug(`Created new pipeline for action: ${String(action)}`);\n }\n \n const pipeline = this.pipelines.get(action)!;\n const handlerId = config.id || `handler_${++this.handlerCounter}`;\n \n // 중복 등록 방지\n if (pipeline.has(handlerId)) {\n this.logger.warn(`Handler with id ${handlerId} already exists for action: ${String(action)}`);\n return () => {};\n }\n \n pipeline.set(handlerId, { handler, config });\n this.logger.debug(`Registered handler for action: ${String(action)}`, { \n handlerId, \n priority: config.priority ?? 0,\n blocking: config.blocking ?? false \n });\n \n // 우선순위로 정렬\n this.sortPipeline(action);\n \n // unregister 함수 반환\n return () => {\n pipeline.delete(handlerId);\n this.logger.debug(`Unregistered handler: ${handlerId} for action: ${String(action)}`);\n };\n }\n\n // Atom setter 등록\n registerAtomSetter(name: string, setter: Function) {\n this.atomSetters.set(name, setter);\n this.logger.debug(`Registered atom setter: ${name}`);\n }\n\n /**\n * Dispatch an action through the pipeline (for actions without payload)\n * @param action - The action to dispatch\n * @returns Promise that resolves when all handlers complete\n */\n async dispatch<K extends keyof T>(\n action: T[K] extends void ? K : never\n ): Promise<void>;\n /**\n * Dispatch an action through the pipeline (for actions with payload)\n * @param action - The action to dispatch\n * @param payload - The payload data to pass to handlers\n * @returns Promise that resolves when all handlers complete\n */\n async dispatch<K extends keyof T>(\n action: K,\n payload: T[K]\n ): Promise<void>;\n /**\n * Internal dispatch implementation\n * @internal\n */\n async dispatch<K extends keyof T>(\n action: K,\n payload?: T[K]\n ): Promise<void> {\n const pipeline = this.pipelines.get(action);\n \n // OTEL 컨텍스트 자동 감지 및 설정\n if (this.logger instanceof OtelConsoleLogger && payload) {\n const otelContext = createOtelContextFromPayload(payload);\n if (otelContext.traceId || otelContext.sessionId) {\n this.logger.setContext(otelContext);\n }\n }\n \n this.logger.debug(`Dispatching action: ${String(action)}`, { payload });\n \n if (!pipeline || pipeline.size === 0) {\n this.logger.warn(`No handlers registered for action: ${String(action)}`);\n return;\n }\n \n let modifiedPayload = payload as T[K];\n const handlers = Array.from(pipeline.values());\n let shouldContinue = true;\n \n this.logger.trace(`Executing pipeline for action: ${String(action)}`, { \n handlerCount: handlers.length \n });\n \n for (const { handler, config } of handlers) {\n if (!shouldContinue) break;\n \n const controller: PipelineController<T[K]> = {\n next: () => { shouldContinue = true; },\n abort: (reason) => {\n shouldContinue = false;\n this.logger.warn(`Pipeline aborted: ${reason}`);\n },\n modifyPayload: (modifier) => {\n modifiedPayload = modifier(modifiedPayload);\n this.logger.trace(`Payload modified for action: ${String(action)}`);\n }\n };\n \n try {\n if (config.blocking) {\n await handler(modifiedPayload, controller);\n } else {\n handler(modifiedPayload, controller);\n }\n } catch (error) {\n this.logger.error(`Error in pipeline handler for action: ${String(action)}`, error);\n if (config.blocking) throw error;\n }\n }\n \n this.logger.debug(`Completed dispatching action: ${String(action)}`);\n }\n\n private sortPipeline<K extends keyof T>(action: K) {\n const pipeline = this.pipelines.get(action);\n if (!pipeline) return;\n \n const sorted = Array.from(pipeline.entries())\n .sort(([, a], [, b]) => {\n const priorityA = a.config.priority ?? 0;\n const priorityB = b.config.priority ?? 0;\n return priorityB - priorityA; // 높은 우선순위가 먼저\n });\n \n pipeline.clear();\n sorted.forEach(([id, data]) => pipeline.set(id, data));\n \n this.logger.trace(`Sorted pipeline for action: ${String(action)}`, {\n handlerCount: sorted.length,\n priorities: sorted.map(([, data]) => data.config.priority ?? 0)\n });\n }\n}","// 기본 액션 타입 정의\nexport interface BaseActionPayloadMap {\n // 기본 액션들은 여기에 정의\n}\n\n// 액션 타입 추출 헬퍼\nexport type ActionType<T extends Record<string, any>> = keyof T;\nexport type ActionPayload<\n T extends Record<string, any>,\n K extends keyof T\n> = T[K];\n\n// 액션 핸들러 타입\nexport type ActionHandlerMap<T extends Record<string, any>> = {\n [K in keyof T]?: (payload: T[K]) => void | Promise<void>;\n};\n\n// 액션 생성 헬퍼\nexport function createAction<T extends Record<string, any>, K extends keyof T>(\n type: K,\n payload: T[K]\n): { type: K; payload: T[K] } {\n return { type, payload };\n}\n\n// 타입 가드\nexport function isAction<T extends Record<string, any>, K extends keyof T>(\n action: any,\n type: K\n): action is { type: K; payload: T[K] } {\n return action?.type === type;\n}"],"x_google_ignoreList":[0,1,2,3],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAA,SAASA,UAAQ,GAAG;AAClB;AAEA,SAAO,OAAO,UAAUA,YAAU,cAAc,OAAO,UAAU,YAAY,OAAO,OAAO,WAAW,SAAUC,KAAG;AACjH,UAAO,OAAOA;EACf,IAAG,SAAUA,KAAG;AACf,UAAOA,OAAK,cAAc,OAAO,UAAUA,IAAE,gBAAgB,UAAUA,QAAM,OAAO,YAAY,WAAW,OAAOA;EACnH,GAAE,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO,SAASD,UAAQ,EAAE;CAC5F;CACD,OAAO,UAAUA,WAAS,OAAO,QAAQ,aAAa,MAAM,OAAO,QAAQ,aAAa,OAAO;;;;;;CCT/F,IAAIE,6BAAiC;CACrC,SAASC,cAAY,GAAG,GAAG;AACzB,MAAI,YAAYD,UAAQ,EAAE,IAAI,CAAC,EAAG,QAAO;EACzC,IAAI,IAAI,EAAE,OAAO;AACjB,MAAI,KAAK,MAAM,GAAG;GAChB,IAAI,IAAI,EAAE,KAAK,GAAG,KAAK,UAAU;AACjC,OAAI,YA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,QAAQ,iBAAiB,WAAW;SAE1C,QAAQ,iBAAiB,WAAW;GAEvC,SAAQ,OAAO;IACd,KAAK,OAAO,MAAM,CAAC,sCAAsC,EAAE,OAAO,OAAO,EAAE,EAAE,MAAM;AACnF,QAAI,OAAO,SAAU,OAAM;GAC5B;EACF;EAED,KAAK,OAAO,MAAM,CAAC,8BAA8B,EAAE,OAAO,OAAO,EAAE,CAAC;CACrE;CAED,AAAQ,aAAgCN,QAAW;EACjD,MAAM,WAAW,KAAK,UAAU,IAAI,OAAO;AAC3C,MAAI,CAAC,SAAU;EAEf,MAAM,SAAS,MAAM,KAAK,SAAS,SAAS,CAAC,CAC1C,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,KAAK;GACtB,MAAM,YAAY,EAAE,OAAO,YAAY;GACvC,MAAM,YAAY,EAAE,OAAO,YAAY;AACvC,UAAO,YAAY;EACpB,EAAC;EAEJ,SAAS,OAAO;EAChB,OAAO,QAAQ,CAAC,CAAC,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,CAAC;EAEtD,KAAK,OAAO,MAAM,CAAC,4BAA4B,EAAE,OAAO,OAAO,EAAE,EAAE;GACjE,cAAc,OAAO;GACrB,YAAY,OAAO,IAAI,CAAC,GAAG,KAAK,KAAK,KAAK,OAAO,YAAY,EAAE;EAChE,EAAC;CACH;AACF;;;;AC5QD,SAAgB,aACdO,MACAC,SAC4B;AAC5B,QAAO;EAAE;EAAM;CAAS;AACzB;AAGD,SAAgB,SACdC,QACAF,MACsC;AACtC,QAAO,QAAQ,SAAS;AACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@context-action/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Type-safe action pipeline management library for JavaScript/TypeScript",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|
|
63
63
|
"build:watch": "tsdown --watch",
|
|
64
|
-
"test": "jest",
|
|
64
|
+
"test": "jest --passWithNoTests",
|
|
65
65
|
"test:watch": "jest --watch",
|
|
66
66
|
"lint": "eslint src --ext .ts",
|
|
67
67
|
"lint:fix": "eslint src --ext .ts --fix",
|