@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,366 @@
|
|
|
1
|
+
import { TypeScriptTokenizer } from "../src/schema-extraction/TypeScriptTokenizer";
|
|
2
|
+
|
|
3
|
+
describe("TypeScriptTokenizer", () => {
|
|
4
|
+
describe("findMatchingBracket", () => {
|
|
5
|
+
describe("Basic bracket matching", () => {
|
|
6
|
+
it("should find matching closing brace for simple object", () => {
|
|
7
|
+
const code = "{ foo: string }";
|
|
8
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
9
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
10
|
+
expect(endPos).toBe(14);
|
|
11
|
+
expect(code[endPos]).toBe("}");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should find matching closing bracket for array", () => {
|
|
15
|
+
const code = "[1, 2, 3]";
|
|
16
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
17
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "[");
|
|
18
|
+
expect(endPos).toBe(8);
|
|
19
|
+
expect(code[endPos]).toBe("]");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should find matching closing paren", () => {
|
|
23
|
+
const code = "(foo, bar)";
|
|
24
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
25
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "(");
|
|
26
|
+
expect(endPos).toBe(9);
|
|
27
|
+
expect(code[endPos]).toBe(")");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should find matching closing angle bracket", () => {
|
|
31
|
+
const code = "<T extends string>";
|
|
32
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
33
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "<");
|
|
34
|
+
expect(endPos).toBe(17);
|
|
35
|
+
expect(code[endPos]).toBe(">");
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("Nested brackets", () => {
|
|
40
|
+
it("should handle nested objects", () => {
|
|
41
|
+
const code = "{ outer: { inner: string } }";
|
|
42
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
43
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
44
|
+
expect(endPos).toBe(27);
|
|
45
|
+
expect(code[endPos]).toBe("}");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should handle deeply nested objects", () => {
|
|
49
|
+
const code = "{ a: { b: { c: { d: string } } } }";
|
|
50
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
51
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
52
|
+
expect(endPos).toBe(33);
|
|
53
|
+
expect(code[endPos]).toBe("}");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should handle nested generics", () => {
|
|
57
|
+
const code = "<Promise<Array<string>>>";
|
|
58
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
59
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "<");
|
|
60
|
+
expect(endPos).toBe(23);
|
|
61
|
+
expect(code[endPos]).toBe(">");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should handle mixed bracket types", () => {
|
|
65
|
+
const code = "{ arr: [1, 2], fn: () => {} }";
|
|
66
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
67
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
68
|
+
expect(endPos).toBe(28);
|
|
69
|
+
expect(code[endPos]).toBe("}");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("String literals", () => {
|
|
74
|
+
it("should ignore brackets inside double-quoted strings", () => {
|
|
75
|
+
const code = '{ pattern: "{user:id}" }';
|
|
76
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
77
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
78
|
+
expect(endPos).toBe(23);
|
|
79
|
+
expect(code[endPos]).toBe("}");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should ignore brackets inside single-quoted strings", () => {
|
|
83
|
+
const code = "{ pattern: '{user:id}' }";
|
|
84
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
85
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
86
|
+
expect(endPos).toBe(23);
|
|
87
|
+
expect(code[endPos]).toBe("}");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should ignore brackets inside backtick strings", () => {
|
|
91
|
+
const code = "{ pattern: `{user:id}` }";
|
|
92
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
93
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
94
|
+
expect(endPos).toBe(23);
|
|
95
|
+
expect(code[endPos]).toBe("}");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should ignore angle brackets inside strings", () => {
|
|
99
|
+
const code = '{ regex: "/test>/" }';
|
|
100
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
101
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
102
|
+
expect(endPos).toBe(19);
|
|
103
|
+
expect(code[endPos]).toBe("}");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should ignore square brackets inside strings", () => {
|
|
107
|
+
const code = '{ pattern: "[0-9]+" }';
|
|
108
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
109
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
110
|
+
expect(endPos).toBe(20);
|
|
111
|
+
expect(code[endPos]).toBe("}");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should handle multiple string literals with brackets", () => {
|
|
115
|
+
const code = '{ a: "{foo}", b: "[bar]", c: "<baz>" }';
|
|
116
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
117
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
118
|
+
expect(endPos).toBe(37);
|
|
119
|
+
expect(code[endPos]).toBe("}");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("Escape sequences", () => {
|
|
124
|
+
it("should handle escaped quotes", () => {
|
|
125
|
+
const code = '{ msg: "He said \\"hi\\"" }';
|
|
126
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
127
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
128
|
+
expect(endPos).toBe(24);
|
|
129
|
+
expect(code[endPos]).toBe("}");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should handle escaped backslashes", () => {
|
|
133
|
+
const code = '{ path: "C:\\\\Users\\\\test" }';
|
|
134
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
135
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
136
|
+
expect(endPos).toBe(26);
|
|
137
|
+
expect(code[endPos]).toBe("}");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should handle escaped brackets inside strings", () => {
|
|
141
|
+
const code = '{ pattern: "\\{escaped\\}" }';
|
|
142
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
143
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
144
|
+
expect(endPos).toBe(25);
|
|
145
|
+
expect(code[endPos]).toBe("}");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("should handle complex escape sequences", () => {
|
|
149
|
+
const code = '{ regex: "\\n\\t\\r\\{\\}\\[\\]" }';
|
|
150
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
151
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
152
|
+
expect(endPos).toBe(26);
|
|
153
|
+
expect(code[endPos]).toBe("}");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("Line comments", () => {
|
|
158
|
+
it("should ignore brackets in line comments", () => {
|
|
159
|
+
const code = "{ // This { is a comment\n foo: string }";
|
|
160
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
161
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
162
|
+
expect(endPos).toBe(39);
|
|
163
|
+
expect(code[endPos]).toBe("}");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("should handle multiple line comments", () => {
|
|
167
|
+
const code = `{
|
|
168
|
+
// Comment with {
|
|
169
|
+
foo: string, // Another { comment
|
|
170
|
+
bar: number
|
|
171
|
+
}`;
|
|
172
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
173
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
174
|
+
expect(code[endPos]).toBe("}");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("should handle line comment at end of file", () => {
|
|
178
|
+
const code = "{ foo: string } // { comment";
|
|
179
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
180
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
181
|
+
expect(endPos).toBe(14);
|
|
182
|
+
expect(code[endPos]).toBe("}");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("Block comments", () => {
|
|
187
|
+
it("should ignore brackets in block comments", () => {
|
|
188
|
+
const code = "{ /* This { is a comment */ foo: string }";
|
|
189
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
190
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
191
|
+
expect(endPos).toBe(40);
|
|
192
|
+
expect(code[endPos]).toBe("}");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should handle multi-line block comments", () => {
|
|
196
|
+
const code = `{
|
|
197
|
+
/*
|
|
198
|
+
* Comment with {
|
|
199
|
+
* More brackets [
|
|
200
|
+
*/
|
|
201
|
+
foo: string
|
|
202
|
+
}`;
|
|
203
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
204
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
205
|
+
expect(code[endPos]).toBe("}");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("should handle multiple block comments", () => {
|
|
209
|
+
const code = "{ /* { */ foo: string, /* [ */ bar: number }";
|
|
210
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
211
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
212
|
+
expect(endPos).toBe(43);
|
|
213
|
+
expect(code[endPos]).toBe("}");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should handle nested block comment syntax", () => {
|
|
217
|
+
const code = "{ /* /* not nested in JS */ foo: string }";
|
|
218
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
219
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
220
|
+
expect(endPos).toBe(40);
|
|
221
|
+
expect(code[endPos]).toBe("}");
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("Complex real-world cases", () => {
|
|
226
|
+
it("should handle Google Docs tool schema case", () => {
|
|
227
|
+
const code = `interface Tool {
|
|
228
|
+
metadata?: {
|
|
229
|
+
title: string;
|
|
230
|
+
description: string;
|
|
231
|
+
};
|
|
232
|
+
execute: () => Promise<Result>;
|
|
233
|
+
}`;
|
|
234
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
235
|
+
const startPos = code.indexOf("{");
|
|
236
|
+
const endPos = tokenizer.findMatchingBracketAt(startPos, "{");
|
|
237
|
+
expect(code[endPos]).toBe("}");
|
|
238
|
+
expect(code.substring(startPos, endPos + 1)).toContain("metadata");
|
|
239
|
+
expect(code.substring(startPos, endPos + 1)).toContain("execute");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should handle handler with string patterns", () => {
|
|
243
|
+
const code = `{
|
|
244
|
+
route: "/api/{id}/items",
|
|
245
|
+
validation: {
|
|
246
|
+
pattern: "[0-9]+",
|
|
247
|
+
format: "<xml>"
|
|
248
|
+
}
|
|
249
|
+
}`;
|
|
250
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
251
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
252
|
+
expect(code[endPos]).toBe("}");
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should handle interface with comments and strings", () => {
|
|
256
|
+
const code = `{
|
|
257
|
+
// Route pattern: /api/{id}
|
|
258
|
+
path: "/users/{id}",
|
|
259
|
+
/* Validation rules {
|
|
260
|
+
complex: true
|
|
261
|
+
} */
|
|
262
|
+
validate: true
|
|
263
|
+
}`;
|
|
264
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
265
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
266
|
+
expect(code[endPos]).toBe("}");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("should handle generic type with nested brackets and strings", () => {
|
|
270
|
+
const code = `FlinkTool<Context, { pattern: "{id}" }, ToolResult<Output>>`;
|
|
271
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
272
|
+
const startPos = code.indexOf("<");
|
|
273
|
+
const endPos = tokenizer.findMatchingBracketAt(startPos, "<");
|
|
274
|
+
expect(endPos).toBe(code.length - 1);
|
|
275
|
+
expect(code[endPos]).toBe(">");
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("Edge cases", () => {
|
|
280
|
+
it("should return -1 for unmatched opening bracket", () => {
|
|
281
|
+
const code = "{ foo: string";
|
|
282
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
283
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
284
|
+
expect(endPos).toBe(-1);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("should handle empty braces", () => {
|
|
288
|
+
const code = "{}";
|
|
289
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
290
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
291
|
+
expect(endPos).toBe(1);
|
|
292
|
+
expect(code[endPos]).toBe("}");
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("should handle whitespace-only content", () => {
|
|
296
|
+
const code = "{ \n \t }";
|
|
297
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
298
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
299
|
+
expect(code[endPos]).toBe("}");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("should handle unclosed string literal gracefully", () => {
|
|
303
|
+
const code = '{ msg: "unclosed string }';
|
|
304
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
305
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
306
|
+
// Unclosed string extends to end, so no matching brace found
|
|
307
|
+
expect(endPos).toBe(-1);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("should handle unclosed block comment gracefully", () => {
|
|
311
|
+
const code = "{ /* unclosed comment }";
|
|
312
|
+
const tokenizer = new TypeScriptTokenizer(code);
|
|
313
|
+
const endPos = tokenizer.findMatchingBracketAt(0, "{");
|
|
314
|
+
// Unclosed comment extends to end, so no matching brace found
|
|
315
|
+
expect(endPos).toBe(-1);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("getNextToken", () => {
|
|
320
|
+
it("should tokenize string literals", () => {
|
|
321
|
+
const tokenizer = new TypeScriptTokenizer('"hello"');
|
|
322
|
+
const token = tokenizer.getNextToken(0);
|
|
323
|
+
expect(token.type).toBe("string");
|
|
324
|
+
expect(token.value).toBe('"hello"');
|
|
325
|
+
expect(token.startPos).toBe(0);
|
|
326
|
+
expect(token.endPos).toBe(7);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("should tokenize line comments", () => {
|
|
330
|
+
const tokenizer = new TypeScriptTokenizer("// comment\n");
|
|
331
|
+
const token = tokenizer.getNextToken(0);
|
|
332
|
+
expect(token.type).toBe("comment");
|
|
333
|
+
expect(token.value).toBe("// comment\n");
|
|
334
|
+
expect(token.startPos).toBe(0);
|
|
335
|
+
expect(token.endPos).toBe(11);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("should tokenize block comments", () => {
|
|
339
|
+
const tokenizer = new TypeScriptTokenizer("/* comment */");
|
|
340
|
+
const token = tokenizer.getNextToken(0);
|
|
341
|
+
expect(token.type).toBe("comment");
|
|
342
|
+
expect(token.value).toBe("/* comment */");
|
|
343
|
+
expect(token.startPos).toBe(0);
|
|
344
|
+
expect(token.endPos).toBe(13);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("should tokenize bracket characters", () => {
|
|
348
|
+
const tokenizer = new TypeScriptTokenizer("{");
|
|
349
|
+
const token = tokenizer.getNextToken(0);
|
|
350
|
+
expect(token.type).toBe("bracket");
|
|
351
|
+
expect(token.value).toBe("{");
|
|
352
|
+
expect(token.startPos).toBe(0);
|
|
353
|
+
expect(token.endPos).toBe(1);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("should tokenize other characters", () => {
|
|
357
|
+
const tokenizer = new TypeScriptTokenizer("x");
|
|
358
|
+
const token = tokenizer.getNextToken(0);
|
|
359
|
+
expect(token.type).toBe("char");
|
|
360
|
+
expect(token.value).toBe("x");
|
|
361
|
+
expect(token.startPos).toBe(0);
|
|
362
|
+
expect(token.endPos).toBe(1);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
});
|