@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
package/cli/run.ts CHANGED
@@ -1,83 +1,66 @@
1
1
  #!/usr/bin/env node
2
- import TypeScriptCompiler from "../src/TypeScriptCompiler";
2
+ import { parseArgs, hasFlag, getOption, normalizeEntry, printHelp, compile, forkApp } from "./cli-utils";
3
+ import { FlinkLogFactory } from "../src/FlinkLogFactory";
4
+ import { loadFlinkConfig } from "../src/utils/loadFlinkConfig";
5
+ import { loadEnvFiles } from "./loadEnvFiles";
3
6
 
4
- module.exports = async function run(args: string[]) {
5
- const startTime = Date.now();
7
+ // Load config BEFORE creating logger
8
+ const flinkConfig = loadFlinkConfig();
9
+ FlinkLogFactory.configure(flinkConfig?.logging);
6
10
 
7
- if (args.includes("--help")) {
8
- console.log(`
9
- Description
10
- Compiles and starts the application.
11
+ module.exports = async function run(args: string[]) {
12
+ const parsed = parseArgs(args);
11
13
 
12
- Usage
13
- $ flink run <dir>
14
+ // Load .env files before anything else so all env vars are available at startup.
15
+ // NODE_ENV defaults to "production" when not explicitly set.
16
+ if (!process.env.NODE_ENV) {
17
+ process.env.NODE_ENV = "production";
18
+ }
14
19
 
15
- <dir> represents the directory of the Flink application.
16
- If no directory is provided, the current directory will be used.
17
-
18
- Options
19
- --entry Entry script for app, default "/src/index.ts"
20
- --help Displays this message
21
- --precompiled Will run a precompiled app, default false
22
- `);
20
+ const initLogger = FlinkLogFactory.createLogger("flink.init");
21
+ const { loaded, injected } = loadEnvFiles(parsed.dir, "production");
23
22
 
24
- process.exit(0);
23
+ if (loaded.length > 0) {
24
+ initLogger.info(`Loaded env files: ${loaded.join(", ")} (${injected} vars injected)`);
25
25
  }
26
26
 
27
- let dir = "./";
28
- if (args[0] && !args[0].startsWith("--")) {
29
- dir = args[0];
27
+ if (hasFlag(parsed, "help")) {
28
+ printHelp({
29
+ description: "Compiles and starts the application.",
30
+ usage: "$ flink run <dir>",
31
+ options: [
32
+ { name: "entry", description: 'Entry script for app, default "/src/index.ts"' },
33
+ { name: "help", description: "Displays this message" },
34
+ { name: "precompiled", description: "Will run a precompiled app, default false" },
35
+ ],
36
+ });
37
+ return;
30
38
  }
31
39
 
32
- let entry = "/src/index.ts";
33
- if (args.includes("--entry")) {
34
- entry = args[args.indexOf("--entry") + 1];
35
- entry = entry.startsWith("/") ? entry : "/" + entry;
36
- }
40
+ const entry = normalizeEntry(getOption(parsed, "entry", "/src/index.ts"));
37
41
 
38
- if (args.includes("--precompiled")) {
39
- if (args.includes("--entry")) {
42
+ if (hasFlag(parsed, "precompiled")) {
43
+ if (parsed.options.has("entry")) {
40
44
  console.warn("WARNING: --entry is ignored when using --precompiled");
41
45
  }
42
46
 
43
- // Collect extra arguments to pass through to the forked process
44
- const extraArgs = args.filter(arg =>
45
- arg !== "--precompiled" &&
46
- !arg.startsWith("--entry") &&
47
- arg !== args[args.indexOf("--entry") + 1]
48
- ).filter(arg => arg !== args[0] || args[0].startsWith("--"));
49
-
50
- const forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js", extraArgs);
51
-
52
- forkedProcess.on("exit", (code: any) => {
53
- process.exit(code);
47
+ forkApp({
48
+ dir: parsed.dir,
49
+ args,
50
+ cliFlags: ["precompiled", "entry"],
54
51
  });
55
52
  return;
56
53
  }
57
54
 
58
- await TypeScriptCompiler.clean(dir);
59
-
60
- const compiler = new TypeScriptCompiler(dir);
61
-
62
- if (!compiler.getPreEmitDiagnostics()) {
63
- process.exit(1);
64
- }
65
-
66
- await Promise.all([compiler.parseRepos(), compiler.parseHandlers(), compiler.parseJobs(), compiler.generateStartScript(entry)]);
67
-
68
- console.log(`Compilation done, took ${Date.now() - startTime}ms`);
69
-
70
- compiler.emit();
71
-
72
- // Collect extra arguments to pass through to the forked process
73
- const extraArgs = args.filter(arg =>
74
- !arg.startsWith("--entry") &&
75
- arg !== args[args.indexOf("--entry") + 1]
76
- ).filter(arg => arg !== args[0] || args[0].startsWith("--"));
77
-
78
- const forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js", extraArgs);
55
+ await compile({
56
+ dir: parsed.dir,
57
+ entry,
58
+ typeCheck: true,
59
+ });
79
60
 
80
- forkedProcess.on("exit", (code: any) => {
81
- process.exit(code);
61
+ forkApp({
62
+ dir: parsed.dir,
63
+ args,
64
+ cliFlags: ["entry"],
82
65
  });
83
66
  };
package/dist/bin/flink.js CHANGED
@@ -1,7 +1,43 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
14
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
3
39
  Object.defineProperty(exports, "__esModule", { value: true });
4
- var commands = ["build", "generate" /* 'generate' is alias for 'build' */, "run", "clean", "help"];
40
+ var commands = ["build", "generate" /* 'generate' is alias for 'build' */, "run", "dev", "clean", "help"];
5
41
  var argv = process.argv.slice(2);
6
42
  var argCommand = argv[0];
7
43
  if (!argCommand || argv[0] === "help") {
@@ -16,5 +52,28 @@ if (argCommand === "generate") {
16
52
  argCommand = "build";
17
53
  }
18
54
  var cmd = require("../cli/" + argCommand);
19
- cmd(argv.slice(1));
55
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
56
+ var error_1;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ _a.trys.push([0, 2, , 3]);
61
+ return [4 /*yield*/, cmd(argv.slice(1))];
62
+ case 1:
63
+ _a.sent();
64
+ return [3 /*break*/, 3];
65
+ case 2:
66
+ error_1 = _a.sent();
67
+ if (process.env.DEBUG === "true") {
68
+ console.error(error_1);
69
+ }
70
+ else {
71
+ console.error("Error: ".concat(error_1.message));
72
+ }
73
+ process.exit(1);
74
+ return [3 /*break*/, 3];
75
+ case 3: return [2 /*return*/];
76
+ }
77
+ });
78
+ }); })();
20
79
  exports.default = (function () { });
package/dist/cli/build.js CHANGED
@@ -36,40 +36,35 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
37
  }
38
38
  };
