@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.
Files changed (280) hide show
  1. package/CHANGELOG.md +1051 -0
  2. package/SCHEMA_EXTRACTION_ANALYSIS.md +494 -0
  3. package/SIMPLE_AST_FEASIBILITY.md +570 -0
  4. package/bin/flink.ts +13 -2
  5. package/cli/build.ts +24 -44
  6. package/cli/clean.ts +13 -25
  7. package/cli/cli-utils.ts +190 -17
  8. package/cli/dev.ts +252 -0
  9. package/cli/loadEnvFiles.ts +116 -0
  10. package/cli/run.ts +45 -62
  11. package/dist/bin/flink.js +61 -2
  12. package/dist/cli/build.js +20 -25
  13. package/dist/cli/clean.js +12 -10
  14. package/dist/cli/cli-utils.d.ts +34 -3
  15. package/dist/cli/cli-utils.js +193 -12
  16. package/dist/cli/dev.d.ts +2 -0
  17. package/dist/cli/dev.js +279 -0
  18. package/dist/cli/loadEnvFiles.d.ts +30 -0
  19. package/dist/cli/loadEnvFiles.js +113 -0
  20. package/dist/cli/run.js +47 -46
  21. package/dist/src/DependencyTracker.d.ts +44 -0
  22. package/dist/src/DependencyTracker.js +239 -0
  23. package/dist/src/FlinkApp.d.ts +163 -10
  24. package/dist/src/FlinkApp.js +847 -184
  25. package/dist/src/FlinkContext.d.ts +41 -0
  26. package/dist/src/FlinkErrors.d.ts +19 -6
  27. package/dist/src/FlinkErrors.js +36 -42
  28. package/dist/src/FlinkHttpHandler.d.ts +219 -26
  29. package/dist/src/FlinkHttpHandler.js +37 -1
  30. package/dist/src/FlinkJob.d.ts +10 -0
  31. package/dist/src/FlinkLog.d.ts +82 -18
  32. package/dist/src/FlinkLog.js +165 -13
  33. package/dist/src/FlinkLogFactory.d.ts +288 -0
  34. package/dist/src/FlinkLogFactory.js +619 -0
  35. package/dist/src/FlinkRepo.d.ts +10 -2
  36. package/dist/src/FlinkRepo.js +11 -1
  37. package/dist/src/FlinkRequestContext.d.ts +63 -0
  38. package/dist/src/FlinkRequestContext.js +74 -0
  39. package/dist/src/FlinkResponse.d.ts +6 -0
  40. package/dist/src/FlinkService.d.ts +38 -0
  41. package/dist/src/FlinkService.js +46 -0
  42. package/dist/src/LeaderElection.d.ts +45 -0
  43. package/dist/src/LeaderElection.js +269 -0
  44. package/dist/src/SchemaCache.d.ts +84 -0
  45. package/dist/src/SchemaCache.js +289 -0
  46. package/dist/src/TypeScriptCompiler.d.ts +161 -51
  47. package/dist/src/TypeScriptCompiler.js +1253 -617
  48. package/dist/src/TypeScriptUtils.js +4 -0
  49. package/dist/src/ai/AgentRunner.d.ts +39 -0
  50. package/dist/src/ai/AgentRunner.js +760 -0
  51. package/dist/src/ai/ConversationAgent.d.ts +279 -0
  52. package/dist/src/ai/ConversationAgent.js +404 -0
  53. package/dist/src/ai/ConversationFlinkAgent.d.ts +278 -0
  54. package/dist/src/ai/ConversationFlinkAgent.js +404 -0
  55. package/dist/src/ai/FlinkAgent.d.ts +690 -0
  56. package/dist/src/ai/FlinkAgent.js +729 -0
  57. package/dist/src/ai/FlinkTool.d.ts +135 -0
  58. package/dist/src/ai/FlinkTool.js +2 -0
  59. package/dist/src/ai/InMemoryConversationAgent.d.ts +121 -0
  60. package/dist/src/ai/InMemoryConversationAgent.js +209 -0
  61. package/dist/src/ai/LLMAdapter.d.ts +148 -0
  62. package/dist/src/ai/LLMAdapter.js +2 -0
  63. package/dist/src/ai/PersistentFlinkAgent.d.ts +278 -0
  64. package/dist/src/ai/PersistentFlinkAgent.js +403 -0
  65. package/dist/src/ai/SubAgentExecutor.d.ts +38 -0
  66. package/dist/src/ai/SubAgentExecutor.js +223 -0
  67. package/dist/src/ai/ToolExecutor.d.ts +64 -0
  68. package/dist/src/ai/ToolExecutor.js +497 -0
  69. package/dist/src/ai/agentInstructions.d.ts +68 -0
  70. package/dist/src/ai/agentInstructions.js +286 -0
  71. package/dist/src/ai/index.d.ts +8 -0
  72. package/dist/src/ai/index.js +26 -0
  73. package/dist/src/ai/instructionFileLoader.d.ts +44 -0
  74. package/dist/src/ai/instructionFileLoader.js +179 -0
  75. package/dist/src/auth/FlinkAuthPlugin.d.ts +1 -1
  76. package/dist/src/handlers/StreamWriterFactory.d.ts +20 -0
  77. package/dist/src/handlers/StreamWriterFactory.js +83 -0
  78. package/dist/src/index.d.ts +14 -0
  79. package/dist/src/index.js +17 -0
  80. package/dist/src/loadPluginSchemas.d.ts +45 -0
  81. package/dist/src/loadPluginSchemas.js +143 -0
  82. package/dist/src/schema-extraction/ComplexTypeDetection.d.ts +40 -0
  83. package/dist/src/schema-extraction/ComplexTypeDetection.js +75 -0
  84. package/dist/src/schema-extraction/TypeScriptSourceParser.d.ts +321 -0
  85. package/dist/src/schema-extraction/TypeScriptSourceParser.js +925 -0
  86. package/dist/src/schema-extraction/TypeScriptSourceParser.spec.d.ts +1 -0
  87. package/dist/src/schema-extraction/TypeScriptSourceParser.spec.js +233 -0
  88. package/dist/src/schema-extraction/TypeScriptTokenizer.d.ts +57 -0
  89. package/dist/src/schema-extraction/TypeScriptTokenizer.js +177 -0
  90. package/dist/src/schema-extraction/index.d.ts +2 -0
  91. package/dist/src/schema-extraction/index.js +20 -0
  92. package/dist/src/schema-extraction/types.d.ts +31 -0
  93. package/dist/src/schema-extraction/types.js +2 -0
  94. package/dist/src/utils/loadFlinkConfig.d.ts +53 -0
  95. package/dist/src/utils/loadFlinkConfig.js +77 -0
  96. package/dist/src/utils.d.ts +30 -0
  97. package/dist/src/utils.js +52 -0
  98. package/dist/src/workers/SchemaGeneratorWorker.d.ts +1 -0
  99. package/dist/src/workers/SchemaGeneratorWorker.js +49 -0
  100. package/dist/src/workers/WorkerPool.d.ts +60 -0
  101. package/dist/src/workers/WorkerPool.js +306 -0
  102. package/examples/logging-hierarchical-example.ts +125 -0
  103. package/package.json +29 -4
  104. package/readme.md +499 -0
  105. package/spec/AgentDescendantDetection.spec.ts +335 -0
  106. package/spec/AgentDuplicateDetection.spec.ts +112 -0
  107. package/spec/AgentObserver.spec.ts +266 -0
  108. package/spec/AgentRunner.spec.ts +1062 -0
  109. package/spec/AsyncLocalStorageContext.spec.ts +223 -0
  110. package/spec/ConversationHooks.spec.ts +257 -0
  111. package/spec/FlinkAgent.spec.ts +681 -0
  112. package/spec/FlinkApp.htmlResponse.spec.ts +260 -0
  113. package/spec/FlinkApp.onError.invocation.spec.ts +151 -0
  114. package/spec/FlinkApp.onError.spec.ts +1 -2
  115. package/spec/FlinkApp.query.spec.ts +107 -0
  116. package/spec/FlinkApp.routeOrdering.spec.ts +61 -0
  117. package/spec/FlinkApp.undefinedResponse.spec.ts +123 -0
  118. package/spec/FlinkApp.validationMode.spec.ts +155 -0
  119. package/spec/FlinkJob.spec.ts +171 -0
  120. package/spec/FlinkLogFactory.spec.ts +337 -0
  121. package/spec/FlinkRepo.spec.ts +1 -1
  122. package/spec/LeaderElection.spec.ts +174 -0
  123. package/spec/StreamingIntegration.spec.ts +139 -0
  124. package/spec/ToolExecutor.spec.ts +465 -0
  125. package/spec/TypeScriptCompiler.spec.ts +1 -1
  126. package/spec/TypeScriptSourceParser.spec.ts +1215 -0
  127. package/spec/TypeScriptTokenizer.spec.ts +366 -0
  128. package/spec/ai/ContextCompaction.spec.ts +405 -0
  129. package/spec/ai/ConversationAgent.spec.ts +520 -0
  130. package/spec/ai/InMemoryConversationAgent.spec.ts +144 -0
  131. package/spec/ai/agentInstructions.spec.ts +358 -0
  132. package/spec/fixtures/agent-instructions/TestAgent.ts +24 -0
  133. package/spec/fixtures/agent-instructions/simple.md +3 -0
  134. package/spec/fixtures/agent-instructions/template.md +18 -0
  135. package/spec/fixtures/agent-instructions/yaml-format.yaml +9 -0
  136. package/spec/mock-project/dist/.tsbuildinfo +1 -0
  137. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar.js +56 -0
  138. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar2.js +58 -0
  139. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema.js +52 -0
  140. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema2.js +52 -0
  141. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema3.js +52 -0
  142. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema.js +54 -0
  143. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema2.js +54 -0
  144. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile.js +57 -0
  145. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile2.js +57 -0
  146. package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler.js +53 -0
  147. package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler2.js +55 -0
  148. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchCar.js +57 -0
  149. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOnboardingSession.js +75 -0
  150. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOrderWithComplexTypes.js +57 -0
  151. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchProductWithIntersection.js +58 -0
  152. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchUserWithUnion.js +58 -0
  153. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostCar.js +54 -0
  154. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogin.js +55 -0
  155. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogout.js +54 -0
  156. package/spec/mock-project/dist/spec/mock-project/src/handlers/PutCar.js +54 -0
  157. package/spec/mock-project/dist/spec/mock-project/src/index.js +83 -0
  158. package/spec/mock-project/dist/spec/mock-project/src/repos/CarRepo.js +26 -0
  159. package/spec/mock-project/dist/spec/mock-project/src/schemas/Car.js +2 -0
  160. package/spec/mock-project/dist/spec/mock-project/src/schemas/DefaultExportSchema.js +2 -0
  161. package/spec/mock-project/dist/spec/mock-project/src/schemas/FileWithTwoSchemas.js +2 -0
  162. package/spec/mock-project/dist/src/FlinkApp.js +1000 -0
  163. package/spec/mock-project/dist/src/FlinkContext.js +2 -0
  164. package/spec/mock-project/dist/src/FlinkErrors.js +143 -0
  165. package/spec/mock-project/dist/src/FlinkHttpHandler.js +47 -0
  166. package/spec/mock-project/dist/src/FlinkJob.js +2 -0
  167. package/spec/mock-project/dist/src/FlinkLog.js +119 -0
  168. package/spec/mock-project/dist/src/FlinkLogFactory.js +617 -0
  169. package/spec/mock-project/dist/src/FlinkPlugin.js +2 -0
  170. package/spec/mock-project/dist/src/FlinkRepo.js +224 -0
  171. package/spec/mock-project/dist/src/FlinkRequestContext.js +74 -0
  172. package/spec/mock-project/dist/src/FlinkResponse.js +2 -0
  173. package/spec/mock-project/dist/src/ai/AgentExecutor.js +279 -0
  174. package/spec/mock-project/dist/src/ai/AgentRunner.js +632 -0
  175. package/spec/mock-project/dist/src/ai/ConversationAgent.js +402 -0
  176. package/spec/mock-project/dist/src/ai/ConversationFlinkAgent.js +422 -0
  177. package/spec/mock-project/dist/src/ai/FlinkAgent.js +699 -0
  178. package/spec/mock-project/dist/src/ai/FlinkTool.js +2 -0
  179. package/spec/mock-project/dist/src/ai/InMemoryConversationAgent.js +209 -0
  180. package/spec/mock-project/dist/src/ai/LLMAdapter.js +2 -0
  181. package/spec/mock-project/dist/src/ai/SubAgentExecutor.js +223 -0
  182. package/spec/mock-project/dist/src/ai/ToolExecutor.js +412 -0
  183. package/spec/mock-project/dist/src/ai/agentInstructions.js +246 -0
  184. package/spec/mock-project/dist/src/auth/FlinkAuthPlugin.js +2 -0
  185. package/spec/mock-project/dist/src/auth/FlinkAuthUser.js +2 -0
  186. package/spec/mock-project/dist/src/handlers/GetCar.js +26 -52
  187. package/spec/mock-project/dist/src/handlers/GetCar.js.map +1 -0
  188. package/spec/mock-project/dist/src/handlers/GetCar2.js +32 -54
  189. package/spec/mock-project/dist/src/handlers/GetCar2.js.map +1 -0
  190. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +26 -48
  191. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js.map +1 -0
  192. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +28 -48
  193. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js.map +1 -0
  194. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +29 -48
  195. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js.map +1 -0
  196. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +26 -50
  197. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js.map +1 -0
  198. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +28 -50
  199. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js.map +1 -0
  200. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +27 -53
  201. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js.map +1 -0
  202. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +29 -53
  203. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js.map +1 -0
  204. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +16 -49
  205. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js.map +1 -0
  206. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +25 -50
  207. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js.map +1 -0
  208. package/spec/mock-project/dist/src/handlers/PatchCar.js +27 -53
  209. package/spec/mock-project/dist/src/handlers/PatchCar.js.map +1 -0
  210. package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js +44 -70
  211. package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js.map +1 -0
  212. package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js +27 -53
  213. package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js.map +1 -0
  214. package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js +28 -54
  215. package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js.map +1 -0
  216. package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js +28 -54
  217. package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js.map +1 -0
  218. package/spec/mock-project/dist/src/handlers/PostCar.js +24 -50
  219. package/spec/mock-project/dist/src/handlers/PostCar.js.map +1 -0
  220. package/spec/mock-project/dist/src/handlers/PostLogin.js +25 -51
  221. package/spec/mock-project/dist/src/handlers/PostLogin.js.map +1 -0
  222. package/spec/mock-project/dist/src/handlers/PostLogout.js +24 -50
  223. package/spec/mock-project/dist/src/handlers/PostLogout.js.map +1 -0
  224. package/spec/mock-project/dist/src/handlers/PutCar.js +24 -50
  225. package/spec/mock-project/dist/src/handlers/PutCar.js.map +1 -0
  226. package/spec/mock-project/dist/src/handlers/StreamWriterFactory.js +83 -0
  227. package/spec/mock-project/dist/src/index.js +52 -76
  228. package/spec/mock-project/dist/src/index.js.map +1 -0
  229. package/spec/mock-project/dist/src/mock-data-generator.js +9 -0
  230. package/spec/mock-project/dist/src/repos/CarRepo.js +12 -24
  231. package/spec/mock-project/dist/src/repos/CarRepo.js.map +1 -0
  232. package/spec/mock-project/dist/src/schemas/Car.js +3 -1
  233. package/spec/mock-project/dist/src/schemas/Car.js.map +1 -0
  234. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +3 -1
  235. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js.map +1 -0
  236. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +3 -1
  237. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js.map +1 -0
  238. package/spec/mock-project/dist/src/utils.js +290 -0
  239. package/spec/mock-project/tsconfig.json +6 -1
  240. package/spec/schema-generation-nested-objects.spec.ts +97 -0
  241. package/spec/testHelpers.ts +49 -0
  242. package/spec/utils.caseConversion.spec.ts +78 -0
  243. package/spec/utils.spec.ts +13 -13
  244. package/src/DependencyTracker.ts +166 -0
  245. package/src/FlinkApp.ts +919 -155
  246. package/src/FlinkContext.ts +43 -0
  247. package/src/FlinkErrors.ts +32 -12
  248. package/src/FlinkHttpHandler.ts +246 -28
  249. package/src/FlinkJob.ts +11 -0
  250. package/src/FlinkLog.ts +119 -12
  251. package/src/FlinkLogFactory.ts +699 -0
  252. package/src/FlinkRepo.ts +10 -3
  253. package/src/FlinkRequestContext.ts +95 -0
  254. package/src/FlinkResponse.ts +6 -0
  255. package/src/FlinkService.ts +49 -0
  256. package/src/LeaderElection.ts +203 -0
  257. package/src/SchemaCache.ts +232 -0
  258. package/src/TypeScriptCompiler.ts +1347 -610
  259. package/src/TypeScriptUtils.ts +5 -0
  260. package/src/ai/AgentRunner.ts +646 -0
  261. package/src/ai/ConversationAgent.ts +413 -0
  262. package/src/ai/FlinkAgent.ts +1069 -0
  263. package/src/ai/FlinkTool.ts +165 -0
  264. package/src/ai/InMemoryConversationAgent.ts +149 -0
  265. package/src/ai/LLMAdapter.ts +126 -0
  266. package/src/ai/ToolExecutor.ts +485 -0
  267. package/src/ai/agentInstructions.ts +245 -0
  268. package/src/ai/index.ts +8 -0
  269. package/src/ai/instructionFileLoader.ts +156 -0
  270. package/src/auth/FlinkAuthPlugin.ts +2 -1
  271. package/src/handlers/StreamWriterFactory.ts +84 -0
  272. package/src/index.ts +14 -0
  273. package/src/loadPluginSchemas.ts +141 -0
  274. package/src/schema-extraction/TypeScriptSourceParser.ts +1058 -0
  275. package/src/schema-extraction/TypeScriptTokenizer.ts +205 -0
  276. package/src/schema-extraction/index.ts +2 -0
  277. package/src/schema-extraction/types.ts +34 -0
  278. package/src/utils/loadFlinkConfig.ts +89 -0
  279. package/src/utils.ts +52 -0
  280. package/tsconfig.json +6 -1
