Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented method to create project #76

Merged
merged 7 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 33 additions & 2 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 {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 name - Name of the project to create.
* @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 Down