39
- var __importDefault = (this && this.__importDefault) || function (mod) {
40
- return (mod && mod.__esModule) ? mod : { "default": mod };
41
- };
42
39
  Object.defineProperty(exports, "__esModule", { value: true });
43
- var TypeScriptCompiler_1 = __importDefault(require("../src/TypeScriptCompiler"));
44
40
  var cli_utils_1 = require("./cli-utils");
45
- module.exports = function run(args) {
41
+ var FlinkLogFactory_1 = require("../src/FlinkLogFactory");
42
+ var loadFlinkConfig_1 = require("../src/utils/loadFlinkConfig");
43
+ // Load config BEFORE creating logger
44
+ var flinkConfig = (0, loadFlinkConfig_1.loadFlinkConfig)();
45
+ FlinkLogFactory_1.FlinkLogFactory.configure(flinkConfig === null || flinkConfig === void 0 ? void 0 : flinkConfig.logging);
46
+ module.exports = function build(args) {
46
47
  return __awaiter(this, void 0, void 0, function () {
47
- var startTime, dir, exclude, compiler;
48
+ var parsed;
48
49
  return __generator(this, function (_a) {
49
50
  switch (_a.label) {
50
51
  case 0:
51
- startTime = Date.now();
52
- if (args.includes("--help")) {
53
- console.log("\n Description\n Builds the application.\n Will generate intermediates files in .flink and compile/transpile\n javascript bundle in /dist folder\n\n Usage\n $ flink build <dir>\n\n <dir> represents the directory of the Flink application.\n If no directory is provided, the current directory will be used.\n \n Options \n --help Displays this message\n ");
54
- process.exit(0);
55
- }
56
- dir = "./";
57
- if (args[0] && !args[0].startsWith("--")) {
58
- dir = args[0];
52
+ parsed = (0, cli_utils_1.parseArgs)(args);
53
+ if ((0, cli_utils_1.hasFlag)(parsed, "help")) {
54
+ (0, cli_utils_1.printHelp)({
55
+ description: "Builds the application.\n Will generate intermediates files in .flink and compile/transpile\n javascript bundle in /dist folder",
56
+ usage: "$ flink build <dir>",
57
+ options: [{ name: "help", description: "Displays this message" }],
58
+ });
59
+ return [2 /*return*/];
59
60
  }
60
- exclude = (0, cli_utils_1.getOption)(args, "exclude", "/spec");
61
- return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
61
+ return [4 /*yield*/, (0, cli_utils_1.compile)({
62
+ dir: parsed.dir,
63
+ typeCheck: true,
64
+ timingLogs: true,
65
+ })];
62
66
  case 1:
63
67
  _a.sent();
64
- compiler = new TypeScriptCompiler_1.default(dir);
65
- if (!compiler.getPreEmitDiagnostics()) {
66
- process.exit(1);
67
- }
68
- return [4 /*yield*/, Promise.all([compiler.parseRepos(), compiler.parseHandlers(exclude.split(",")), compiler.parseJobs(), compiler.generateStartScript()])];
69
- case 2:
70
- _a.sent();
71
- console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
72
- compiler.emit();
73
68
  return [2 /*return*/];
74
69
  }
75
70
  });
package/dist/cli/clean.js CHANGED
@@ -41,21 +41,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  };
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  var TypeScriptCompiler_1 = __importDefault(require("../src/TypeScriptCompiler"));
44
- module.exports = function run(args) {
44
+ var cli_utils_1 = require("./cli-utils");
45
+ module.exports = function clean(args) {
45
46
  return __awaiter(this, void 0, void 0, function () {
46
- var dir, cleanedFolder;
47
+ var parsed, cleanedFolder;
47
48
  return __generator(this, function (_a) {
48
49
  switch (_a.label) {
49
50
  case 0:
50
- if (args.includes("--help")) {
51
- console.log("\n Description\n Removes all generated files.\n\n Usage\n $ flink clean <dir>\n\n <dir> represents the directory of the Flink application.\n If no directory is provided, the current directory will be used.\n \n Options\n --help Displays this message\n ");
52
- process.exit(0);
51
+ parsed = (0, cli_utils_1.parseArgs)(args);
52
+ if ((0, cli_utils_1.hasFlag)(parsed, "help")) {
53
+ (0, cli_utils_1.printHelp)({
54
+ description: "Removes all generated files.",
55
+ usage: "$ flink clean <dir>",
56
+ options: [{ name: "help", description: "Displays this message" }],
57
+ });
58
+ return [2 /*return*/];
53
59
  }
54
- dir = "./";
55
- if (args[0] && !args[0].startsWith("--")) {
56
- dir = args[0];
57
- }
58
- return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
60
+ return [4 /*yield*/, TypeScriptCompiler_1.default.clean(parsed.dir)];
59
61
  case 1:
60
62
  cleanedFolder = _a.sent();
61
63
  console.log("Cleaned directory ".concat(cleanedFolder));
@@ -1,3 +1,34 @@
1
- export declare function getOption(args: string[], name: string, defaultValue: string | boolean, opts?: {
2
- isBoolean?: boolean;
3
- }): string | boolean;
1
+ export interface ParsedArgs {
2
+ dir: string;
3
+ flags: Set<string>;
4
+ options: Map<string, string>;
5
+ }
6
+ export declare function parseArgs(args: string[]): ParsedArgs;
7
+ export declare function hasFlag(parsed: ParsedArgs, name: string): boolean;
8
+ export declare function getOption(parsed: ParsedArgs, name: string, defaultValue: string): string;
9
+ export declare function normalizeEntry(entry: string): string;
10
+ interface HelpOption {
11
+ name: string;
12
+ description: string;
13
+ }
14
+ interface HelpConfig {
15
+ description: string;
16
+ usage: string;
17
+ options: HelpOption[];
18
+ }
19
+ export declare function printHelp(config: HelpConfig): void;
20
+ export interface CompileOptions {
21
+ dir: string;
22
+ entry?: string;
23
+ typeCheck?: boolean;
24
+ timingLogs?: boolean;
25
+ }
26
+ export declare function compile(opts: CompileOptions): Promise<void>;
27
+ export interface ForkOptions {
28
+ dir: string;
29
+ args: string[];
30
+ cliFlags: string[];
31
+ stdio?: "inherit" | "pipe" | "ignore";
32
+ }
33
+ export declare function forkApp(opts: ForkOptions): ReturnType<typeof require>;
34
+ export {};
@@ -1,19 +1,200 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
2
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.parseArgs = parseArgs;
43
+ exports.hasFlag = hasFlag;
3
44
  exports.getOption = getOption;
4
- function getOption(args, name, defaultValue, opts) {
5
- if (opts === void 0) { opts = {}; }
6
- var option = "--".concat(name);
7
- if (args.includes(option)) {
8
- if (opts.isBoolean && args[args.indexOf(option) + 1] !== "false") {
9
- return true;
45
+ exports.normalizeEntry = normalizeEntry;
46
+ exports.printHelp = printHelp;
47
+ exports.compile = compile;
48
+ exports.forkApp = forkApp;
49
+ var TypeScriptCompiler_1 = __importDefault(require("../src/TypeScriptCompiler"));
50
+ function parseArgs(args) {
51
+ var flags = new Set();
52
+ var options = new Map();
53
+ var dir = "./";
54
+ var i = 0;
55
+ // First non-flag arg is the directory
56
+ if (args[0] && !args[0].startsWith("--")) {
57
+ dir = args[0];
58
+ i = 1;
59
+ }
60
+ while (i < args.length) {
61
+ var arg = args[i];
62
+ if (arg.startsWith("--")) {
63
+ var name = arg.slice(2);
64
+ var next = args[i + 1];
65
+ if (next && !next.startsWith("--")) {
66
+ options.set(name, next);
67
+ i += 2;
68
+ }
69
+ else {
70
+ flags.add(name);
71
+ i += 1;
72
+ }
73
+ }
74
+ else {
75
+ i += 1;
76
+ }
77
+ }
78
+ return { dir: dir, flags: flags, options: options };
79
+ }
80
+ function hasFlag(parsed, name) {
81
+ return parsed.flags.has(name);
82
+ }
83
+ function getOption(parsed, name, defaultValue) {
84
+ var _a;
85
+ return (_a = parsed.options.get(name)) !== null && _a !== void 0 ? _a : defaultValue;
86
+ }
87
+ function normalizeEntry(entry) {
88
+ return entry.startsWith("/") ? entry : "/" + entry;
89
+ }
90
+ function printHelp(config) {
91
+ var optionLines = config.options
92
+ .map(function (opt) { return " --".concat(opt.name.padEnd(14), " ").concat(opt.description); })
93
+ .join("\n");
94
+ console.log("\n Description\n ".concat(config.description, "\n\n Usage\n ").concat(config.usage, "\n\n <dir> represents the directory of the Flink application.\n If no directory is provided, the current directory will be used.\n\n Options\n").concat(optionLines, "\n"));
95
+ }
96
+ function compile(opts) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var dir, entry, _a, typeCheck, _b, timingLogs, start, time, stepStart, compiler;
99
+ return __generator(this, function (_c) {
100
+ switch (_c.label) {
101
+ case 0:
102
+ dir = opts.dir, entry = opts.entry, _a = opts.typeCheck, typeCheck = _a === void 0 ? true : _a, _b = opts.timingLogs, timingLogs = _b === void 0 ? false : _b;
103
+ start = timingLogs ? Date.now() : 0;
104
+ time = function (label, stepStart) {
105
+ if (timingLogs) {
106
+ console.log("\u23F1\uFE0F ".concat(label, ": ").concat(Date.now() - stepStart, "ms"));
107
+ }
108
+ };
109
+ return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
110
+ case 1:
111
+ _c.sent();
112
+ stepStart = Date.now();
113
+ compiler = new TypeScriptCompiler_1.default(dir);
114
+ time("Compiler initialization", stepStart);
115
+ stepStart = Date.now();
116
+ return [4 /*yield*/, compiler.parseRepos()];
117
+ case 2:
118
+ _c.sent();
119
+ return [4 /*yield*/, compiler.parseTools()];
120
+ case 3:
121
+ _c.sent();
122
+ return [4 /*yield*/, compiler.parseAgents()];
123
+ case 4:
124
+ _c.sent();
125
+ return [4 /*yield*/, compiler.parseJobs()];
126
+ case 5:
127
+ _c.sent();
128
+ return [4 /*yield*/, compiler.parseServices()];
129
+ case 6:
130
+ _c.sent();
131
+ return [4 /*yield*/, compiler.parseAllExtensionDirs()];
132
+ case 7:
133
+ _c.sent();
134
+ return [4 /*yield*/, compiler.parseHandlers()];
135
+ case 8:
136
+ _c.sent();
137
+ return [4 /*yield*/, compiler.generateStartScript(entry)];
138
+ case 9:
139
+ _c.sent();
140
+ return [4 /*yield*/, compiler.generateAllSchemas()];
141
+ case 10:
142
+ _c.sent();
143
+ return [4 /*yield*/, compiler.saveAllModifiedFiles()];
144
+ case 11:
145
+ _c.sent();
146
+ if (typeCheck) {
147
+ stepStart = Date.now();
148
+ if (!compiler.getPreEmitDiagnostics()) {
149
+ throw new Error("Type checking failed");
150
+ }
151
+ time("Type checking (getPreEmitDiagnostics)", stepStart);
152
+ }
153
+ stepStart = Date.now();
154
+ if (!(process.env.FLINK_USE_TSC === "true")) return [3 /*break*/, 12];
155
+ compiler.emitWithTsc();
156
+ return [3 /*break*/, 14];
157
+ case 12: return [4 /*yield*/, compiler.emit()];
158
+ case 13:
159
+ _c.sent();
160
+ _c.label = 14;
161
+ case 14:
162
+ time("Transpilation (".concat(process.env.FLINK_USE_TSC === "true" ? "tsc" : "swc", ")"), stepStart);
163
+ if (timingLogs) {
164
+ console.log("Compilation done in ".concat(Date.now() - start, "ms"));
165
+ }
166
+ return [2 /*return*/];
167
+ }
168
+ });
169
+ });
170
+ }
171
+ function forkApp(opts) {
172
+ var dir = opts.dir, args = opts.args, cliFlags = opts.cliFlags, stdio = opts.stdio;
173
+ // Filter out CLI-specific flags and their values from args passed to child process
174
+ var cliSet = new Set(cliFlags.map(function (f) { return "--".concat(f); }));
175
+ var extraArgs = [];
176
+ for (var i = 0; i < args.length; i++) {
177
+ if (cliSet.has(args[i])) {
178
+ // Skip this flag and its value (if the next arg is not a flag)
179
+ var next = args[i + 1];
180
+ if (next && !next.startsWith("--")) {
181
+ i++; // skip value too
182
+ }
183
+ continue;
10
184
  }
11
- var value = args[args.indexOf(option) + 1];
12
- if (!value || value.startsWith("--")) {
13
- console.log("WARN: Missing value for option", option);
14
- process.exit(1);
185
+ // Skip the dir argument (first non-flag arg)
186
+ if (i === 0 && !args[i].startsWith("--")) {
187
+ continue;
15
188
  }
16
- return value;
189
+ extraArgs.push(args[i]);
190
+ }
191
+ var forkOpts = {};
192
+ if (stdio) {
193
+ forkOpts.stdio = stdio;
17
194
  }
18
- return defaultValue;
195
+ var forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js", extraArgs, forkOpts);
196
+ forkedProcess.on("exit", function (code) {
197
+ process.exit(code);
198
+ });
199
+ return forkedProcess;
19
200
  }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};