composed-di 0.3.0 → 0.4.1-alpha.0

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 (81) hide show
  1. package/dist/cli/index.d.ts +3 -0
  2. package/dist/cli/index.d.ts.map +1 -0
  3. package/dist/cli/index.js +277 -0
  4. package/dist/cli/index.js.map +1 -0
  5. package/dist/compiler/analyzer.d.ts +37 -0
  6. package/dist/compiler/analyzer.d.ts.map +1 -0
  7. package/dist/compiler/analyzer.js +208 -0
  8. package/dist/compiler/analyzer.js.map +1 -0
  9. package/dist/compiler/callGraphWalker.d.ts +46 -0
  10. package/dist/compiler/callGraphWalker.d.ts.map +1 -0
  11. package/dist/compiler/callGraphWalker.js +211 -0
  12. package/dist/compiler/callGraphWalker.js.map +1 -0
  13. package/dist/compiler/codeGenerator.d.ts +36 -0
  14. package/dist/compiler/codeGenerator.d.ts.map +1 -0
  15. package/dist/compiler/codeGenerator.js +182 -0
  16. package/dist/compiler/codeGenerator.js.map +1 -0
  17. package/dist/compiler/dependencyResolver.d.ts +34 -0
  18. package/dist/compiler/dependencyResolver.d.ts.map +1 -0
  19. package/dist/compiler/dependencyResolver.js +147 -0
  20. package/dist/compiler/dependencyResolver.js.map +1 -0
  21. package/dist/compiler/index.d.ts +26 -0
  22. package/dist/compiler/index.d.ts.map +1 -0
  23. package/dist/compiler/index.js +78 -0
  24. package/dist/compiler/index.js.map +1 -0
  25. package/dist/compiler/types.d.ts +73 -0
  26. package/dist/compiler/types.d.ts.map +1 -0
  27. package/dist/compiler/types.js +6 -0
  28. package/dist/compiler/types.js.map +1 -0
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/openTelemetryTracer.d.ts +16 -0
  34. package/dist/openTelemetryTracer.d.ts.map +1 -0
  35. package/dist/openTelemetryTracer.js +56 -0
  36. package/dist/openTelemetryTracer.js.map +1 -0
  37. package/dist/serviceModule.d.ts +40 -1
  38. package/dist/serviceModule.d.ts.map +1 -1
  39. package/dist/serviceModule.js +107 -12
  40. package/dist/serviceModule.js.map +1 -1
  41. package/dist/traceable.d.ts +18 -0
  42. package/dist/traceable.d.ts.map +1 -0
  43. package/dist/traceable.js +32 -0
  44. package/dist/traceable.js.map +1 -0
  45. package/dist/tracer.d.ts +24 -0
  46. package/dist/tracer.d.ts.map +1 -0
  47. package/dist/tracer.js +27 -0
  48. package/dist/tracer.js.map +1 -0
  49. package/dist/tracing/consoleTracer.d.ts +12 -0
  50. package/dist/tracing/consoleTracer.d.ts.map +1 -0
  51. package/dist/tracing/consoleTracer.js +48 -0
  52. package/dist/tracing/consoleTracer.js.map +1 -0
  53. package/dist/tracing/noopTracer.d.ts +13 -0
  54. package/dist/tracing/noopTracer.d.ts.map +1 -0
  55. package/dist/tracing/noopTracer.js +18 -0
  56. package/dist/tracing/noopTracer.js.map +1 -0
  57. package/dist/tracing/otelTracer.d.ts +16 -0
  58. package/dist/tracing/otelTracer.d.ts.map +1 -0
  59. package/dist/tracing/otelTracer.js +56 -0
  60. package/dist/tracing/otelTracer.js.map +1 -0
  61. package/dist/tracing/tracer.d.ts +13 -0
  62. package/dist/tracing/tracer.d.ts.map +1 -0
  63. package/dist/tracing/tracer.js +3 -0
  64. package/dist/tracing/tracer.js.map +1 -0
  65. package/dist/tracing/xrayTracer.d.ts +15 -0
  66. package/dist/tracing/xrayTracer.d.ts.map +1 -0
  67. package/dist/tracing/xrayTracer.js +51 -0
  68. package/dist/tracing/xrayTracer.js.map +1 -0
  69. package/dist/tracing-test/otel-demo.d.ts +14 -0
  70. package/dist/tracing-test/otel-demo.d.ts.map +1 -0
  71. package/dist/tracing-test/otel-demo.js +213 -0
  72. package/dist/tracing-test/otel-demo.js.map +1 -0
  73. package/package.json +10 -1
  74. package/src/index.ts +1 -0
  75. package/src/serviceModule.ts +151 -15
  76. package/src/tracing/consoleTracer.ts +47 -0
  77. package/src/tracing/noopTracer.ts +15 -0
  78. package/src/tracing/otelTracer.ts +58 -0
  79. package/src/tracing/tracer.ts +12 -0
  80. package/src/tracing/xrayTracer.ts +50 -0
  81. package/src/tracing-test/otel-demo.ts +225 -0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,277 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ const commander_1 = require("commander");
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const compiler_1 = require("../compiler");
50
+ const program = new commander_1.Command();
51
+ program
52
+ .name('lazy-di')
53
+ .description('ServiceModule compiler for lazy-di')
54
+ .version('0.3.1');
55
+ program
56
+ .command('compile')
57
+ .description('Compile a ServiceModule from an entry point function')
58
+ .requiredOption('-e, --entry <file>', 'Entry point file path')
59
+ .requiredOption('-f, --function <name>', 'Entry point function name')
60
+ .option('-c, --config <file>', 'Path to tsconfig.json', './tsconfig.json')
61
+ .option('-o, --output <file>', 'Output file path for generated module')
62
+ .option('-m, --manifest <file>', 'Output file path for JSON manifest')
63
+ .option('-d, --diagnostics', 'Show diagnostics report')
64
+ .option('--quiet', 'Suppress output except errors')
65
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
66
+ try {
67
+ const { entry, function: functionName, config, output, manifest, diagnostics, quiet } = options;
68
+ // Resolve paths
69
+ const entryFile = path.resolve(process.cwd(), entry);
70
+ const tsconfigPath = path.resolve(process.cwd(), config);
71
+ // Check if files exist
72
+ if (!fs.existsSync(entryFile)) {
73
+ console.error(`Error: Entry point file not found: ${entryFile}`);
74
+ process.exit(1);
75
+ }
76
+ if (!fs.existsSync(tsconfigPath)) {
77
+ console.error(`Error: tsconfig.json not found: ${tsconfigPath}`);
78
+ process.exit(1);
79
+ }
80
+ if (!quiet) {
81
+ console.log('Compiling ServiceModule...');
82
+ console.log(` Entry point: ${entryFile}#${functionName}`);
83
+ console.log(` Config: ${tsconfigPath}`);
84
+ }
85
+ // Compile
86
+ const result = compiler_1.ServiceModuleCompiler.compile({
87
+ tsconfigPath,
88
+ entryPointFile: entryFile,
89
+ entryPointFunction: functionName,
90
+ });
91
+ // Show warnings
92
+ if (result.warnings.length > 0 && !quiet) {
93
+ console.warn('\nWarnings:');
94
+ for (const warning of result.warnings) {
95
+ console.warn(` - ${warning}`);
96
+ }
97
+ }
98
+ // Write output file
99
+ if (output) {
100
+ const outputPath = path.resolve(process.cwd(), output);
101
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
102
+ fs.writeFileSync(outputPath, result.generatedCode, 'utf-8');
103
+ if (!quiet) {
104
+ console.log(`\nGenerated module written to: ${outputPath}`);
105
+ }
106
+ }
107
+ else if (!quiet) {
108
+ console.log('\nGenerated code:');
109
+ console.log('─'.repeat(80));
110
+ console.log(result.generatedCode);
111
+ console.log('─'.repeat(80));
112
+ }
113
+ // Write manifest
114
+ if (manifest) {
115
+ const manifestPath = path.resolve(process.cwd(), manifest);
116
+ const manifestJson = compiler_1.ServiceModuleCompiler.generateManifest(result);
117
+ fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
118
+ fs.writeFileSync(manifestPath, manifestJson, 'utf-8');
119
+ if (!quiet) {
120
+ console.log(`Manifest written to: ${manifestPath}`);
121
+ }
122
+ }
123
+ // Show diagnostics
124
+ if (diagnostics) {
125
+ console.log('\n' + compiler_1.ServiceModuleCompiler.generateDiagnostics(result));
126
+ }
127
+ if (!quiet) {
128
+ console.log(`\n✓ Compilation successful! Found ${result.requiredFactories.length} required factories.`);
129
+ }
130
+ process.exit(0);
131
+ }
132
+ catch (error) {
133
+ console.error('Error during compilation:');
134
+ console.error(error instanceof Error ? error.message : String(error));
135
+ if (error instanceof Error && error.stack) {
136
+ console.error('\nStack trace:');
137
+ console.error(error.stack);
138
+ }
139
+ process.exit(1);
140
+ }
141
+ }));
142
+ program
143
+ .command('watch')
144
+ .description('Watch mode - recompile on file changes')
145
+ .requiredOption('-e, --entry <file>', 'Entry point file path')
146
+ .requiredOption('-f, --function <name>', 'Entry point function name')
147
+ .option('-c, --config <file>', 'Path to tsconfig.json', './tsconfig.json')
148
+ .option('-o, --output <file>', 'Output file path for generated module')
149
+ .option('-m, --manifest <file>', 'Output file path for JSON manifest')
150
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
151
+ try {
152
+ const { entry, function: functionName, config, output, manifest } = options;
153
+ // Resolve paths
154
+ const entryFile = path.resolve(process.cwd(), entry);
155
+ const tsconfigPath = path.resolve(process.cwd(), config);
156
+ // Check if files exist
157
+ if (!fs.existsSync(entryFile)) {
158
+ console.error(`Error: Entry point file not found: ${entryFile}`);
159
+ process.exit(1);
160
+ }
161
+ if (!fs.existsSync(tsconfigPath)) {
162
+ console.error(`Error: tsconfig.json not found: ${tsconfigPath}`);
163
+ process.exit(1);
164
+ }
165
+ console.log('Starting watch mode...');
166
+ console.log(` Entry point: ${entryFile}#${functionName}`);
167
+ console.log(` Config: ${tsconfigPath}`);
168
+ console.log('\nWatching for changes. Press Ctrl+C to stop.\n');
169
+ let compileTimeout = null;
170
+ const compile = () => {
171
+ try {
172
+ const startTime = Date.now();
173
+ console.log(`[${new Date().toLocaleTimeString()}] Compiling...`);
174
+ const result = compiler_1.ServiceModuleCompiler.compile({
175
+ tsconfigPath,
176
+ entryPointFile: entryFile,
177
+ entryPointFunction: functionName,
178
+ });
179
+ // Show warnings
180
+ if (result.warnings.length > 0) {
181
+ console.warn('Warnings:');
182
+ for (const warning of result.warnings) {
183
+ console.warn(` - ${warning}`);
184
+ }
185
+ }
186
+ // Write output file
187
+ if (output) {
188
+ const outputPath = path.resolve(process.cwd(), output);
189
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
190
+ fs.writeFileSync(outputPath, result.generatedCode, 'utf-8');
191
+ }
192
+ // Write manifest
193
+ if (manifest) {
194
+ const manifestPath = path.resolve(process.cwd(), manifest);
195
+ const manifestJson = compiler_1.ServiceModuleCompiler.generateManifest(result);
196
+ fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
197
+ fs.writeFileSync(manifestPath, manifestJson, 'utf-8');
198
+ }
199
+ const duration = Date.now() - startTime;
200
+ console.log(`[${new Date().toLocaleTimeString()}] ✓ Compiled successfully in ${duration}ms (${result.requiredFactories.length} factories)\n`);
201
+ }
202
+ catch (error) {
203
+ console.error(`[${new Date().toLocaleTimeString()}] ✗ Compilation failed:`);
204
+ console.error(error instanceof Error ? error.message : String(error));
205
+ console.log('');
206
+ }
207
+ };
208
+ // Initial compile
209
+ compile();
210
+ // Watch for changes
211
+ const watchDir = path.dirname(entryFile);
212
+ fs.watch(watchDir, { recursive: true }, (eventType, filename) => {
213
+ if (filename && filename.endsWith('.ts')) {
214
+ // Debounce to avoid multiple compilations
215
+ if (compileTimeout) {
216
+ clearTimeout(compileTimeout);
217
+ }
218
+ compileTimeout = setTimeout(() => {
219
+ compile();
220
+ }, 100);
221
+ }
222
+ });
223
+ // Keep process running
224
+ process.on('SIGINT', () => {
225
+ console.log('\nStopping watch mode...');
226
+ process.exit(0);
227
+ });
228
+ }
229
+ catch (error) {
230
+ console.error('Error setting up watch mode:');
231
+ console.error(error instanceof Error ? error.message : String(error));
232
+ process.exit(1);
233
+ }
234
+ }));
235
+ program
236
+ .command('analyze')
237
+ .description('Analyze a project without generating code')
238
+ .option('-c, --config <file>', 'Path to tsconfig.json', './tsconfig.json')
239
+ .action((options) => __awaiter(void 0, void 0, void 0, function* () {
240
+ try {
241
+ const { config } = options;
242
+ const tsconfigPath = path.resolve(process.cwd(), config);
243
+ if (!fs.existsSync(tsconfigPath)) {
244
+ console.error(`Error: tsconfig.json not found: ${tsconfigPath}`);
245
+ process.exit(1);
246
+ }
247
+ console.log('Analyzing project...');
248
+ console.log(` Config: ${tsconfigPath}\n`);
249
+ const { ProjectAnalyzer } = yield Promise.resolve().then(() => __importStar(require('../compiler/analyzer')));
250
+ const analyzer = new ProjectAnalyzer(tsconfigPath);
251
+ const analysis = analyzer.analyze();
252
+ console.log('Analysis Results:');
253
+ console.log('─'.repeat(80));
254
+ console.log(`\nServiceKeys found: ${analysis.serviceKeys.size}`);
255
+ for (const [name, key] of analysis.serviceKeys) {
256
+ const type = key.isSelector ? 'ServiceSelectorKey' : 'ServiceKey';
257
+ console.log(` - ${name} (${type}: ${key.keyName})`);
258
+ }
259
+ console.log(`\nServiceFactories found: ${analysis.serviceFactories.size}`);
260
+ for (const [name, factory] of analysis.serviceFactories) {
261
+ const deps = factory.dependsOn.length > 0
262
+ ? ` [depends on: ${factory.dependsOn.join(', ')}]`
263
+ : '';
264
+ console.log(` - ${name} (${factory.factoryType}, provides: ${factory.provides})${deps}`);
265
+ }
266
+ console.log('\n' + '─'.repeat(80));
267
+ console.log(`\n✓ Analysis complete!`);
268
+ process.exit(0);
269
+ }
270
+ catch (error) {
271
+ console.error('Error during analysis:');
272
+ console.error(error instanceof Error ? error.message : String(error));
273
+ process.exit(1);
274
+ }
275
+ }));
276
+ program.parse(process.argv);
277
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,uCAAyB;AACzB,2CAA6B;AAC7B,0CAAoD;AAEpD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,oCAAoC,CAAC;KACjD,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,sDAAsD,CAAC;KACnE,cAAc,CAAC,oBAAoB,EAAE,uBAAuB,CAAC;KAC7D,cAAc,CAAC,uBAAuB,EAAE,2BAA2B,CAAC;KACpE,MAAM,CACL,qBAAq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O,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gBAClD,CAAC,CAAC,EAAE,CAAC;YACP,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,KAAK,OAAO,CAAC,WAAW,eAAe,OAAO,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;QAC5F,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAA,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import * as ts from 'typescript';
2
+ import { AnalysisResult } from './types';
3
+ /**
4
+ * Analyzes a TypeScript project to collect all ServiceKey and ServiceFactory declarations
5
+ */
6
+ export declare class ProjectAnalyzer {
7
+ private program;
8
+ private checker;
9
+ private serviceKeys;
10
+ private serviceFactories;
11
+ constructor(tsconfigPath: string);
12
+ /**
13
+ * Analyzes all source files in the program
14
+ */
15
+ analyze(): AnalysisResult;
16
+ /**
17
+ * Visits a source file and collects ServiceKey and ServiceFactory declarations
18
+ */
19
+ private visitSourceFile;
20
+ /**
21
+ * Checks if a variable declaration is a ServiceKey or ServiceSelectorKey
22
+ */
23
+ private checkServiceKeyDeclaration;
24
+ /**
25
+ * Checks if a variable declaration is a ServiceFactory
26
+ */
27
+ private checkServiceFactoryDeclaration;
28
+ /**
29
+ * Gets the TypeScript program
30
+ */
31
+ getProgram(): ts.Program;
32
+ /**
33
+ * Gets the TypeScript type checker
34
+ */
35
+ getTypeChecker(): ts.TypeChecker;
36
+ }
37
+ //# sourceMappingURL=analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../../src/compiler/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAGL,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,WAAW,CAA0C;IAC7D,OAAO,CAAC,gBAAgB,CAA8C;gBAE1D,YAAY,EAAE,MAAM;IAiBhC;;OAEG;IACI,OAAO,IAAI,cAAc;IAwBhC;;OAEG;IACH,OAAO,CAAC,eAAe;IAgBvB;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAqDlC;;OAEG;IACH,OAAO,CAAC,8BAA8B;IAoEtC;;OAEG;IACI,UAAU,IAAI,EAAE,CAAC,OAAO;IAI/B;;OAEG;IACI,cAAc,IAAI,EAAE,CAAC,WAAW;CAGxC"}
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ProjectAnalyzer = void 0;
37
+ const ts = __importStar(require("typescript"));
38
+ const path = __importStar(require("path"));
39
+ /**
40
+ * Analyzes a TypeScript project to collect all ServiceKey and ServiceFactory declarations
41
+ */
42
+ class ProjectAnalyzer {
43
+ constructor(tsconfigPath) {
44
+ this.serviceKeys = new Map();
45
+ this.serviceFactories = new Map();
46
+ // Load the tsconfig.json
47
+ const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
48
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath));
49
+ // Create a TypeScript program
50
+ this.program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options);
51
+ this.checker = this.program.getTypeChecker();
52
+ }
53
+ /**
54
+ * Analyzes all source files in the program
55
+ */
56
+ analyze() {
57
+ // Process each source file
58
+ for (const sourceFile of this.program.getSourceFiles()) {
59
+ // Skip declaration files and node_modules
60
+ if (sourceFile.isDeclarationFile || sourceFile.fileName.includes('node_modules')) {
61
+ continue;
62
+ }
63
+ this.visitSourceFile(sourceFile);
64
+ }
65
+ // Build key-to-factory map
66
+ const keyToFactory = new Map();
67
+ for (const [factoryName, factory] of this.serviceFactories) {
68
+ keyToFactory.set(factory.provides, factoryName);
69
+ }
70
+ return {
71
+ serviceKeys: this.serviceKeys,
72
+ serviceFactories: this.serviceFactories,
73
+ keyToFactory,
74
+ };
75
+ }
76
+ /**
77
+ * Visits a source file and collects ServiceKey and ServiceFactory declarations
78
+ */
79
+ visitSourceFile(sourceFile) {
80
+ const visit = (node) => {
81
+ // Look for variable declarations
82
+ if (ts.isVariableStatement(node)) {
83
+ for (const declaration of node.declarationList.declarations) {
84
+ this.checkServiceKeyDeclaration(declaration, sourceFile);
85
+ this.checkServiceFactoryDeclaration(declaration, sourceFile);
86
+ }
87
+ }
88
+ ts.forEachChild(node, visit);
89
+ };
90
+ visit(sourceFile);
91
+ }
92
+ /**
93
+ * Checks if a variable declaration is a ServiceKey or ServiceSelectorKey
94
+ */
95
+ checkServiceKeyDeclaration(declaration, sourceFile) {
96
+ var _a, _b;
97
+ if (!declaration.initializer || !ts.isNewExpression(declaration.initializer)) {
98
+ return;
99
+ }
100
+ const newExpr = declaration.initializer;
101
+ const typeName = newExpr.expression.getText(sourceFile);
102
+ // Check if it's a ServiceKey or ServiceSelectorKey
103
+ if (typeName !== 'ServiceKey' && typeName !== 'ServiceSelectorKey') {
104
+ return;
105
+ }
106
+ const varName = declaration.name.getText(sourceFile);
107
+ const isSelector = typeName === 'ServiceSelectorKey';
108
+ if (isSelector) {
109
+ // ServiceSelectorKey([key1, key2, ...])
110
+ const arrayArg = (_a = newExpr.arguments) === null || _a === void 0 ? void 0 : _a[0];
111
+ const selectorValues = [];
112
+ if (arrayArg && ts.isArrayLiteralExpression(arrayArg)) {
113
+ for (const element of arrayArg.elements) {
114
+ selectorValues.push(element.getText(sourceFile));
115
+ }
116
+ }
117
+ this.serviceKeys.set(varName, {
118
+ name: varName,
119
+ keyName: `ServiceSelector[${selectorValues.join(', ')}]`,
120
+ filePath: sourceFile.fileName,
121
+ isSelector: true,
122
+ selectorValues,
123
+ });
124
+ }
125
+ else {
126
+ // ServiceKey('KeyName')
127
+ const keyNameArg = (_b = newExpr.arguments) === null || _b === void 0 ? void 0 : _b[0];
128
+ const keyName = keyNameArg && ts.isStringLiteral(keyNameArg)
129
+ ? keyNameArg.text
130
+ : varName;
131
+ this.serviceKeys.set(varName, {
132
+ name: varName,
133
+ keyName,
134
+ filePath: sourceFile.fileName,
135
+ isSelector: false,
136
+ });
137
+ }
138
+ }
139
+ /**
140
+ * Checks if a variable declaration is a ServiceFactory
141
+ */
142
+ checkServiceFactoryDeclaration(declaration, sourceFile) {
143
+ if (!declaration.initializer || !ts.isCallExpression(declaration.initializer)) {
144
+ return;
145
+ }
146
+ const callExpr = declaration.initializer;
147
+ const callText = callExpr.expression.getText(sourceFile);
148
+ // Check if it's ServiceFactory.singleton or ServiceFactory.oneShot
149
+ if (callText !== 'ServiceFactory.singleton' &&
150
+ callText !== 'ServiceFactory.oneShot') {
151
+ return;
152
+ }
153
+ const factoryType = callText.endsWith('singleton') ? 'singleton' : 'oneShot';
154
+ const varName = declaration.name.getText(sourceFile);
155
+ // Extract the config object argument
156
+ const configArg = callExpr.arguments[0];
157
+ if (!configArg || !ts.isObjectLiteralExpression(configArg)) {
158
+ return;
159
+ }
160
+ let provides;
161
+ const dependsOn = [];
162
+ // Parse the config object
163
+ for (const prop of configArg.properties) {
164
+ if (!ts.isPropertyAssignment(prop))
165
+ continue;
166
+ const propName = prop.name.getText(sourceFile);
167
+ if (propName === 'provides') {
168
+ provides = prop.initializer.getText(sourceFile);
169
+ }
170
+ else if (propName === 'dependsOn') {
171
+ let arrayExpr = prop.initializer;
172
+ // Handle 'as const' assertion: [key1, key2] as const
173
+ if (ts.isAsExpression(arrayExpr)) {
174
+ arrayExpr = arrayExpr.expression;
175
+ }
176
+ if (ts.isArrayLiteralExpression(arrayExpr)) {
177
+ for (const element of arrayExpr.elements) {
178
+ dependsOn.push(element.getText(sourceFile));
179
+ }
180
+ }
181
+ }
182
+ }
183
+ if (!provides) {
184
+ return;
185
+ }
186
+ this.serviceFactories.set(varName, {
187
+ name: varName,
188
+ provides,
189
+ dependsOn,
190
+ filePath: sourceFile.fileName,
191
+ factoryType,
192
+ });
193
+ }
194
+ /**
195
+ * Gets the TypeScript program
196
+ */
197
+ getProgram() {
198
+ return this.program;
199
+ }
200
+ /**
201
+ * Gets the TypeScript type checker
202
+ */
203
+ getTypeChecker() {
204
+ return this.checker;
205
+ }
206
+ }
207
+ exports.ProjectAnalyzer = ProjectAnalyzer;
208
+ //# sourceMappingURL=analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../src/compiler/analyzer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,2CAA6B;AAO7B;;GAEG;AACH,MAAa,eAAe;IAM1B,YAAY,YAAoB;QAHxB,gBAAW,GAAG,IAAI,GAAG,EAA+B,CAAC;QACrD,qBAAgB,GAAG,IAAI,GAAG,EAAmC,CAAC;QAGpE,yBAAyB;QACzB,MAAM,UAAU,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACpE,MAAM,YAAY,GAAG,EAAE,CAAC,0BAA0B,CAChD,UAAU,CAAC,MAAM,EACjB,EAAE,CAAC,GAAG,EACN,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAC3B,CAAC;QAEF,8BAA8B;QAC9B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC,aAAa,CAC7B,YAAY,CAAC,SAAS,EACtB,YAAY,CAAC,OAAO,CACrB,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;IAC/C,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,2BAA2B;QAC3B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;YACvD,0CAA0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oB,CAAC,IAAI,CAAC;gBAAE,SAAS;YAE7C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAE/C,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;gBAC5B,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAClD,CAAC;iBAAM,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;gBACpC,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC;gBAEjC,qDAAqD;gBACrD,IAAI,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;oBACjC,SAAS,GAAG,SAAS,CAAC,UAAU,CAAC;gBACnC,CAAC;gBAED,IAAI,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAC;oBAC3C,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;wBACzC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;oBAC9C,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO;QACT,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE;YACjC,IAAI,EAAE,OAAO;YACb,QAAQ;YACR,SAAS;YACT,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,cAAc;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAjND,0CAiNC"}
@@ -0,0 +1,46 @@
1
+ import * as ts from 'typescript';
2
+ import { AnalysisResult } from './types';
3
+ /**
4
+ * Walks the call graph starting from an entry point function
5
+ * and collects all ServiceKey usages via module.get() and module.getOrNull()
6
+ */
7
+ export declare class CallGraphWalker {
8
+ private program;
9
+ private checker;
10
+ private analysis;
11
+ private visitedFunctions;
12
+ private collectedKeys;
13
+ constructor(program: ts.Program, checker: ts.TypeChecker, analysis: AnalysisResult);
14
+ /**
15
+ * Starts walking from the entry point function
16
+ * @param entryPointFile Path to the file containing the entry point
17
+ * @param entryPointFunction Name of the entry point function
18
+ * @returns Set of ServiceKey variable names used in the call graph
19
+ */
20
+ walk(entryPointFile: string, entryPointFunction: string): Set<string>;
21
+ /**
22
+ * Finds a function declaration by name in a source file
23
+ */
24
+ private findFunction;
25
+ /**
26
+ * Visits a function and collects all service key usages
27
+ */
28
+ private visitFunction;
29
+ /**
30
+ * Checks if a call expression is module.get() or module.getOrNull()
31
+ */
32
+ private checkServiceModuleCall;
33
+ /**
34
+ * Checks if a call expression is a function call and follows it
35
+ */
36
+ private checkFunctionCall;
37
+ /**
38
+ * Gets a unique identifier for a function
39
+ */
40
+ private getFunctionId;
41
+ /**
42
+ * Gets all collected ServiceKey names
43
+ */
44
+ getCollectedKeys(): Set<string>;
45
+ }
46
+ //# sourceMappingURL=callGraphWalker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callGraphWalker.d.ts","sourceRoot":"","sources":["../../src/compiler/callGraphWalker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,aAAa,CAAqB;gBAGxC,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,QAAQ,EAAE,cAAc;IAO1B;;;;;OAKG;IACI,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAoB5E;;OAEG;IACH,OAAO,CAAC,YAAY;IAuCpB;;OAEG;IACH,OAAO,CAAC,aAAa;IA2BrB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAgD9B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA2CzB;;OAEG;IACH,OAAO,CAAC,aAAa;IAQrB;;OAEG;IACI,gBAAgB,IAAI,GAAG,CAAC,MAAM,CAAC;CAGvC"}