@@ -1,24 +1,88 @@
1
+ type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
2
+ /**
3
+ * Simple logging utility with proper stdout/stderr separation
4
+ *
5
+ * Following Unix/POSIX best practices:
6
+ * - trace, debug, info → stdout (normal output)
7
+ * - warn, error → stderr (diagnostic output)
8
+ *
9
+ * Benefits:
10
+ * - Respects flink.config.js logging configuration
11
+ * - Container orchestration can capture streams separately
12
+ * - Shell redirection works correctly (command > out.log 2> err.log)
13
+ * - Log aggregation tools can route differently
14
+ * - Monitoring systems can alert on stderr only
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { log } from "@flink-app/flink";
19
+ *
20
+ * log.trace("Detailed trace info");
21
+ * log.debug("Debug information");
22
+ * log.info("General information");
23
+ * log.warn("Warning message");
24
+ * log.error("Error message");
25
+ * ```
26
+ *
27
+ * @example Configure via flink.config.js
28
+ * ```javascript
29
+ * module.exports = {
30
+ * logging: {
31
+ * components: {
32
+ * "app": "debug" // Enable debug for default log
33
+ * }
34
+ * }
35
+ * };
36
+ * ```
37
+ */
1
38
  export declare const log: {
39
+ /**
40
+ * Trace logs (stdout)
41
+ * Use for extremely detailed diagnostic information (most verbose level)
42
+ */
43
+ trace: (...args: any[]) => void;
44
+ /**
45
+ * Debug logs (stdout)
46
+ * Use for detailed diagnostic information during development
47
+ */
2
48
  debug: (...args: any[]) => void;
49
+ /**
50
+ * Info logs (stdout)
51
+ * Use for general informational messages about application state
52
+ */
3
53
  info: (...args: any[]) => void;
54
+ /**
55
+ * Warning logs (stderr)
56
+ * Use for potentially harmful situations that aren't errors
57
+ * Writes to stderr following Unix/POSIX best practices
58
+ */
4
59
  warn: (...args: any[]) => void;
60
+ /**
61
+ * Error logs (stderr)
62
+ * Use for error events that might still allow the app to continue
63
+ * Writes to stderr following Unix/POSIX best practices
64
+ */
5
65
  error: (...args: any[]) => void;
6
- json: (...args: any) => void;
7
- bgColorLog: (ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
8
- reverse?: boolean | undefined;
9
- bold?: boolean | undefined;
10
- italic?: boolean | undefined;
11
- dim?: boolean | undefined;
12
- underscore?: boolean | undefined;
13
- strikethrough?: boolean | undefined;
14
- }) => void;
15
- fontColorLog: (ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
16
- reverse?: boolean | undefined;
17
- bold?: boolean | undefined;
18
- italic?: boolean | undefined;
19
- dim?: boolean | undefined;
20
- underscore?: boolean | undefined;
21
- strikethrough?: boolean | undefined;
22
- }) => void;
23
- setLevel: (level: "debug" | "info" | "warn" | "error") => void;
66
+ /**
67
+ * JSON output (stdout)
68
+ * Use for structured data output
69
+ */
70
+ json: (...args: any[]) => void;
71
+ /**
72
+ * Colored background log (stdout)
73
+ * Use for highlighted messages during development
74
+ */
75
+ bgColorLog: (color: string, ...args: any[]) => void;
76
+ /**
77
+ * Colored font log (stdout)
78
+ * Use for colored messages during development
79
+ */
80
+ fontColorLog: (color: string, ...args: any[]) => void;
81
+ /**
82
+ * Set log level for the default "app" logger
83
+ *
84
+ * @deprecated Use flink.config.js or FlinkLogFactory.setComponentLevel("app", level) instead
85
+ */
86
+ setLevel: (level: LogLevel) => void;
24
87
  };
