@aiready/core 0.24.19 → 0.24.21

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 (39) hide show
  1. package/dist/chunk-3NEZ5M7Y.mjs +385 -340
  2. package/dist/chunk-5IVDH26E.mjs +142 -88
  3. package/dist/chunk-BE52N7T2.mjs +892 -0
  4. package/dist/chunk-GQMKSUA4.mjs +381 -336
  5. package/dist/chunk-LRM26BOB.mjs +381 -336
  6. package/dist/chunk-MOM3IXCA.mjs +146 -91
  7. package/dist/chunk-OT6FOHL4.mjs +144 -88
  8. package/dist/chunk-OVWWYI75.mjs +307 -0
  9. package/dist/chunk-U3IY2CFC.mjs +18 -22
  10. package/dist/chunk-WPFXQH5F.mjs +307 -0
  11. package/dist/chunk-WUDUSXUE.mjs +366 -0
  12. package/dist/chunk-YQATXOKD.mjs +36 -0
  13. package/dist/chunk-YVPVNRFQ.mjs +937 -0
  14. package/dist/client/index.mjs +2 -2
  15. package/dist/csharp-parser-JE5MWHQS.mjs +9 -0
  16. package/dist/csharp-parser-XW7WHE77.mjs +5 -9
  17. package/dist/go-parser-KTG4CGF5.mjs +5 -9
  18. package/dist/go-parser-T7PR6WJI.mjs +9 -0
  19. package/dist/index-CcP12wb-.d.mts +996 -693
  20. package/dist/index-CcP12wb-.d.ts +996 -693
  21. package/dist/index-DGbarGnr.d.mts +996 -693
  22. package/dist/index-DGbarGnr.d.ts +996 -693
  23. package/dist/index-slasaNzr.d.mts +998 -695
  24. package/dist/index-slasaNzr.d.ts +998 -695
  25. package/dist/index.d.mts +32 -1
  26. package/dist/index.d.ts +32 -1
  27. package/dist/index.js +35 -2
  28. package/dist/index.mjs +41 -9
  29. package/dist/java-parser-EOKMGQ6B.mjs +5 -9
  30. package/dist/java-parser-WGOXKULP.mjs +9 -0
  31. package/dist/python-parser-7NCR7VCQ.mjs +8 -0
  32. package/dist/python-parser-BCI7JVLF.mjs +4 -8
  33. package/dist/typescript-parser-3KYGSSY5.mjs +3 -0
  34. package/dist/typescript-parser-4BA4VYAF.mjs +3 -7
  35. package/dist/typescript-parser-FOUPHVFI.mjs +3 -7
  36. package/dist/typescript-parser-G3TSNR7O.mjs +7 -0
  37. package/dist/typescript-parser-RMNCTHRD.mjs +3 -7
  38. package/dist/typescript-parser-WALISXF4.mjs +7 -0
  39. package/package.json +11 -10
