@mnemonica/tactica 0.1.0 → 0.1.2
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/README.md +340 -262
- package/lib/analyzer.d.ts +195 -7
- package/lib/analyzer.js +1584 -19
- package/lib/analyzer.js.map +1 -1
- package/lib/cli.d.ts +6 -0
- package/lib/cli.js +202 -6
- package/lib/cli.js.map +1 -1
- package/lib/generator.d.ts +41 -7
- package/lib/generator.js +243 -49
- package/lib/generator.js.map +1 -1
- package/lib/graph.d.ts +4 -0
- package/lib/graph.js +11 -0
- package/lib/graph.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +39 -9
- package/lib/index.js.map +1 -1
- package/lib/topologica-analyzer.d.ts +85 -0
- package/lib/topologica-analyzer.js +509 -0
- package/lib/topologica-analyzer.js.map +1 -0
- package/lib/types.d.ts +110 -0
- package/lib/writer.d.ts +25 -13
- package/lib/writer.js +94 -51
- package/lib/writer.js.map +1 -1
- package/package.json +22 -24
- package/lib/plugin.d.ts +0 -8
- package/lib/plugin.js +0 -128
- package/lib/plugin.js.map +0 -1
package/lib/analyzer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import { AnalyzeResult } from './types';
|
|
2
|
+
import { AnalyzeResult, DefinitionInfo, UsageInfo, EDSInfo, FlowInfo } from './types';
|
|
3
3
|
import { TypeGraphImpl } from './graph';
|
|
4
4
|
/**
|
|
5
5
|
* AST Analyzer for finding Mnemonica define() and decorate() calls
|
|
@@ -7,7 +7,18 @@ import { TypeGraphImpl } from './graph';
|
|
|
7
7
|
export declare class MnemonicaAnalyzer {
|
|
8
8
|
private errors;
|
|
9
9
|
private graph;
|
|
10
|
+
private definitions;
|
|
11
|
+
private usages;
|
|
12
|
+
private edsUsages;
|
|
13
|
+
private flowUsages;
|
|
14
|
+
private typeAliases;
|
|
15
|
+
private variableToTypeMap;
|
|
10
16
|
constructor(program?: ts.Program);
|
|
17
|
+
/**
|
|
18
|
+
* Reset usage-related state for a fresh pass.
|
|
19
|
+
* Call before the usage-collection pass to avoid duplicates from definition pass.
|
|
20
|
+
*/
|
|
21
|
+
resetUsages(): void;
|
|
11
22
|
/**
|
|
12
23
|
* Analyze a source file for Mnemonica type definitions
|
|
13
24
|
*/
|
|
@@ -20,6 +31,31 @@ export declare class MnemonicaAnalyzer {
|
|
|
20
31
|
* Get the type graph
|
|
21
32
|
*/
|
|
22
33
|
getGraph(): TypeGraphImpl;
|
|
34
|
+
/**
|
|
35
|
+
* Get collected definitions
|
|
36
|
+
*/
|
|
37
|
+
getDefinitions(): Map<string, DefinitionInfo>;
|
|
38
|
+
/**
|
|
39
|
+
* Get collected usages
|
|
40
|
+
*/
|
|
41
|
+
getUsages(): Map<string, UsageInfo[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get collected EDS usages
|
|
44
|
+
*/
|
|
45
|
+
getEDSUsages(): Map<string, EDSInfo[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get collected flow usages
|
|
48
|
+
*/
|
|
49
|
+
getFlowUsages(): Map<string, FlowInfo[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Add a topologica type to the analyzer for usage tracking.
|
|
52
|
+
* This allows the analyzer to recognize topologica types when collecting usages.
|
|
53
|
+
*/
|
|
54
|
+
addTopologicaType(fullPath: string, node: import('./types').TypeNode): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set parent nodes in a source file to enable AST traversal up
|
|
57
|
+
*/
|
|
58
|
+
private setParentNodesInSourceFile;
|
|
23
59
|
/**
|
|
24
60
|
* Visit a node in the AST
|
|
25
61
|
*/
|
|
@@ -29,15 +65,35 @@ export declare class MnemonicaAnalyzer {
|
|
|
29
65
|
*/
|
|
30
66
|
private isDefineCall;
|
|
31
67
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
68
|
+
* Extract config options from define() call
|
|
69
|
+
*/
|
|
70
|
+
private extractConfig;
|
|
71
|
+
/**
|
|
72
|
+
* Check if a node is a @decorate() decorator
|
|
73
|
+
*/
|
|
34
74
|
private isDecorateDecorator;
|
|
35
75
|
/**
|
|
36
76
|
* Process a define() call
|
|
37
77
|
*/
|
|
38
78
|
private processDefineCall;
|
|
39
79
|
/**
|
|
40
|
-
|
|
80
|
+
* Track variable assignments that capture define() results
|
|
81
|
+
* e.g., const User = define('UserEntity', ...) maps "User" -> "UserEntity"
|
|
82
|
+
* For chained calls like const X = define('A').define('B'), we map X -> A (the root type)
|
|
83
|
+
*/
|
|
84
|
+
private trackVariableAssignment;
|
|
85
|
+
/**
|
|
86
|
+
* Track variable assignments from lookup() calls
|
|
87
|
+
* e.g., const SentienceConstructor = lookup('Sentience') maps "SentienceConstructor" -> "Sentience"
|
|
88
|
+
*/
|
|
89
|
+
private trackLookupAssignment;
|
|
90
|
+
/**
|
|
91
|
+
* Track variable assignments from new Type() calls
|
|
92
|
+
* e.g., const user = new UserType() maps "user" -> "UserType"
|
|
93
|
+
*/
|
|
94
|
+
private trackNewAssignment;
|
|
95
|
+
/**
|
|
96
|
+
* Process a @decorate() decorator
|
|
41
97
|
*/
|
|
42
98
|
private processDecorateDecorator;
|
|
43
99
|
/**
|
|
@@ -49,27 +105,159 @@ export declare class MnemonicaAnalyzer {
|
|
|
49
105
|
*/
|
|
50
106
|
private findParentType;
|
|
51
107
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
108
|
+
* Find a parent type by its name, searching in the graph
|
|
109
|
+
*/
|
|
110
|
+
private findParentTypeByName;
|
|
111
|
+
/**
|
|
112
|
+
* Get property chain from nested access
|
|
113
|
+
*/
|
|
54
114
|
private getPropertyChain;
|
|
55
115
|
/**
|
|
56
116
|
* Extract properties from constructor function
|
|
57
117
|
*/
|
|
58
118
|
private extractProperties;
|
|
119
|
+
/**
|
|
120
|
+
* Build a type map from all parameters with inline object type annotations
|
|
121
|
+
* Returns a map of "paramName.propertyName" -> type
|
|
122
|
+
*/
|
|
123
|
+
private buildDataTypeMap;
|
|
124
|
+
/**
|
|
125
|
+
* Extract property access chain (e.g., "dataRenamed.id" from dataRenamed.id)
|
|
126
|
+
* Handles fallbacks like: data.permissions || []
|
|
127
|
+
*/
|
|
128
|
+
private getPropertyAccessChain;
|
|
59
129
|
/**
|
|
60
130
|
* Extract property assignment from statement
|
|
61
131
|
*/
|
|
62
132
|
private extractPropertyFromStatement;
|
|
63
133
|
/**
|
|
64
|
-
* Extract properties from class declaration
|
|
134
|
+
* Extract properties from class declaration (including methods and getters)
|
|
65
135
|
*/
|
|
66
136
|
private extractClassProperties;
|
|
137
|
+
/**
|
|
138
|
+
* Extract class property types for method return type inference
|
|
139
|
+
* Maps property names to their TypeScript type strings
|
|
140
|
+
* Note: Includes private/protected properties for method inference
|
|
141
|
+
*/
|
|
142
|
+
private extractClassPropertyTypes;
|
|
143
|
+
/**
|
|
144
|
+
* Infer method type from method declaration
|
|
145
|
+
*/
|
|
146
|
+
private inferMethodType;
|
|
147
|
+
/**
|
|
148
|
+
* Extract properties from `this` parameter type annotation
|
|
149
|
+
* Handles patterns like: function(this: SomeType, data: SomeType) { }
|
|
150
|
+
*/
|
|
151
|
+
private extractThisParamProperties;
|
|
152
|
+
/**
|
|
153
|
+
* Infer TypeScript type from type node
|
|
154
|
+
*/
|
|
67
155
|
/**
|
|
68
156
|
* Infer TypeScript type from type node
|
|
69
157
|
*/
|
|
70
158
|
private inferType;
|
|
159
|
+
/**
|
|
160
|
+
* Infer return type from a method declaration
|
|
161
|
+
* Uses explicit return type annotation or infers from return statements
|
|
162
|
+
*/
|
|
163
|
+
private inferReturnType;
|
|
164
|
+
/**
|
|
165
|
+
* Infer return type by analyzing return statements in the method body
|
|
166
|
+
*/
|
|
167
|
+
private inferReturnTypeFromBody;
|
|
168
|
+
/**
|
|
169
|
+
* Get full text from a qualified name (e.g., Namespace.Type)
|
|
170
|
+
*/
|
|
171
|
+
private getQualifiedNameText;
|
|
71
172
|
/**
|
|
72
173
|
* Infer type from initializer
|
|
73
174
|
*/
|
|
74
175
|
private inferTypeFromInitializer;
|
|
176
|
+
/**
|
|
177
|
+
* Collect usage information for type references
|
|
178
|
+
*/
|
|
179
|
+
private collectUsage;
|
|
180
|
+
/**
|
|
181
|
+
* Get function name from expression (identifier or property access)
|
|
182
|
+
*/
|
|
183
|
+
private getFunctionName;
|
|
184
|
+
/**
|
|
185
|
+
* Add a usage to the collection
|
|
186
|
+
*/
|
|
187
|
+
private addUsage;
|
|
188
|
+
/**
|
|
189
|
+
* Collect EDS (Execution Data Storage) usage information
|
|
190
|
+
*/
|
|
191
|
+
private collectEDS;
|
|
192
|
+
/**
|
|
193
|
+
* Resolve type from EDS call argument (best effort)
|
|
194
|
+
*/
|
|
195
|
+
private resolveEDSArgumentType;
|
|
196
|
+
/**
|
|
197
|
+
* Add an EDS usage to the collection
|
|
198
|
+
*/
|
|
199
|
+
private addEDS;
|
|
200
|
+
/**
|
|
201
|
+
* Collect native flow patterns (instance usage after creation)
|
|
202
|
+
* Phase 1: property access, method calls, arguments, return, destructuring, etc.
|
|
203
|
+
*/
|
|
204
|
+
private collectFlow;
|
|
205
|
+
/**
|
|
206
|
+
* Collect property access flow (read or conditional)
|
|
207
|
+
*/
|
|
208
|
+
private collectFlowPropertyAccess;
|
|
209
|
+
/**
|
|
210
|
+
* Collect element access flow: user['name']
|
|
211
|
+
*/
|
|
212
|
+
private collectFlowElementAccess;
|
|
213
|
+
/**
|
|
214
|
+
* Collect assignment flow: user.name = value or user = other
|
|
215
|
+
*/
|
|
216
|
+
private collectFlowAssignment;
|
|
217
|
+
/**
|
|
218
|
+
* Collect method call flow: user.validate()
|
|
219
|
+
*/
|
|
220
|
+
private collectFlowMethodCall;
|
|
221
|
+
/**
|
|
222
|
+
* Collect argument passing flow: processUser(user)
|
|
223
|
+
*/
|
|
224
|
+
private collectFlowArgumentPass;
|
|
225
|
+
/**
|
|
226
|
+
* Collect destructuring flow: const { name } = user
|
|
227
|
+
*/
|
|
228
|
+
private collectFlowDestructure;
|
|
229
|
+
/**
|
|
230
|
+
* Collect return flow: return user
|
|
231
|
+
*/
|
|
232
|
+
private collectFlowReturn;
|
|
233
|
+
/**
|
|
234
|
+
* Collect spread flow: { ...user }
|
|
235
|
+
*/
|
|
236
|
+
private collectFlowSpread;
|
|
237
|
+
/**
|
|
238
|
+
* Resolve type from an expression (identifier, property access, etc.)
|
|
239
|
+
*/
|
|
240
|
+
private resolveExpressionType;
|
|
241
|
+
/**
|
|
242
|
+
* Add a flow usage to the collection
|
|
243
|
+
*/
|
|
244
|
+
private addFlow;
|
|
245
|
+
/**
|
|
246
|
+
* Get type name from expression (identifier or property access)
|
|
247
|
+
*/
|
|
248
|
+
private getTypeNameFromExpression;
|
|
249
|
+
/**
|
|
250
|
+
* Resolve full type path from property access
|
|
251
|
+
*/
|
|
252
|
+
private resolveTypePath;
|
|
253
|
+
/**
|
|
254
|
+
* Check if a name looks like a type (starts with uppercase)
|
|
255
|
+
*/
|
|
256
|
+
private isLikelyTypeName;
|
|
257
|
+
/**
|
|
258
|
+
* Extract constructor parameters from define() call
|
|
259
|
+
* This is used for TypeRegistry constructor signatures
|
|
260
|
+
* Preserves parameter names and expands object types to their structure
|
|
261
|
+
*/
|
|
262
|
+
private extractConstructorParams;
|
|
75
263
|
}
|