88
+ export {};
@@ -1,26 +1,178 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
4
10
  };
5
11
  Object.defineProperty(exports, "__esModule", { value: true });
6
12
  exports.log = void 0;
7
- var node_color_log_1 = __importDefault(require("node-color-log"));
13
+ var FlinkLogFactory_1 = require("./FlinkLogFactory");
14
+ /**
15
+ * Lazy-loaded application logger using FlinkLogFactory
16
+ *
17
+ * This logger uses the component name "app" and respects all
18
+ * logging configuration from flink.config.js and environment variables.
19
+ *
20
+ * Configured via:
21
+ * - flink.config.js: components["app"] = "debug"
22
+ * - Environment: LOG_LEVEL=debug
23
+ * - Programmatic: FlinkLogFactory.setComponentLevel("app", "debug")
24
+ */
25
+ var appLogger = null;
26
+ /**
27
+ * Get or create the app logger (lazy initialization)
28
+ */
29
+ function getAppLogger() {
30
+ if (!appLogger) {
31
+ appLogger = FlinkLogFactory_1.FlinkLogFactory.createLogger("app");
32
+ }
33
+ return appLogger;
34
+ }
35
+ /**
36
+ * Simple logging utility with proper stdout/stderr separation
37
+ *
38
+ * Following Unix/POSIX best practices:
39
+ * - trace, debug, info → stdout (normal output)
40
+ * - warn, error → stderr (diagnostic output)
41
+ *
42
+ * Benefits:
43
+ * - Respects flink.config.js logging configuration
44
+ * - Container orchestration can capture streams separately
45
+ * - Shell redirection works correctly (command > out.log 2> err.log)
46
+ * - Log aggregation tools can route differently
47
+ * - Monitoring systems can alert on stderr only
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * import { log } from "@flink-app/flink";
52
+ *
53
+ * log.trace("Detailed trace info");
54
+ * log.debug("Debug information");
55
+ * log.info("General information");
56
+ * log.warn("Warning message");
57
+ * log.error("Error message");
58
+ * ```
59
+ *
60
+ * @example Configure via flink.config.js
61
+ * ```javascript
62
+ * module.exports = {
63
+ * logging: {
64
+ * components: {
65
+ * "app": "debug" // Enable debug for default log
66
+ * }
67
+ * }
68
+ * };
69
+ * ```
70
+ */
8
71
  exports.log = {
9
- debug: node_color_log_1.default.debug.bind(node_color_log_1.default),
10
- info: node_color_log_1.default.info.bind(node_color_log_1.default),
11
- warn: node_color_log_1.default.warn.bind(node_color_log_1.default),
12
- error: node_color_log_1.default.error.bind(node_color_log_1.default),
72
+ /**
73
+ * Trace logs (stdout)
74
+ * Use for extremely detailed diagnostic information (most verbose level)
75
+ */
76
+ trace: function () {
77
+ var _a;
78
+ var args = [];
79
+ for (var _i = 0; _i < arguments.length; _i++) {
80
+ args[_i] = arguments[_i];
81
+ }
82
+ return (_a = getAppLogger()).trace.apply(_a, args);
83
+ },
84
+ /**
85
+ * Debug logs (stdout)
86
+ * Use for detailed diagnostic information during development
87
+ */
88
+ debug: function () {
89
+ var _a;
90
+ var args = [];
91
+ for (var _i = 0; _i < arguments.length; _i++) {
92
+ args[_i] = arguments[_i];
93
+ }
94
+ return (_a = getAppLogger()).debug.apply(_a, args);
95
+ },
96
+ /**
97
+ * Info logs (stdout)
98
+ * Use for general informational messages about application state
99
+ */
100
+ info: function () {
101
+ var _a;
102
+ var args = [];
103
+ for (var _i = 0; _i < arguments.length; _i++) {
104
+ args[_i] = arguments[_i];
105
+ }
106
+ return (_a = getAppLogger()).info.apply(_a, args);
107
+ },
108
+ /**
109
+ * Warning logs (stderr)
110
+ * Use for potentially harmful situations that aren't errors
111
+ * Writes to stderr following Unix/POSIX best practices
112
+ */
113
+ warn: function () {
114
+ var _a;
115
+ var args = [];
116
+ for (var _i = 0; _i < arguments.length; _i++) {
117
+ args[_i] = arguments[_i];
118
+ }
119
+ return (_a = getAppLogger()).warn.apply(_a, args);
120
+ },
121
+ /**
122
+ * Error logs (stderr)
123
+ * Use for error events that might still allow the app to continue
124
+ * Writes to stderr following Unix/POSIX best practices
125
+ */
126
+ error: function () {
127
+ var _a;
128
+ var args = [];
129
+ for (var _i = 0; _i < arguments.length; _i++) {
130
+ args[_i] = arguments[_i];
131
+ }
132
+ return (_a = getAppLogger()).error.apply(_a, args);
133
+ },
134
+ /**
135
+ * JSON output (stdout)
136
+ * Use for structured data output
137
+ */
13
138
  json: function () {
139
+ var _a;
14
140
  var args = [];
15
141
  for (var _i = 0; _i < arguments.length; _i++) {
16
142
  args[_i] = arguments[_i];
17
143
  }
18
- for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
19
- var o = args_1[_a];
20
- console.log(JSON.stringify(o, null, 2));
144
+ return (_a = getAppLogger()).json.apply(_a, args);
145
+ },
146
+ /**
147
+ * Colored background log (stdout)
148
+ * Use for highlighted messages during development
149
+ */
150
+ bgColorLog: function (color) {
151
+ var _a;
152
+ var args = [];
153
+ for (var _i = 1; _i < arguments.length; _i++) {
154
+ args[_i - 1] = arguments[_i];
155
+ }
156
+ return (_a = getAppLogger()).bgColorLog.apply(_a, __spreadArray([color], args, false));
157
+ },
158
+ /**
159
+ * Colored font log (stdout)
160
+ * Use for colored messages during development
161
+ */
162
+ fontColorLog: function (color) {
163
+ var _a;
164
+ var args = [];
165
+ for (var _i = 1; _i < arguments.length; _i++) {
166
+ args[_i - 1] = arguments[_i];
21
167
  }
168
+ return (_a = getAppLogger()).fontColorLog.apply(_a, __spreadArray([color], args, false));
169
+ },
170
+ /**
171
+ * Set log level for the default "app" logger
172
+ *
173
+ * @deprecated Use flink.config.js or FlinkLogFactory.setComponentLevel("app", level) instead
174
+ */
175
+ setLevel: function (level) {
176
+ getAppLogger().setLevel(level);
22
177
  },
23
- bgColorLog: node_color_log_1.default.bgColorLog.bind(node_color_log_1.default),
24
- fontColorLog: node_color_log_1.default.fontColorLog.bind(node_color_log_1.default),
25
- setLevel: function (level) { return node_color_log_1.default.setLevel.bind(node_color_log_1.default)(level); },
26
178
  };
