Skip to content

Commit d65ba06

Browse files
changes
1 parent d9aa1e8 commit d65ba06

File tree

8 files changed

+89
-57
lines changed

8 files changed

+89
-57
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.30",
3+
"version": "1.1.31",
44
"description": "",
55
"keywords": [],
66
"author": "",
@@ -18,7 +18,7 @@
1818
"license": "MIT",
1919
"homepage": "https://codeboltai.github.io",
2020
"dependencies": {
21-
"@codebolt/common": "^1.0.4",
21+
"@codebolt/types": "^1.0.8",
2222
"typedoc-plugin-missing-exports": "^2.2.0",
2323
"ws": "^8.17.0"
2424
},

src/modules/browser.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cbws from './websocket';
2-
import {GoToPageResponse,UrlResponse} from '@codebolt/common'
2+
import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived} from '@codebolt/types'
33
/**
44
* A module for interacting with a browser through WebSockets.
55
*/
@@ -17,7 +17,7 @@ const cbbrowser = {
1717

1818
/**
1919
* Retrieves the current URL of the browser's active page.
20-
* @returns {Promise<any>} A promise that resolves with the URL.
20+
* @returns {Promise<UrlResponse>} A promise that resolves with the URL.
2121
*/
2222
getUrl: ():Promise<UrlResponse> => {
2323
return new Promise((resolve, reject) => {
@@ -37,7 +37,7 @@ const cbbrowser = {
3737
/**
3838
* Navigates to a specified URL.
3939
* @param {string} url - The URL to navigate to.
40-
* @returns {Promise<any>} A promise that resolves when navigation is complete.
40+
* @returns {Promise<GoToPageResponse>} A promise that resolves when navigation is complete.
4141
*/
4242
goToPage: (url: string):Promise<GoToPageResponse> => {
4343
return new Promise((resolve, reject) => {
@@ -67,9 +67,9 @@ const cbbrowser = {
6767

6868
/**
6969
* Retrieves the HTML content of the current page.
70-
* @returns {Promise<string>} A promise that resolves with the HTML content.
70+
* @returns {Promise<HtmlReceived>} A promise that resolves with the HTML content.
7171
*/
72-
getHTML: () => {
72+
getHTML: ():Promise<HtmlReceived> => {
7373
return new Promise((resolve, reject) => {
7474
cbws.getWebsocket.send(JSON.stringify({
7575
"type": "browserEvent",
@@ -86,9 +86,9 @@ const cbbrowser = {
8686

8787
/**
8888
* Retrieves the Markdown content of the current page.
89-
* @returns {Promise<any>} A promise that resolves with the Markdown content.
89+
* @returns {Promise<GetMarkdownResponse>} A promise that resolves with the Markdown content.
9090
*/
91-
getMarkdown: () => {
91+
getMarkdown: ():Promise<GetMarkdownResponse> => {
9292
return new Promise((resolve, reject) => {
9393
cbws.getWebsocket.send(JSON.stringify({
9494
"type": "browserEvent",

src/modules/chat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// chat.ts
22
import cbws from './websocket';
33
import { EventEmitter } from 'events';
4-
import {ChatMessage} from '@codebolt/common'
4+
import {ChatMessage} from '@codebolt/types'
55

66

77

src/modules/codeutils.ts

+40-27
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import cbws from './websocket';
2+
import { GetJsTreeResponse, MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
23

34
/**
45
* A utility module for working with code.
56
*/
67
const cbcodeutils = {
7-
88

9-
getCodeTree: (): Promise<any> => {
10-
return new Promise((resolve, reject) => {
11-
cbws.getWebsocket.send(JSON.stringify({
12-
"type": "codeEvent",
13-
"action":"getCodeTree"
14-
}));
15-
cbws.getWebsocket.on('message', (data: string) => {
16-
const response = JSON.parse(data);
17-
if (response.type === "getCodeTreeResponse") {
18-
resolve(response.markdown); // Resolve the Promise with the response data
19-
}
20-
});
21-
});
22-
},
23-
getJsTree: (filePath:string): Promise<any> => {
9+
/**
10+
* Retrieves a JavaScript tree structure for a given file path.
11+
* @param {string} filePath - The path of the file to retrieve the JS tree for.
12+
* @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
13+
*/
14+
getJsTree: (filePath: string): Promise<GetJsTreeResponse> => {
2415
return new Promise((resolve, reject) => {
2516
cbws.getWebsocket.send(JSON.stringify({
2617
"type": "codeEvent",
@@ -32,12 +23,17 @@ const cbcodeutils = {
3223
cbws.getWebsocket.on('message', (data: string) => {
3324
const response = JSON.parse(data);
3425
if (response.type === "getJsTreeResponse") {
35-
resolve(resolve); // Resolve the Promise with the response data
26+
resolve(response); // Resolve the Promise with the response data
3627
}
3728
});
3829
});
3930
},
40-
getAllFilesAsMarkDown:()=>{
31+
32+
/**
33+
* Retrieves all files as Markdown.
34+
* @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
35+
*/
36+
getAllFilesAsMarkDown: (): Promise<string> => {
4137
return new Promise((resolve, reject) => {
4238
cbws.getWebsocket.send(JSON.stringify({
4339
"type": "codeEvent",
@@ -46,12 +42,20 @@ const cbcodeutils = {
4642
cbws.getWebsocket.on('message', (data: string) => {
4743
const response = JSON.parse(data);
4844
if (response.type === "getAllFilesMarkdownResponse") {
49-
resolve(response.markdown); // Resolve the Promise with the response data
45+
resolve(response); // Resolve the Promise with the response data
5046
}
5147
});
5248
});
5349
},
54-
performMatch:(matcherDefinition:object, problemPatterns:[], problems:[])=>{
50+
51+
/**
52+
* Performs a matching operation based on the provided matcher definition and problem patterns.
53+
* @param {object} matcherDefinition - The definition of the matcher.
54+
* @param {Array} problemPatterns - The patterns to match against.
55+
* @param {Array} problems - The list of problems.
56+
* @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
57+
*/
58+
performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]): Promise<MatchProblemResponse> => {
5559
return new Promise((resolve, reject) => {
5660
cbws.getWebsocket.send(JSON.stringify({
5761
"type": "codeEvent",
@@ -64,40 +68,49 @@ const cbcodeutils = {
6468
cbws.getWebsocket.on('message', (data: string) => {
6569
const response = JSON.parse(data);
6670
if (response.type === "getgetJsTreeResponse") {
67-
resolve(resolve); // Resolve the Promise with the response data
71+
resolve(response); // Resolve the Promise with the response data
6872
}
6973
});
7074
});
7175
},
72-
getMatcherList:()=>{
76+
77+
/**
78+
* Retrieves the list of matchers.
79+
* @returns {Promise<GetMatcherListTreeResponse>} A promise that resolves with the list of matchers response.
80+
*/
81+
getMatcherList: (): Promise<GetMatcherListTreeResponse> => {
7382
return new Promise((resolve, reject) => {
7483
cbws.getWebsocket.send(JSON.stringify({
7584
"type": "codeEvent",
7685
"action":"getMatcherList",
77-
7886
}));
7987
cbws.getWebsocket.on('message', (data: string) => {
8088
const response = JSON.parse(data);
8189
if (response.type === "getMatcherListTreeResponse") {
82-
resolve(resolve); // Resolve the Promise with the response data
90+
resolve(response); // Resolve the Promise with the response data
8391
}
8492
});
8593
});
8694
},
87-
matchDetail:(matcher:string)=>{
95+
96+
/**
97+
* Retrieves details of a match.
98+
* @param {string} matcher - The matcher to retrieve details for.
99+
* @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
100+
*/
101+
matchDetail: (matcher: string): Promise<getMatchDetail> => {
88102
return new Promise((resolve, reject) => {
89103
cbws.getWebsocket.send(JSON.stringify({
90104
"type": "codeEvent",
91105
"action":"getMatchDetail",
92106
payload:{
93107
match:matcher
94108
}
95-
96109
}));
97110
cbws.getWebsocket.on('message', (data: string) => {
98111
const response = JSON.parse(data);
99112
if (response.type === "matchDetailTreeResponse") {
100-
resolve(resolve); // Resolve the Promise with the response data
113+
resolve(response); // Resolve the Promise with the response data
101114
}
102115
});
103116
});

src/modules/dbmemory.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import cbws from './websocket';
2+
import {MemorySetResponse,MemoryGetResponse } from '@codebolt/types';
23

34
/**
45
* A module for handling in-memory database operations via WebSocket.
@@ -8,9 +9,9 @@ const dbmemory = {
89
* Adds a key-value pair to the in-memory database.
910
* @param {string} key - The key under which to store the value.
1011
* @param {any} value - The value to be stored.
11-
* @returns {Promise<any>} A promise that resolves with the response from the memory set event.
12+
* @returns {Promise<MemorySetResponse>} A promise that resolves with the response from the memory set event.
1213
*/
13-
addKnowledge: (key: string, value: any): Promise<any> => {
14+
addKnowledge: (key: string, value: any): Promise<MemorySetResponse> => {
1415
return new Promise((resolve, reject) => {
1516
cbws.getWebsocket.send(JSON.stringify({
1617
"type": "memoryEvent",
@@ -29,9 +30,9 @@ const dbmemory = {
2930
/**
3031
* Retrieves a value from the in-memory database by key.
3132
* @param {string} key - The key of the value to retrieve.
32-
* @returns {Promise<any>} A promise that resolves with the response from the memory get event.
33+
* @returns {Promise<MemoryGetResponse>} A promise that resolves with the response from the memory get event.
3334
*/
34-
getKnowledge: (key: string): Promise<any> => {
35+
getKnowledge: (key: string): Promise<MemoryGetResponse> => {
3536
return new Promise((resolve, reject) => {
3637
cbws.getWebsocket.send(JSON.stringify({
3738
"type": "memoryEvent",

src/modules/fs.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cbws from './websocket';
2-
2+
import {CreateFileResponse,CreateFolderResponse,ReadFileResponse,UpdateFileResponse,DeleteFileResponse,DeleteFolderResponse} from '@codebolt/types'
33
/**
44
* @module cbfs
55
* @description This module provides functionality to interact with the filesystem.
@@ -11,9 +11,9 @@ const cbfs = {
1111
* @param {string} fileName - The name of the file to create.
1212
* @param {string} source - The source content to write into the file.
1313
* @param {string} filePath - The path where the file should be created.
14-
* @returns {Promise<any>} A promise that resolves with the server response.
14+
* @returns {Promise<CreateFileResponse>} A promise that resolves with the server response.
1515
*/
16-
createFile: (fileName: string, source: string, filePath: string): Promise<any> => {
16+
createFile: (fileName: string, source: string, filePath: string): Promise<CreateFileResponse> => {
1717
return new Promise((resolve, reject) => {
1818
cbws.getWebsocket.send(JSON.stringify({
1919
"type":"fsEvent",
@@ -37,9 +37,9 @@ const cbfs = {
3737
* @description Creates a new folder.
3838
* @param {string} folderName - The name of the folder to create.
3939
* @param {string} folderPath - The path where the folder should be created.
40-
* @returns {Promise<any>} A promise that resolves with the server response.
40+
* @returns {Promise<CreateFolderResponse>} A promise that resolves with the server response.
4141
*/
42-
createFolder: (folderName: string, folderPath: string): Promise<any> => {
42+
createFolder: (folderName: string, folderPath: string): Promise<CreateFolderResponse> => {
4343
return new Promise((resolve, reject) => {
4444
cbws.getWebsocket.send(JSON.stringify({
4545
"type":"fsEvent",
@@ -62,9 +62,9 @@ const cbfs = {
6262
* @description Reads the content of a file.
6363
* @param {string} filename - The name of the file to read.
6464
* @param {string} filePath - The path of the file to read.
65-
* @returns {Promise<any>} A promise that resolves with the server response.
65+
* @returns {Promise<ReadFileResponse>} A promise that resolves with the server response.
6666
*/
67-
readFile: (filename: string, filePath: string): Promise<any> => {
67+
readFile: (filename: string, filePath: string): Promise<ReadFileResponse> => {
6868
return new Promise((resolve, reject) => {
6969
cbws.getWebsocket.send(JSON.stringify({
7070
"type":"fsEvent",
@@ -88,9 +88,9 @@ const cbfs = {
8888
* @param {string} filename - The name of the file to update.
8989
* @param {string} filePath - The path of the file to update.
9090
* @param {string} newContent - The new content to write into the file.
91-
* @returns {Promise<any>} A promise that resolves with the server response.
91+
* @returns {Promise<UpdateFileResponse>} A promise that resolves with the server response.
9292
*/
93-
updateFile: (filename: string, filePath: string, newContent: string): Promise<any> => {
93+
updateFile: (filename: string, filePath: string, newContent: string): Promise<UpdateFileResponse> => {
9494
return new Promise((resolve, reject) => {
9595
cbws.getWebsocket.send(JSON.stringify({
9696
"type":"fsEvent",
@@ -114,9 +114,9 @@ const cbfs = {
114114
* @description Deletes a file.
115115
* @param {string} filename - The name of the file to delete.
116116
* @param {string} filePath - The path of the file to delete.
117-
* @returns {Promise<any>} A promise that resolves with the server response.
117+
* @returns {Promise<DeleteFileResponse>} A promise that resolves with the server response.
118118
*/
119-
deleteFile: (filename: string, filePath: string): Promise<any> => {
119+
deleteFile: (filename: string, filePath: string): Promise<DeleteFileResponse> => {
120120
return new Promise((resolve, reject) => {
121121
cbws.getWebsocket.send(JSON.stringify({
122122
"type":"fsEvent",
@@ -139,9 +139,9 @@ const cbfs = {
139139
* @description Deletes a folder.
140140
* @param {string} foldername - The name of the folder to delete.
141141
* @param {string} folderpath - The path of the folder to delete.
142-
* @returns {Promise<any>} A promise that resolves with the server response.
142+
* @returns {Promise<DeleteFolderResponse>} A promise that resolves with the server response.
143143
*/
144-
deleteFolder: (foldername: string, folderpath: string): Promise<any> => {
144+
deleteFolder: (foldername: string, folderpath: string): Promise<DeleteFolderResponse> => {
145145
return new Promise((resolve, reject) => {
146146
cbws.getWebsocket.send(JSON.stringify({
147147
"type":"fsEvent",

src/modules/tokenizer.ts

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ const tokenizer = {
2626
}
2727
});
2828
});
29+
},
30+
31+
getToken: async (key: string): Promise<any> => {
32+
return new Promise((resolve, reject) => {
33+
cbws.getWebsocket.send(JSON.stringify({
34+
"type":"tokenizerEvent",
35+
"action": "getToken",
36+
"message": {
37+
item: key
38+
},
39+
}));
40+
cbws.getWebsocket.on('message', (data: string) => {
41+
const response = JSON.parse(data);
42+
if (response.type === "getTokenResponse") {
43+
resolve(response);
44+
}
45+
});
46+
});
2947
}
3048
}
3149

0 commit comments

Comments
 (0)