Skip to content

Commit

Permalink
Merge branch 'main' into table-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
md-abid-hussain authored Nov 26, 2024
2 parents b7ec2f3 + 7fc7da6 commit d056a3d
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default class Constants {
/** MindsDB ML Engines endpoint. */
public static readonly BASE_MLENGINES_URI = '/api/handlers/byom';

public static readonly FILES_URI = '/api/files';

public static readonly BASE_CALLBACK_URI = '/cloud/callback/model_status';


Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Projects = new ProjectsModule.ProjectsRestApiClient(
defaultAxiosInstance,
httpAuthenticator
);
const Tables = new TablesModule.TablesRestApiClient(SQL);
const Tables = new TablesModule.TablesRestApiClient(SQL, defaultAxiosInstance, httpAuthenticator);
const Views = new ViewsModule.ViewsRestApiClient(SQL);
const Jobs = new JobsModule.JobsRestApiClient(SQL);
const MLEngines = new MLEnginesModule.MLEnginesRestApiClient(
Expand Down
17 changes: 16 additions & 1 deletion src/ml_engines/ml_engine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MLEngineApiClient from './ml_enginesApiClient';
import { Readable } from 'stream';

/**
* Represents a MindsDB mlEngine and all supported operations.
Expand Down Expand Up @@ -36,13 +37,26 @@ export default class MLEngine {
}

/**
* Lists all mlEngines for the user.
* Creates a mlEngine with the given name, engine, and parameters.
* @param {string | Readable} [codeFilePath] - Path to the code file or Readable of to be used for the mlEngine.
* @param {string | Readable} [modulesFilePath] - Path to the modules file or Readable of to be used for the mlEngine.
* @param {string} [type] - Type of the mlEngine to be created.
* @returns {Promise<MLEngine>} - Newly created mlEngine.
* @throws {MindsDbError} - Something went wrong creating the mlEngine.
*/
async configure(codeFilePath:string | Readable,modulesFilePath:string | Readable,type:'venv' | 'inhouse'): Promise<void> {
await this.mlEnginesApiClient.createMLEngine(this.name,codeFilePath,modulesFilePath,type);
}


/* Lists all mlEngines for the user.
* @returns {Promise<Array<MLEngine>>} - List of all mlEngines.
*/
async list(): Promise<Array<MLEngine>> {
return this.mlEnginesApiClient.getAllMLEngines();
}


/**
* Removes a specified mlEngine by its name.
* @param {string} mlEngineName - The name of the mlEngine to remove.
Expand All @@ -53,6 +67,7 @@ export default class MLEngine {
await this.mlEnginesApiClient.deleteMLEngine(mlEngineName);
}


/** Deletes this mlEngine.
* @throws {MindsDbError} - Something went wrong deleting the mlEngine.
*/
Expand Down
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
20 changes: 20 additions & 0 deletions src/tables/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,26 @@ export default class Table {
await this.tablesApiClient.deleteTable(this.name, this.integration);
}

/**
* Deletes specific row (or multiple rows) from the table present in the given integration.
* @param {string} select - select statement to specify which rows should be deleted.
* @throws {MindsDbError} - Something went wrong deleting the data from the table.
*/
async deleteFromTable(select?:string):Promise<void> {
await this.tablesApiClient.deleteFromTable(this.name,this.integration,select);
}

/**
* Updates a table from its integration.
* @param {string} updateQuery - The SQL UPDATE query to run for updating the table.
* @throws {MindsDbError} - Something went wrong deleting the table.
*/
async update(updateQuery: string): Promise<void> {
await this.tablesApiClient.updateTable(this.name, this.integration,updateQuery);
}
}

* Insert data into this table.
* @param {string} select - SELECT query to insert data from.
* @throws {MindsDbError} - Something went wrong inserting data into the table.
Expand All @@ -63,3 +82,4 @@ export default class Table {
await this.tablesApiClient.insertTable(this.name, this.integration, select);
}
}

49 changes: 36 additions & 13 deletions src/tables/tablesApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,36 @@ export default abstract class TablesApiClient {
abstract deleteTable(name: string, integration: string): Promise<void>;

/**
* Insert data into this table.
* @param {string} name - Name of the table to be deleted.
* @param {string} integration - Name of the integration the table to be deleted is a part of.
* @param {string} select - SELECT query to insert data from.
* @throws {MindsDbError} - Something went wrong inserting data into the table.
* Updates a table from its integration.
* @param {string} name - Name of the table to be updated.
* @param {string} integration - Name of the integration the table to be updated is a part of.
* @param {string} updateQuery - The SQL UPDATE query to run for updating the table.
* @throws {MindsDbError} - Something went wrong deleting the table.
*/
abstract insertTable(
abstract updateTable(
name: string,
integration: string,
select: string
updateQuery: string
): Promise<void>;

/*
* Deletes specific row (or multiple rows) from the table present in the given integration.
* @param {string} name - Name of the table from which data is to be deleted.
* @param {string} integration - Name of the integration the table is a part of.
* @param {string} select - select statement to specify which rows should be deleted.
* @throws {MindsDbError} - Something went wrong deleting the data from the table.
*/
abstract deleteFromTable(name: string, integration: string, select?: string): Promise<void>;

/*
* Insert data into this table.
* @param {string} name - Name of the table to be deleted.
* @param {string} integration - Name of the integration the table to be deleted is a part of.
* @param {string} select - SELECT query to insert data from.
* @throws {MindsDbError} - Something went wrong inserting data into the table.
*/
abstract insertTable(name: string, integration: string, select: string): Promise<void>;

/**
* Deletes a file from the files integration.
* @param {string} name - Name of the file to be deleted.
Expand All @@ -61,11 +80,15 @@ export default abstract class TablesApiClient {
abstract deleteFile(name: string): Promise<void>;

/**
* Removes a table from its integration.
* @param {string} name - Name of the table to be removed.
* @param {string} integration - Name of the integration the table belongs to.
* @returns {Promise<void>} - Resolves when the table is successfully removed.
* @throws {MindsDbError} - Something went wrong removing the table.
* Uploads a file to a remote server or storage service.
*
* @param filePath - The local path to the file that needs to be uploaded.
* @param fileName - The name that the file should have on the remote server after the upload.
*
* @returns A promise that resolves when the file has been successfully uploaded.
* The promise does not return any value upon success.
*
* @throws {Error} - If there is an error during the file upload process, the promise is rejected with an error message.
*/
abstract removeTable(name: string, integration: string): Promise<void>;
abstract uploadFile(filePath: string, fileName: string, original_file_name ?: string): Promise<void>;
}
Loading

0 comments on commit d056a3d

Please sign in to comment.