Skip to content

Commit bcf5fdf

Browse files
fix projects methods and doc comment
1 parent 2a45a36 commit bcf5fdf

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/projects/project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import ProjectsApiClient from './projectsApiClient';
22

33
/**
4-
* Represents a MindsDB project and all supported operations.
4+
* Represents a MindsDB project and all supported operation related to project.
55
*/
66
export default class Project {
7-
/** API client to use for executing mlEngine operations. */
7+
/** API client to use for executing project operations. */
88
projectApiClient: ProjectsApiClient;
99

10-
/** Name of the mlEngine. */
10+
/** Name of the project. */
1111
name: string;
1212

1313
/**

src/projects/projectsApiClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@ import Project from './project';
33
/** Abstract class outlining Project operations supported by the SDK. */
44
export default abstract class ProjectsApiClient {
55
/**
6-
* Gets all MindsDB projects for the current user.
6+
* Gets all MindsDB projects.
7+
*
78
* @returns {Promise<Array<Project>>} - All projects.
89
*/
910
abstract getAllProjects(): Promise<Array<Project>>;
1011

12+
/**
13+
* Gets a MindsDB project by name.
14+
*
15+
* @param {string} name - Name of the project to get.
16+
*/
17+
abstract getProject(name: string): Promise<Project>;
18+
1119
/**
1220
* Creates a new MindsDB project.
13-
* @param {string} name - Name of the project.
21+
*
22+
* @param {string} name - Name of the project to create.
1423
* @returns {Promise<Project>} - The created project.
1524
*/
1625
abstract createProject(name: string): Promise<Project>;
1726

1827
/**
28+
* Delete a MindsDB project by name.
1929
*
2030
* @param {string} name - Name of the project to delete.
2131
*/

src/projects/projectsRestApiClient.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
2020

2121
/**
2222
* Constructor for Projects API client.
23+
* @param {SqlApiClient} sqlClient - SQL API client to send all SQL query requests.
2324
* @param {Axios} client - Axios instance to send all HTTP requests.
25+
* @param {HttpAuthenticator} authenticator - Authenticator to use for reauthenticate if needed.
2426
*/
2527
constructor(
2628
sqlClient: SqlApiClient,
@@ -42,6 +44,7 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
4244

4345
/**
4446
* Gets all MindsDB projects for the current user.
47+
*
4548
* @returns {Promise<Array<Project>>} - All projects.
4649
* @throws {MindsDbError} - Something went wrong fetching projects.
4750
*/
@@ -56,15 +59,42 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
5659
if (!projectsResponse.data) {
5760
return [];
5861
}
59-
return projectsResponse.data;
62+
63+
const projects = projectsResponse.data.map((project: any) => {
64+
return new Project(this, project.name);
65+
});
66+
67+
return projects;
6068
} catch (error) {
6169
throw MindsDbError.fromHttpError(error, projectsUrl);
6270
}
6371
}
6472

6573
/**
74+
* Gets a MindsDB project by name.
6675
*
67-
* @param name - Name of the project to create.
76+
* @param {string} name - Name of the project to get.
77+
* @returns {Promise<Project>} - The project.
78+
*/
79+
override async getProject(name: string): Promise<Project> {
80+
const projectsUrl = this.getProjectsUrl() + `/${name}`;
81+
const { authenticator, client } = this;
82+
83+
const projectResponse = await client.get(
84+
projectsUrl,
85+
getBaseRequestConfig(authenticator)
86+
);
87+
if (!projectResponse.data) {
88+
throw new MindsDbError('Project not found');
89+
}
90+
91+
return new Project(this, projectResponse.data.name);
92+
}
93+
94+
/**
95+
* Creates a new MindsDB project.
96+
*
97+
* @param {string} name - Name of the project to create.
6898
* @returns {Promise<Project>} - The created project.
6999
*/
70100
override async createProject(name: string): Promise<Project> {
@@ -79,6 +109,7 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
79109
}
80110

81111
/**
112+
* Delete a MindsDB project by name.
82113
*
83114
* @param {string} name - Name of the project to delete.
84115
*/
@@ -90,5 +121,4 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
90121
throw new MindsDbError(sqlQueryResult.error_message);
91122
}
92123
}
93-
94124
}

0 commit comments

Comments
 (0)