From e5e53557c935e7c3fd31428d19c699f894ba6748 Mon Sep 17 00:00:00 2001 From: lborv Date: Tue, 28 Oct 2025 20:37:04 +0200 Subject: [PATCH] feat: expand FewLineSDK with comprehensive database, query, command, and function management methods --- src/index.ts | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) diff --git a/src/index.ts b/src/index.ts index 1753890..449dfd4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -101,4 +101,289 @@ export class FewLineSDK { return response.data; } + + async getProjectInfo(): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/project/info`, + "GET" + ); + + return response.data; + } + + /** + * Database management part + */ + async createDatabase(projectId: string): Promise { + 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 { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/database/node/create`, + "POST", + { + host, + port, + username, + password, + } + ); + + return response.data; + } + + async getTables(databaseId: string): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/database/tables/${databaseId}`, + "GET" + ); + + return response.data; + } + + async getColumns(databaseId: string, tableName: string): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/database/columns/${databaseId}/${tableName}`, + "GET" + ); + + return response.data; + } + + async migrateUp(databaseId: string): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/database/migration/up/${databaseId}`, + "GET" + ); + + return response.data; + } + + async migrateDown(databaseId: string): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/database/migration/down/${databaseId}`, + "GET" + ); + + return response.data; + } + + async createMigration( + up: string, + down: string, + databaseId: string + ): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/database/migration/create`, + "POST", + { + up, + down, + databaseId, + } + ); + + return response.data; + } + + async runQuery(databaseId: string, query: string): Promise { + 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 { + 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 { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/query/update/${id}`, + "POST", + updateData + ); + + return response.data; + } + + async query( + id: string, + query: Record, + headers: Record = {}, + isPublic: boolean = false + ): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/query/${isPublic ? "run-public" : "run"}/${id}`, + "POST", + query, + headers + ); + + return response.data; + } + + async deleteQuery(id: string): Promise { + 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 { + 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 { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/command/update/${id}`, + "POST", + updateData + ); + + return response.data; + } + + async command( + id: string, + command: Record, + headers: Record = {}, + isPublic: boolean = false + ): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/command/${isPublic ? "run-public" : "run"}/${id}`, + "POST", + command, + headers + ); + + return response.data; + } + + async deleteCommand(id: string): Promise { + 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 { + 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 { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/functions/create`, + "POST", + { + name, + source, + } + ); + + return response.data; + } + + async deleteFunction(name: string): Promise { + const response = await this.createRequestWithAuthHeaders( + `${this.url}/functions/delete/${name}`, + "DELETE" + ); + + return response.data; + } }