@@ -0,0 +1,288 @@
1
+ type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
2
+ /**
3
+ * Component-specific logger with independent log level control
4
+ */
5
+ export declare class ComponentLogger {
6
+ private componentName;
7
+ private componentLevel;
8
+ private namedLogger;
9
+ constructor(componentName: string);
10
+ /**
11
+ * Set log level for this specific component.
12
+ * Overrides the global log level.
13
+ */
14
+ setLevel(level: LogLevel): void;
15
+ /**
16
+ * Clear component-specific level and fall back to global level
17
+ */
18
+ clearLevel(): void;
19
+ /**
20
+ * Check if a message should be logged based on component and global levels
21
+ */
22
+ private shouldLog;
23
+ trace(...args: any[]): void;
24
+ debug(...args: any[]): void;
25
+ info(...args: any[]): void;
26
+ warn(...args: any[]): void;
27
+ error(...args: any[]): void;
28
+ json(...args: any[]): void;
29
+ bgColorLog(color: string, ...args: any[]): void;
30
+ fontColorLog(color: string, ...args: any[]): void;
31
+ }
32
+ /**
33
+ * Configuration for logging system
34
+ */
35
+ export interface LoggingConfig {
36
+ /**
37
+ * Global log level (default: "info")
38
+ */
39
+ global?: LogLevel;
40
+ /**
41
+ * Show timestamps in log messages (default: true)
42
+ */
43
+ showTimestamps?: boolean;
44
+ /**
45
+ * Component-specific log levels with wildcard support
46
+ *
47
+ * Supports:
48
+ * - Exact match: "flink.ai.openai" → matches only "flink.ai.openai"
49
+ * - Prefix match: "flink.ai." → matches "flink.ai.openai", "flink.ai.anthropic", etc.
50
+ * - Single-level wildcard: "flink.ai.*" → matches "flink.ai.openai" but NOT "flink.ai.openai.v4"
51
+ * - Multi-level wildcard: "flink.ai.**" → matches any depth under "flink.ai"
52
+ *
53
+ * @example
54
+ * {
55
+ * "flink.ai.openai": "trace", // exact match
56
+ * "flink.ai.*": "debug", // single-level wildcard
57
+ * "flink.database.**": "warn", // multi-level wildcard
58
+ * "flink.handlers.": "info" // prefix match (trailing dot)
59
+ * }
60
+ */
61
+ components?: Record<string, LogLevel>;
62
+ /**
63
+ * @internal
64
+ * Internal use only - hierarchical configurations parsed from components map
65
+ */
66
+ hierarchical?: Array<{
67
+ prefix: string;
68
+ level: LogLevel;
69
+ specificity: number;
70
+ }>;
71
+ /**
72
+ * @internal
73
+ * Internal use only - wildcard configurations parsed from components map
74
+ */
75
+ wildcards?: Array<{
76
+ pattern: string;
77
+ level: LogLevel;
78
+ specificity: number;
79
+ }>;
80
+ }
81
+ /**
82
+ * Factory for creating component-specific loggers with hierarchical level control
83
+ */
84
+ export declare class FlinkLogFactory {
85
+ private static globalLevel;
86
+ private static loggers;
87
+ private static initialized;
88
+ private static showTimestamps;
89
+ /**
90
+ * Store component configurations from environment/config for lazy application
91
+ */
92
+ private static componentConfigs;
93
+ /**
94
+ * Hierarchical prefix configurations (Java-style)
95
+ * Sorted by specificity (most specific first) for efficient matching
96
+ */
97
+ private static hierarchicalConfigs;
98
+ /**
99
+ * Wildcard pattern configurations (optional, advanced)
100
+ * Sorted by specificity (most specific first) for efficient matching
101
+ */
102
+ private static wildcardConfigs;
103
+ /**
104
+ * Set the global log level (affects all loggers without component-specific levels)
105
+ */
106
+ static setGlobalLevel(level: LogLevel): void;
107
+ /**
108
+ * Get the current global log level
109
+ */
110
+ static getGlobalLevel(): LogLevel;
111
+ /**
112
+ * Get all registered loggers (useful for debugging)
113
+ */
114
+ static getLoggers(): Map<string, ComponentLogger>;
115
+ /**
116
+ * Enable or disable timestamps in log messages
117
+ */
118
+ static setShowTimestamps(show: boolean): void;
119
+ /**
120
+ * Check if timestamps are enabled
121
+ */
122
+ static getShowTimestamps(): boolean;
123
+ /**
124
+ * Clear all component-specific log levels (fall back to global)
125
+ */
126
+ static resetComponentLevels(): void;
127
+ /**
128
+ * Clear all hierarchical prefix configurations
129
+ */
130
+ static resetHierarchicalLevels(): void;
131
+ /**
132
+ * Clear all wildcard pattern configurations
133
+ */
134
+ static resetWildcardLevels(): void;
135
+ /**
136
+ * Set log level for a specific component by name (exact match)
137
+ */
138
+ static setComponentLevel(componentName: string, level: LogLevel | null): void;
139
+ /**
140
+ * Set hierarchical prefix-based log level (Java-style)
141
+ * @param prefix Logger name prefix (e.g., "flink.ai" matches all "flink.ai.*")
142
+ * @param level Log level to apply
143
+ *
144
+ * @example
145
+ * FlinkLogFactory.setHierarchicalLevel("flink.ai", "debug");
146
+ * // Now all loggers starting with "flink.ai." will use debug level
147
+ * // This includes the exact match "flink.ai" AND all children "flink.ai.*"
148
+ */
149
+ static setHierarchicalLevel(prefix: string, level: LogLevel): void;
150
+ /**
151
+ * Set wildcard pattern-based log level (advanced)
152
+ * @param pattern Wildcard pattern (e.g., "flink.ai.*" or "flink.ai.**")
153
+ * @param level Log level to apply
154
+ *
155
+ * @example
156
+ * FlinkLogFactory.setWildcardLevel("flink.ai.*", "debug");
157
+ * // Matches flink.ai.openai but NOT flink.ai.openai.v4
158
+ *
159
+ * FlinkLogFactory.setWildcardLevel("flink.ai.**", "trace");
160
+ * // Matches any depth under flink.ai.
161
+ */
162
+ static setWildcardLevel(pattern: string, level: LogLevel): void;
163
+ /**
164
+ * Get the effective log level for a component (resolved through hierarchy)
165
+ * @param componentName Component name to check
166
+ * @returns Resolved log level or null if only global level applies
167
+ */
168
+ static getEffectiveLevel(componentName: string): LogLevel | null;
169
+ /**
170
+ * Initialize logging from environment variables and/or configuration file
171
+ *
172
+ * Priority (highest to lowest):
173
+ * 1. Config file (flink.config.js)
174
+ * 2. Environment variable (LOG_LEVEL=debug)
175
+ *
176
+ * @param fileConfig Optional logging configuration from flink.config.js
177
+ *
178
+ * @example Environment Variable
179
+ * ```bash
180
+ * LOG_LEVEL=debug pnpm run dev
181
+ * ```
182
+ *
183
+ * @example Config File (flink.config.js)
184
+ * ```javascript
185
+ * module.exports = {
186
+ * logging: {
187
+ * global: "info",
188
+ * showTimestamps: true,
189
+ * components: {
190
+ * "flink.ai.openai": "trace", // exact match
191
+ * "flink.ai.*": "debug", // single-level wildcard
192
+ * "flink.database.**": "warn", // multi-level wildcard
193
+ * "flink.handlers.": "info" // prefix match
194
+ * }
195
+ * }
196
+ * };
197
+ * ```
198
+ */
199
+ static configure(fileConfig?: LoggingConfig): void;
200
+ /**
201
+ * Parse logging configuration from environment variables
202
+ * Supports only LOG_LEVEL for global level setting
203
+ */
204
+ private static parseEnvironment;
205
+ /**
206
+ * Normalize logger name to lowercase (Java-style convention)
207
+ * @param name Logger name or pattern
208
+ * @returns Normalized lowercase name
209
+ */
210
+ private static normalize;
211
+ /**
212
+ * Determine if a name should be treated as a hierarchical prefix
213
+ * @param name Normalized logger name
214
+ * @returns True if it should be treated as a prefix
215
+ */
216
+ private static shouldTreatAsPrefix;
217
+ /**
218
+ * Calculate specificity for prefix matching
219
+ * More specific prefixes (more segments) have higher specificity
220
+ * @param prefix Prefix string (may or may not end with dot)
221
+ * @returns Specificity score (number of segments)
222
+ */
223
+ private static calculatePrefixSpecificity;
224
+ /**
225
+ * Calculate specificity for wildcard patterns
226
+ * More specific patterns (more non-wildcard segments) have higher specificity
227
+ * For same segment count, * (single-level) is more specific than ** (multi-level)
228
+ * @param pattern Wildcard pattern
229
+ * @returns Specificity score (base + decimal for wildcard type)
230
+ */
231
+ private static calculateWildcardSpecificity;
232
+ /**
233
+ * Resolve component log level through hierarchical matching
234
+ * Order of precedence (highest to lowest):
235
+ * 1. Exact match
236
+ * 2. Most specific prefix match
237
+ * 3. Less specific prefix match
238
+ * 4. Wildcard pattern match
239
+ * 5. null (falls back to global level)
240
+ *
241
+ * @param componentName Component name to resolve
242
+ * @returns Resolved log level or null
243
+ */
244
+ private static resolveComponentLevel;
245
+ /**
246
+ * Simple wildcard matching for logger patterns
247
+ * Supports:
248
+ * - * matches single segment (flink.ai.* matches flink.ai.openai)
249
+ * - ** matches any depth (flink.ai.** matches flink.ai.openai.v4)
250
+ * - Partial segment match (flink.ai.open* matches flink.ai.openai)
251
+ *
252
+ * @param name Logger name to match
253
+ * @param pattern Wildcard pattern
254
+ * @returns True if pattern matches
255
+ */
256
+ private static matchWildcard;
257
+ /**
258
+ * Parse components map and classify entries into exact, prefix, or wildcard matches
259
+ * @param components Components map from config
260
+ * @returns Classified configuration
261
+ */
262
+ private static parseComponentsMap;
263
+ /**
264
+ * Check if a string is a valid log level
265
+ */
266
+ private static isValidLogLevel;
267
+ /**
268
+ * Create or retrieve a component-specific logger
269
+ * Automatically applies environment/config settings when logger is created
270
+ * Supports hierarchical prefix matching (Java-style)
271
+ *
272
+ * @param componentName Logger name (lowercase dot notation recommended, e.g., "flink.ai.openai")
273
+ * @returns ComponentLogger instance
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Java-style hierarchical naming (recommended)
278
+ * const log = FlinkLogFactory.createLogger("flink.ai.openai");
279
+ * const dbLog = FlinkLogFactory.createLogger("flink.database.mongodb");
280
+ *
281
+ * // Case insensitive - these create the same logger
282
+ * const log1 = FlinkLogFactory.createLogger("flink.ai.openai");
283
+ * const log2 = FlinkLogFactory.createLogger("Flink.AI.OpenAI"); // Same instance
284
+ * ```
285
+ */
286
+ static createLogger(componentName: string): ComponentLogger;
287
+ }
288
+ export {};