@codebolt/codeboltjs 2.2.2 → 2.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/codeboltjs",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -11,6 +11,16 @@
11
11
  "README.md",
12
12
  "LICENSE"
13
13
  ],
14
+ "scripts": {
15
+ "build": "tsc && node script/copy-wasm.js",
16
+ "build:webpack": "webpack",
17
+ "build:all": "npm run build && npm run build:webpack",
18
+ "build:docs": "typedoc --plugin typedoc-plugin-missing-exports",
19
+ "build:jsondocs": "typedoc --plugin typedoc-plugin-missing-exports --json out.json --pretty",
20
+ "test": "echo \"Integration tests require WebSocket server - skipping for release\" && exit 0",
21
+ "clean": "powershell -Command \"Remove-Item -Path 'dist' -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path 'build' -Recurse -Force -ErrorAction SilentlyContinue\"",
22
+ "lint": "eslint src/**/*.ts && tsc --noEmit"
23
+ },
14
24
  "repository": {
15
25
  "type": "git",
16
26
  "url": "git+https://github.com/codeboltai/codeboltjs.git",
@@ -22,6 +32,7 @@
22
32
  "access": "public"
23
33
  },
24
34
  "dependencies": {
35
+ "@codebolt/types": "workspace:*",
25
36
  "@types/uuid": "^10.0.0",
26
37
  "buffer": "^6.0.3",
27
38
  "execa": "^9.5.2",
@@ -32,9 +43,8 @@
32
43
  "timers": "^0.1.1",
33
44
  "util": "^0.12.5",
34
45
  "uuid": "^11.1.0",
35
- "ws": "^8.17.0",
36
- "yargs": "^17.7.2",
37
- "@codebolt/types": "1.0.16"
46
+ "ws": "^8.18.3",
47
+ "yargs": "^17.7.2"
38
48
  },
39
49
  "devDependencies": {
40
50
  "@types/events": "^3.0.3",
@@ -42,14 +52,14 @@
42
52
  "@types/node": "^20.14.2",
43
53
  "@types/uri-templates": "^0.1.34",
44
54
  "@types/ws": "^8.5.10",
45
- "jest": "^29.7.0",
55
+ "jest": "^30.2.0",
46
56
  "jest-serial-runner": "^1.2.1",
47
57
  "ts-loader": "^9.5.1",
48
58
  "typedoc": "^0.28.10",
49
59
  "typedoc-plugin-markdown": "^3.15.0",
50
60
  "typedoc-plugin-missing-exports": "^4.1.0",
51
61
  "typescript": "^5.4.5",
52
- "webpack": "^5.91.0",
62
+ "webpack": "^5.102.1",
53
63
  "webpack-cli": "^5.1.4"
54
64
  },
55
65
  "jest": {
@@ -60,15 +70,5 @@
60
70
  "types": "./dist/index.d.ts",
61
71
  "default": "./dist/index.js"
62
72
  }
63
- },
64
- "scripts": {
65
- "build": "tsc && node script/copy-wasm.js",
66
- "build:webpack": "webpack",
67
- "build:all": "npm run build && npm run build:webpack",
68
- "build:docs": "typedoc --plugin typedoc-plugin-missing-exports",
69
- "build:jsondocs": "typedoc --plugin typedoc-plugin-missing-exports --json out.json --pretty",
70
- "test": "echo \"Integration tests require WebSocket server - skipping for release\" && exit 0",
71
- "clean": "powershell -Command \"Remove-Item -Path 'dist' -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path 'build' -Recurse -Force -ErrorAction SilentlyContinue\"",
72
- "lint": "eslint src/**/*.ts && tsc --noEmit"
73
73
  }
