feat: expand FewLineSDK with comprehensive database, query, command, and function management methods
This commit is contained in:
285
src/index.ts
285
src/index.ts
@ -101,4 +101,289 @@ export class FewLineSDK {
|
|||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getProjectInfo(): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/project/info`,
|
||||||
|
"GET"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database management part
|
||||||
|
*/
|
||||||
|
async createDatabase(projectId: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/create`,
|
||||||
|
"POST",
|
||||||
|
{ projectId }
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createNode(
|
||||||
|
host: string,
|
||||||
|
port: number,
|
||||||
|
username: string,
|
||||||
|
password: string
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/node/create`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTables(databaseId: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/tables/${databaseId}`,
|
||||||
|
"GET"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getColumns(databaseId: string, tableName: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/columns/${databaseId}/${tableName}`,
|
||||||
|
"GET"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async migrateUp(databaseId: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/migration/up/${databaseId}`,
|
||||||
|
"GET"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async migrateDown(databaseId: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/migration/down/${databaseId}`,
|
||||||
|
"GET"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createMigration(
|
||||||
|
up: string,
|
||||||
|
down: string,
|
||||||
|
databaseId: string
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/migration/create`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
up,
|
||||||
|
down,
|
||||||
|
databaseId,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async runQuery(databaseId: string, query: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/database/query/${databaseId}`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
query,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query and Commands part
|
||||||
|
*/
|
||||||
|
|
||||||
|
async createQuery(
|
||||||
|
projectToken: string,
|
||||||
|
source: string,
|
||||||
|
isTypescript: number = 0,
|
||||||
|
isPublic: number = 0
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/query/create`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
source,
|
||||||
|
isTypescript,
|
||||||
|
isPublic,
|
||||||
|
projectToken,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateQuery(
|
||||||
|
id: string,
|
||||||
|
updateData: Partial<{
|
||||||
|
source: string;
|
||||||
|
isTypescript?: number;
|
||||||
|
isPublic?: number;
|
||||||
|
}>
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/query/update/${id}`,
|
||||||
|
"POST",
|
||||||
|
updateData
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async query(
|
||||||
|
id: string,
|
||||||
|
query: Record<string, any>,
|
||||||
|
headers: Record<string, any> = {},
|
||||||
|
isPublic: boolean = false
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/query/${isPublic ? "run-public" : "run"}/${id}`,
|
||||||
|
"POST",
|
||||||
|
query,
|
||||||
|
headers
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteQuery(id: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/query/delete/${id}`,
|
||||||
|
"DELETE"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createCommand(
|
||||||
|
projectToken: string,
|
||||||
|
source: string,
|
||||||
|
isTypescript: number = 0,
|
||||||
|
isPublic: number = 0
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/command/create`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
source,
|
||||||
|
isTypescript,
|
||||||
|
isPublic,
|
||||||
|
projectToken,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateCommand(
|
||||||
|
id: string,
|
||||||
|
updateData: Partial<{
|
||||||
|
source: string;
|
||||||
|
isTypescript?: number;
|
||||||
|
isPublic?: number;
|
||||||
|
}>
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/command/update/${id}`,
|
||||||
|
"POST",
|
||||||
|
updateData
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async command(
|
||||||
|
id: string,
|
||||||
|
command: Record<string, any>,
|
||||||
|
headers: Record<string, any> = {},
|
||||||
|
isPublic: boolean = false
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/command/${isPublic ? "run-public" : "run"}/${id}`,
|
||||||
|
"POST",
|
||||||
|
command,
|
||||||
|
headers
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteCommand(id: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/command/delete/${id}`,
|
||||||
|
"DELETE"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis management part
|
||||||
|
*/
|
||||||
|
async createRedisNode(
|
||||||
|
host: string,
|
||||||
|
port: number,
|
||||||
|
user: string,
|
||||||
|
password: string
|
||||||
|
): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/redis/node/create`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
user,
|
||||||
|
password,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Functions management part
|
||||||
|
*/
|
||||||
|
|
||||||
|
async createFunction(name: string, source: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/functions/create`,
|
||||||
|
"POST",
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
source,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteFunction(name: string): Promise<any> {
|
||||||
|
const response = await this.createRequestWithAuthHeaders(
|
||||||
|
`${this.url}/functions/delete/${name}`,
|
||||||
|
"DELETE"
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user