Skip to content

Commit

Permalink
fix projects methods and doc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
md-abid-hussain committed Nov 18, 2024
1 parent 2a45a36 commit bcf5fdf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/projects/project.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ProjectsApiClient from './projectsApiClient';

/**
* Represents a MindsDB project and all supported operations.
* Represents a MindsDB project and all supported operation related to project.
*/
export default class Project {
/** API client to use for executing mlEngine operations. */
/** API client to use for executing project operations. */
projectApiClient: ProjectsApiClient;

/** Name of the mlEngine. */
/** Name of the project. */
name: string;

/**
Expand Down
14 changes: 12 additions & 2 deletions src/projects/projectsApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ import Project from './project';
/** Abstract class outlining Project operations supported by the SDK. */
export default abstract class ProjectsApiClient {
/**
* Gets all MindsDB projects for the current user.
* Gets all MindsDB projects.
*
* @returns {Promise<Array<Project>>} - All projects.
*/
abstract getAllProjects(): Promise<Array<Project>>;

/**
* Gets a MindsDB project by name.
*
* @param {string} name - Name of the project to get.
*/
abstract getProject(name: string): Promise<Project>;

/**
* Creates a new MindsDB project.
* @param {string} name - Name of the project.
*
* @param {string} name - Name of the project to create.
* @returns {Promise<Project>} - The created project.
*/
abstract createProject(name: string): Promise<Project>;

/**
* Delete a MindsDB project by name.
*
* @param {string} name - Name of the project to delete.
*/
Expand Down
36 changes: 33 additions & 3 deletions src/projects/projectsRestApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {

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

/**
* Gets all MindsDB projects for the current user.
*
* @returns {Promise<Array<Project>>} - All projects.
* @throws {MindsDbError} - Something went wrong fetching projects.
*/
Expand All @@ -56,15 +59,42 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
if (!projectsResponse.data) {
return [];
}
return projectsResponse.data;

const projects = projectsResponse.data.map((project: any) => {
return new Project(this, project.name);
});

return projects;
} catch (error) {
throw MindsDbError.fromHttpError(error, projectsUrl);
}
}

/**
* Gets a MindsDB project by name.
*
* @param name - Name of the project to create.
* @param {string} name - Name of the project to get.
* @returns {Promise<Project>} - The project.
*/
override async getProject(name: string): Promise<Project> {
const projectsUrl = this.getProjectsUrl() + `/${name}`;
const { authenticator, client } = this;

const projectResponse = await client.get(
projectsUrl,
getBaseRequestConfig(authenticator)
);
if (!projectResponse.data) {
throw new MindsDbError('Project not found');
}

return new Project(this, projectResponse.data.name);
}

/**
* Creates a new MindsDB project.
*
* @param {string} name - Name of the project to create.
* @returns {Promise<Project>} - The created project.
*/
override async createProject(name: string): Promise<Project> {
Expand All @@ -79,6 +109,7 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
}

/**
* Delete a MindsDB project by name.
*
* @param {string} name - Name of the project to delete.
*/
Expand All @@ -90,5 +121,4 @@ export default class ProjectsRestApiClient extends ProjectsApiClient {
throw new MindsDbError(sqlQueryResult.error_message);
}
}

}

0 comments on commit bcf5fdf

Please sign in to comment.