@@ -0,0 +1,366 @@
1
+ import { ParseError } from './chunk-U3IY2CFC.mjs';
2
+
3
+ // src/parsers/typescript-parser.ts
4
+ import { parse } from '@typescript-eslint/typescript-estree';
5
+ var TypeScriptParser = class {
6
+ constructor() {
7
+ this.language = 'typescript' /* TypeScript */;
8
+ this.extensions = ['.ts', '.tsx', '.js', '.jsx'];
9
+ }
10
+ async initialize() {}
11
+ canHandle(filePath) {
12
+ return this.extensions.some((ext) => filePath.endsWith(ext));
13
+ }
14
+ async getAST(code, filePath) {
15
+ try {
16
+ return parse(code, {
17
+ filePath,
18
+ loc: true,
19
+ range: true,
20
+ tokens: true,
21
+ comment: true,
22
+ jsx: filePath.endsWith('x'),
23
+ });
24
+ } catch (error) {
25
+ const err = error;
26
+ throw new ParseError(err.message || 'Unknown error', filePath, {
27
+ line: err.lineNumber || 1,
28
+ column: err.column || 0,
29
+ });
30
+ }
31
+ }
32
+ parse(code, filePath) {
33
+ try {
34
+ const ast = parse(code, {
35
+ filePath,
36
+ loc: true,
37
+ range: true,
38
+ tokens: true,
39
+ comment: true,
40
+ jsx: filePath.endsWith('x'),
41
+ });
42
+ const imports = this.extractImports(ast);
43
+ const exports = this.extractExports(ast, code, filePath);
44
+ return {
45
+ exports,
46
+ imports,
47
+ language: this.language,
48
+ };
49
+ } catch (error) {
50
+ throw new ParseError(error.message, filePath, {
51
+ line: error.lineNumber || 1,
52
+ column: error.column || 0,
53
+ });
54
+ }
55
+ }
56
+ getNamingConventions() {
57
+ return {
58
+ variablePattern: /^[a-z][a-zA-Z0-9]*$/,
59
+ functionPattern: /^[a-z][a-zA-Z0-9]*$/,
60
+ classPattern: /^[A-Z][a-zA-Z0-9]*$/,
61
+ constantPattern: /^[A-Z][A-Z0-9_]*$/,
62
+ typePattern: /^[A-Z][a-zA-Z0-9]*$/,
63
+ interfacePattern: /^I?[A-Z][a-zA-Z0-9]*$/,
64
+ };
65
+ }
66
+ analyzeMetadata(node, code) {
67
+ if (!code) return {};
68
+ return {
69
+ isPure: this.isLikelyPure(node),
70
+ hasSideEffects: !this.isLikelyPure(node),
71
+ };
72
+ }
73
+ extractImports(ast) {
74
+ const imports = [];
75
+ for (const node of ast.body) {
76
+ if (node.type === 'ImportDeclaration') {
77
+ const specifiers = [];
78
+ let isTypeOnly = false;
79
+ if (node.importKind === 'type') {
80
+ isTypeOnly = true;
81
+ }
82
+ for (const spec of node.specifiers) {
83
+ if (spec.type === 'ImportSpecifier') {
84
+ const imported = spec.imported;
85
+ const name =
86
+ imported.type === 'Identifier' ? imported.name : imported.value;
87
+ specifiers.push(name);
88
+ } else if (spec.type === 'ImportDefaultSpecifier') {
89
+ specifiers.push('default');
90
+ } else if (spec.type === 'ImportNamespaceSpecifier') {
91
+ specifiers.push('*');
92
+ }
93
+ }
94
+ imports.push({
95
+ source: node.source.value,
96
+ specifiers,
97
+ isTypeOnly,
98
+ loc: node.loc
99
+ ? {
100
+ start: {
101
+ line: node.loc.start.line,
102
+ column: node.loc.start.column,
103
+ },
104
+ end: { line: node.loc.end.line, column: node.loc.end.column },
105
+ }
106
+ : void 0,
107
+ });
108
+ }
109
+ }
110
+ return imports;
111
+ }
112
+ extractExports(ast, code, filePath) {
113
+ const exports = [];
114
+ for (const node of ast.body) {
115
+ if (node.type === 'ExportNamedDeclaration') {
116
+ if (node.declaration) {
117
+ const declaration = node.declaration;
118
+ if (
119
+ (declaration.type === 'FunctionDeclaration' ||
120
+ declaration.type === 'TSDeclareFunction') &&
121
+ declaration.id
122
+ ) {
123
+ exports.push(
124
+ this.createExport(
125
+ declaration.id.name,
126
+ 'function',
127
+ node,
128
+ // Pass the outer ExportNamedDeclaration
129
+ code,
130
+ filePath
131
+ )
132
+ );
133
+ } else if (
134
+ declaration.type === 'ClassDeclaration' &&
135
+ declaration.id
136
+ ) {
137
+ exports.push(
138
+ this.createExport(
139
+ declaration.id.name,
140
+ 'class',
141
+ node,
142
+ // Pass the outer ExportNamedDeclaration
143
+ code,
144
+ filePath
145
+ )
146
+ );
147
+ } else if (declaration.type === 'TSTypeAliasDeclaration') {
148
+ exports.push(
149
+ this.createExport(
150
+ declaration.id.name,
151
+ 'type',
152
+ node,
153
+ // Pass the outer ExportNamedDeclaration
154
+ code,
155
+ filePath
156
+ )
157
+ );
158
+ } else if (declaration.type === 'TSInterfaceDeclaration') {
159
+ exports.push(
160
+ this.createExport(
161
+ declaration.id.name,
162
+ 'interface',
163
+ node,
164
+ // Pass the outer ExportNamedDeclaration
165
+ code,
166
+ filePath
167
+ )
168
+ );
169
+ } else if (declaration.type === 'VariableDeclaration') {
170
+ for (const decl of declaration.declarations) {
171
+ if (decl.id.type === 'Identifier') {
172
+ exports.push(
173
+ this.createExport(
174
+ decl.id.name,
175
+ 'const',
176
+ node,
177
+ code,
178
+ filePath,
179
+ decl.init
180
+ )
181
+ );
182
+ }
183
+ }
184
+ }
185
+ }
186
+ } else if (node.type === 'ExportDefaultDeclaration') {
187
+ exports.push(
188
+ this.createExport('default', 'default', node, code, filePath)
189
+ );
190
+ }
191
+ }
192
+ return exports;
193
+ }
194
+ createExport(name, type, node, code, filePath, initializer) {
195
+ const documentation = this.extractDocumentation(node, code);
196
+ let methodCount;
197
+ let propertyCount;
198
+ let parameters;
199
+ let isPrimitive = false;
200
+ let isTyped = false;
201
+ if (initializer) {
202
+ if (
203
+ initializer.type === 'Literal' ||
204
+ (initializer.type === 'TemplateLiteral' &&
205
+ initializer.expressions.length === 0)
206
+ ) {
207
+ isPrimitive = true;
208
+ }
209
+ }
210
+ let structNode =
211
+ node.type === 'ExportNamedDeclaration' && node.declaration
212
+ ? node.declaration
213
+ : node.type === 'ExportDefaultDeclaration'
214
+ ? node.declaration
215
+ : node;
216
+ if (!structNode) structNode = node;
217
+ if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) {
218
+ if (
219
+ structNode.type === 'TSTypeAliasDeclaration' ||
220
+ structNode.type === 'TSInterfaceDeclaration' ||
221
+ structNode.type === 'TSEnumDeclaration'
222
+ ) {
223
+ isTyped = true;
224
+ } else if (
225
+ structNode.type === 'FunctionDeclaration' ||
226
+ structNode.type === 'TSDeclareFunction'
227
+ ) {
228
+ const func = structNode;
229
+ const hasReturnType = !!func.returnType;
230
+ const allParamsTyped =
231
+ func.params.length === 0 ||
232
+ func.params.every((p) => !!p.typeAnnotation);
233
+ isTyped = hasReturnType && allParamsTyped;
234
+ } else if (structNode.type === 'VariableDeclaration') {
235
+ const variable = structNode;
236
+ isTyped = variable.declarations.every(
237
+ (d) => !!d.id.typeAnnotation || !!d.init
238
+ );
239
+ } else if (structNode.type === 'ClassDeclaration') {
240
+ isTyped = true;
241
+ }
242
+ } else if (filePath.endsWith('.js') || filePath.endsWith('.jsx')) {
243
+ isTyped = false;
244
+ }
245
+ if (
246
+ structNode.type === 'ClassDeclaration' ||
247
+ structNode.type === 'TSInterfaceDeclaration'
248
+ ) {
249
+ const body =
250
+ structNode.type === 'ClassDeclaration'
251
+ ? structNode.body.body
252
+ : structNode.body.body;
253
+ methodCount = body.filter(
254
+ (m) => m.type === 'MethodDefinition' || m.type === 'TSMethodSignature'
255
+ ).length;
256
+ propertyCount = body.filter(
257
+ (m) =>
258
+ m.type === 'PropertyDefinition' || m.type === 'TSPropertySignature'
259
+ ).length;
260
+ if (structNode.type === 'ClassDeclaration') {
261
+ const constructor = body.find(
262
+ (m) => m.type === 'MethodDefinition' && m.kind === 'constructor'
263
+ );
264
+ if (constructor && constructor.value && constructor.value.params) {
265
+ parameters = constructor.value.params
266
+ .map((p) => {
267
+ if (p.type === 'Identifier') return p.name;
268
+ if (
269
+ p.type === 'TSParameterProperty' &&
270
+ p.parameter.type === 'Identifier'
271
+ ) {
272
+ return p.parameter.name;
273
+ }
274
+ return void 0;
275
+ })
276
+ .filter((p) => !!p);
277
+ }
278
+ }
279
+ }
280
+ if (
281
+ !parameters &&
282
+ (structNode.type === 'FunctionDeclaration' ||
283
+ structNode.type === 'TSDeclareFunction' ||
284
+ structNode.type === 'MethodDefinition')
285
+ ) {
286
+ const funcNode =
287
+ structNode.type === 'MethodDefinition' ? structNode.value : structNode;
288
+ if (funcNode && funcNode.params) {
289
+ parameters = funcNode.params
290
+ .map((p) => {
291
+ if (p.type === 'Identifier') return p.name;
292
+ return void 0;
293
+ })
294
+ .filter((p) => !!p);
295
+ }
296
+ }
297
+ return {
298
+ name,
299
+ type,
300
+ isPrimitive,
301
+ loc: node.loc
302
+ ? {
303
+ start: { line: node.loc.start.line, column: node.loc.start.column },
304
+ end: { line: node.loc.end.line, column: node.loc.end.column },
305
+ }
306
+ : void 0,
307
+ documentation,
308
+ methodCount,
309
+ propertyCount,
310
+ parameters,
311
+ isPure: this.isLikelyPure(node),
312
+ hasSideEffects: !this.isLikelyPure(node),
313
+ isTyped,
314
+ };
315
+ }
316
+ extractDocumentation(node, code) {
317
+ if (node.range) {
318
+ const start = node.range[0];
319
+ const precedingCode = code.substring(0, start);
320
+ const jsdocMatch = precedingCode.match(/\/\*\*([\s\S]*?)\*\/\s*$/);
321
+ if (jsdocMatch) {
322
+ return {
323
+ content: jsdocMatch[1].trim(),
324
+ type: 'jsdoc',
325
+ };
326
+ }
327
+ }
328
+ return void 0;
329
+ }
330
+ isLikelyPure(node) {
331
+ const sn =
332
+ node.type === 'ExportNamedDeclaration' && node.declaration
333
+ ? node.declaration
334
+ : node.type === 'ExportDefaultDeclaration'
335
+ ? node.declaration
336
+ : node;
337
+ if (!sn) return false;
338
+ if (sn.type === 'VariableDeclaration' && sn.kind === 'const') return true;
339
+ if (
340
+ sn.type === 'FunctionDeclaration' ||
341
+ sn.type === 'TSDeclareFunction' ||
342
+ sn.type === 'MethodDefinition'
343
+ ) {
344
+ const body = sn.type === 'MethodDefinition' ? sn.value.body : sn.body;
345
+ if (body && body.type === 'BlockStatement') {
346
+ const bodyContent = JSON.stringify(body, (_, v) =>
347
+ typeof v === 'bigint' ? v.toString() : v
348
+ );
349
+ if (
350
+ bodyContent.includes('"name":"console"') ||
351
+ bodyContent.includes('"name":"process"') ||
352
+ bodyContent.includes('"name":"fs"') ||
353
+ bodyContent.includes('"name":"fetch"') ||
354
+ bodyContent.includes('"name":"axios"')
355
+ ) {
356
+ return false;
357
+ }
358
+ return true;
359
+ }
360
+ return true;
361
+ }
362
+ return false;
363
+ }
364
+ };
365
+
366
+ export { TypeScriptParser };
@@ -0,0 +1,36 @@
1
+ // src/types/language.ts
2
+ var Language = /* @__PURE__ */ ((Language2) => {
3
+ Language2["TypeScript"] = "typescript";
4
+ Language2["JavaScript"] = "javascript";
5
+ Language2["Python"] = "python";
6
+ Language2["Java"] = "java";
7
+ Language2["Go"] = "go";
8
+ Language2["Rust"] = "rust";
9
+ Language2["CSharp"] = "csharp";
10
+ return Language2;
11
+ })(Language || {});
12
+ var LANGUAGE_EXTENSIONS = {
13
+ ".ts": "typescript" /* TypeScript */,
14
+ ".tsx": "typescript" /* TypeScript */,
15
+ ".js": "javascript" /* JavaScript */,
16
+ ".jsx": "javascript" /* JavaScript */,
17
+ ".py": "python" /* Python */,
18
+ ".java": "java" /* Java */,
19
+ ".go": "go" /* Go */,
20
+ ".rs": "rust" /* Rust */,
21
+ ".cs": "csharp" /* CSharp */
22
+ };
23
+ var ParseError = class extends Error {
24
+ constructor(message, filePath, loc) {
25
+ super(message);
26
+ this.filePath = filePath;
27
+ this.loc = loc;
28
+ this.name = "ParseError";
29
+ }
30
+ };
31
+
32
+ export {
33
+ Language,
34
+ LANGUAGE_EXTENSIONS,
35
+ ParseError
36
+ };