74
- }
74
+ }
@@ -1,37 +0,0 @@
1
- import type { ASTNode } from "../types/commonTypes";
2
- /**
3
- * A collection of code parser functions.
4
- */
5
- declare const cbcodeparsers: {
6
- /**
7
- * Retrieves the classes in a given file.
8
- * @param file The file to parse for classes.
9
- */
10
- getClassesInFile: (file: string) => Promise<{
11
- error: string;
12
- } | {
13
- name: any;
14
- location: string;
15
- }[]>;
16
- /**
17
- * Retrieves the functions in a given class within a file.
18
- * @param file The file containing the class.
19
- * @param className The name of the class to parse for functions.
20
- */
21
- getFunctionsinClass: (file: string, className: string) => Promise<{
22
- error: string;
23
- } | {
24
- name: string;
25
- class: string;
26
- location: string;
27
- }[]>;
28
- /**
29
- * Generates an Abstract Syntax Tree (AST) for a given file.
30
- * @param file The file to generate an AST for.
31
- * @param className The name of the class to focus the AST generation on.
32
- */
33
- getAstTreeInFile: (file: string, className?: string) => Promise<ASTNode | {
34
- error: string;
35
- }>;
36
- };
37
- export default cbcodeparsers;
@@ -1,329 +0,0 @@
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
- const codeparser_1 = require("@codebolt/codeparser");
37
- const fs = __importStar(require("fs/promises"));
38
- const path = __importStar(require("path"));
39
- /**
40
- * A collection of code parser functions.
41
- */
42
- const cbcodeparsers = {
43
- /**
44
- * Retrieves the classes in a given file.
45
- * @param file The file to parse for classes.
46
- */
47
- getClassesInFile: async (file) => {
48
- // Check if file exists
49
- try {
50
- await fs.access(file);
51
- }
52
- catch (error) {
53
- return { error: `File does not exist or is not accessible: ${file}` };
54
- }
55
- // Get file extension and determine if we support it
56
- const ext = path.extname(file).toLowerCase().slice(1);
57
- const supportedExtensions = ['js', 'jsx', 'ts', 'tsx', 'py', 'rs', 'go', 'c', 'h', 'cpp', 'hpp', 'cs', 'rb', 'java', 'php', 'swift'];
58
- if (!supportedExtensions.includes(ext)) {
59
- return { error: `Unsupported file type: ${ext}` };
60
- }
61
- // Load language parser for this file
62
- const languageParsers = await (0, codeparser_1.loadRequiredLanguageParsers)([file]);
63
- // Parse the file
64
- const result = await (0, codeparser_1.parseFile)(file, languageParsers);
65
- // Filter for class definitions only
66
- const lines = (result === null || result === void 0 ? void 0 : result.split('\n')) || [];
67
- const classes = [];
68
- let currentClass = null;
69
- for (const line of lines) {
70
- // Match line patterns from the parseFile result format
71
- if (line.includes('@definition.class')) {
72
- // Extract the class name from the line
73
- const className = line.split('@')[0].trim();
74
- currentClass = { name: className, location: file };
75
- classes.push(currentClass);
76
- }
77
- }
78
- // If no classes found, try to use AST approach
79
- if (classes.length === 0) {
80
- try {
81
- // Get the file extension
82
- const ext = path.extname(file).toLowerCase().slice(1);
83
- // Load language parser
84
- const languageParsers = await (0, codeparser_1.loadRequiredLanguageParsers)([file]);
85
- // Get the parser for this file type
86
- const { parser } = languageParsers[ext] || {};
87
- if (parser) {
88
- // Read the file content
89
- const fileContent = await fs.readFile(file, 'utf8');
90
- // Parse the file to get AST
91
- const tree = parser.parse(fileContent);
92
- // Function to find class nodes in the AST
93
- const findClassNodes = (node) => {
94
- const classNodes = [];
95
- if (node.type === 'class_declaration' ||
96
- node.type === 'class' ||
97
- node.type === 'class_definition') {
98
- classNodes.push(node);
99
- }
100
- // Recursively search children
101
- for (let i = 0; i < node.childCount; i++) {
102
- const childResults = findClassNodes(node.child(i));
103
- classNodes.push(...childResults);
104
- }
105
- return classNodes;
106
- };
107
- const classNodes = findClassNodes(tree.rootNode);
108
- // Extract class names from the nodes
109
- for (const node of classNodes) {
110
- // For most languages, the class name is in a child node
111
- // Let's attempt to extract it from the text
112
- const text = node.text;
113
- const classMatch = text.match(/class\s+([a-zA-Z_$][0-9a-zA-Z_$]*)/);
114
- if (classMatch && classMatch[1]) {
115
- classes.push({
116
- name: classMatch[1],
117
- location: file
118
- });
119
- }
120
- }
121
- }
122
- }
123
- catch (error) {
124
- console.error('Error trying AST approach:', error);
125
- }
126
- }
127
- return classes;
128
- },
129
- /**
130
- * Retrieves the functions in a given class within a file.
131
- * @param file The file containing the class.
132
- * @param className The name of the class to parse for functions.
133
- */
134
- getFunctionsinClass: async (file, className) => {
135
- // Check if file exists
136
- try {
137
- await fs.access(file);
138
- }
139
- catch (error) {
140
- return { error: `File does not exist or is not accessible: ${file}` };
141
- }
142
- // Load language parser for this file
143
- const languageParsers = await (0, codeparser_1.loadRequiredLanguageParsers)([file]);
144
- // Parse the file
145
- const result = await (0, codeparser_1.parseFile)(file, languageParsers);
146
- // Extract content
147
- const fileContent = await fs.readFile(file, 'utf8');
148
- // Parse the file content to find the class and its methods
149
- const lines = (result === null || result === void 0 ? void 0 : result.split('\n')) || [];
150
- const functions = [];
151
- // Use AST approach to find methods within the class
152
- try {
153
- // Get the file extension
154
- const ext = path.extname(file).toLowerCase().slice(1);
155
- // Get the parser for this file type
156
- const { parser } = languageParsers[ext] || {};
157
- if (parser) {
158
- // Parse the file to get AST
159
- const tree = parser.parse(fileContent);
160
- // Find the class node
161
- const findClassNode = (node) => {
162
- if ((node.type === 'class_declaration' ||
163
- node.type === 'class' ||
164
- node.type === 'class_definition') &&
165
- node.text.includes(className)) {
166
- return node;
167
- }
168
- // Recursively search children
169
- for (let i = 0; i < node.childCount; i++) {
170
- const child = node.child(i);
171
- const result = findClassNode(child);
172
- if (result)
173
- return result;
174
- }
175
- return null;
176
- };
177
- const classNode = findClassNode(tree.rootNode);
178
- if (classNode) {
179
- // Function to find method nodes within the class
180
- const findMethodNodes = (node) => {
181
- const methodNodes = [];
182
- // Different languages use different node types for methods
183
- if (node.type === 'method_definition' ||
184
- node.type === 'method' ||
185
- node.type === 'method_declaration' ||
186
- node.type === 'function' ||
187
- node.type === 'function_definition') {
188
- methodNodes.push(node);
189
- }
190
- // Recursively search children
191
- for (let i = 0; i < node.childCount; i++) {
192
- const childResults = findMethodNodes(node.child(i));
193
- methodNodes.push(...childResults);
194
- }
195
- return methodNodes;
196
- };
197
- const methodNodes = findMethodNodes(classNode);
198
- // Extract method names from the nodes
199
- for (const node of methodNodes) {
200
- // Try to find method name from node text
201
- let methodName = '';
202
- // Different pattern matching based on language type
203
- if (ext === 'py') {
204
- // Python methods: def method_name(
205
- const methodMatch = node.text.match(/def\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/);
206
- if (methodMatch && methodMatch[1]) {
207
- methodName = methodMatch[1];
208
- }
209
- }
210
- else if (['js', 'jsx', 'ts', 'tsx'].includes(ext)) {
211
- // JavaScript/TypeScript methods: methodName( or methodName =
212
- const methodMatch = node.text.match(/([a-zA-Z_$][a-zA-Z0-9_$]*)\s*[\(=]/);
213
- if (methodMatch && methodMatch[1]) {
214
- methodName = methodMatch[1];
215
- }
216
- }
217
- else {
218
- // Generic approach for other languages
219
- // Look for identifiers followed by parentheses
220
- const methodMatch = node.text.match(/([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/);
221
- if (methodMatch && methodMatch[1]) {
222
- methodName = methodMatch[1];
223
- }
224
- }
225
- if (methodName && !['constructor', '__init__'].includes(methodName)) {
226
- functions.push({
227
- name: methodName,
228
- class: className,
229
- location: file
230
- });
231
- }
232
- }
233
- }
234
- }
235
- }
236
- catch (error) {
237
- console.error('Error parsing methods:', error);
238
- }
239
- return functions;
240
- },
241
- /**
242
- * Generates an Abstract Syntax Tree (AST) for a given file.
243
- * @param file The file to generate an AST for.
244
- * @param className The name of the class to focus the AST generation on.
245
- */
246
- getAstTreeInFile: async (file, className) => {
247
- try {
248
- await fs.access(file);
249
- }
250
- catch (error) {
251
- return { error: `File does not exist or is not accessible: ${file}` };
252
- }
253
- // Get file extension and determine if we support it
254
- const ext = path.extname(file).toLowerCase().slice(1);
255
- const supportedExtensions = ['js', 'jsx', 'ts', 'tsx', 'py', 'rs', 'go', 'c', 'h', 'cpp', 'hpp', 'cs', 'rb', 'java', 'php', 'swift'];
256
- if (!supportedExtensions.includes(ext)) {
257
- return { error: `Unsupported file type: ${ext}` };
258
- }
259
- // Load language parser for this file
260
- const languageParsers = await (0, codeparser_1.loadRequiredLanguageParsers)([file]);
261
- // Get the parser for this file type
262
- const { parser } = languageParsers[ext] || {};
263
- if (!parser) {
264
- return { error: `No parser available for file type: ${ext}` };
265
- }
266
- // Read the file content
267
- const fileContent = await fs.readFile(file, 'utf8');
268
- // Parse the file to get AST
269
- const tree = parser.parse(fileContent);
270
- // If className is provided, find and return only that class's AST
271
- if (className) {
272
- // Function to recursively search for the class node
273
- const findClassNode = (node) => {
274
- if ((node.type === 'class_declaration' ||
275
- node.type === 'abstract_class_declaration' ||
276
- node.type === 'class_definition') &&
277
- node.text.includes(className)) {
278
- return node;
279
- }
280
- // Recursively search children
281
- for (let i = 0; i < node.childCount; i++) {
282
- const child = node.child(i);
283
- const result = findClassNode(child);
284
- if (result)
285
- return result;
286
- }
287
- return null;
288
- };
289
- const classNode = findClassNode(tree.rootNode);
290
- if (classNode) {
291
- // Convert the class node to a JSON-serializable object
292
- const serializeNode = (node) => {
293
- const result = {
294
- type: node.type,
295
- text: node.text,
296
- startPosition: { row: node.startPosition.row, column: node.startPosition.column },
297
- endPosition: { row: node.endPosition.row, column: node.endPosition.column },
298
- children: []
299
- };
300
- for (let i = 0; i < node.childCount; i++) {
301
- result.children.push(serializeNode(node.child(i)));
302
- }
303
- return result;
304
- };
305
- return serializeNode(classNode);
306
- }
307
- else {
308
- return { error: `Class '${className}' not found in file: ${file}` };
309
- }
310
- }
311
- // Otherwise return the full AST
312
- // Convert the full tree to a JSON-serializable object
313
- const serializeNode = (node) => {
314
- const result = {
315
- type: node.type,
316
- text: node.text,
317
- startPosition: { row: node.startPosition.row, column: node.startPosition.column },
318
- endPosition: { row: node.endPosition.row, column: node.endPosition.column },
319
- children: []
320
- };
321
- for (let i = 0; i < node.childCount; i++) {
322
- result.children.push(serializeNode(node.child(i)));
323
- }
324
- return result;
325
- };
326
- return serializeNode(tree.rootNode);
327
- }
328
- };
329
- exports.default = cbcodeparsers;