@flink-app/flink 0.14.3 → 2.0.0-alpha.100
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/CHANGELOG.md +1051 -0
- package/SCHEMA_EXTRACTION_ANALYSIS.md +494 -0
- package/SIMPLE_AST_FEASIBILITY.md +570 -0
- package/bin/flink.ts +13 -2
- package/cli/build.ts +24 -44
- package/cli/clean.ts +13 -25
- package/cli/cli-utils.ts +190 -17
- package/cli/dev.ts +252 -0
- package/cli/loadEnvFiles.ts +116 -0
- package/cli/run.ts +45 -62
- package/dist/bin/flink.js +61 -2
- package/dist/cli/build.js +20 -25
- package/dist/cli/clean.js +12 -10
- package/dist/cli/cli-utils.d.ts +34 -3
- package/dist/cli/cli-utils.js +193 -12
- package/dist/cli/dev.d.ts +2 -0
- package/dist/cli/dev.js +279 -0
- package/dist/cli/loadEnvFiles.d.ts +30 -0
- package/dist/cli/loadEnvFiles.js +113 -0
- package/dist/cli/run.js +47 -46
- package/dist/src/DependencyTracker.d.ts +44 -0
- package/dist/src/DependencyTracker.js +239 -0
- package/dist/src/FlinkApp.d.ts +163 -10
- package/dist/src/FlinkApp.js +847 -184
- package/dist/src/FlinkContext.d.ts +41 -0
- package/dist/src/FlinkErrors.d.ts +19 -6
- package/dist/src/FlinkErrors.js +36 -42
- package/dist/src/FlinkHttpHandler.d.ts +219 -26
- package/dist/src/FlinkHttpHandler.js +37 -1
- package/dist/src/FlinkJob.d.ts +10 -0
- package/dist/src/FlinkLog.d.ts +82 -18
- package/dist/src/FlinkLog.js +165 -13
- package/dist/src/FlinkLogFactory.d.ts +288 -0
- package/dist/src/FlinkLogFactory.js +619 -0
- package/dist/src/FlinkRepo.d.ts +10 -2
- package/dist/src/FlinkRepo.js +11 -1
- package/dist/src/FlinkRequestContext.d.ts +63 -0
- package/dist/src/FlinkRequestContext.js +74 -0
- package/dist/src/FlinkResponse.d.ts +6 -0
- package/dist/src/FlinkService.d.ts +38 -0
- package/dist/src/FlinkService.js +46 -0
- package/dist/src/LeaderElection.d.ts +45 -0
- package/dist/src/LeaderElection.js +269 -0
- package/dist/src/SchemaCache.d.ts +84 -0
- package/dist/src/SchemaCache.js +289 -0
- package/dist/src/TypeScriptCompiler.d.ts +161 -51
- package/dist/src/TypeScriptCompiler.js +1253 -617
- package/dist/src/TypeScriptUtils.js +4 -0
- package/dist/src/ai/AgentRunner.d.ts +39 -0
- package/dist/src/ai/AgentRunner.js +760 -0
- package/dist/src/ai/ConversationAgent.d.ts +279 -0
- package/dist/src/ai/ConversationAgent.js +404 -0
- package/dist/src/ai/ConversationFlinkAgent.d.ts +278 -0
- package/dist/src/ai/ConversationFlinkAgent.js +404 -0
- package/dist/src/ai/FlinkAgent.d.ts +690 -0
- package/dist/src/ai/FlinkAgent.js +729 -0
- package/dist/src/ai/FlinkTool.d.ts +135 -0
- package/dist/src/ai/FlinkTool.js +2 -0
- package/dist/src/ai/InMemoryConversationAgent.d.ts +121 -0
- package/dist/src/ai/InMemoryConversationAgent.js +209 -0
- package/dist/src/ai/LLMAdapter.d.ts +148 -0
- package/dist/src/ai/LLMAdapter.js +2 -0
- package/dist/src/ai/PersistentFlinkAgent.d.ts +278 -0
- package/dist/src/ai/PersistentFlinkAgent.js +403 -0
- package/dist/src/ai/SubAgentExecutor.d.ts +38 -0
- package/dist/src/ai/SubAgentExecutor.js +223 -0
- package/dist/src/ai/ToolExecutor.d.ts +64 -0
- package/dist/src/ai/ToolExecutor.js +497 -0
- package/dist/src/ai/agentInstructions.d.ts +68 -0
- package/dist/src/ai/agentInstructions.js +286 -0
- package/dist/src/ai/index.d.ts +8 -0
- package/dist/src/ai/index.js +26 -0
- package/dist/src/ai/instructionFileLoader.d.ts +44 -0
- package/dist/src/ai/instructionFileLoader.js +179 -0
- package/dist/src/auth/FlinkAuthPlugin.d.ts +1 -1
- package/dist/src/handlers/StreamWriterFactory.d.ts +20 -0
- package/dist/src/handlers/StreamWriterFactory.js +83 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +17 -0
- package/dist/src/loadPluginSchemas.d.ts +45 -0
- package/dist/src/loadPluginSchemas.js +143 -0
- package/dist/src/schema-extraction/ComplexTypeDetection.d.ts +40 -0
- package/dist/src/schema-extraction/ComplexTypeDetection.js +75 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.d.ts +321 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.js +925 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.spec.d.ts +1 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.spec.js +233 -0
- package/dist/src/schema-extraction/TypeScriptTokenizer.d.ts +57 -0
- package/dist/src/schema-extraction/TypeScriptTokenizer.js +177 -0
- package/dist/src/schema-extraction/index.d.ts +2 -0
- package/dist/src/schema-extraction/index.js +20 -0
- package/dist/src/schema-extraction/types.d.ts +31 -0
- package/dist/src/schema-extraction/types.js +2 -0
- package/dist/src/utils/loadFlinkConfig.d.ts +53 -0
- package/dist/src/utils/loadFlinkConfig.js +77 -0
- package/dist/src/utils.d.ts +30 -0
- package/dist/src/utils.js +52 -0
- package/dist/src/workers/SchemaGeneratorWorker.d.ts +1 -0
- package/dist/src/workers/SchemaGeneratorWorker.js +49 -0
- package/dist/src/workers/WorkerPool.d.ts +60 -0
- package/dist/src/workers/WorkerPool.js +306 -0
- package/examples/logging-hierarchical-example.ts +125 -0
- package/package.json +29 -4
- package/readme.md +499 -0
- package/spec/AgentDescendantDetection.spec.ts +335 -0
- package/spec/AgentDuplicateDetection.spec.ts +112 -0
- package/spec/AgentObserver.spec.ts +266 -0
- package/spec/AgentRunner.spec.ts +1062 -0
- package/spec/AsyncLocalStorageContext.spec.ts +223 -0
- package/spec/ConversationHooks.spec.ts +257 -0
- package/spec/FlinkAgent.spec.ts +681 -0
- package/spec/FlinkApp.htmlResponse.spec.ts +260 -0
- package/spec/FlinkApp.onError.invocation.spec.ts +151 -0
- package/spec/FlinkApp.onError.spec.ts +1 -2
- package/spec/FlinkApp.query.spec.ts +107 -0
- package/spec/FlinkApp.routeOrdering.spec.ts +61 -0
- package/spec/FlinkApp.undefinedResponse.spec.ts +123 -0
- package/spec/FlinkApp.validationMode.spec.ts +155 -0
- package/spec/FlinkJob.spec.ts +171 -0
- package/spec/FlinkLogFactory.spec.ts +337 -0
- package/spec/FlinkRepo.spec.ts +1 -1
- package/spec/LeaderElection.spec.ts +174 -0
- package/spec/StreamingIntegration.spec.ts +139 -0
- package/spec/ToolExecutor.spec.ts +465 -0
- package/spec/TypeScriptCompiler.spec.ts +1 -1
- package/spec/TypeScriptSourceParser.spec.ts +1215 -0
- package/spec/TypeScriptTokenizer.spec.ts +366 -0
- package/spec/ai/ContextCompaction.spec.ts +405 -0
- package/spec/ai/ConversationAgent.spec.ts +520 -0
- package/spec/ai/InMemoryConversationAgent.spec.ts +144 -0
- package/spec/ai/agentInstructions.spec.ts +358 -0
- package/spec/fixtures/agent-instructions/TestAgent.ts +24 -0
- package/spec/fixtures/agent-instructions/simple.md +3 -0
- package/spec/fixtures/agent-instructions/template.md +18 -0
- package/spec/fixtures/agent-instructions/yaml-format.yaml +9 -0
- package/spec/mock-project/dist/.tsbuildinfo +1 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar.js +56 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar2.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema2.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema3.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema2.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile2.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler.js +53 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler2.js +55 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchCar.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOnboardingSession.js +75 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOrderWithComplexTypes.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchProductWithIntersection.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchUserWithUnion.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostCar.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogin.js +55 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogout.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PutCar.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/index.js +83 -0
- package/spec/mock-project/dist/spec/mock-project/src/repos/CarRepo.js +26 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/Car.js +2 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/DefaultExportSchema.js +2 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/FileWithTwoSchemas.js +2 -0
- package/spec/mock-project/dist/src/FlinkApp.js +1000 -0
- package/spec/mock-project/dist/src/FlinkContext.js +2 -0
- package/spec/mock-project/dist/src/FlinkErrors.js +143 -0
- package/spec/mock-project/dist/src/FlinkHttpHandler.js +47 -0
- package/spec/mock-project/dist/src/FlinkJob.js +2 -0
- package/spec/mock-project/dist/src/FlinkLog.js +119 -0
- package/spec/mock-project/dist/src/FlinkLogFactory.js +617 -0
- package/spec/mock-project/dist/src/FlinkPlugin.js +2 -0
- package/spec/mock-project/dist/src/FlinkRepo.js +224 -0
- package/spec/mock-project/dist/src/FlinkRequestContext.js +74 -0
- package/spec/mock-project/dist/src/FlinkResponse.js +2 -0
- package/spec/mock-project/dist/src/ai/AgentExecutor.js +279 -0
- package/spec/mock-project/dist/src/ai/AgentRunner.js +632 -0
- package/spec/mock-project/dist/src/ai/ConversationAgent.js +402 -0
- package/spec/mock-project/dist/src/ai/ConversationFlinkAgent.js +422 -0
- package/spec/mock-project/dist/src/ai/FlinkAgent.js +699 -0
- package/spec/mock-project/dist/src/ai/FlinkTool.js +2 -0
- package/spec/mock-project/dist/src/ai/InMemoryConversationAgent.js +209 -0
- package/spec/mock-project/dist/src/ai/LLMAdapter.js +2 -0
- package/spec/mock-project/dist/src/ai/SubAgentExecutor.js +223 -0
- package/spec/mock-project/dist/src/ai/ToolExecutor.js +412 -0
- package/spec/mock-project/dist/src/ai/agentInstructions.js +246 -0
- package/spec/mock-project/dist/src/auth/FlinkAuthPlugin.js +2 -0
- package/spec/mock-project/dist/src/auth/FlinkAuthUser.js +2 -0
- package/spec/mock-project/dist/src/handlers/GetCar.js +26 -52
- package/spec/mock-project/dist/src/handlers/GetCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCar2.js +32 -54
- package/spec/mock-project/dist/src/handlers/GetCar2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +26 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +28 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +29 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +26 -50
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +28 -50
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +27 -53
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +29 -53
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +16 -49
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +25 -50
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchCar.js +27 -53
- package/spec/mock-project/dist/src/handlers/PatchCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js +44 -70
- package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js +27 -53
- package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js +28 -54
- package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js +28 -54
- package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostCar.js +24 -50
- package/spec/mock-project/dist/src/handlers/PostCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostLogin.js +25 -51
- package/spec/mock-project/dist/src/handlers/PostLogin.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostLogout.js +24 -50
- package/spec/mock-project/dist/src/handlers/PostLogout.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PutCar.js +24 -50
- package/spec/mock-project/dist/src/handlers/PutCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/StreamWriterFactory.js +83 -0
- package/spec/mock-project/dist/src/index.js +52 -76
- package/spec/mock-project/dist/src/index.js.map +1 -0
- package/spec/mock-project/dist/src/mock-data-generator.js +9 -0
- package/spec/mock-project/dist/src/repos/CarRepo.js +12 -24
- package/spec/mock-project/dist/src/repos/CarRepo.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/Car.js +3 -1
- package/spec/mock-project/dist/src/schemas/Car.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +3 -1
- package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +3 -1
- package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js.map +1 -0
- package/spec/mock-project/dist/src/utils.js +290 -0
- package/spec/mock-project/tsconfig.json +6 -1
- package/spec/schema-generation-nested-objects.spec.ts +97 -0
- package/spec/testHelpers.ts +49 -0
- package/spec/utils.caseConversion.spec.ts +78 -0
- package/spec/utils.spec.ts +13 -13
- package/src/DependencyTracker.ts +166 -0
- package/src/FlinkApp.ts +919 -155
- package/src/FlinkContext.ts +43 -0
- package/src/FlinkErrors.ts +32 -12
- package/src/FlinkHttpHandler.ts +246 -28
- package/src/FlinkJob.ts +11 -0
- package/src/FlinkLog.ts +119 -12
- package/src/FlinkLogFactory.ts +699 -0
- package/src/FlinkRepo.ts +10 -3
- package/src/FlinkRequestContext.ts +95 -0
- package/src/FlinkResponse.ts +6 -0
- package/src/FlinkService.ts +49 -0
- package/src/LeaderElection.ts +203 -0
- package/src/SchemaCache.ts +232 -0
- package/src/TypeScriptCompiler.ts +1347 -610
- package/src/TypeScriptUtils.ts +5 -0
- package/src/ai/AgentRunner.ts +646 -0
- package/src/ai/ConversationAgent.ts +413 -0
- package/src/ai/FlinkAgent.ts +1069 -0
- package/src/ai/FlinkTool.ts +165 -0
- package/src/ai/InMemoryConversationAgent.ts +149 -0
- package/src/ai/LLMAdapter.ts +126 -0
- package/src/ai/ToolExecutor.ts +485 -0
- package/src/ai/agentInstructions.ts +245 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/instructionFileLoader.ts +156 -0
- package/src/auth/FlinkAuthPlugin.ts +2 -1
- package/src/handlers/StreamWriterFactory.ts +84 -0
- package/src/index.ts +14 -0
- package/src/loadPluginSchemas.ts +141 -0
- package/src/schema-extraction/TypeScriptSourceParser.ts +1058 -0
- package/src/schema-extraction/TypeScriptTokenizer.ts +205 -0
- package/src/schema-extraction/index.ts +2 -0
- package/src/schema-extraction/types.ts +34 -0
- package/src/utils/loadFlinkConfig.ts +89 -0
- package/src/utils.ts +52 -0
- package/tsconfig.json +6 -1
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.FlinkLogFactory = exports.ComponentLogger = void 0;
|
|
27
|
+
var node_color_log_1 = __importDefault(require("node-color-log"));
|
|
28
|
+
var LOG_LEVELS = {
|
|
29
|
+
trace: 0,
|
|
30
|
+
debug: 1,
|
|
31
|
+
info: 2,
|
|
32
|
+
warn: 3,
|
|
33
|
+
error: 4,
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Component-specific logger with independent log level control
|
|
37
|
+
*/
|
|
38
|
+
var ComponentLogger = /** @class */ (function () {
|
|
39
|
+
function ComponentLogger(componentName) {
|
|
40
|
+
this.componentLevel = null;
|
|
41
|
+
this.componentName = componentName;
|
|
42
|
+
this.namedLogger = node_color_log_1.default.createNamedLogger(componentName);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set log level for this specific component.
|
|
46
|
+
* Overrides the global log level.
|
|
47
|
+
*/
|
|
48
|
+
ComponentLogger.prototype.setLevel = function (level) {
|
|
49
|
+
this.componentLevel = level;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Clear component-specific level and fall back to global level
|
|
53
|
+
*/
|
|
54
|
+
ComponentLogger.prototype.clearLevel = function () {
|
|
55
|
+
this.componentLevel = null;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Check if a message should be logged based on component and global levels
|
|
59
|
+
*/
|
|
60
|
+
ComponentLogger.prototype.shouldLog = function (messageLevel) {
|
|
61
|
+
var _a;
|
|
62
|
+
var effectiveLevel = (_a = this.componentLevel) !== null && _a !== void 0 ? _a : FlinkLogFactory.getGlobalLevel();
|
|
63
|
+
return LOG_LEVELS[messageLevel] >= LOG_LEVELS[effectiveLevel];
|
|
64
|
+
};
|
|
65
|
+
ComponentLogger.prototype.trace = function () {
|
|
66
|
+
var args = [];
|
|
67
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
68
|
+
args[_i] = arguments[_i];
|
|
69
|
+
}
|
|
70
|
+
if (this.shouldLog("trace")) {
|
|
71
|
+
// node-color-log doesn't support trace, use console.log for stdout
|
|
72
|
+
if (FlinkLogFactory.getShowTimestamps()) {
|
|
73
|
+
var timestamp = new Date().toISOString();
|
|
74
|
+
console.log.apply(console, __spreadArray(["".concat(timestamp, " [").concat(this.componentName, "] [TRACE]")], args, false));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log.apply(console, __spreadArray(["[".concat(this.componentName, "] [TRACE]")], args, false));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
ComponentLogger.prototype.debug = function () {
|
|
82
|
+
var _a;
|
|
83
|
+
var args = [];
|
|
84
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
85
|
+
args[_i] = arguments[_i];
|
|
86
|
+
}
|
|
87
|
+
if (this.shouldLog("debug")) {
|
|
88
|
+
(_a = this.namedLogger).debug.apply(_a, args);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
ComponentLogger.prototype.info = function () {
|
|
92
|
+
var _a;
|
|
93
|
+
var args = [];
|
|
94
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
95
|
+
args[_i] = arguments[_i];
|
|
96
|
+
}
|
|
97
|
+
if (this.shouldLog("info")) {
|
|
98
|
+
(_a = this.namedLogger).info.apply(_a, args);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
ComponentLogger.prototype.warn = function () {
|
|
102
|
+
var args = [];
|
|
103
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
104
|
+
args[_i] = arguments[_i];
|
|
105
|
+
}
|
|
106
|
+
if (this.shouldLog("warn")) {
|
|
107
|
+
// Use console.warn to write to stderr (Unix/POSIX best practice)
|
|
108
|
+
if (FlinkLogFactory.getShowTimestamps()) {
|
|
109
|
+
var timestamp = new Date().toISOString();
|
|
110
|
+
console.warn.apply(console, __spreadArray(["".concat(timestamp, " [").concat(this.componentName, "] [WARN]")], args, false));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.warn.apply(console, __spreadArray(["[".concat(this.componentName, "] [WARN]")], args, false));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
ComponentLogger.prototype.error = function () {
|
|
118
|
+
var args = [];
|
|
119
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
120
|
+
args[_i] = arguments[_i];
|
|
121
|
+
}
|
|
122
|
+
if (this.shouldLog("error")) {
|
|
123
|
+
// Use console.error to write to stderr (Unix/POSIX best practice)
|
|
124
|
+
if (FlinkLogFactory.getShowTimestamps()) {
|
|
125
|
+
var timestamp = new Date().toISOString();
|
|
126
|
+
console.error.apply(console, __spreadArray(["".concat(timestamp, " [").concat(this.componentName, "] [ERROR]")], args, false));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.error.apply(console, __spreadArray(["[".concat(this.componentName, "] [ERROR]")], args, false));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
ComponentLogger.prototype.json = function () {
|
|
134
|
+
var args = [];
|
|
135
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
136
|
+
args[_i] = arguments[_i];
|
|
137
|
+
}
|
|
138
|
+
if (this.shouldLog("debug")) {
|
|
139
|
+
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
|
|
140
|
+
var o = args_1[_a];
|
|
141
|
+
console.log(JSON.stringify(o, null, 2));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
ComponentLogger.prototype.bgColorLog = function (color) {
|
|
146
|
+
var _a;
|
|
147
|
+
var args = [];
|
|
148
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
149
|
+
args[_i - 1] = arguments[_i];
|
|
150
|
+
}
|
|
151
|
+
if (this.shouldLog("debug")) {
|
|
152
|
+
(_a = this.namedLogger).bgColorLog.apply(_a, __spreadArray([color], args, false));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
ComponentLogger.prototype.fontColorLog = function (color) {
|
|
156
|
+
var _a;
|
|
157
|
+
var args = [];
|
|
158
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
159
|
+
args[_i - 1] = arguments[_i];
|
|
160
|
+
}
|
|
161
|
+
if (this.shouldLog("info")) {
|
|
162
|
+
(_a = this.namedLogger).fontColorLog.apply(_a, __spreadArray([color], args, false));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return ComponentLogger;
|
|
166
|
+
}());
|
|
167
|
+
exports.ComponentLogger = ComponentLogger;
|
|
168
|
+
/**
|
|
169
|
+
* Factory for creating component-specific loggers with hierarchical level control
|
|
170
|
+
*/
|
|
171
|
+
var FlinkLogFactory = /** @class */ (function () {
|
|
172
|
+
function FlinkLogFactory() {
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Set the global log level (affects all loggers without component-specific levels)
|
|
176
|
+
*/
|
|
177
|
+
FlinkLogFactory.setGlobalLevel = function (level) {
|
|
178
|
+
FlinkLogFactory.globalLevel = level;
|
|
179
|
+
// node-color-log doesn't support trace, so use debug as the effective level
|
|
180
|
+
var effectiveLevel = level === "trace" ? "debug" : level;
|
|
181
|
+
node_color_log_1.default.setLevel(effectiveLevel);
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Get the current global log level
|
|
185
|
+
*/
|
|
186
|
+
FlinkLogFactory.getGlobalLevel = function () {
|
|
187
|
+
return FlinkLogFactory.globalLevel;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Get all registered loggers (useful for debugging)
|
|
191
|
+
*/
|
|
192
|
+
FlinkLogFactory.getLoggers = function () {
|
|
193
|
+
return FlinkLogFactory.loggers;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Enable or disable timestamps in log messages
|
|
197
|
+
*/
|
|
198
|
+
FlinkLogFactory.setShowTimestamps = function (show) {
|
|
199
|
+
FlinkLogFactory.showTimestamps = show;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Check if timestamps are enabled
|
|
203
|
+
*/
|
|
204
|
+
FlinkLogFactory.getShowTimestamps = function () {
|
|
205
|
+
return FlinkLogFactory.showTimestamps;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Clear all component-specific log levels (fall back to global)
|
|
209
|
+
*/
|
|
210
|
+
FlinkLogFactory.resetComponentLevels = function () {
|
|
211
|
+
FlinkLogFactory.componentConfigs = {};
|
|
212
|
+
for (var _i = 0, _a = Array.from(FlinkLogFactory.loggers.values()); _i < _a.length; _i++) {
|
|
213
|
+
var logger = _a[_i];
|
|
214
|
+
logger.clearLevel();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Clear all hierarchical prefix configurations
|
|
219
|
+
*/
|
|
220
|
+
FlinkLogFactory.resetHierarchicalLevels = function () {
|
|
221
|
+
FlinkLogFactory.hierarchicalConfigs = [];
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Clear all wildcard pattern configurations
|
|
225
|
+
*/
|
|
226
|
+
FlinkLogFactory.resetWildcardLevels = function () {
|
|
227
|
+
FlinkLogFactory.wildcardConfigs = [];
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Set log level for a specific component by name (exact match)
|
|
231
|
+
*/
|
|
232
|
+
FlinkLogFactory.setComponentLevel = function (componentName, level) {
|
|
233
|
+
var normalized = FlinkLogFactory.normalize(componentName);
|
|
234
|
+
if (level === null) {
|
|
235
|
+
// Remove exact match configuration
|
|
236
|
+
delete FlinkLogFactory.componentConfigs[normalized];
|
|
237
|
+
var logger = FlinkLogFactory.loggers.get(normalized);
|
|
238
|
+
if (logger) {
|
|
239
|
+
logger.clearLevel();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// Set exact match configuration
|
|
244
|
+
FlinkLogFactory.componentConfigs[normalized] = level;
|
|
245
|
+
var logger = FlinkLogFactory.loggers.get(normalized);
|
|
246
|
+
if (logger) {
|
|
247
|
+
logger.setLevel(level);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Set hierarchical prefix-based log level (Java-style)
|
|
253
|
+
* @param prefix Logger name prefix (e.g., "flink.ai" matches all "flink.ai.*")
|
|
254
|
+
* @param level Log level to apply
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* FlinkLogFactory.setHierarchicalLevel("flink.ai", "debug");
|
|
258
|
+
* // Now all loggers starting with "flink.ai." will use debug level
|
|
259
|
+
* // This includes the exact match "flink.ai" AND all children "flink.ai.*"
|
|
260
|
+
*/
|
|
261
|
+
FlinkLogFactory.setHierarchicalLevel = function (prefix, level) {
|
|
262
|
+
var normalized = FlinkLogFactory.normalize(prefix);
|
|
263
|
+
// Ensure prefix ends with dot for consistent matching
|
|
264
|
+
var prefixWithDot = normalized.endsWith(".") ? normalized : normalized + ".";
|
|
265
|
+
var specificity = FlinkLogFactory.calculatePrefixSpecificity(normalized);
|
|
266
|
+
// Remove existing config for this prefix if it exists
|
|
267
|
+
FlinkLogFactory.hierarchicalConfigs = FlinkLogFactory.hierarchicalConfigs.filter(function (c) { return c.prefix !== prefixWithDot; });
|
|
268
|
+
// Add new config
|
|
269
|
+
FlinkLogFactory.hierarchicalConfigs.push({
|
|
270
|
+
prefix: prefixWithDot,
|
|
271
|
+
level: level,
|
|
272
|
+
specificity: specificity,
|
|
273
|
+
});
|
|
274
|
+
// Also set exact match for the prefix itself (without trailing dot)
|
|
275
|
+
// This ensures "flink.ai.openai" matches when using setHierarchicalLevel("flink.ai.openai", "debug")
|
|
276
|
+
FlinkLogFactory.componentConfigs[normalized] = level;
|
|
277
|
+
// Sort by specificity (most specific first) for efficient matching
|
|
278
|
+
FlinkLogFactory.hierarchicalConfigs.sort(function (a, b) { return b.specificity - a.specificity; });
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Set wildcard pattern-based log level (advanced)
|
|
282
|
+
* @param pattern Wildcard pattern (e.g., "flink.ai.*" or "flink.ai.**")
|
|
283
|
+
* @param level Log level to apply
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* FlinkLogFactory.setWildcardLevel("flink.ai.*", "debug");
|
|
287
|
+
* // Matches flink.ai.openai but NOT flink.ai.openai.v4
|
|
288
|
+
*
|
|
289
|
+
* FlinkLogFactory.setWildcardLevel("flink.ai.**", "trace");
|
|
290
|
+
* // Matches any depth under flink.ai.
|
|
291
|
+
*/
|
|
292
|
+
FlinkLogFactory.setWildcardLevel = function (pattern, level) {
|
|
293
|
+
var normalized = FlinkLogFactory.normalize(pattern);
|
|
294
|
+
var specificity = FlinkLogFactory.calculateWildcardSpecificity(normalized);
|
|
295
|
+
// Remove existing config for this pattern if it exists
|
|
296
|
+
FlinkLogFactory.wildcardConfigs = FlinkLogFactory.wildcardConfigs.filter(function (c) { return c.pattern !== normalized; });
|
|
297
|
+
// Add new config
|
|
298
|
+
FlinkLogFactory.wildcardConfigs.push({
|
|
299
|
+
pattern: normalized,
|
|
300
|
+
level: level,
|
|
301
|
+
specificity: specificity,
|
|
302
|
+
});
|
|
303
|
+
// Sort by specificity (most specific first) for efficient matching
|
|
304
|
+
FlinkLogFactory.wildcardConfigs.sort(function (a, b) { return b.specificity - a.specificity; });
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Get the effective log level for a component (resolved through hierarchy)
|
|
308
|
+
* @param componentName Component name to check
|
|
309
|
+
* @returns Resolved log level or null if only global level applies
|
|
310
|
+
*/
|
|
311
|
+
FlinkLogFactory.getEffectiveLevel = function (componentName) {
|
|
312
|
+
return FlinkLogFactory.resolveComponentLevel(componentName);
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Initialize logging from environment variables and/or configuration file
|
|
316
|
+
*
|
|
317
|
+
* Priority (highest to lowest):
|
|
318
|
+
* 1. Config file (flink.config.js)
|
|
319
|
+
* 2. Environment variable (LOG_LEVEL=debug)
|
|
320
|
+
*
|
|
321
|
+
* @param fileConfig Optional logging configuration from flink.config.js
|
|
322
|
+
*
|
|
323
|
+
* @example Environment Variable
|
|
324
|
+
* ```bash
|
|
325
|
+
* LOG_LEVEL=debug pnpm run dev
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @example Config File (flink.config.js)
|
|
329
|
+
* ```javascript
|
|
330
|
+
* module.exports = {
|
|
331
|
+
* logging: {
|
|
332
|
+
* global: "info",
|
|
333
|
+
* showTimestamps: true,
|
|
334
|
+
* components: {
|
|
335
|
+
* "flink.ai.openai": "trace", // exact match
|
|
336
|
+
* "flink.ai.*": "debug", // single-level wildcard
|
|
337
|
+
* "flink.database.**": "warn", // multi-level wildcard
|
|
338
|
+
* "flink.handlers.": "info" // prefix match
|
|
339
|
+
* }
|
|
340
|
+
* }
|
|
341
|
+
* };
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
FlinkLogFactory.configure = function (fileConfig) {
|
|
345
|
+
var _a;
|
|
346
|
+
if (FlinkLogFactory.initialized) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// 1. Parse environment variables (lowest priority)
|
|
350
|
+
var envConfig = FlinkLogFactory.parseEnvironment();
|
|
351
|
+
// 2. Parse file config components map (highest priority)
|
|
352
|
+
var fileComponentsParsed = { exact: {}, hierarchical: [], wildcards: [] };
|
|
353
|
+
if (fileConfig === null || fileConfig === void 0 ? void 0 : fileConfig.components) {
|
|
354
|
+
fileComponentsParsed = FlinkLogFactory.parseComponentsMap(fileConfig.components);
|
|
355
|
+
}
|
|
356
|
+
// 3. Merge configurations
|
|
357
|
+
var finalConfig = {
|
|
358
|
+
global: (fileConfig === null || fileConfig === void 0 ? void 0 : fileConfig.global) || envConfig.global || "info",
|
|
359
|
+
showTimestamps: (_a = fileConfig === null || fileConfig === void 0 ? void 0 : fileConfig.showTimestamps) !== null && _a !== void 0 ? _a : true, // default: true
|
|
360
|
+
exact: __assign({}, fileComponentsParsed.exact),
|
|
361
|
+
hierarchical: __spreadArray([], fileComponentsParsed.hierarchical, true),
|
|
362
|
+
wildcards: __spreadArray([], fileComponentsParsed.wildcards, true),
|
|
363
|
+
};
|
|
364
|
+
// 4. Apply global level
|
|
365
|
+
FlinkLogFactory.setGlobalLevel(finalConfig.global);
|
|
366
|
+
// 5. Apply timestamp setting
|
|
367
|
+
FlinkLogFactory.setShowTimestamps(finalConfig.showTimestamps);
|
|
368
|
+
// 6. Store exact component configs
|
|
369
|
+
FlinkLogFactory.componentConfigs = finalConfig.exact;
|
|
370
|
+
// 7. Store hierarchical configs (sorted by specificity)
|
|
371
|
+
FlinkLogFactory.hierarchicalConfigs = finalConfig.hierarchical.sort(function (a, b) { return b.specificity - a.specificity; });
|
|
372
|
+
// 8. Store wildcard configs (sorted by specificity)
|
|
373
|
+
FlinkLogFactory.wildcardConfigs = finalConfig.wildcards.sort(function (a, b) { return b.specificity - a.specificity; });
|
|
374
|
+
FlinkLogFactory.initialized = true;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Parse logging configuration from environment variables
|
|
378
|
+
* Supports only LOG_LEVEL for global level setting
|
|
379
|
+
*/
|
|
380
|
+
FlinkLogFactory.parseEnvironment = function () {
|
|
381
|
+
var config = {};
|
|
382
|
+
if (process.env.LOG_LEVEL) {
|
|
383
|
+
var level = process.env.LOG_LEVEL.toLowerCase();
|
|
384
|
+
if (FlinkLogFactory.isValidLogLevel(level)) {
|
|
385
|
+
config.global = level;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return config;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Normalize logger name to lowercase (Java-style convention)
|
|
392
|
+
* @param name Logger name or pattern
|
|
393
|
+
* @returns Normalized lowercase name
|
|
394
|
+
*/
|
|
395
|
+
FlinkLogFactory.normalize = function (name) {
|
|
396
|
+
return name.toLowerCase();
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Determine if a name should be treated as a hierarchical prefix
|
|
400
|
+
* @param name Normalized logger name
|
|
401
|
+
* @returns True if it should be treated as a prefix
|
|
402
|
+
*/
|
|
403
|
+
FlinkLogFactory.shouldTreatAsPrefix = function (name) {
|
|
404
|
+
// Default: if name contains dots, treat as hierarchical prefix
|
|
405
|
+
// This covers the common case where "flink.ai" should match "flink.ai.*"
|
|
406
|
+
return name.includes(".");
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* Calculate specificity for prefix matching
|
|
410
|
+
* More specific prefixes (more segments) have higher specificity
|
|
411
|
+
* @param prefix Prefix string (may or may not end with dot)
|
|
412
|
+
* @returns Specificity score (number of segments)
|
|
413
|
+
*/
|
|
414
|
+
FlinkLogFactory.calculatePrefixSpecificity = function (prefix) {
|
|
415
|
+
// Remove trailing dot if present
|
|
416
|
+
var normalized = prefix.endsWith(".") ? prefix.slice(0, -1) : prefix;
|
|
417
|
+
// Count dot-separated segments
|
|
418
|
+
return normalized.split(".").filter(function (s) { return s.length > 0; }).length;
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Calculate specificity for wildcard patterns
|
|
422
|
+
* More specific patterns (more non-wildcard segments) have higher specificity
|
|
423
|
+
* For same segment count, * (single-level) is more specific than ** (multi-level)
|
|
424
|
+
* @param pattern Wildcard pattern
|
|
425
|
+
* @returns Specificity score (base + decimal for wildcard type)
|
|
426
|
+
*/
|
|
427
|
+
FlinkLogFactory.calculateWildcardSpecificity = function (pattern) {
|
|
428
|
+
var segments = pattern.split(".");
|
|
429
|
+
var nonWildcardCount = segments.filter(function (seg) { return seg !== "*" && seg !== "**" && seg.length > 0; }).length;
|
|
430
|
+
// Base specificity: number of non-wildcard segments
|
|
431
|
+
var specificity = nonWildcardCount * 10;
|
|
432
|
+
// Add fractional specificity based on wildcard type
|
|
433
|
+
// * (single-level) = more specific than ** (multi-level)
|
|
434
|
+
if (pattern.includes("*")) {
|
|
435
|
+
if (pattern.includes("**")) {
|
|
436
|
+
specificity += 1; // ** is less specific
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
specificity += 5; // * is more specific
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return specificity;
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* Resolve component log level through hierarchical matching
|
|
446
|
+
* Order of precedence (highest to lowest):
|
|
447
|
+
* 1. Exact match
|
|
448
|
+
* 2. Most specific prefix match
|
|
449
|
+
* 3. Less specific prefix match
|
|
450
|
+
* 4. Wildcard pattern match
|
|
451
|
+
* 5. null (falls back to global level)
|
|
452
|
+
*
|
|
453
|
+
* @param componentName Component name to resolve
|
|
454
|
+
* @returns Resolved log level or null
|
|
455
|
+
*/
|
|
456
|
+
FlinkLogFactory.resolveComponentLevel = function (componentName) {
|
|
457
|
+
var normalized = FlinkLogFactory.normalize(componentName);
|
|
458
|
+
// 1. Try exact match first (O(1) - fastest, highest priority)
|
|
459
|
+
if (FlinkLogFactory.componentConfigs[normalized]) {
|
|
460
|
+
return FlinkLogFactory.componentConfigs[normalized];
|
|
461
|
+
}
|
|
462
|
+
// 2. Try hierarchical prefix matches (O(n) where n = number of prefixes)
|
|
463
|
+
// Already sorted by specificity (most specific first)
|
|
464
|
+
for (var _i = 0, _a = FlinkLogFactory.hierarchicalConfigs; _i < _a.length; _i++) {
|
|
465
|
+
var config = _a[_i];
|
|
466
|
+
if (normalized.startsWith(config.prefix)) {
|
|
467
|
+
return config.level;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// 3. Try wildcard patterns (O(n) where n = number of patterns)
|
|
471
|
+
// Already sorted by specificity (most specific first)
|
|
472
|
+
for (var _b = 0, _c = FlinkLogFactory.wildcardConfigs; _b < _c.length; _b++) {
|
|
473
|
+
var config = _c[_b];
|
|
474
|
+
if (FlinkLogFactory.matchWildcard(normalized, config.pattern)) {
|
|
475
|
+
return config.level;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
// 4. No match - fall back to global level
|
|
479
|
+
return null;
|
|
480
|
+
};
|
|
481
|
+
/**
|
|
482
|
+
* Simple wildcard matching for logger patterns
|
|
483
|
+
* Supports:
|
|
484
|
+
* - * matches single segment (flink.ai.* matches flink.ai.openai)
|
|
485
|
+
* - ** matches any depth (flink.ai.** matches flink.ai.openai.v4)
|
|
486
|
+
* - Partial segment match (flink.ai.open* matches flink.ai.openai)
|
|
487
|
+
*
|
|
488
|
+
* @param name Logger name to match
|
|
489
|
+
* @param pattern Wildcard pattern
|
|
490
|
+
* @returns True if pattern matches
|
|
491
|
+
*/
|
|
492
|
+
FlinkLogFactory.matchWildcard = function (name, pattern) {
|
|
493
|
+
// Special handling for ** (multi-level wildcard)
|
|
494
|
+
// Need to process dots BEFORE replacing **
|
|
495
|
+
// Step 1: Escape dots first (before any other processing)
|
|
496
|
+
var regexPattern = pattern.replace(/\./g, "\\.");
|
|
497
|
+
// Step 2: Replace ** with placeholder (matches anything including dots)
|
|
498
|
+
regexPattern = regexPattern.replace(/\*\*/g, "___DOUBLE_STAR___");
|
|
499
|
+
// Step 3: Replace single * with single-segment match (non-dot chars)
|
|
500
|
+
regexPattern = regexPattern.replace(/\*/g, "[^\\.]+");
|
|
501
|
+
// Step 4: Replace ** placeholder with multi-segment match
|
|
502
|
+
regexPattern = regexPattern.replace(/___DOUBLE_STAR___/g, ".*");
|
|
503
|
+
var regex = new RegExp("^".concat(regexPattern, "$"));
|
|
504
|
+
return regex.test(name);
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* Parse components map and classify entries into exact, prefix, or wildcard matches
|
|
508
|
+
* @param components Components map from config
|
|
509
|
+
* @returns Classified configuration
|
|
510
|
+
*/
|
|
511
|
+
FlinkLogFactory.parseComponentsMap = function (components) {
|
|
512
|
+
var exact = {};
|
|
513
|
+
var hierarchical = [];
|
|
514
|
+
var wildcards = [];
|
|
515
|
+
for (var _i = 0, _a = Object.entries(components); _i < _a.length; _i++) {
|
|
516
|
+
var _b = _a[_i], key = _b[0], level = _b[1];
|
|
517
|
+
var normalized = FlinkLogFactory.normalize(key);
|
|
518
|
+
if (normalized.includes("*")) {
|
|
519
|
+
// Wildcard pattern (e.g., "flink.ai.*" or "flink.ai.**")
|
|
520
|
+
wildcards.push({
|
|
521
|
+
pattern: normalized,
|
|
522
|
+
level: level,
|
|
523
|
+
specificity: FlinkLogFactory.calculateWildcardSpecificity(normalized),
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
else if (normalized.endsWith(".")) {
|
|
527
|
+
// Prefix match (e.g., "flink.ai.")
|
|
528
|
+
hierarchical.push({
|
|
529
|
+
prefix: normalized,
|
|
530
|
+
level: level,
|
|
531
|
+
specificity: FlinkLogFactory.calculatePrefixSpecificity(normalized),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
else if (normalized.includes(".")) {
|
|
535
|
+
// Ambiguous: could be exact or prefix
|
|
536
|
+
// Store as BOTH exact and hierarchical
|
|
537
|
+
exact[normalized] = level;
|
|
538
|
+
hierarchical.push({
|
|
539
|
+
prefix: normalized + ".",
|
|
540
|
+
level: level,
|
|
541
|
+
specificity: FlinkLogFactory.calculatePrefixSpecificity(normalized),
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
// Simple name (no dots) - exact match only
|
|
546
|
+
exact[normalized] = level;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
// Sort by specificity (most specific first)
|
|
550
|
+
hierarchical.sort(function (a, b) { return b.specificity - a.specificity; });
|
|
551
|
+
wildcards.sort(function (a, b) { return b.specificity - a.specificity; });
|
|
552
|
+
return { exact: exact, hierarchical: hierarchical, wildcards: wildcards };
|
|
553
|
+
};
|
|
554
|
+
/**
|
|
555
|
+
* Check if a string is a valid log level
|
|
556
|
+
*/
|
|
557
|
+
FlinkLogFactory.isValidLogLevel = function (level) {
|
|
558
|
+
return ["trace", "debug", "info", "warn", "error"].includes(level);
|
|
559
|
+
};
|
|
560
|
+
/**
|
|
561
|
+
* Create or retrieve a component-specific logger
|
|
562
|
+
* Automatically applies environment/config settings when logger is created
|
|
563
|
+
* Supports hierarchical prefix matching (Java-style)
|
|
564
|
+
*
|
|
565
|
+
* @param componentName Logger name (lowercase dot notation recommended, e.g., "flink.ai.openai")
|
|
566
|
+
* @returns ComponentLogger instance
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* // Java-style hierarchical naming (recommended)
|
|
571
|
+
* const log = FlinkLogFactory.createLogger("flink.ai.openai");
|
|
572
|
+
* const dbLog = FlinkLogFactory.createLogger("flink.database.mongodb");
|
|
573
|
+
*
|
|
574
|
+
* // Case insensitive - these create the same logger
|
|
575
|
+
* const log1 = FlinkLogFactory.createLogger("flink.ai.openai");
|
|
576
|
+
* const log2 = FlinkLogFactory.createLogger("Flink.AI.OpenAI"); // Same instance
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
FlinkLogFactory.createLogger = function (componentName) {
|
|
580
|
+
// Initialize from environment and config file if not already done
|
|
581
|
+
if (!FlinkLogFactory.initialized) {
|
|
582
|
+
var loadFlinkConfig = require("./utils/loadFlinkConfig").loadFlinkConfig;
|
|
583
|
+
var flinkConfig = loadFlinkConfig();
|
|
584
|
+
FlinkLogFactory.configure(flinkConfig === null || flinkConfig === void 0 ? void 0 : flinkConfig.logging);
|
|
585
|
+
}
|
|
586
|
+
// Normalize to lowercase for consistent lookup
|
|
587
|
+
var normalized = FlinkLogFactory.normalize(componentName);
|
|
588
|
+
if (!FlinkLogFactory.loggers.has(normalized)) {
|
|
589
|
+
var logger = new ComponentLogger(normalized);
|
|
590
|
+
FlinkLogFactory.loggers.set(normalized, logger);
|
|
591
|
+
// Resolve level through hierarchical matching
|
|
592
|
+
var resolvedLevel = FlinkLogFactory.resolveComponentLevel(normalized);
|
|
593
|
+
if (resolvedLevel) {
|
|
594
|
+
logger.setLevel(resolvedLevel);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return FlinkLogFactory.loggers.get(normalized);
|
|
598
|
+
};
|
|
599
|
+
FlinkLogFactory.globalLevel = "info";
|
|
600
|
+
FlinkLogFactory.loggers = new Map();
|
|
601
|
+
FlinkLogFactory.initialized = false;
|
|
602
|
+
FlinkLogFactory.showTimestamps = true;
|
|
603
|
+
/**
|
|
604
|
+
* Store component configurations from environment/config for lazy application
|
|
605
|
+
*/
|
|
606
|
+
FlinkLogFactory.componentConfigs = {};
|
|
607
|
+
/**
|
|
608
|
+
* Hierarchical prefix configurations (Java-style)
|
|
609
|
+
* Sorted by specificity (most specific first) for efficient matching
|
|
610
|
+
*/
|
|
611
|
+
FlinkLogFactory.hierarchicalConfigs = [];
|
|
612
|
+
/**
|
|
613
|
+
* Wildcard pattern configurations (optional, advanced)
|
|
614
|
+
* Sorted by specificity (most specific first) for efficient matching
|
|
615
|
+
*/
|
|
616
|
+
FlinkLogFactory.wildcardConfigs = [];
|
|
617
|
+
return FlinkLogFactory;
|
|
618
|
+
}());
|
|
619
|
+
exports.FlinkLogFactory = FlinkLogFactory;
|
package/dist/src/FlinkRepo.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Do
|
|
|
14
14
|
collection: Collection;
|
|
15
15
|
private _ctx?;
|
|
16
16
|
set ctx(ctx: FlinkContext);
|
|
17
|
-
get ctx():
|
|
17
|
+
get ctx(): C;
|
|
18
18
|
constructor(collectionName: string, db: Db, client?: MongoClient | undefined);
|
|
19
19
|
findAll(query?: {}): Promise<Model[]>;
|
|
20
20
|
getById(id: string | ObjectId): Promise<Model | null>;
|
|
@@ -22,6 +22,10 @@ export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Do
|
|
|
22
22
|
create<C = Omit<Model, "_id">>(model: C): Promise<C & {
|
|
23
23
|
_id: string;
|
|
24
24
|
}>;
|
|
25
|
+
updateById(id: string | ObjectId, model: PartialModel<Model>): Promise<Model | null>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use `updateById` instead. This will be removed in a future major version.
|
|
28
|
+
*/
|
|
25
29
|
updateOne(id: string | ObjectId, model: PartialModel<Model>): Promise<Model | null>;
|
|
26
30
|
updateMany<U = PartialModel<Model>>(query: any, model: U): Promise<number>;
|
|
27
31
|
deleteById(id: string | ObjectId): Promise<number>;
|
|
@@ -33,6 +37,10 @@ export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Do
|
|
|
33
37
|
* @returns
|
|
34
38
|
*/
|
|
35
39
|
buildId(id: string | ObjectId): ObjectId;
|
|
36
|
-
|
|
40
|
+
protected objectIdToString<T>(doc: T & {
|
|
41
|
+
_id?: any;
|
|
42
|
+
}): T & {
|
|
43
|
+
_id?: any;
|
|
44
|
+
};
|
|
37
45
|
}
|
|
38
46
|
export {};
|
package/dist/src/FlinkRepo.js
CHANGED
|
@@ -139,7 +139,7 @@ var FlinkRepo = /** @class */ (function () {
|
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
};
|
|
142
|
-
FlinkRepo.prototype.
|
|
142
|
+
FlinkRepo.prototype.updateById = function (id, model) {
|
|
143
143
|
return __awaiter(this, void 0, void 0, function () {
|
|
144
144
|
var oid, _id, modelWithoutId, res;
|
|
145
145
|
return __generator(this, function (_a) {
|
|
@@ -161,6 +161,16 @@ var FlinkRepo = /** @class */ (function () {
|
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* @deprecated Use `updateById` instead. This will be removed in a future major version.
|
|
166
|
+
*/
|
|
167
|
+
FlinkRepo.prototype.updateOne = function (id, model) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
return [2 /*return*/, this.updateById(id, model)];
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
};
|
|
164
174
|
FlinkRepo.prototype.updateMany = function (query, model) {
|
|
165
175
|
return __awaiter(this, void 0, void 0, function () {
|
|
166
176
|
var _a, _id, modelWithoutId, modifiedCount;
|