@singlestore/client
Advanced tools
Comparing version 0.0.35 to 0.0.36
import { AnyAI, CreateChatCompletionResult } from '@singlestore/ai'; | ||
import * as mysql2_promise from 'mysql2/promise'; | ||
import { PoolOptions, Pool, ResultSetHeader, FieldPacket } from 'mysql2/promise'; | ||
export { FieldPacket, ResultSetHeader, RowDataPacket } from 'mysql2/promise'; | ||
import { Optional, Tail, Defined } from '@repo/utils'; | ||
export { escape } from 'mysql2'; | ||
type APIVersion = 1 | 2; | ||
declare class API { | ||
private readonly _apiKey?; | ||
private readonly _version; | ||
private readonly _baseURL; | ||
constructor(_apiKey?: string | undefined, _version?: APIVersion); | ||
execute<T = any>(url: string, { version, ...params }?: RequestInit & { | ||
version?: APIVersion; | ||
}): Promise<T>; | ||
} | ||
declare abstract class APIManager { | ||
protected readonly _api: API; | ||
protected abstract readonly _baseURL: string; | ||
constructor(_api: API); | ||
protected _execute<T = any>(...[url, params]: Partial<Parameters<API["execute"]>>): Promise<T>; | ||
} | ||
interface ConnectionConfig extends Partial<Omit<PoolOptions, "name" | "database">> { | ||
} | ||
type ConnectionClient = Pool; | ||
declare class Connection { | ||
config: ConnectionConfig; | ||
client: Pool; | ||
client: ConnectionClient; | ||
constructor(config: ConnectionConfig); | ||
static create(config: ConnectionConfig): Connection; | ||
disconnect(): Promise<void>; | ||
} | ||
type ColumnName = string; | ||
type ColumnType = any; | ||
interface ColumnSchema { | ||
name: string; | ||
name: ColumnName; | ||
type: string; | ||
nullable?: boolean; | ||
primaryKey?: boolean; | ||
autoIncrement?: boolean; | ||
default?: any; | ||
clauses?: string[]; | ||
nullable: boolean; | ||
primaryKey: boolean; | ||
autoIncrement: boolean; | ||
default: any; | ||
clauses: string[]; | ||
} | ||
interface ColumnInfo<T extends string = string> { | ||
name: T; | ||
interface AddColumnSchema extends Optional<ColumnSchema, "nullable" | "primaryKey" | "autoIncrement" | "default" | "clauses"> { | ||
} | ||
interface ColumnInfo<TName extends ColumnName> { | ||
name: TName; | ||
type: string; | ||
@@ -34,19 +57,35 @@ null: string; | ||
} | ||
declare class Column { | ||
private _connection; | ||
databaseName: string; | ||
tableName: string; | ||
name: string; | ||
declare class Column<TName extends ColumnName, TTableName extends TableName, TDatabaseName extends DatabaseName> { | ||
private _client; | ||
private _path; | ||
constructor(_connection: Connection, databaseName: string, tableName: string, name: string); | ||
static normalizeInfo<T extends string = string>(info: any): ColumnInfo<T>; | ||
static schemaToClauses(schema: ColumnSchema): string; | ||
static add(connection: Connection, databaseName: string, tableName: string, schema: ColumnSchema): Promise<Column>; | ||
static drop(connection: Connection, databaseName: string, tableName: string, name: string): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
showInfo(): Promise<ColumnInfo<string>>; | ||
name: TName; | ||
tableName: TTableName; | ||
databaseName: TDatabaseName; | ||
constructor(_client: ConnectionClient, _path: string, name: TName, tableName: TTableName, databaseName: TDatabaseName); | ||
static schemaToClauses(schema: Partial<ColumnSchema>): string; | ||
static drop<TName extends ColumnName, TTableName extends TableName, TDatabaseName extends DatabaseName>(client: ConnectionClient, databaseName: TDatabaseName, tableName: TTableName, name: TName): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
static normalizeInfo<TName extends ColumnName>(info: any): ColumnInfo<TName>; | ||
static modify<TName extends ColumnName>(client: ConnectionClient, path: string, name: TName, schema: Partial<Omit<ColumnSchema, "name">>): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
static rename<TName extends ColumnName>(client: ConnectionClient, path: string, name: TName, newName: ColumnName): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
static showInfo<TName extends ColumnName, TTableName extends TableName, TDatabaseName extends DatabaseName>(client: ConnectionClient, databaseName: TDatabaseName, tableName: TTableName, name: TName): Promise<ColumnInfo<TName>>; | ||
drop(): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
modify(schema: Partial<Omit<ColumnSchema, "name">>): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
rename(newName: string): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
modify(...args: Parameters<typeof Column.modify> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
rename(...[newName, ...args]: Parameters<typeof Column.rename> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
showInfo(): Promise<ColumnInfo<TName>>; | ||
} | ||
declare class ColumnManager<TTableName extends TableName, TTableType extends TableType, TDatabaseName extends DatabaseName> { | ||
private _client; | ||
tableName: TTableName; | ||
databaseName: TDatabaseName; | ||
private _path; | ||
constructor(_client: ConnectionClient, tableName: TTableName, databaseName: TDatabaseName); | ||
use<TName extends TableColumnName<TTableType> | (ColumnName & {})>(name: TName): Column<TName, TTableName, TDatabaseName>; | ||
add<TSchema extends AddColumnSchema>(schema: TSchema): Promise<Column<TSchema["name"], TTableName, TDatabaseName>>; | ||
drop(name: TableColumnName<TTableType> | (ColumnName & {})): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
modify(name: TableColumnName<TTableType> | (ColumnName & {}), ...args: Parameters<typeof Column.modify> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
rename(name: TableColumnName<TTableType> | (ColumnName & {}), ...args: Parameters<typeof Column.rename> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
showInfo<TName extends TableColumnName<TTableType> | (ColumnName & {})>(name: TName, ...args: Parameters<typeof Column.showInfo> extends [any, any, any, any, ...infer Rest] ? Rest : never): Promise<ColumnInfo<TName>>; | ||
} | ||
type MergeUnion<T> = (T extends any ? (i: T) => void : never) extends (i: infer U) => void ? { | ||
@@ -62,7 +101,3 @@ [K in keyof U]: U[K]; | ||
as: TAs; | ||
on: [ | ||
(string & {}) | keyof TTableType["columns"], | ||
JoinOperator, | ||
(string & {}) | keyof TDatabaseType["tables"][K]["columns"] | ||
]; | ||
on: [(string & {}) | keyof TTableType, JoinOperator, (string & {}) | keyof TDatabaseType["tables"][K]["columns"]]; | ||
}; | ||
@@ -73,3 +108,3 @@ }[keyof TDatabaseType["tables"]]; | ||
}[TJoinClauses[number]["as"]]; | ||
type SelectClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ("*" | keyof TTableType["columns"] | ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses> | `${TJoinClauseAs}.*` | `${string} AS ${string}`)[]; | ||
type SelectClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ("*" | keyof TTableType | ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses> | `${TJoinClauseAs}.*` | `${string} AS ${string}`)[]; | ||
type WhereOperator<TColumnValue> = TColumnValue extends string ? { | ||
@@ -92,3 +127,3 @@ eq?: TColumnValue; | ||
type WhereClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ({ | ||
[K in keyof TTableType["columns"]]?: WhereOperator<TTableType["columns"][K]> | TTableType["columns"][K]; | ||
[K in keyof TTableType]?: WhereOperator<TTableType[K]> | TTableType[K]; | ||
} & { | ||
@@ -102,6 +137,6 @@ [K in TJoinClauses[number] as K["as"]]: { | ||
}; | ||
type GroupByClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ((string & {}) | keyof TTableType["columns"] | ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>)[]; | ||
type GroupByClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = ((string & {}) | keyof TTableType | ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>)[]; | ||
type OrderByDirection = "asc" | "desc"; | ||
type OrderByClause<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[]> = { | ||
[K in (string & {}) | keyof TTableType["columns"] | Extract<ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, string>]?: OrderByDirection; | ||
[K in (string & {}) | keyof TTableType | Extract<ExtractJoinClauseColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, string>]?: OrderByDirection; | ||
}; | ||
@@ -118,4 +153,4 @@ interface QueryBuilderParams<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>> { | ||
type AnyQueryBuilderParams = QueryBuilderParams<any, any, any, any, any>; | ||
type ExtractSelectedQueryColumns<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>> = TSelectClause extends (infer TColumn)[] ? MergeUnion<TColumn extends "*" ? TTableType["columns"] : TColumn extends keyof TTableType["columns"] ? { | ||
[K in TColumn]: TTableType["columns"][K]; | ||
type ExtractSelectedQueryColumns<TTableType extends TableType, TDatabaseType extends DatabaseType, TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>> = TSelectClause extends (infer TColumn)[] ? MergeUnion<TColumn extends "*" ? TTableType : TColumn extends keyof TTableType ? { | ||
[K in TColumn]: TTableType[K]; | ||
} : TColumn extends `${infer TJoinAs}.${infer TJoinColumn}` ? TJoinAs extends TJoinClauseAs ? TJoinColumn extends keyof TDatabaseType["tables"][Extract<TJoinClauses[number], { | ||
@@ -158,19 +193,20 @@ as: TJoinAs; | ||
interface TableType { | ||
name: string; | ||
columns: Record<string, ColumnType>; | ||
type TableName = string; | ||
interface TableType extends Record<TableName, ColumnType> { | ||
} | ||
interface TableSchema<TType extends TableType> { | ||
name: TType["name"]; | ||
interface TableSchema<TName extends TableName, TType extends TableType> { | ||
name: TName; | ||
columns: { | ||
[K in keyof TType["columns"]]: Omit<ColumnSchema, "name">; | ||
[K in keyof TType]: Omit<AddColumnSchema, "name">; | ||
}; | ||
primaryKeys?: string[]; | ||
fulltextKeys?: string[]; | ||
clauses?: string[]; | ||
primaryKeys: string[]; | ||
fulltextKeys: string[]; | ||
clauses: string[]; | ||
} | ||
interface TableInfo<TName extends string> { | ||
interface CreateTableSchema<TName extends TableName, TType extends TableType> extends Optional<TableSchema<TName, TType>, "primaryKeys" | "fulltextKeys" | "clauses"> { | ||
} | ||
interface TableInfo<TName extends TableName> { | ||
name: TName; | ||
} | ||
interface TableInfoExtended<TName extends string> extends TableInfo<TName> { | ||
interface TableInfoExtended<TName extends TableName> extends TableInfo<TName> { | ||
tableType: string; | ||
@@ -180,44 +216,57 @@ distributed: boolean; | ||
} | ||
type TableColumnName<TType extends TableType> = Extract<keyof TType["columns"], string>; | ||
type TableColumnName<TType extends TableType> = Extract<keyof TType, string>; | ||
type VectorScoreKey = "v_score"; | ||
declare class Table<TTableType extends TableType = TableType, TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined> { | ||
private _connection; | ||
databaseName: string; | ||
name: TTableType["name"]; | ||
declare class Table<TName extends TableName, TType extends TableType, TDatabaseType extends DatabaseType, TAI extends AnyAI | undefined> { | ||
private _client; | ||
name: TName; | ||
databaseName: TDatabaseType["name"]; | ||
private _ai?; | ||
private _path; | ||
vScoreKey: VectorScoreKey; | ||
constructor(_connection: Connection, databaseName: string, name: TTableType["name"], _ai?: TAi | undefined); | ||
column: ColumnManager<TName, TType, TDatabaseType["name"]>; | ||
constructor(_client: ConnectionClient, name: TName, databaseName: TDatabaseType["name"], _ai?: TAI | undefined); | ||
private get ai(); | ||
static normalizeInfo<TName extends string, TExtended extends boolean>(info: any, extended?: TExtended): TExtended extends true ? TableInfoExtended<TName> : TableInfo<TName>; | ||
static schemaToClauses(schema: TableSchema<TableType>): string; | ||
static create<TType extends TableType = TableType, TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined>(connection: Connection, databaseName: string, schema: TableSchema<TType>, ai?: TAi): Promise<Table<TType, TDatabaseType, TAi>>; | ||
static drop(connection: Connection, databaseName: string, name: string): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? TableInfoExtended<string> : TableInfo<string>>; | ||
static schemaToClauses(schema: CreateTableSchema<TableName, TableType>): string; | ||
static normalizeInfo<TName extends TableName, TExtended extends boolean, _ReturnType = TExtended extends true ? TableInfoExtended<TName> : TableInfo<TName>>(info: any, extended?: TExtended): _ReturnType; | ||
static drop<TName extends TableName, TDatabaseName extends DatabaseName>(client: ConnectionClient, databaseName: TDatabaseName, name: TName): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
static truncate<TName extends TableName, TDatabaseName extends DatabaseName>(client: ConnectionClient, databaseName: TDatabaseName, tableName: TName): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
static rename<TName extends TableName, TDatabaseName extends DatabaseName>(client: ConnectionClient, databaseName: TDatabaseName, name: TName, newName: TableName): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
drop(): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
column(name: TableColumnName<TTableType> | (string & {})): Column; | ||
showColumnsInfo(): Promise<ColumnInfo<TableColumnName<TTableType>>[]>; | ||
addColumn(schema: ColumnSchema): Promise<Column>; | ||
dropColumn(name: TableColumnName<TTableType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? TableInfoExtended<TName> : TableInfo<TName>>; | ||
showColumnsInfo(): Promise<ColumnInfo<Extract<keyof TType, string>>[]>; | ||
truncate(): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
rename(newName: string): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
insert(values: Partial<TTableType["columns"]> | Partial<TTableType["columns"]>[]): Promise<[ResultSetHeader, FieldPacket[]][]>; | ||
find<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>>(params?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<ExtractSelectedQueryColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>[]>; | ||
update(values: Partial<TTableType["columns"]>, where: WhereClause<TTableType, TDatabaseType, any, any>): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
delete(where?: WhereClause<TTableType, TDatabaseType, any, any>): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
vectorSearch<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, TParams extends { | ||
rename(...[newName, ...args]: Parameters<typeof Table.rename> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
insert(values: Partial<TType> | Partial<TType>[]): Promise<[ResultSetHeader, FieldPacket[]][]>; | ||
find<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TType, TDatabaseType, TJoinClauseAs, TJoinClauses>>(params?: QueryBuilderParams<TType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<ExtractSelectedQueryColumns<TType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>[]>; | ||
update(values: Partial<TType>, where: WhereClause<TType, TDatabaseType, any, any>): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
delete(where?: WhereClause<TType, TDatabaseType, any, any>): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
vectorSearch<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TType, TDatabaseType, TJoinClauseAs, TJoinClauses>, TParams extends { | ||
prompt: string; | ||
vectorColumn: TableColumnName<TTableType>; | ||
embeddingParams?: TAi extends AnyAI ? Parameters<TAi["embeddings"]["create"]>[1] : never; | ||
}>(params: TParams, queryParams?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<(ExtractSelectedQueryColumns<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause> & { | ||
vectorColumn: TableColumnName<TType>; | ||
embeddingParams?: TAI extends AnyAI ? Parameters<TAI["embeddings"]["create"]>[1] : never; | ||
}>(params: TParams, queryParams?: QueryBuilderParams<TType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<(ExtractSelectedQueryColumns<TType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause> & { | ||
v_score: number; | ||
})[]>; | ||
createChatCompletion<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TTableType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses>, TParams extends Parameters<this["vectorSearch"]>[0] & (TAi extends AnyAI ? Parameters<TAi["chatCompletions"]["create"]>[0] : never) & { | ||
createChatCompletion<TJoinClauseAs extends string, TJoinClauses extends JoinClause<TType, TDatabaseType, TJoinClauseAs>[], TSelectClause extends SelectClause<TType, TDatabaseType, TJoinClauseAs, TJoinClauses>, TParams extends Parameters<this["vectorSearch"]>[0] & (TAI extends AnyAI ? Parameters<TAI["chatCompletions"]["create"]>[0] : never) & { | ||
template?: string; | ||
}>(params: TParams, queryParams?: QueryBuilderParams<TTableType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<CreateChatCompletionResult<TParams["stream"]>>; | ||
}>(params: TParams, queryParams?: QueryBuilderParams<TType, TDatabaseType, TJoinClauseAs, TJoinClauses, TSelectClause>): Promise<CreateChatCompletionResult<TParams["stream"]>>; | ||
} | ||
declare class TableManager<TDatabaseType extends DatabaseType, TAI extends AnyAI | undefined> { | ||
private _client; | ||
private _ai; | ||
databaseName: TDatabaseType["name"]; | ||
constructor(_client: ConnectionClient, _ai: TAI, databaseName: TDatabaseType["name"]); | ||
static create<TName extends TableName, TType extends TableType, TDatabaseType extends DatabaseType, TAI extends AnyAI | undefined>(client: ConnectionClient, databaseName: TDatabaseType["name"], schema: CreateTableSchema<TName, TType>, ai?: TAI): Promise<Table<TName, TType, TDatabaseType, TAI>>; | ||
use<TName extends DatabaseTableName<TDatabaseType> | (TableName & {}), TType>(name: TName): Table<TName, TType extends TableType ? TType : TName extends DatabaseTableName<TDatabaseType> ? TDatabaseType["tables"][TName] : TableType, TDatabaseType, TAI>; | ||
create<TName extends TableName, TType extends TableType>(schema: CreateTableSchema<TName, TType>): Promise<Table<TName, TType, TDatabaseType, TAI>>; | ||
drop(name: DatabaseTableName<TDatabaseType> | (TableName & {}), ...args: Parameters<typeof Table.drop> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
truncate(name: DatabaseTableName<TDatabaseType> | (TableName & {}), ...args: Parameters<typeof Table.truncate> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
rename(name: DatabaseTableName<TDatabaseType> | (TableName & {}), ...args: Parameters<typeof Table.rename> extends [any, any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
} | ||
type DatabaseName = string; | ||
interface DatabaseType { | ||
name: string; | ||
tables: Record<string, TableType>; | ||
name: DatabaseName; | ||
tables: Record<PropertyKey, TableType>; | ||
} | ||
@@ -227,9 +276,9 @@ interface DatabaseSchema<TType extends DatabaseType> { | ||
tables?: { | ||
[K in keyof TType["tables"]]: Omit<TableSchema<TType["tables"][K]>, "name">; | ||
[K in keyof TType["tables"]]: Omit<CreateTableSchema<Extract<K, string>, TType["tables"][K]>, "name">; | ||
}; | ||
} | ||
interface DatabaseInfo<T extends string = string> { | ||
name: T; | ||
interface DatabaseInfo<TType extends DatabaseType> { | ||
name: TType["name"]; | ||
} | ||
interface DatabaseInfoExtended<T extends string> extends DatabaseInfo<T> { | ||
interface DatabaseInfoExtended<TType extends DatabaseType> extends DatabaseInfo<TType> { | ||
commits: number; | ||
@@ -252,25 +301,27 @@ role: string; | ||
} | ||
type DatabaseTableName<TType extends DatabaseType> = Extract<keyof TType["tables"], string>; | ||
type InferDatabaseType<T> = T extends Database<infer TType, any, any> ? TType : never; | ||
type DatabaseTablesToRecords<TTables extends DatabaseType["tables"]> = { | ||
[K in keyof TTables]: TTables[K]["columns"][]; | ||
[K in keyof TTables]: TTables[K][]; | ||
}; | ||
type AnyDatabase = Database<any, AnyAI | undefined>; | ||
type DatabaseTableName<TType extends DatabaseType> = Extract<keyof TType["tables"], string>; | ||
type InferDatabaseType<T> = T extends Database<infer U, any> ? U : never; | ||
declare class Database<TDatabaseType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined> { | ||
private _connection; | ||
name: TDatabaseType["name"]; | ||
workspaceName?: string | undefined; | ||
private _ai?; | ||
constructor(_connection: Connection, name: TDatabaseType["name"], workspaceName?: string | undefined, _ai?: TAi | undefined); | ||
static normalizeInfo<TName extends string = string, TExtended extends boolean = false>(info: any, extended?: TExtended): TExtended extends true ? DatabaseInfoExtended<TName> : DatabaseInfo<TName>; | ||
static create<TType extends DatabaseType = DatabaseType, TAi extends AnyAI | undefined = undefined>(connection: Connection, schema: DatabaseSchema<TType>, workspaceName?: string, ai?: TAi): Promise<Database<TType, TAi>>; | ||
static drop(connection: Connection, name: string): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? DatabaseInfoExtended<TDatabaseType["name"]> : DatabaseInfo<TDatabaseType["name"]>>; | ||
type AnyDatabase = Database<any, any, any>; | ||
declare class Database<TType extends DatabaseType, TWorkspaceName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined> { | ||
private _client; | ||
private _ai; | ||
name: TType["name"]; | ||
workspaceName: TWorkspaceName; | ||
table: TableManager<TType, TAI>; | ||
constructor(_client: ConnectionClient, _ai: TAI, name: TType["name"], workspaceName: TWorkspaceName); | ||
static drop<TName extends DatabaseName>(client: ConnectionClient, name: TName): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
static normalizeInfo<TType extends DatabaseType, TExtended extends boolean, _ReturnType = TExtended extends true ? DatabaseInfoExtended<TType> : DatabaseInfo<TType>>(info: any, extended?: TExtended): _ReturnType; | ||
drop(...args: Parameters<typeof Database.drop> extends [any, any, ...infer Rest] ? Rest : never): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
showInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<TExtended extends true ? DatabaseInfoExtended<TType> : DatabaseInfo<TType>>; | ||
showTablesInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<(TExtended extends true ? TableInfoExtended<Extract<keyof TType["tables"], string>> : TableInfo<Extract<keyof TType["tables"], string>>)[]>; | ||
describe(): Promise<{ | ||
tables: { | ||
columns: ColumnInfo<Extract<keyof (TDatabaseType["tables"][Extract<keyof TDatabaseType["tables"], string>] extends TableType ? TDatabaseType["tables"][Extract<keyof TDatabaseType["tables"], string>] : TableType)["columns"], string>>[]; | ||
columns: ColumnInfo<Extract<keyof (Extract<keyof TType["tables"], string> extends infer T ? T extends Extract<keyof TType["tables"], string> ? T extends Extract<keyof TType["tables"], string> ? TType["tables"][T] : TableType : never : never), string>>[]; | ||
tableType: string; | ||
distributed: boolean; | ||
storageType: string; | ||
name: Extract<keyof TDatabaseType["tables"], string>; | ||
name: Extract<keyof TType["tables"], string>; | ||
}[]; | ||
@@ -293,49 +344,698 @@ commits: number; | ||
pendingBlobFSyncs: number; | ||
name: TDatabaseType["name"]; | ||
name: TType["name"]; | ||
}>; | ||
drop(): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
table<TType, TName extends DatabaseTableName<TDatabaseType> | (string & {}) = DatabaseTableName<TDatabaseType> | (string & {})>(name: TName): Table<TType extends TableType ? TType : TDatabaseType["tables"][TName] extends TableType ? TDatabaseType["tables"][TName] : TableType, TDatabaseType, TAi>; | ||
showTablesInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<(TExtended extends true ? TableInfoExtended<Extract<keyof TDatabaseType["tables"], string>> : TableInfo<Extract<keyof TDatabaseType["tables"], string>>)[]>; | ||
createTable<TType extends TableType = TableType>(schema: TableSchema<TType>): Promise<Table<TType, TDatabaseType, TAi>>; | ||
dropTable(name: DatabaseTableName<TDatabaseType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
query<T extends any[]>(statement: string): Promise<T[]>; | ||
query<TReturnType extends any[]>(statement: string): Promise<TReturnType[]>; | ||
} | ||
interface WorkspaceType { | ||
databases: Record<string, DatabaseType>; | ||
declare class DatabaseManager<TWorkspaceName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined> { | ||
private _client; | ||
private _ai; | ||
workspaceName: TWorkspaceName; | ||
constructor(_client: ConnectionClient, _ai: TAI, workspaceName: TWorkspaceName); | ||
use<TType extends DatabaseType>(name: TType["name"]): Database<TType, TWorkspaceName, TAI>; | ||
create<TType extends DatabaseType>(schema: DatabaseSchema<TType>): Promise<Database<TType, TWorkspaceName, TAI>>; | ||
drop(...args: Tail<Parameters<typeof Database.drop>>): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
} | ||
interface WorkspaceSchema<TWorkspaceType extends WorkspaceType> { | ||
interface CreateWorkspaceConnectionConfig<TName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined> extends ConnectionConfig { | ||
name?: TName; | ||
ai?: TAI; | ||
} | ||
declare class WorkspaceConnection<TName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined> extends Connection { | ||
name: TName; | ||
private _ai; | ||
database: DatabaseManager<TName, TAI>; | ||
constructor({ name, ai, ...config }: CreateWorkspaceConnectionConfig<TName, TAI>); | ||
static create<TName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined>(config: CreateWorkspaceConnectionConfig<TName, TAI>): WorkspaceConnection<TName, TAI>; | ||
} | ||
interface PrivateConnectionSchema { | ||
privateConnectionID: string; | ||
workspaceGroupID: string; | ||
workspaceID: string; | ||
serviceName: string; | ||
type: "INBOUND" | "OUTBOUND"; | ||
status: "PENDING" | "ACTIVE" | "DELETED"; | ||
allowList: string; | ||
outboundAllowList: string; | ||
createdAt: string; | ||
deletedAt: string; | ||
updatedAt: string; | ||
activeAt: string; | ||
} | ||
interface PrivateConnection extends Omit<PrivateConnectionSchema, "createdAt" | "deletedAt" | "updatedAt" | "activeAt"> { | ||
createdAt: Date; | ||
deletedAt: Date; | ||
updatedAt: Date; | ||
activeAt: Date; | ||
} | ||
interface GetWorkspacePrivateConnectionParams<TIsKai extends boolean | undefined> { | ||
isKai?: TIsKai; | ||
} | ||
declare class WorkspacePrivateConnectionManager extends APIManager { | ||
private _workspaceID; | ||
private _groupID; | ||
protected _baseURL: string; | ||
constructor(api: API, _workspaceID: WorkspaceSchema["workspaceID"], _groupID: WorkspaceSchema["workspaceGroupID"]); | ||
static getBaseURL(workspaceID: WorkspaceSchema["workspaceID"]): string; | ||
get<TIsKai extends boolean | undefined = undefined>(params?: GetWorkspacePrivateConnectionParams<TIsKai>): Promise<TIsKai extends undefined ? PrivateConnectionSchema[] : { | ||
serviceName: string; | ||
}>; | ||
outbundAllowList(): Promise<{ | ||
outboundAllowList: string; | ||
}[]>; | ||
} | ||
type WorkspaceSize = "S-00"; | ||
interface WorkspaceResumeAttachmentSchema { | ||
attachment: "READWRITE" | "READONLY"; | ||
database: string; | ||
error: string; | ||
success: boolean; | ||
} | ||
interface WorkspaceResumeAttachment extends Omit<WorkspaceResumeAttachmentSchema, "attachment"> { | ||
type: WorkspaceResumeAttachmentSchema["attachment"]; | ||
} | ||
interface WorkspaceAutoSuspendSchema { | ||
suspendType: "IDLE" | "SCHEDULED"; | ||
idleAfterSeconds: number; | ||
idleChangedAt: string | undefined; | ||
scheduledChangedAt: string | undefined; | ||
scheduledSuspendAt: string | undefined; | ||
suspendTypeChangedAt: string | undefined; | ||
} | ||
interface WorkspaceAutoSuspend extends Omit<WorkspaceAutoSuspendSchema, "idleChangedAt" | "scheduledChangedAt" | "scheduledSuspendAt" | "suspendTypeChangedAt"> { | ||
idleChangedAt: Date | undefined; | ||
scheduledChangedAt: Date | undefined; | ||
scheduledSuspendAt: Date | undefined; | ||
suspendTypeChangedAt: Date | undefined; | ||
} | ||
interface WorkspaceSchema { | ||
workspaceID: string; | ||
workspaceGroupID: string; | ||
name: string; | ||
databases: { | ||
[K in keyof TWorkspaceType["databases"]]: Omit<DatabaseSchema<TWorkspaceType["databases"][K]>, "name">; | ||
endpoint: string; | ||
size: WorkspaceSize; | ||
state: "ACTIVE" | "PENDING" | "SUSPENDED" | "FAILED" | "TERMINATED"; | ||
scaleFactor: 1 | 2 | 4; | ||
scalingProgress: number | undefined; | ||
cacheConfig: 1 | 2 | 4; | ||
kaiEnabled: boolean; | ||
deploymentType: "PRODUCTION" | "NON-PRODUCTION"; | ||
createdAt: string; | ||
lastResumedAt: string | undefined; | ||
terminatedAt: string | undefined; | ||
autoSuspend: WorkspaceAutoSuspendSchema | undefined; | ||
resumeAttachments: WorkspaceResumeAttachmentSchema[]; | ||
} | ||
interface UpdateWorkspaceBody extends Partial<Pick<WorkspaceSchema, "size" | "deploymentType" | "cacheConfig" | "scaleFactor">> { | ||
enableKai?: boolean; | ||
autoSuspend?: { | ||
suspendType?: WorkspaceAutoSuspendSchema["suspendType"] | "DISABLED"; | ||
suspendAfterSeconds?: number; | ||
}; | ||
} | ||
interface ConnectWorkspaceConfig<TWorkspaceType extends WorkspaceType, TAi extends AnyAI | undefined> extends ConnectionConfig { | ||
name?: WorkspaceSchema<TWorkspaceType>["name"]; | ||
ai?: TAi; | ||
interface ResumeWorkspaceBody { | ||
disableAutoSuspend?: boolean; | ||
} | ||
type WorkspaceDatabaseName<TWorkspaceType extends WorkspaceType> = Extract<keyof TWorkspaceType["databases"], string>; | ||
declare class Workspace<TWorkspaceType extends WorkspaceType = WorkspaceType, TAi extends AnyAI | undefined = undefined> { | ||
connection: Connection; | ||
name?: string | undefined; | ||
private _ai?; | ||
constructor(connection: Connection, name?: string | undefined, _ai?: TAi | undefined); | ||
static connect<TWorkspaceType extends WorkspaceType = WorkspaceType, TAi extends AnyAI | undefined = undefined>({ ai, name, ...config }: ConnectWorkspaceConfig<TWorkspaceType, TAi>): Workspace<TWorkspaceType, TAi>; | ||
database<TType, TName extends WorkspaceDatabaseName<TWorkspaceType> | (string & {}) = WorkspaceDatabaseName<TWorkspaceType> | (string & {})>(name: TName): Database<TType extends DatabaseType ? TType : TWorkspaceType["databases"][TName] extends DatabaseType ? TWorkspaceType["databases"][TName] : DatabaseType, TAi>; | ||
createDatabase<TType extends DatabaseType = DatabaseType>(schema: DatabaseSchema<TType>): Promise<Database<TType, TAi>>; | ||
dropDatabase(name: WorkspaceDatabaseName<TWorkspaceType> | (string & {})): Promise<[ResultSetHeader, FieldPacket[]]>; | ||
showDatabasesInfo<TExtended extends boolean = false>(extended?: TExtended): Promise<(TExtended extends true ? DatabaseInfoExtended<WorkspaceDatabaseName<TWorkspaceType>> : DatabaseInfo<WorkspaceDatabaseName<TWorkspaceType>>)[]>; | ||
interface ConnectWorkspaceConfig$1<TName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined> extends Omit<CreateWorkspaceConnectionConfig<TName, TAI>, "name" | "host" | "ai"> { | ||
} | ||
declare class Workspace<TName extends WorkspaceSchema["name"], TAI extends AnyAI | undefined> extends APIManager { | ||
private _ai; | ||
id: WorkspaceSchema["workspaceID"]; | ||
groupID: WorkspaceSchema["workspaceGroupID"]; | ||
name: TName; | ||
endpoint: WorkspaceSchema["endpoint"]; | ||
size: WorkspaceSchema["size"]; | ||
state: WorkspaceSchema["state"]; | ||
scaleFactor: WorkspaceSchema["scaleFactor"]; | ||
scalingProgress: WorkspaceSchema["scalingProgress"]; | ||
cacheConfig: WorkspaceSchema["cacheConfig"]; | ||
kaiEnabled: WorkspaceSchema["kaiEnabled"]; | ||
deploymentType: WorkspaceSchema["deploymentType"]; | ||
createdAt: Date; | ||
lastResumedAt: Date | undefined; | ||
terminatedAt: Date | undefined; | ||
autoSuspend: WorkspaceAutoSuspend | undefined; | ||
resumeAttachments: WorkspaceResumeAttachment[] | undefined; | ||
protected _baseURL: string; | ||
privateConnection: WorkspacePrivateConnectionManager; | ||
constructor(api: API, _ai: TAI, id: WorkspaceSchema["workspaceID"], groupID: WorkspaceSchema["workspaceGroupID"], name: TName, endpoint: WorkspaceSchema["endpoint"], size: WorkspaceSchema["size"], state: WorkspaceSchema["state"], scaleFactor: WorkspaceSchema["scaleFactor"], scalingProgress: WorkspaceSchema["scalingProgress"], cacheConfig: WorkspaceSchema["cacheConfig"], kaiEnabled: WorkspaceSchema["kaiEnabled"], deploymentType: WorkspaceSchema["deploymentType"], createdAt: Date, lastResumedAt: Date | undefined, terminatedAt: Date | undefined, autoSuspend: WorkspaceAutoSuspend | undefined, resumeAttachments: WorkspaceResumeAttachment[] | undefined); | ||
static getBaseURL(id: WorkspaceSchema["workspaceID"]): string; | ||
static update(api: API, id: WorkspaceSchema["workspaceID"], body: UpdateWorkspaceBody): Promise<WorkspaceSchema["workspaceID"]>; | ||
static delete(api: API, id: WorkspaceSchema["workspaceID"]): Promise<WorkspaceSchema["workspaceID"]>; | ||
static resume(api: API, id: WorkspaceSchema["workspaceID"], body?: ResumeWorkspaceBody): Promise<WorkspaceSchema["workspaceID"]>; | ||
static suspend(api: API, id: WorkspaceSchema["workspaceID"]): Promise<WorkspaceSchema["workspaceID"]>; | ||
static getState(api: API, id: WorkspaceSchema["workspaceID"]): Promise<WorkspaceSchema["state"]>; | ||
connect(config: ConnectWorkspaceConfig$1<TName, TAI>): WorkspaceConnection<TName, TAI>; | ||
update(body: UpdateWorkspaceBody): Promise<string>; | ||
delete(): Promise<string>; | ||
resume(body?: ResumeWorkspaceBody): Promise<string>; | ||
suspend(): Promise<string>; | ||
getState(): Promise<"ACTIVE" | "PENDING" | "SUSPENDED" | "FAILED" | "TERMINATED">; | ||
} | ||
interface SingleStoreClientConfig<TAi extends AnyAI | undefined> { | ||
ai?: TAi; | ||
type BillingMetric = "ComputeCredit" | "StorageAvgByte"; | ||
interface BillingUsageSchema { | ||
resourceID: string; | ||
resourceName: string; | ||
resourceType: string; | ||
startTime: string; | ||
endTime: string; | ||
value: string; | ||
} | ||
interface WorkspaceConfig<TWorkspaceType extends WorkspaceType, TAi extends AnyAI | undefined> extends Omit<ConnectWorkspaceConfig<TWorkspaceType, TAi>, "ai"> { | ||
interface StorageAvgByteBillingUsageSchema extends BillingUsageSchema { | ||
} | ||
declare class SingleStoreClient<TAi extends AnyAI | undefined = undefined> { | ||
interface StorageAvgByteBillingUsage extends Omit<StorageAvgByteBillingUsageSchema, "startTime" | "endTime"> { | ||
startTime: Date; | ||
endTime: Date; | ||
} | ||
interface ComputeCreditBillingUsageSchema extends BillingUsageSchema { | ||
ownerID: string | null | undefined; | ||
} | ||
interface ComputeCreditBillingUsage extends Omit<ComputeCreditBillingUsageSchema, "startTime" | "endTime"> { | ||
startTime: Date; | ||
endTime: Date; | ||
} | ||
interface BillingSchema<T extends BillingMetric> { | ||
metric: T; | ||
description: string; | ||
Usage: (T extends "ComputeCredit" ? ComputeCreditBillingUsageSchema : StorageAvgByteBillingUsageSchema)[]; | ||
} | ||
interface Billing<TMetric extends BillingMetric, TUsage extends StorageAvgByteBillingUsage | ComputeCreditBillingUsage> { | ||
metric: TMetric; | ||
description: string; | ||
usage: TUsage[]; | ||
} | ||
interface StorageAvgByteBilling extends Billing<"StorageAvgByte", StorageAvgByteBillingUsage> { | ||
} | ||
interface ComputeCreditBilling extends Billing<"ComputeCredit", ComputeCreditBillingUsage> { | ||
} | ||
interface GetBillingParams { | ||
metric: BillingMetric; | ||
startTime: Date; | ||
endTime: Date; | ||
aggregateBy?: "hour" | "day" | "month"; | ||
} | ||
declare class BillingManager extends APIManager { | ||
protected _baseURL: string; | ||
get<T extends GetBillingParams, _TReturnType = T["metric"] extends "ComputeCredit" ? ComputeCreditBilling[] : StorageAvgByteBilling[]>({ metric, startTime, endTime, aggregateBy }: T): Promise<_TReturnType>; | ||
} | ||
interface JobRuntime { | ||
name: "notebooks-cpu-small" | "notebooks-cpu-medium" | "notebooks-gpu-t4"; | ||
description: string; | ||
} | ||
interface JobMetadata { | ||
count: number; | ||
avgDurationInSeconds: number | null; | ||
maxDurationInSeconds: number | null; | ||
status: "Unknown" | "Scheduled" | "Running" | "Completed" | "Failed" | "Error" | "Canceled"; | ||
} | ||
interface JobScheduleSchema { | ||
mode: "Recurring" | "Once"; | ||
startAt: string | null; | ||
executionIntervalInMinutes: number | null; | ||
} | ||
interface JobSchedule extends Omit<JobScheduleSchema, "startAt"> { | ||
startAt: Date | null; | ||
} | ||
interface JobTargetConfig { | ||
targetID: string; | ||
targetType: "Workspace" | "Cluster" | "VirtualWorkspace"; | ||
resumeTarget: boolean; | ||
databaseName: string; | ||
} | ||
interface JobExecutionConfig { | ||
notebookPath: string; | ||
createSnapshot: boolean; | ||
maxAllowedExecutionDurationInMinutes: number; | ||
} | ||
interface JobSchema { | ||
jobID: string; | ||
name: string; | ||
description: string | null; | ||
enqueuedBy: string; | ||
jobMetadata: JobMetadata[]; | ||
schedule: JobScheduleSchema; | ||
targetConfig: JobTargetConfig; | ||
executionConfig: JobExecutionConfig; | ||
completedExecutionsCount: number; | ||
createdAt: string; | ||
terminatedAt: string | null; | ||
} | ||
interface JobParameter { | ||
type: "string" | "integer" | "float" | "boolean"; | ||
name: string; | ||
value: string; | ||
} | ||
interface JobExecutionSchema { | ||
id: string; | ||
number: number; | ||
jobID: string; | ||
scheduledStartTime: string; | ||
startedAt: string | null; | ||
finishedAt: string | null; | ||
snapshotNotebookPath: string | null; | ||
status: "Scheduled" | "Running" | "Completed" | "Failed"; | ||
} | ||
interface JobExecution extends Omit<JobExecutionSchema, "scheduledStartTime" | "startedAt" | "finishedAt"> { | ||
scheduledStartTime: Date; | ||
startedAt: Date | null; | ||
finishedAt: Date | null; | ||
} | ||
declare class Job extends APIManager { | ||
id: JobSchema["jobID"]; | ||
name: JobSchema["name"]; | ||
description: JobSchema["description"]; | ||
enqueuedBy: JobSchema["enqueuedBy"]; | ||
executionConfig: JobSchema["executionConfig"]; | ||
metadata: JobSchema["jobMetadata"]; | ||
targetConfig: JobSchema["targetConfig"]; | ||
completedExecutionsCount: JobSchema["completedExecutionsCount"]; | ||
schedule: JobSchedule; | ||
createdAt: Date; | ||
terminatedAt: Date | null; | ||
protected _baseURL: string; | ||
constructor(_api: API, id: JobSchema["jobID"], name: JobSchema["name"], description: JobSchema["description"], enqueuedBy: JobSchema["enqueuedBy"], executionConfig: JobSchema["executionConfig"], metadata: JobSchema["jobMetadata"], targetConfig: JobSchema["targetConfig"], completedExecutionsCount: JobSchema["completedExecutionsCount"], schedule: JobSchedule, createdAt: Date, terminatedAt: Date | null); | ||
static getBaseURL(id: JobSchema["jobID"]): string; | ||
static delete(api: API, id: JobSchema["jobID"]): Promise<boolean>; | ||
static getExecutions(api: API, id: JobSchema["jobID"], start: number, end: number): Promise<JobExecution[]>; | ||
static getParameters(api: API, id: JobSchema["jobID"]): Promise<JobParameter[]>; | ||
delete(): Promise<boolean>; | ||
getExecutions(start: number, end: number): Promise<JobExecution[]>; | ||
getParameters(): Promise<JobParameter[]>; | ||
} | ||
interface CreateJobBody { | ||
name?: JobSchema["name"]; | ||
description?: JobSchema["description"]; | ||
executionConfig: { | ||
runtimeName?: string; | ||
notebookPath: string; | ||
createSnapshot?: boolean; | ||
}; | ||
parameters?: JobParameter[]; | ||
schedule: Optional<JobSchedule, "executionIntervalInMinutes" | "startAt">; | ||
targetConfig?: Optional<JobTargetConfig, "databaseName" | "resumeTarget">; | ||
} | ||
declare class JobManager extends APIManager { | ||
protected _baseURL: string; | ||
private _create; | ||
create(body: CreateJobBody): Promise<Job>; | ||
get(id: JobSchema["jobID"]): Promise<Job>; | ||
delete(...args: Tail<Parameters<typeof Job.delete>>): Promise<boolean>; | ||
getExecutions(...args: Tail<Parameters<typeof Job.getExecutions>>): Promise<JobExecution[]>; | ||
getParameters(...args: Tail<Parameters<typeof Job.getParameters>>): Promise<JobParameter[]>; | ||
getRuntimes(): Promise<JobRuntime[]>; | ||
} | ||
interface OrganizationSchema { | ||
orgID: string; | ||
name: string; | ||
} | ||
interface Organization extends Omit<OrganizationSchema, "orgID"> { | ||
id: string; | ||
} | ||
declare class OrganizationManager extends APIManager { | ||
protected _baseURL: string; | ||
get(): Promise<Organization>; | ||
} | ||
type RegionProvider = "AWS" | "GCP" | "Azure"; | ||
type RegionName = "US West 2 (Oregon)" | "US East 1 (N. Virginia)" | "Europe West 1 (Ireland)" | "Europe Central 1 (Frankfurt)" | "US East 1 (N. Virginia) - HD2" | "Asia Pacific Northeast 2 (Seoul)" | "Asia Pacific Southeast 1 (Singapore)" | "Asia Pacific Southeast 3 (Jakarta)" | "Europe West 2 (London)" | "Middle East 1 (UAE)" | "Asia Pacific Southeast 2 (Sydney)" | "US East 2 (Ohio)" | "Europe West 3 (Paris)" | "Canada Central 1 (Montreal)" | "Africa South 1 (Cape Town)" | "South America East 1 (Sao Paulo)" | "Asia Pacific South 1 (Mumbai)" | "Europe North 1 (Stockholm)"; | ||
interface RegionSchema { | ||
regionID: string; | ||
region: RegionName; | ||
provider: RegionProvider; | ||
} | ||
interface Region extends Omit<RegionSchema, "regionID" | "region"> { | ||
id: string; | ||
name: RegionName; | ||
} | ||
declare class RegionManager extends APIManager { | ||
protected _baseURL: string; | ||
get<T extends { | ||
id: RegionSchema["regionID"]; | ||
} | { | ||
name: RegionSchema["region"]; | ||
} | undefined = undefined, _ReturnType = T extends { | ||
id: RegionSchema["regionID"]; | ||
} | { | ||
name: RegionSchema["region"]; | ||
} ? Region | undefined : Region[]>(where?: T): Promise<_ReturnType>; | ||
} | ||
interface SecretSchema { | ||
secretID: string; | ||
name: string; | ||
value: string | undefined; | ||
lastUpdatedBy: string; | ||
lastUpdatedAt: string; | ||
createdBy: string; | ||
createdAt: string; | ||
} | ||
declare class Secret extends APIManager { | ||
id: SecretSchema["secretID"]; | ||
name: SecretSchema["name"]; | ||
value: SecretSchema["value"]; | ||
lastUpdatedBy: SecretSchema["lastUpdatedBy"]; | ||
lastUpdatedAt: Date; | ||
createdBy: SecretSchema["createdBy"]; | ||
createdAt: Date; | ||
protected _baseURL: string; | ||
constructor(api: API, id: SecretSchema["secretID"], name: SecretSchema["name"], value: SecretSchema["value"], lastUpdatedBy: SecretSchema["lastUpdatedBy"], lastUpdatedAt: Date, createdBy: SecretSchema["createdBy"], createdAt: Date); | ||
static getBaseURL(id: SecretSchema["secretID"]): string; | ||
static update(api: API, id: SecretSchema["secretID"], value: Defined<SecretSchema["value"]>): Promise<Secret>; | ||
static delete(api: API, id: SecretSchema["secretID"]): Promise<SecretSchema["secretID"]>; | ||
update(value: Defined<SecretSchema["value"]>): Promise<Secret>; | ||
delete(): Promise<string>; | ||
} | ||
interface CreateSecretBody { | ||
name: SecretSchema["name"]; | ||
value: Defined<SecretSchema["value"]>; | ||
} | ||
declare class SecretManager extends APIManager { | ||
protected _baseURL: string; | ||
private _create; | ||
create(body: CreateSecretBody): Promise<Secret>; | ||
get<T extends { | ||
id: SecretSchema["secretID"]; | ||
} | { | ||
name: SecretSchema["name"]; | ||
} | undefined = undefined, _TReturnType = T extends undefined ? Secret[] : Secret | undefined>(where?: T): Promise<_TReturnType>; | ||
update(...args: Tail<Parameters<typeof Secret.update>>): Promise<Secret>; | ||
delete(...args: Tail<Parameters<typeof Secret.delete>>): Promise<string>; | ||
} | ||
interface TeamMemberTeamSchema { | ||
teamID: string; | ||
name: string; | ||
description: string; | ||
} | ||
interface TeamMemberTeam extends Omit<TeamMemberTeamSchema, "teamID"> { | ||
id: string; | ||
} | ||
interface TeamMemberUserSchema { | ||
userID: string; | ||
firstName: string; | ||
lastName: string; | ||
email: string; | ||
} | ||
interface TeamMemberUser extends Omit<TeamMemberUserSchema, "userID"> { | ||
id: string; | ||
} | ||
interface TeamSchema { | ||
teamID: string; | ||
name: string; | ||
description: string; | ||
memberTeams: TeamMemberTeamSchema[] | undefined; | ||
memberUsers: TeamMemberUserSchema[] | undefined; | ||
createdAt: string; | ||
} | ||
interface UpdateTeamBody extends Partial<Pick<TeamSchema, "name" | "description">> { | ||
} | ||
declare class Team extends APIManager { | ||
id: TeamSchema["teamID"]; | ||
name: TeamSchema["name"]; | ||
description: TeamSchema["description"]; | ||
memberTeams: TeamMemberTeam[] | undefined; | ||
memberUsers: TeamMemberUser[] | undefined; | ||
createdAt: Date; | ||
protected _baseURL: string; | ||
constructor(api: API, id: TeamSchema["teamID"], name: TeamSchema["name"], description: TeamSchema["description"], memberTeams: TeamMemberTeam[] | undefined, memberUsers: TeamMemberUser[] | undefined, createdAt: Date); | ||
static getBaseURL(id: TeamSchema["teamID"]): string; | ||
static update(api: API, id: TeamSchema["teamID"], body: UpdateTeamBody): Promise<TeamSchema["teamID"]>; | ||
static delete(api: API, id: TeamSchema["teamID"]): Promise<TeamSchema["teamID"]>; | ||
static addMemberTeams(api: API, id: TeamSchema["teamID"], teamIDs: TeamMemberTeamSchema["teamID"][]): Promise<TeamSchema["teamID"]>; | ||
static removeMemberTeams(api: API, id: TeamSchema["teamID"], teamIDs: TeamMemberTeamSchema["teamID"][]): Promise<TeamSchema["teamID"]>; | ||
static addMemberUsers(api: API, id: TeamSchema["teamID"], userIDs: TeamMemberUserSchema["userID"][]): Promise<TeamSchema["teamID"]>; | ||
static removeMemberUsers(api: API, id: TeamSchema["teamID"], userIDs: TeamMemberUserSchema["userID"][]): Promise<TeamSchema["teamID"]>; | ||
update(body: UpdateTeamBody): Promise<string>; | ||
delete(): Promise<string>; | ||
addMemberTeams(teamIDs: TeamMemberTeamSchema["teamID"][]): Promise<string>; | ||
removeMemberTeams(teamIDs: TeamMemberTeamSchema["teamID"][]): Promise<string>; | ||
addMemberUsers(userIDs: TeamMemberUserSchema["userID"][]): Promise<string>; | ||
removeMemberUsers(userIDs: TeamMemberUserSchema["userID"][]): Promise<string>; | ||
} | ||
interface CreateTeamBody { | ||
name: TeamSchema["name"]; | ||
description?: TeamSchema["description"]; | ||
memberTeams?: TeamMemberTeamSchema["teamID"][]; | ||
memberUsers?: TeamMemberUserSchema["userID"][]; | ||
} | ||
declare class TeamManager extends APIManager { | ||
protected _baseURL: string; | ||
private _create; | ||
create({ memberTeams, memberUsers, ...body }: CreateTeamBody): Promise<Team>; | ||
get<T extends { | ||
id: TeamSchema["teamID"]; | ||
} | { | ||
name: TeamSchema["name"]; | ||
} | { | ||
description: TeamSchema["description"]; | ||
} | undefined = undefined, _TReturnType = T extends undefined ? Team[] : Team | undefined>(where?: T): Promise<_TReturnType>; | ||
update(...args: Parameters<typeof Team.update> extends [any, ...infer Rest] ? Rest : never): Promise<string>; | ||
delete(...args: Tail<Parameters<typeof Team.delete>>): Promise<string>; | ||
addMemberTeams(...args: Tail<Parameters<typeof Team.addMemberTeams>>): Promise<string>; | ||
removeMemberTeams(...args: Tail<Parameters<typeof Team.removeMemberTeams>>): Promise<string>; | ||
addMemberUsers(...args: Tail<Parameters<typeof Team.addMemberUsers>>): Promise<string>; | ||
removeMemberUsers(...args: Tail<Parameters<typeof Team.removeMemberUsers>>): Promise<string>; | ||
} | ||
interface CreateWorkspaceBody extends Pick<WorkspaceSchema, "name">, Partial<Pick<WorkspaceSchema, "cacheConfig" | "scaleFactor" | "size">>, Pick<UpdateWorkspaceBody, "enableKai" | "autoSuspend"> { | ||
} | ||
type GetWorkspaceSelectParam = (keyof WorkspaceSchema)[] | undefined; | ||
type GetWorkspaceWhereParam = { | ||
id: WorkspaceSchema["workspaceID"]; | ||
} | { | ||
name: WorkspaceSchema["name"]; | ||
} | undefined; | ||
interface GetWorkspaceParams<TSelect extends GetWorkspaceSelectParam = undefined, TWhere extends GetWorkspaceWhereParam = undefined> { | ||
select?: TSelect; | ||
where?: TWhere; | ||
includeTerminated?: boolean; | ||
} | ||
type WorkspaceBySelect<TSelect extends GetWorkspaceSelectParam> = TSelect extends (keyof Workspace<any, any>)[] ? Pick<Workspace<any, any>, TSelect[number]> : Workspace<any, any>; | ||
declare class WorkspaceManager<TAI extends AnyAI | undefined> extends APIManager { | ||
private _ai; | ||
constructor(config?: SingleStoreClientConfig<TAi>); | ||
workspace<TWorkspaceType extends WorkspaceType = WorkspaceType>(config: WorkspaceConfig<TWorkspaceType, TAi>): Workspace<TWorkspaceType, TAi>; | ||
private _workspaceGroupID; | ||
protected _baseURL: string; | ||
constructor(api: API, _ai: TAI, _workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"]); | ||
private _create; | ||
create(body: CreateWorkspaceBody): Promise<Workspace<any, any> | undefined>; | ||
get<TSelect extends GetWorkspaceSelectParam = undefined, TWhere extends GetWorkspaceWhereParam = undefined, _TReturnType = TWhere extends { | ||
id: WorkspaceSchema["workspaceID"]; | ||
} ? WorkspaceBySelect<TSelect> | undefined : WorkspaceBySelect<TSelect>[]>({ where, select, includeTerminated }?: GetWorkspaceParams<TSelect, TWhere>): Promise<_TReturnType>; | ||
update(...args: Tail<Parameters<typeof Workspace.update>>): Promise<string>; | ||
delete(...args: Tail<Parameters<typeof Workspace.delete>>): Promise<string>; | ||
resume(...args: Tail<Parameters<typeof Workspace.resume>>): Promise<string>; | ||
suspend(...args: Tail<Parameters<typeof Workspace.suspend>>): Promise<string>; | ||
getState(...args: Tail<Parameters<typeof Workspace.getState>>): Promise<"ACTIVE" | "PENDING" | "SUSPENDED" | "FAILED" | "TERMINATED">; | ||
} | ||
export { type AnyDatabase, type AnyQueryBuilderParams, Column, type ColumnInfo, type ColumnSchema, type ColumnType, type ConnectWorkspaceConfig, Connection, type ConnectionConfig, Database, type DatabaseInfo, type DatabaseInfoExtended, type DatabaseSchema, type DatabaseTableName, type DatabaseTablesToRecords, type DatabaseType, type ExtractJoinClauseColumns, type ExtractSelectedQueryColumns, type GroupByClause, type InferDatabaseType, type JoinClause, type OrderByClause, type OrderByDirection, QueryBuilder, type QueryBuilderParams, type SelectClause, SingleStoreClient, type SingleStoreClientConfig, Table, type TableColumnName, type TableInfo, type TableInfoExtended, type TableSchema, type TableType, type WhereClause, type WhereOperator, Workspace, type WorkspaceConfig, type WorkspaceDatabaseName, type WorkspaceSchema, type WorkspaceType }; | ||
type WorkspaceGroupStageContent = string | any[]; | ||
interface WorkspaceGroupStageSchema { | ||
name: string; | ||
content: WorkspaceGroupStageContent; | ||
type: "json" | "directory" | null; | ||
path: string; | ||
format: string | null; | ||
mimetype: string | null; | ||
size: number; | ||
writable: boolean; | ||
created: string; | ||
last_modified: string; | ||
} | ||
interface UpdateWorkspaceGroupStageBody { | ||
newPath?: WorkspaceGroupStageSchema["path"]; | ||
} | ||
declare class WorkspaceGroupStage extends APIManager { | ||
private _workspaceGroupID; | ||
name: WorkspaceGroupStageSchema["name"]; | ||
content: WorkspaceGroupStageSchema["content"]; | ||
type: WorkspaceGroupStageSchema["type"]; | ||
path: WorkspaceGroupStageSchema["path"]; | ||
format: WorkspaceGroupStageSchema["format"]; | ||
mimetype: WorkspaceGroupStageSchema["mimetype"]; | ||
size: WorkspaceGroupStageSchema["size"]; | ||
writable: WorkspaceGroupStageSchema["writable"]; | ||
createdAt: Date | undefined; | ||
modifiedAt: Date | undefined; | ||
protected _baseURL: string; | ||
constructor(api: API, _workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"], name: WorkspaceGroupStageSchema["name"], content: WorkspaceGroupStageSchema["content"], type: WorkspaceGroupStageSchema["type"], path: WorkspaceGroupStageSchema["path"], format: WorkspaceGroupStageSchema["format"], mimetype: WorkspaceGroupStageSchema["mimetype"], size: WorkspaceGroupStageSchema["size"], writable: WorkspaceGroupStageSchema["writable"], createdAt: Date | undefined, modifiedAt: Date | undefined); | ||
static getBaseURL(workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"], path: WorkspaceGroupStageSchema["path"]): string; | ||
static serializePath(path?: WorkspaceGroupStageSchema["path"]): string; | ||
static formatPath(id: WorkspaceGroupSchema["workspaceGroupID"], path?: WorkspaceGroupStageSchema["path"]): string; | ||
static mergePaths(...paths: (string | undefined)[]): string; | ||
static get(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], path?: WorkspaceGroupStageSchema["path"]): Promise<WorkspaceGroupStage>; | ||
static update(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], path: WorkspaceGroupStageSchema["path"], body: UpdateWorkspaceGroupStageBody): Promise<Pick<WorkspaceGroupStage, "name" | "path">>; | ||
static delete(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], path: WorkspaceGroupStage["path"]): Promise<Pick<WorkspaceGroupStage, "name" | "path">>; | ||
static createFolder(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], path: WorkspaceGroupStage["path"], name: string): Promise<WorkspaceGroupStage>; | ||
static uploadFile(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], path: WorkspaceGroupStage["path"], file: File): Promise<void>; | ||
get(path?: WorkspaceGroupStage["path"]): Promise<WorkspaceGroupStage>; | ||
update(body: UpdateWorkspaceGroupStageBody, path?: WorkspaceGroupStage["path"]): Promise<Pick<WorkspaceGroupStage, "name" | "path">>; | ||
delete(path?: WorkspaceGroupStage["path"]): Promise<Pick<WorkspaceGroupStage, "name" | "path">>; | ||
createFolder(name: string, path?: WorkspaceGroupStage["path"]): Promise<WorkspaceGroupStage>; | ||
uploadFile(file: File, path?: WorkspaceGroupStage["path"]): Promise<void>; | ||
} | ||
declare class WorkspaceGroupStageManager extends APIManager { | ||
private _workspaceGroupID; | ||
protected _baseURL: string; | ||
constructor(api: API, _workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"]); | ||
static getBaseURL(workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"]): string; | ||
get(...args: Parameters<typeof WorkspaceGroupStage.get> extends [any, any, ...infer Rest] ? Rest : never): Promise<WorkspaceGroupStage>; | ||
update(...args: Parameters<typeof WorkspaceGroupStage.update> extends [any, any, ...infer Rest] ? Rest : never): Promise<Pick<WorkspaceGroupStage, "name" | "path">>; | ||
delete(...args: Parameters<typeof WorkspaceGroupStage.delete> extends [any, any, ...infer Rest] ? Rest : never): Promise<Pick<WorkspaceGroupStage, "name" | "path">>; | ||
createFolder(...args: Parameters<typeof WorkspaceGroupStage.createFolder> extends [any, any, ...infer Rest] ? Rest : never): Promise<WorkspaceGroupStage>; | ||
} | ||
interface ReplicatedDatabaseSchema { | ||
region: RegionName; | ||
databaseName: string; | ||
duplicationState: "Pending" | "Active" | "Inactive" | "Error"; | ||
} | ||
interface StorageDRStatusSchema { | ||
compute: { | ||
storageDRType: "Failover" | "Failback" | "PreProvisionStart" | "PreProvisionStop"; | ||
storageDRState: "Active" | "Completed" | "Failed" | "Expired" | "Canceled"; | ||
completedAttachments: number; | ||
completedWorkspaces: number; | ||
totalAttachments: number; | ||
totalWorkspaces: number; | ||
}; | ||
storage: ReplicatedDatabaseSchema[]; | ||
} | ||
declare class WorkspaceGroupStorageManager extends APIManager { | ||
private _workspaceGroupID; | ||
protected _baseURL: string; | ||
constructor(api: API, _workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"]); | ||
static getBaseURL(workspaceGroupID: WorkspaceGroupSchema["workspaceGroupID"]): string; | ||
getStatus(): Promise<StorageDRStatusSchema>; | ||
getRegions(): Promise<Region[]>; | ||
} | ||
interface WorkspaceGroupUpdateWindowSchema { | ||
day: number; | ||
hour: number; | ||
} | ||
interface WorkspaceGroupUpdateWindow extends Omit<WorkspaceGroupUpdateWindowSchema, "day"> { | ||
day: "mo" | "tu" | "we" | "th" | "fr" | "sa" | "su"; | ||
} | ||
interface WorkspaceGroupSchema { | ||
workspaceGroupID: string; | ||
name: string; | ||
regionID: string; | ||
state: "ACTIVE" | "PENDING" | "FAILED" | "TERMINATED"; | ||
smartDRStatus: "ACTIVE" | "STANDBY" | undefined; | ||
allowAllTraffic: boolean | undefined; | ||
firewallRanges: string[]; | ||
updateWindow: WorkspaceGroupUpdateWindowSchema; | ||
createdAt: string; | ||
expiresAt: string | undefined; | ||
terminatedAt: string | undefined; | ||
} | ||
interface UpdateWorkspaceGroupBody extends Partial<Pick<WorkspaceGroupSchema, "name" | "allowAllTraffic" | "firewallRanges">> { | ||
expiresAt?: Date; | ||
adminPassword?: string; | ||
updateWindow?: WorkspaceGroupUpdateWindow; | ||
} | ||
declare const updateWindowDaysMap: Record<number, WorkspaceGroupUpdateWindow["day"]>; | ||
declare class WorkspaceGroup<TAI extends AnyAI | undefined> extends APIManager { | ||
private _ai; | ||
private _organization; | ||
id: WorkspaceGroupSchema["workspaceGroupID"]; | ||
name: WorkspaceGroupSchema["name"]; | ||
regionID: WorkspaceGroupSchema["regionID"]; | ||
state: WorkspaceGroupSchema["state"]; | ||
smartDRStatus: WorkspaceGroupSchema["smartDRStatus"]; | ||
allowAllTraffic: WorkspaceGroupSchema["allowAllTraffic"]; | ||
firewallRanges: WorkspaceGroupSchema["firewallRanges"]; | ||
updateWindow: WorkspaceGroupUpdateWindow | undefined; | ||
createdAt: Date; | ||
expiresAt: Date | undefined; | ||
terminatedAt: Date | undefined; | ||
protected _baseURL: string; | ||
stage: WorkspaceGroupStageManager; | ||
storage: WorkspaceGroupStorageManager; | ||
workspace: WorkspaceManager<TAI>; | ||
constructor(api: API, _ai: TAI, _organization: OrganizationManager, id: WorkspaceGroupSchema["workspaceGroupID"], name: WorkspaceGroupSchema["name"], regionID: WorkspaceGroupSchema["regionID"], state: WorkspaceGroupSchema["state"], smartDRStatus: WorkspaceGroupSchema["smartDRStatus"], allowAllTraffic: WorkspaceGroupSchema["allowAllTraffic"], firewallRanges: WorkspaceGroupSchema["firewallRanges"], updateWindow: WorkspaceGroupUpdateWindow | undefined, createdAt: Date, expiresAt: Date | undefined, terminatedAt: Date | undefined); | ||
static getBaseURL(id: WorkspaceGroupSchema["workspaceGroupID"]): string; | ||
static serializeUpdateWindow(updateWindow: WorkspaceGroupUpdateWindow): WorkspaceGroupUpdateWindowSchema; | ||
static update(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], body: UpdateWorkspaceGroupBody): Promise<WorkspaceGroupSchema["workspaceGroupID"]>; | ||
static delete(api: API, id: WorkspaceGroupSchema["workspaceGroupID"], force?: boolean): Promise<WorkspaceGroupSchema["workspaceGroupID"]>; | ||
update(...args: Parameters<typeof WorkspaceGroup.update> extends [any, any, ...infer Rest] ? Rest : never): Promise<string>; | ||
delete(...args: Parameters<typeof WorkspaceGroup.delete> extends [any, any, ...infer Rest] ? Rest : never): Promise<string>; | ||
getPrivateConnections(): Promise<PrivateConnection[]>; | ||
getMetrics(): Promise<string>; | ||
} | ||
interface CreateWorkspaceGroupBody { | ||
name: WorkspaceGroupSchema["name"]; | ||
adminPassword?: string; | ||
allowAllTraffic?: boolean; | ||
firewallRanges?: string[]; | ||
regionName: RegionName; | ||
updateWindow?: WorkspaceGroupUpdateWindow; | ||
dataBucketKMSKeyID?: string; | ||
backupBucketKMSKeyID?: string; | ||
expiresAt?: Date; | ||
} | ||
type GetWorkspaceGroupSelectParam = (keyof WorkspaceGroupSchema)[] | undefined; | ||
type GetWorkspaceGroupWhereParam = { | ||
id: WorkspaceGroupSchema["workspaceGroupID"]; | ||
} | { | ||
name: WorkspaceGroupSchema["name"]; | ||
} | undefined; | ||
interface GetWorkspaceGroupParams<TSelect extends GetWorkspaceGroupSelectParam = undefined, TWhere extends GetWorkspaceGroupWhereParam = undefined> { | ||
select?: TSelect; | ||
where?: TWhere; | ||
includeTerminated?: boolean; | ||
} | ||
type WorkspaceGroupBySelect<TSelect extends GetWorkspaceGroupSelectParam> = TSelect extends (keyof WorkspaceGroup<any>)[] ? Pick<WorkspaceGroup<any>, TSelect[number]> : WorkspaceGroup<any>; | ||
declare class WorkspaceGroupManager<TAI extends AnyAI | undefined> extends APIManager { | ||
private _ai; | ||
private _organization; | ||
private _region; | ||
protected _baseURL: string; | ||
constructor(_api: API, _ai: TAI, _organization: OrganizationManager, _region: RegionManager); | ||
private _create; | ||
create({ regionName, firewallRanges, ...body }: CreateWorkspaceGroupBody): Promise<{ | ||
workspaceGroup: WorkspaceGroup<TAI>; | ||
adminPassword: string | undefined; | ||
}>; | ||
get<TSelect extends GetWorkspaceGroupSelectParam = undefined, TWhere extends GetWorkspaceGroupWhereParam = undefined, _TReturnType = TWhere extends { | ||
id: WorkspaceGroupSchema["workspaceGroupID"]; | ||
} ? WorkspaceGroupBySelect<TSelect> | undefined : WorkspaceGroupBySelect<TSelect>[]>({ where, select, includeTerminated }?: GetWorkspaceGroupParams<TSelect, TWhere>): Promise<_TReturnType>; | ||
update(...args: Tail<Parameters<typeof WorkspaceGroup.update>>): Promise<string>; | ||
delete(...args: Tail<Parameters<typeof WorkspaceGroup.delete>>): Promise<string>; | ||
} | ||
interface SingleStoreClientConfig<TAI extends AnyAI | undefined> { | ||
ai?: TAI; | ||
apiKey?: string; | ||
} | ||
interface ConnectWorkspaceConfig<TName extends WorkspaceSchema["name"] | undefined, TAI extends AnyAI | undefined> extends Omit<CreateWorkspaceConnectionConfig<TName, TAI>, "ai"> { | ||
} | ||
declare class SingleStoreClient<TAI extends AnyAI | undefined = undefined> { | ||
private _ai; | ||
private _api; | ||
billing: BillingManager; | ||
job: JobManager; | ||
organization: OrganizationManager; | ||
region: RegionManager; | ||
secret: SecretManager; | ||
team: TeamManager; | ||
workspaceGroup: WorkspaceGroupManager<TAI>; | ||
constructor(config?: SingleStoreClientConfig<TAI>); | ||
connect<TName extends WorkspaceSchema["name"] | undefined = undefined>(config: ConnectWorkspaceConfig<TName, TAI>): WorkspaceConnection<TName, TAI>; | ||
} | ||
export { API, APIManager, type APIVersion, type AddColumnSchema, type AnyDatabase, type AnyQueryBuilderParams, type Billing, BillingManager, type BillingMetric, type BillingSchema, type BillingUsageSchema, Column, type ColumnInfo, ColumnManager, type ColumnName, type ColumnSchema, type ColumnType, type ComputeCreditBilling, type ComputeCreditBillingUsage, type ComputeCreditBillingUsageSchema, type ConnectWorkspaceConfig, Connection, type ConnectionClient, type ConnectionConfig, type CreateJobBody, type CreateSecretBody, type CreateTableSchema, type CreateTeamBody, type CreateWorkspaceConnectionConfig, type CreateWorkspaceGroupBody, Database, type DatabaseInfo, type DatabaseInfoExtended, DatabaseManager, type DatabaseName, type DatabaseSchema, type DatabaseTableName, type DatabaseTablesToRecords, type DatabaseType, type ExtractJoinClauseColumns, type ExtractSelectedQueryColumns, type GetBillingParams, type GetWorkspaceGroupParams, type GetWorkspaceGroupSelectParam, type GetWorkspaceGroupWhereParam, type GetWorkspaceParams, type GetWorkspacePrivateConnectionParams, type GetWorkspaceSelectParam, type GetWorkspaceWhereParam, type GroupByClause, type InferDatabaseType, Job, type JobExecution, type JobExecutionConfig, type JobExecutionSchema, JobManager, type JobMetadata, type JobParameter, type JobRuntime, type JobSchedule, type JobScheduleSchema, type JobSchema, type JobTargetConfig, type JoinClause, type OrderByClause, type OrderByDirection, type Organization, OrganizationManager, type OrganizationSchema, type PrivateConnection, type PrivateConnectionSchema, QueryBuilder, type QueryBuilderParams, type Region, RegionManager, type RegionName, type RegionProvider, type RegionSchema, type ReplicatedDatabaseSchema, type ResumeWorkspaceBody, Secret, SecretManager, type SecretSchema, type SelectClause, SingleStoreClient, type SingleStoreClientConfig, type StorageAvgByteBilling, type StorageAvgByteBillingUsage, type StorageAvgByteBillingUsageSchema, type StorageDRStatusSchema, Table, type TableColumnName, type TableInfo, type TableInfoExtended, TableManager, type TableName, type TableSchema, type TableType, Team, TeamManager, type TeamMemberTeam, type TeamMemberTeamSchema, type TeamMemberUser, type TeamMemberUserSchema, type TeamSchema, type UpdateTeamBody, type UpdateWorkspaceBody, type UpdateWorkspaceGroupBody, type UpdateWorkspaceGroupStageBody, type VectorScoreKey, type WhereClause, type WhereOperator, Workspace, type WorkspaceAutoSuspend, type WorkspaceAutoSuspendSchema, WorkspaceConnection, WorkspaceGroup, WorkspaceGroupManager, type WorkspaceGroupSchema, WorkspaceGroupStage, type WorkspaceGroupStageContent, WorkspaceGroupStageManager, type WorkspaceGroupStageSchema, WorkspaceGroupStorageManager, type WorkspaceGroupUpdateWindow, type WorkspaceGroupUpdateWindowSchema, WorkspaceManager, WorkspacePrivateConnectionManager, type WorkspaceResumeAttachment, type WorkspaceResumeAttachmentSchema, type WorkspaceSchema, type WorkspaceSize, updateWindowDaysMap }; |
1340
dist/index.js
@@ -29,5 +29,457 @@ "use strict"; | ||
// src/api/index.ts | ||
var API = class { | ||
constructor(_apiKey, _version = 1) { | ||
this._apiKey = _apiKey; | ||
this._version = _version; | ||
this._baseURL = `https://api.singlestore.com`; | ||
} | ||
_baseURL; | ||
async execute(url, { version = this._version, ...params } = {}) { | ||
if (!this._apiKey) { | ||
throw new Error( | ||
"The Management API key is undefined. Please generate a valid API key. For more info read: https://docs.singlestore.com/cloud/reference/management-api/#generate-an-api-key" | ||
); | ||
} | ||
const _url = `${this._baseURL}/v${version}${url}`; | ||
const response = await fetch(_url, { | ||
method: "GET", | ||
...params, | ||
headers: { | ||
"Content-Type": "application/json", | ||
...params?.headers, | ||
"Authorization": `Bearer ${this._apiKey}` | ||
} | ||
}); | ||
const contentType = response.headers.get("content-type"); | ||
if (contentType?.startsWith("text/plain")) { | ||
return response.text(); | ||
} | ||
return response.json(); | ||
} | ||
}; | ||
// src/api/manager.ts | ||
var APIManager = class { | ||
constructor(_api) { | ||
this._api = _api; | ||
} | ||
_execute(...[url, params]) { | ||
return this._api.execute(`${this._baseURL}${url ?? ""}`, params); | ||
} | ||
}; | ||
// src/billing/manager.ts | ||
var BillingManager = class extends APIManager { | ||
_baseURL = "/billing"; | ||
async get({ metric, startTime, endTime, aggregateBy }) { | ||
const params = new URLSearchParams({ metric }); | ||
Object.entries({ startTime, endTime }).forEach(([key, value]) => { | ||
params.set(key, value.toISOString().split(".")[0] + "Z"); | ||
}); | ||
if (aggregateBy) { | ||
params.set("aggregateBy", aggregateBy); | ||
} | ||
const response = await this._execute(`/usage?${params.toString()}`); | ||
return response.billingUsage.map((data) => { | ||
const usage = data.Usage.map((usage2) => { | ||
return { | ||
...usage2, | ||
startTime: new Date(startTime), | ||
endTime: new Date(endTime) | ||
}; | ||
}); | ||
if (metric === "ComputeCredit") { | ||
return { | ||
metric: "ComputeCredit", | ||
description: data.description, | ||
usage | ||
}; | ||
} | ||
return { | ||
metric: "StorageAvgByte", | ||
description: data.description, | ||
usage | ||
}; | ||
}); | ||
} | ||
}; | ||
// src/job/index.ts | ||
var Job = class _Job extends APIManager { | ||
constructor(_api, id, name, description, enqueuedBy, executionConfig, metadata, targetConfig, completedExecutionsCount, schedule, createdAt, terminatedAt) { | ||
super(_api); | ||
this.id = id; | ||
this.name = name; | ||
this.description = description; | ||
this.enqueuedBy = enqueuedBy; | ||
this.executionConfig = executionConfig; | ||
this.metadata = metadata; | ||
this.targetConfig = targetConfig; | ||
this.completedExecutionsCount = completedExecutionsCount; | ||
this.schedule = schedule; | ||
this.createdAt = createdAt; | ||
this.terminatedAt = terminatedAt; | ||
this._baseURL = _Job.getBaseURL(this.id); | ||
} | ||
_baseURL; | ||
static getBaseURL(id) { | ||
return `/jobs/${id}`; | ||
} | ||
static async delete(api, id) { | ||
return api.execute(this.getBaseURL(id), { method: "DELETE" }); | ||
} | ||
static async getExecutions(api, id, start, end) { | ||
const params = new URLSearchParams({ start: start.toString(), end: end.toString() }); | ||
const response = await api.execute(`${this.getBaseURL(id)}/executions?${params.toString()}`); | ||
return response.executions.map((execution) => { | ||
return { | ||
id: execution.executionID, | ||
number: execution.executionNumber, | ||
jobID: execution.jobID, | ||
scheduledStartTime: new Date(execution.scheduledStartTime), | ||
startedAt: new Date(execution.startedAt), | ||
finishedAt: new Date(execution.finishedAt), | ||
snapshotNotebookPath: execution.snapshotNotebookPath, | ||
status: execution.status | ||
}; | ||
}); | ||
} | ||
static async getParameters(api, id) { | ||
return api.execute(`${this.getBaseURL(id)}/parameters`); | ||
} | ||
async delete() { | ||
return _Job.delete(this._api, this.id); | ||
} | ||
async getExecutions(start, end) { | ||
return _Job.getExecutions(this._api, this.id, start, end); | ||
} | ||
async getParameters() { | ||
return _Job.getParameters(this._api, this.id); | ||
} | ||
}; | ||
// src/job/manager.ts | ||
var JobManager = class extends APIManager { | ||
_baseURL = "/jobs"; | ||
_create(data) { | ||
return new Job( | ||
this._api, | ||
data.jobID, | ||
data.name, | ||
data.description, | ||
data.enqueuedBy, | ||
data.executionConfig, | ||
data.jobMetadata, | ||
data.targetConfig, | ||
data.completedExecutionsCount, | ||
{ ...data.schedule, startAt: data.schedule.startAt ? new Date(data.schedule.startAt) : null }, | ||
new Date(data.createdAt), | ||
data.terminatedAt ? new Date(data.terminatedAt) : null | ||
); | ||
} | ||
async create(body) { | ||
const response = await this._execute("", { method: "POST", body: JSON.stringify(body) }); | ||
return this._create(response); | ||
} | ||
async get(id) { | ||
const response = await this._execute(`/${id}`); | ||
return this._create(response); | ||
} | ||
async delete(...args) { | ||
return Job.delete(this._api, ...args); | ||
} | ||
async getExecutions(...args) { | ||
return Job.getExecutions(this._api, ...args); | ||
} | ||
async getParameters(...args) { | ||
return Job.getParameters(this._api, ...args); | ||
} | ||
async getRuntimes() { | ||
return this._execute("/runtimes"); | ||
} | ||
}; | ||
// src/organization/manager.ts | ||
var OrganizationManager = class extends APIManager { | ||
_baseURL = "/organizations"; | ||
async get() { | ||
const respnose = await this._execute("/current"); | ||
return { | ||
id: respnose.orgID, | ||
name: respnose.name | ||
}; | ||
} | ||
}; | ||
// src/region/manager.ts | ||
var RegionManager = class extends APIManager { | ||
_baseURL = "/regions"; | ||
async get(where) { | ||
const response = await this._execute(); | ||
if (where && ("id" in where || "name" in where)) { | ||
const region = response.find((region2) => { | ||
if ("id" in where) return region2.regionID === where.id; | ||
if ("name" in where) return region2.region === where.name; | ||
return false; | ||
}); | ||
if (!region) return void 0; | ||
return { | ||
id: region.regionID, | ||
name: region.region, | ||
provider: region.provider | ||
}; | ||
} | ||
return response.map((data) => ({ | ||
id: data.regionID, | ||
name: data.region, | ||
provider: data.provider | ||
})); | ||
} | ||
}; | ||
// src/secret/index.ts | ||
var Secret = class _Secret extends APIManager { | ||
constructor(api, id, name, value, lastUpdatedBy, lastUpdatedAt, createdBy, createdAt) { | ||
super(api); | ||
this.id = id; | ||
this.name = name; | ||
this.value = value; | ||
this.lastUpdatedBy = lastUpdatedBy; | ||
this.lastUpdatedAt = lastUpdatedAt; | ||
this.createdBy = createdBy; | ||
this.createdAt = createdAt; | ||
this._baseURL = _Secret.getBaseURL(this.id); | ||
} | ||
_baseURL; | ||
static getBaseURL(id) { | ||
return `/secrets/${id}`; | ||
} | ||
static async update(api, id, value) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify({ value }) | ||
}); | ||
return new _Secret( | ||
api, | ||
response.secretID, | ||
response.name, | ||
response.value, | ||
response.lastUpdatedBy, | ||
new Date(response.lastUpdatedAt), | ||
response.createdBy, | ||
new Date(response.createdAt) | ||
); | ||
} | ||
static async delete(api, id) { | ||
const response = await api.execute(this.getBaseURL(id), { method: "DELETE" }); | ||
return response.secretID; | ||
} | ||
async update(value) { | ||
return _Secret.update(this._api, this.id, value); | ||
} | ||
async delete() { | ||
return _Secret.delete(this._api, this.id); | ||
} | ||
}; | ||
// src/secret/manager.ts | ||
var SecretManager = class extends APIManager { | ||
_baseURL = "/secrets"; | ||
_create(data) { | ||
return new Secret( | ||
this._api, | ||
data.secretID, | ||
data.name, | ||
data.value, | ||
data.lastUpdatedBy, | ||
new Date(data.lastUpdatedAt), | ||
data.createdBy, | ||
new Date(data.createdAt) | ||
); | ||
} | ||
async create(body) { | ||
const response = await this._execute("", { | ||
method: "POST", | ||
body: JSON.stringify(body) | ||
}); | ||
return this._create(response.secret); | ||
} | ||
async get(where) { | ||
let url = ""; | ||
const params = new URLSearchParams(); | ||
if (where) { | ||
if ("name" in where) { | ||
params.set("name", where.name); | ||
} else if ("id" in where) { | ||
url = `${url}/${where.id}`; | ||
} | ||
} | ||
const response = await this._execute(`${url}?${params.toString()}`); | ||
if ("secrets" in response) { | ||
if (!where) { | ||
return response.secrets.map((data) => this._create(data)); | ||
} | ||
if (response.secrets[0]) { | ||
return this._create(response.secrets[0]); | ||
} | ||
} | ||
if ("secret" in response && response.secret) { | ||
return this._create(response.secret); | ||
} | ||
return []; | ||
} | ||
async update(...args) { | ||
return Secret.update(this._api, ...args); | ||
} | ||
async delete(...args) { | ||
return Secret.delete(this._api, ...args); | ||
} | ||
}; | ||
// src/team/index.ts | ||
var Team = class _Team extends APIManager { | ||
constructor(api, id, name, description, memberTeams, memberUsers, createdAt) { | ||
super(api); | ||
this.id = id; | ||
this.name = name; | ||
this.description = description; | ||
this.memberTeams = memberTeams; | ||
this.memberUsers = memberUsers; | ||
this.createdAt = createdAt; | ||
this._baseURL = _Team.getBaseURL(this.id); | ||
} | ||
_baseURL; | ||
static getBaseURL(id) { | ||
return `/teams/${id}`; | ||
} | ||
static async update(api, id, body) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify(body) | ||
}); | ||
return response.teamID; | ||
} | ||
static async delete(api, id) { | ||
const response = await api.execute(this.getBaseURL(id), { method: "DELETE" }); | ||
return response.teamID; | ||
} | ||
static async addMemberTeams(api, id, teamIDs) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify({ addMemberTeamIDs: teamIDs }) | ||
}); | ||
return response.teamID; | ||
} | ||
static async removeMemberTeams(api, id, teamIDs) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify({ removeMemberTeamIDs: teamIDs }) | ||
}); | ||
return response.teamID; | ||
} | ||
static async addMemberUsers(api, id, userIDs) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify({ addMemberUserIDs: userIDs }) | ||
}); | ||
return response.teamID; | ||
} | ||
static async removeMemberUsers(api, id, userIDs) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify({ removeMemberUserIDs: userIDs }) | ||
}); | ||
return response.teamID; | ||
} | ||
async update(body) { | ||
return _Team.update(this._api, this.id, body); | ||
} | ||
async delete() { | ||
return _Team.delete(this._api, this.id); | ||
} | ||
async addMemberTeams(teamIDs) { | ||
return _Team.addMemberTeams(this._api, this.id, teamIDs); | ||
} | ||
async removeMemberTeams(teamIDs) { | ||
return _Team.removeMemberTeams(this._api, this.id, teamIDs); | ||
} | ||
async addMemberUsers(userIDs) { | ||
return _Team.addMemberUsers(this._api, this.id, userIDs); | ||
} | ||
async removeMemberUsers(userIDs) { | ||
return _Team.removeMemberUsers(this._api, this.id, userIDs); | ||
} | ||
}; | ||
// src/team/manager.ts | ||
var TeamManager = class extends APIManager { | ||
_baseURL = "/teams"; | ||
_create(data) { | ||
return new Team( | ||
this._api, | ||
data.teamID, | ||
data.name, | ||
data.description, | ||
data.memberTeams?.map(({ teamID, ...team }) => ({ ...team, id: teamID })), | ||
data.memberUsers?.map(({ userID, ...user }) => ({ ...user, id: userID })), | ||
new Date(data.createdAt) | ||
); | ||
} | ||
async create({ memberTeams, memberUsers, ...body }) { | ||
let newTeam = await this._execute("", { | ||
method: "POST", | ||
body: JSON.stringify(body) | ||
}); | ||
if (memberTeams?.length || memberUsers?.length) { | ||
await this._execute(`/${newTeam.teamID}`, { | ||
method: "PATCH", | ||
body: JSON.stringify({ | ||
addMemberTeamIDs: memberTeams, | ||
addMemberUserIDs: memberUsers | ||
}) | ||
}); | ||
newTeam = await this._execute(`/${newTeam.teamID}`); | ||
} | ||
return this._create(newTeam); | ||
} | ||
async get(where) { | ||
let url = ""; | ||
const params = new URLSearchParams(); | ||
if (where) { | ||
if ("id" in where) { | ||
url = `${url}/${where.id}`; | ||
} else { | ||
params.set(...Object.entries(where)[0]); | ||
} | ||
} | ||
const response = await this._execute(`${url}?${params.toString()}`); | ||
if (Array.isArray(response)) { | ||
return response.map((data) => this._create(data)); | ||
} | ||
return this._create(response); | ||
} | ||
async update(...args) { | ||
return Team.update(this._api, ...args); | ||
} | ||
async delete(...args) { | ||
return Team.delete(this._api, ...args); | ||
} | ||
async addMemberTeams(...args) { | ||
return Team.addMemberTeams(this._api, ...args); | ||
} | ||
async removeMemberTeams(...args) { | ||
return Team.removeMemberTeams(this._api, ...args); | ||
} | ||
async addMemberUsers(...args) { | ||
return Team.addMemberUsers(this._api, ...args); | ||
} | ||
async removeMemberUsers(...args) { | ||
return Team.removeMemberUsers(this._api, ...args); | ||
} | ||
}; | ||
// src/connection.ts | ||
var import_promise = require("mysql2/promise"); | ||
var Connection = class _Connection { | ||
var Connection = class { | ||
constructor(config) { | ||
@@ -38,5 +490,2 @@ this.config = config; | ||
client; | ||
static create(config) { | ||
return new _Connection(config); | ||
} | ||
async disconnect() { | ||
@@ -47,12 +496,24 @@ await this.client.end(); | ||
// src/column.ts | ||
// src/column/index.ts | ||
var Column = class _Column { | ||
constructor(_connection, databaseName, tableName, name) { | ||
this._connection = _connection; | ||
constructor(_client, _path, name, tableName, databaseName) { | ||
this._client = _client; | ||
this._path = _path; | ||
this.name = name; | ||
this.tableName = tableName; | ||
this.databaseName = databaseName; | ||
this.tableName = tableName; | ||
this.name = name; | ||
this._path = [databaseName, tableName].join("."); | ||
} | ||
_path; | ||
static schemaToClauses(schema) { | ||
const clauses = [`\`${schema.name}\``]; | ||
if (schema.type) clauses.push(schema.type); | ||
if (schema.nullable !== void 0 && !schema.nullable) clauses.push("NOT NULL"); | ||
if (schema.primaryKey) clauses.push("PRIMARY KEY"); | ||
if (schema.autoIncrement) clauses.push("AUTO_INCREMENT"); | ||
if (schema.default !== void 0) clauses.push(`DEFAULT ${schema.default}`); | ||
return [...clauses, ...schema.clauses || []].filter(Boolean).join(" "); | ||
} | ||
static async drop(client, databaseName, tableName, name) { | ||
return client.execute(` ALTER TABLE ${databaseName}.${tableName} DROP COLUMN ${name} | ||
`); | ||
} | ||
static normalizeInfo(info) { | ||
@@ -68,43 +529,70 @@ return { | ||
} | ||
static schemaToClauses(schema) { | ||
const clauses = [`\`${schema.name}\``]; | ||
if (schema.type) clauses.push(schema.type); | ||
if (schema.nullable !== void 0 && !schema.nullable) clauses.push("NOT NULL"); | ||
if (schema.primaryKey) clauses.push("PRIMARY KEY"); | ||
if (schema.autoIncrement) clauses.push("AUTO_INCREMENT"); | ||
if (schema.default !== void 0) clauses.push(`DEFAULT ${schema.default}`); | ||
return [...clauses, ...schema.clauses || []].filter(Boolean).join(" "); | ||
} | ||
static async add(connection, databaseName, tableName, schema) { | ||
const clauses = _Column.schemaToClauses(schema); | ||
await connection.client.execute(` ALTER TABLE ${databaseName}.${tableName} ADD COLUMN ${clauses} | ||
static async modify(client, path, name, schema) { | ||
const clauses = _Column.schemaToClauses({ type: "", ...schema, name }); | ||
return client.execute(` ALTER TABLE ${path} MODIFY COLUMN ${clauses} | ||
`); | ||
return new _Column(connection, databaseName, tableName, schema.name); | ||
} | ||
static drop(connection, databaseName, tableName, name) { | ||
return connection.client.execute(` ALTER TABLE ${databaseName}.${tableName} DROP COLUMN ${name} | ||
static async rename(client, path, name, newName) { | ||
const result = await client.execute(` ALTER TABLE ${path} CHANGE ${name} ${newName} | ||
`); | ||
return result; | ||
} | ||
async showInfo() { | ||
const [rows] = await this._connection.client.query( | ||
`SHOW COLUMNS IN ${this.tableName} IN ${this.databaseName} LIKE '${this.name}'` | ||
); | ||
static async showInfo(client, databaseName, tableName, name) { | ||
const [rows] = await client.query(`SHOW COLUMNS IN ${tableName} IN ${databaseName} LIKE '${name}'`); | ||
return _Column.normalizeInfo(rows[0]); | ||
} | ||
drop() { | ||
return _Column.drop(this._connection, this.databaseName, this.tableName, this.name); | ||
async drop() { | ||
return _Column.drop(this._client, this.databaseName, this.tableName, this.name); | ||
} | ||
modify(schema) { | ||
const clauses = _Column.schemaToClauses({ type: "", ...schema, name: this.name }); | ||
return this._connection.client.execute(` ALTER TABLE ${this._path} MODIFY COLUMN ${clauses} | ||
`); | ||
async modify(...args) { | ||
return _Column.modify(this._client, this._path, this.name, ...args); | ||
} | ||
async rename(newName) { | ||
const result = await this._connection.client.execute(` ALTER TABLE ${this._path} CHANGE ${this.name} ${newName} | ||
`); | ||
async rename(...[newName, ...args]) { | ||
const result = await _Column.rename(this._client, this._path, this.name, newName, ...args); | ||
this.name = newName; | ||
return result; | ||
} | ||
async showInfo() { | ||
return _Column.showInfo(this._client, this.databaseName, this.tableName, this.name); | ||
} | ||
}; | ||
// src/column/manager.ts | ||
var ColumnManager = class { | ||
constructor(_client, tableName, databaseName) { | ||
this._client = _client; | ||
this.tableName = tableName; | ||
this.databaseName = databaseName; | ||
this._path = [databaseName, tableName].join("."); | ||
} | ||
_path; | ||
use(name) { | ||
return new Column(this._client, this._path, name, this.tableName, this.databaseName); | ||
} | ||
async add(schema) { | ||
const clauses = Column.schemaToClauses(schema); | ||
await this._client.execute(` ALTER TABLE ${this.databaseName}.${this.tableName} ADD COLUMN ${clauses} | ||
`); | ||
return new Column( | ||
this._client, | ||
this._path, | ||
schema.name, | ||
this.tableName, | ||
this.databaseName | ||
); | ||
} | ||
async drop(name) { | ||
return Column.drop(this._client, this.databaseName, this.tableName, name); | ||
} | ||
async modify(name, ...args) { | ||
return Column.modify(this._client, this._path, name, ...args); | ||
} | ||
async rename(name, ...args) { | ||
return Column.rename(this._client, this._path, name, ...args); | ||
} | ||
async showInfo(name, ...args) { | ||
return Column.showInfo(this._client, this.databaseName, this.tableName, name, ...args); | ||
} | ||
}; | ||
// src/query/builder.ts | ||
@@ -262,19 +750,31 @@ var import_mysql2 = require("mysql2"); | ||
// src/table.ts | ||
// src/table/index.ts | ||
var Table = class _Table { | ||
constructor(_connection, databaseName, name, _ai) { | ||
this._connection = _connection; | ||
constructor(_client, name, databaseName, _ai) { | ||
this._client = _client; | ||
this.name = name; | ||
this.databaseName = databaseName; | ||
this.name = name; | ||
this._ai = _ai; | ||
this._path = [databaseName, name].join("."); | ||
this.column = new ColumnManager(this._client, this.name, this.databaseName); | ||
} | ||
_path; | ||
vScoreKey = "v_score"; | ||
column; | ||
get ai() { | ||
if (!this._ai) { | ||
throw new Error("AnyAI instance is undefined. Ensure ai is properly initialized before accessing."); | ||
throw new Error("AI instance is undefined. Ensure ai is properly initialized before accessing."); | ||
} | ||
return this._ai; | ||
} | ||
static schemaToClauses(schema) { | ||
const clauses = [ | ||
...Object.entries(schema.columns).map(([name, schema2]) => { | ||
return Column.schemaToClauses({ ...schema2, name }); | ||
}) | ||
]; | ||
if (schema.primaryKeys?.length) clauses.push(`PRIMARY KEY (${schema.primaryKeys.join(", ")})`); | ||
if (schema.fulltextKeys?.length) clauses.push(`FULLTEXT KEY (${schema.fulltextKeys.join(", ")})`); | ||
return [...clauses, ...schema.clauses || []].filter(Boolean).join(", "); | ||
} | ||
static normalizeInfo(info, extended) { | ||
@@ -290,22 +790,17 @@ const name = info[Object.keys(info).find((key) => key.startsWith("Tables_in_"))]; | ||
} | ||
static schemaToClauses(schema) { | ||
const clauses = [ | ||
...Object.entries(schema.columns).map(([name, schema2]) => { | ||
return Column.schemaToClauses({ ...schema2, name }); | ||
}) | ||
]; | ||
if (schema.primaryKeys?.length) clauses.push(`PRIMARY KEY (${schema.primaryKeys.join(", ")})`); | ||
if (schema.fulltextKeys?.length) clauses.push(`FULLTEXT KEY (${schema.fulltextKeys.join(", ")})`); | ||
return [...clauses, ...schema.clauses || []].filter(Boolean).join(", "); | ||
static async drop(client, databaseName, name) { | ||
return client.execute(` DROP TABLE IF EXISTS ${databaseName}.${name} | ||
`); | ||
} | ||
static async create(connection, databaseName, schema, ai) { | ||
const clauses = _Table.schemaToClauses(schema); | ||
await connection.client.execute(` CREATE TABLE IF NOT EXISTS ${databaseName}.${schema.name} (${clauses}) | ||
static async truncate(client, databaseName, tableName) { | ||
return client.execute(` TRUNCATE TABLE ${databaseName}.${tableName} | ||
`); | ||
return new _Table(connection, databaseName, schema.name, ai); | ||
} | ||
static drop(connection, databaseName, name) { | ||
return connection.client.execute(` DROP TABLE IF EXISTS ${databaseName}.${name} | ||
static async rename(client, databaseName, name, newName) { | ||
return client.execute(` ALTER TABLE ${databaseName}.${name} RENAME TO ${newName} | ||
`); | ||
} | ||
async drop() { | ||
return _Table.drop(this._client, this.databaseName, this.name); | ||
} | ||
async showInfo(extended) { | ||
@@ -315,33 +810,18 @@ const clauses = [`SHOW TABLES IN ${this.databaseName}`]; | ||
clauses.push(`LIKE '${this.name}'`); | ||
const [rows] = await this._connection.client.query(clauses.join(" ")); | ||
const [rows] = await this._client.query(clauses.join(" ")); | ||
return _Table.normalizeInfo(rows[0], extended); | ||
} | ||
drop() { | ||
return _Table.drop(this._connection, this.databaseName, this.name); | ||
} | ||
column(name) { | ||
return new Column(this._connection, this.databaseName, this.name, name); | ||
} | ||
async showColumnsInfo() { | ||
const [rows] = await this._connection.client.query(`SHOW COLUMNS IN ${this.name} IN ${this.databaseName}`); | ||
const [rows] = await this._client.query(`SHOW COLUMNS IN ${this.name} IN ${this.databaseName}`); | ||
return rows.map((row) => Column.normalizeInfo(row)); | ||
} | ||
addColumn(schema) { | ||
return Column.add(this._connection, this.databaseName, this.name, schema); | ||
async truncate() { | ||
return _Table.truncate(this._client, this.databaseName, this.name); | ||
} | ||
dropColumn(name) { | ||
return Column.drop(this._connection, this.databaseName, this.name, name); | ||
} | ||
truncate() { | ||
return this._connection.client.execute(` TRUNCATE TABLE ${this._path} | ||
`); | ||
} | ||
async rename(newName) { | ||
const result = await this._connection.client.execute(` ALTER TABLE ${this._path} RENAME TO ${newName} | ||
`); | ||
async rename(...[newName, ...args]) { | ||
const result = await _Table.rename(this._client, this.databaseName, this.name, newName, ...args); | ||
this.name = newName; | ||
this._path = [this.databaseName, newName].join("."); | ||
return result; | ||
} | ||
insert(values) { | ||
async insert(values) { | ||
const _values = Array.isArray(values) ? values : [values]; | ||
@@ -353,3 +833,3 @@ const keys = Object.keys(_values[0]); | ||
const query = `INSERT INTO ${this._path} (${keys}) VALUES ${placeholders}`; | ||
return this._connection.client.execute(query, Object.values(data)); | ||
return this._client.execute(query, Object.values(data)); | ||
}) | ||
@@ -361,10 +841,10 @@ ); | ||
const query = queryBuilder.buildQuery(params); | ||
const [rows] = await this._connection.client.execute(query); | ||
const [rows] = await this._client.execute(query); | ||
return rows; | ||
} | ||
update(values, where) { | ||
async update(values, where) { | ||
const _where = new QueryBuilder(this.databaseName, this.name).buildWhereClause(where); | ||
const columnAssignments = Object.keys(values).map((key) => `${key} = ?`).join(", "); | ||
const query = `UPDATE ${this._path} SET ${columnAssignments} ${_where}`; | ||
return this._connection.client.execute(query, Object.values(values)); | ||
return this._client.execute(query, Object.values(values)); | ||
} | ||
@@ -375,3 +855,3 @@ delete(where) { | ||
const query = `DELETE FROM ${this._path} ${_where}`; | ||
return this._connection.client.execute(query); | ||
return this._client.execute(query); | ||
} | ||
@@ -390,3 +870,3 @@ async vectorSearch(params, queryParams) { | ||
`; | ||
const [rows] = await this._connection.client.execute(query); | ||
const [rows] = await this._client.execute(query); | ||
return rows[1]; | ||
@@ -409,10 +889,45 @@ } | ||
// src/database.ts | ||
// src/table/manager.ts | ||
var TableManager = class _TableManager { | ||
constructor(_client, _ai, databaseName) { | ||
this._client = _client; | ||
this._ai = _ai; | ||
this.databaseName = databaseName; | ||
} | ||
static async create(client, databaseName, schema, ai) { | ||
const clauses = Table.schemaToClauses(schema); | ||
await client.execute(` CREATE TABLE IF NOT EXISTS ${databaseName}.${schema.name} (${clauses}) | ||
`); | ||
return new Table(client, schema.name, databaseName, ai); | ||
} | ||
use(name) { | ||
return new Table(this._client, name, this.databaseName, this._ai); | ||
} | ||
async create(schema) { | ||
return _TableManager.create(this._client, this.databaseName, schema, this._ai); | ||
} | ||
async drop(name, ...args) { | ||
return Table.drop(this._client, this.databaseName, name, ...args); | ||
} | ||
async truncate(name, ...args) { | ||
return Table.truncate(this._client, this.databaseName, name, ...args); | ||
} | ||
async rename(name, ...args) { | ||
return Table.rename(this._client, this.databaseName, name, ...args); | ||
} | ||
}; | ||
// src/database/index.ts | ||
var Database = class _Database { | ||
constructor(_connection, name, workspaceName, _ai) { | ||
this._connection = _connection; | ||
constructor(_client, _ai, name, workspaceName) { | ||
this._client = _client; | ||
this._ai = _ai; | ||
this.name = name; | ||
this.workspaceName = workspaceName; | ||
this._ai = _ai; | ||
this.table = new TableManager(this._client, this._ai, this.name); | ||
} | ||
table; | ||
static async drop(client, name) { | ||
return client.execute(`DROP DATABASE IF EXISTS ${name}`); | ||
} | ||
static normalizeInfo(info, extended) { | ||
@@ -441,18 +956,5 @@ const name = info[Object.keys(info).find((key) => key.startsWith("Database"))]; | ||
} | ||
static async create(connection, schema, workspaceName, ai) { | ||
const clauses = [`CREATE DATABASE IF NOT EXISTS ${schema.name}`]; | ||
if (workspaceName) clauses.push(`ON WORKSPACE \`${workspaceName}\``); | ||
await connection.client.execute(clauses.join(" ")); | ||
if (schema.tables) { | ||
await Promise.all( | ||
Object.entries(schema.tables).map(([name, tableSchema]) => { | ||
return Table.create(connection, schema.name, { ...tableSchema, name }); | ||
}) | ||
); | ||
} | ||
return new _Database(connection, schema.name, workspaceName, ai); | ||
async drop(...args) { | ||
return _Database.drop(this._client, this.name, ...args); | ||
} | ||
static drop(connection, name) { | ||
return connection.client.execute(`DROP DATABASE IF EXISTS ${name}`); | ||
} | ||
async showInfo(extended) { | ||
@@ -462,5 +964,13 @@ const clauses = ["SHOW DATABASES"]; | ||
clauses.push(`LIKE '${this.name}'`); | ||
const [rows] = await this._connection.client.query(clauses.join(" ")); | ||
const [rows] = await this._client.query(clauses.join(" ")); | ||
return _Database.normalizeInfo(rows[0], extended); | ||
} | ||
async showTablesInfo(extended) { | ||
const clauses = [`SHOW TABLES IN ${this.name}`]; | ||
if (extended) clauses.push("EXTENDED"); | ||
const [rows] = await this._client.query(clauses.join(" ")); | ||
return rows.map((row) => { | ||
return Table.normalizeInfo(row, extended); | ||
}); | ||
} | ||
async describe() { | ||
@@ -471,63 +981,579 @@ const [info, tablesInfo] = await Promise.all([this.showInfo(true), this.showTablesInfo(true)]); | ||
tables: await Promise.all( | ||
tablesInfo.map(async (table) => ({ ...table, columns: await this.table(table.name).showColumnsInfo() })) | ||
tablesInfo.map(async (tableInfo) => { | ||
const table = this.table.use(tableInfo.name); | ||
return { ...tableInfo, columns: await table.showColumnsInfo() }; | ||
}) | ||
) | ||
}; | ||
} | ||
drop() { | ||
return _Database.drop(this._connection, this.name); | ||
async query(statement) { | ||
const statements = [`USE ${this.name}`, statement].join(";\n"); | ||
const [rows] = await this._client.execute(statements); | ||
return rows.slice(1); | ||
} | ||
table(name) { | ||
return new Table(this._connection, this.name, name, this._ai); | ||
}; | ||
// src/database/manager.ts | ||
var DatabaseManager = class { | ||
constructor(_client, _ai, workspaceName) { | ||
this._client = _client; | ||
this._ai = _ai; | ||
this.workspaceName = workspaceName; | ||
} | ||
async showTablesInfo(extended) { | ||
const clauses = [`SHOW TABLES IN ${this.name}`]; | ||
if (extended) clauses.push("EXTENDED"); | ||
const [rows] = await this._connection.client.query(clauses.join(" ")); | ||
return rows.map((row) => Table.normalizeInfo(row, extended)); | ||
use(name) { | ||
return new Database(this._client, this._ai, name, this.workspaceName); | ||
} | ||
createTable(schema) { | ||
return Table.create(this._connection, this.name, schema, this._ai); | ||
async create(schema) { | ||
const clauses = [`CREATE DATABASE IF NOT EXISTS ${schema.name}`]; | ||
if (this.workspaceName) clauses.push(`ON WORKSPACE \`${this.workspaceName}\``); | ||
await this._client.execute(clauses.join(" ")); | ||
if (schema.tables) { | ||
await Promise.all( | ||
Object.entries(schema.tables).map(([name, tableSchema]) => { | ||
return TableManager.create(this._client, schema.name, { ...tableSchema, name }, this._ai); | ||
}) | ||
); | ||
} | ||
return new Database(this._client, this._ai, schema.name, this.workspaceName); | ||
} | ||
dropTable(name) { | ||
return Table.drop(this._connection, this.name, name); | ||
async drop(...args) { | ||
return Database.drop(this._client, ...args); | ||
} | ||
async query(statement) { | ||
const statements = [`USE ${this.name}`, statement].join(";\n"); | ||
const [rows] = await this._connection.client.execute(statements); | ||
return rows.slice(1); | ||
}; | ||
// src/workspace/connection.ts | ||
var WorkspaceConnection = class _WorkspaceConnection extends Connection { | ||
name; | ||
_ai; | ||
database; | ||
constructor({ name, ai, ...config }) { | ||
super(config); | ||
this.name = name; | ||
this._ai = ai; | ||
this.database = new DatabaseManager(this.client, this._ai, this.name); | ||
} | ||
static create(config) { | ||
return new _WorkspaceConnection(config); | ||
} | ||
}; | ||
// src/workspace.ts | ||
var Workspace = class _Workspace { | ||
constructor(connection, name, _ai) { | ||
this.connection = connection; | ||
// ../utils/dist/index.mjs | ||
function getKeyByValue(object, value) { | ||
for (const key in object) { | ||
if (object[key] === value) { | ||
return key; | ||
} | ||
} | ||
return void 0; | ||
} | ||
// src/workspace/private-connection/manager.ts | ||
var import_url = require("url"); | ||
var WorkspacePrivateConnectionManager = class _WorkspacePrivateConnectionManager extends APIManager { | ||
constructor(api, _workspaceID, _groupID) { | ||
super(api); | ||
this._workspaceID = _workspaceID; | ||
this._groupID = _groupID; | ||
this._baseURL = _WorkspacePrivateConnectionManager.getBaseURL(this._workspaceID); | ||
} | ||
_baseURL; | ||
static getBaseURL(workspaceID) { | ||
return `/workspaces/${workspaceID}/privateConnections`; | ||
} | ||
async get(params) { | ||
const searchParams = new import_url.URLSearchParams({ workspaceGroupID: this._groupID }); | ||
return this._execute( | ||
`${params?.isKai ? "/kai" : ""}?${searchParams.toString()}` | ||
); | ||
} | ||
async outbundAllowList() { | ||
return this._execute("/outbundAllowList"); | ||
} | ||
}; | ||
// src/workspace/index.ts | ||
var Workspace = class _Workspace extends APIManager { | ||
constructor(api, _ai, id, groupID, name, endpoint, size, state, scaleFactor, scalingProgress, cacheConfig, kaiEnabled, deploymentType, createdAt, lastResumedAt, terminatedAt, autoSuspend, resumeAttachments) { | ||
super(api); | ||
this._ai = _ai; | ||
this.id = id; | ||
this.groupID = groupID; | ||
this.name = name; | ||
this.endpoint = endpoint; | ||
this.size = size; | ||
this.state = state; | ||
this.scaleFactor = scaleFactor; | ||
this.scalingProgress = scalingProgress; | ||
this.cacheConfig = cacheConfig; | ||
this.kaiEnabled = kaiEnabled; | ||
this.deploymentType = deploymentType; | ||
this.createdAt = createdAt; | ||
this.lastResumedAt = lastResumedAt; | ||
this.terminatedAt = terminatedAt; | ||
this.autoSuspend = autoSuspend; | ||
this.resumeAttachments = resumeAttachments; | ||
this._baseURL = _Workspace.getBaseURL(this.id); | ||
this.privateConnection = new WorkspacePrivateConnectionManager(this._api, this.id, this.groupID); | ||
} | ||
_baseURL; | ||
privateConnection; | ||
static getBaseURL(id) { | ||
return `/workspaces/${id}`; | ||
} | ||
static async update(api, id, body) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify(body) | ||
}); | ||
return response.workspaceID; | ||
} | ||
static async delete(api, id) { | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "DELETE" | ||
}); | ||
return response.workspaceID; | ||
} | ||
static async resume(api, id, body = {}) { | ||
const response = await api.execute(`${this.getBaseURL(id)}/resume`, { | ||
method: "POST", | ||
body: JSON.stringify(body) | ||
}); | ||
return response.workspaceID; | ||
} | ||
static async suspend(api, id) { | ||
const response = await api.execute(`${this.getBaseURL(id)}/suspend`, { | ||
method: "POST" | ||
}); | ||
return response.workspaceID; | ||
} | ||
static async getState(api, id) { | ||
const searchParams = new URLSearchParams({ fields: "state" }); | ||
const respone = await api.execute(`${this.getBaseURL(id)}?${searchParams.toString()}`); | ||
return respone.state; | ||
} | ||
connect(config) { | ||
return WorkspaceConnection.create({ ...config, name: this.name, ai: this._ai, host: this.endpoint }); | ||
} | ||
async update(body) { | ||
return _Workspace.update(this._api, this.id, body); | ||
} | ||
async delete() { | ||
return _Workspace.delete(this._api, this.id); | ||
} | ||
async resume(body) { | ||
return _Workspace.resume(this._api, this.id, body); | ||
} | ||
async suspend() { | ||
return _Workspace.suspend(this._api, this.id); | ||
} | ||
async getState() { | ||
return _Workspace.getState(this._api, this.id); | ||
} | ||
}; | ||
// src/workspace/manager.ts | ||
var WorkspaceManager = class extends APIManager { | ||
constructor(api, _ai, _workspaceGroupID) { | ||
super(api); | ||
this._ai = _ai; | ||
this._workspaceGroupID = _workspaceGroupID; | ||
} | ||
static connect({ | ||
ai, | ||
name, | ||
...config | ||
}) { | ||
const connection = new Connection(config); | ||
return new _Workspace(connection, name, ai); | ||
_baseURL = "/workspaces"; | ||
_create(data) { | ||
return new Workspace( | ||
this._api, | ||
this._ai, | ||
data.workspaceID, | ||
data.workspaceGroupID, | ||
data.name, | ||
data.endpoint, | ||
data.size, | ||
data.state, | ||
data.scaleFactor, | ||
data.scalingProgress, | ||
data.cacheConfig, | ||
data.kaiEnabled, | ||
data.deploymentType, | ||
new Date(data.createdAt), | ||
data.lastResumedAt ? new Date(data.lastResumedAt) : void 0, | ||
data.terminatedAt ? new Date(data.terminatedAt) : void 0, | ||
data.autoSuspend ? { | ||
...data.autoSuspend, | ||
idleChangedAt: data.autoSuspend.idleChangedAt ? new Date(data.autoSuspend.idleChangedAt) : void 0, | ||
scheduledChangedAt: data.autoSuspend.scheduledChangedAt ? new Date(data.autoSuspend.scheduledChangedAt) : void 0, | ||
scheduledSuspendAt: data.autoSuspend.scheduledSuspendAt ? new Date(data.autoSuspend.scheduledSuspendAt) : void 0, | ||
suspendTypeChangedAt: data.autoSuspend.suspendTypeChangedAt ? new Date(data.autoSuspend.suspendTypeChangedAt) : void 0 | ||
} : void 0, | ||
data.resumeAttachments?.map(({ attachment: type, ...attachment }) => ({ ...attachment, type })) | ||
); | ||
} | ||
database(name) { | ||
return new Database(this.connection, name, this.name, this._ai); | ||
async create(body) { | ||
const response = await this._execute("", { | ||
method: "POST", | ||
body: JSON.stringify({ ...body, workspaceGroupID: this._workspaceGroupID }) | ||
}); | ||
if (typeof response === "string") { | ||
throw new Error(response); | ||
} | ||
return this.get({ where: { id: response.workspaceID } }); | ||
} | ||
createDatabase(schema) { | ||
return Database.create(this.connection, schema, this.name, this._ai); | ||
async get({ where, select, includeTerminated } = {}) { | ||
let url = ""; | ||
const searchParams = new URLSearchParams({ | ||
workspaceGroupID: this._workspaceGroupID, | ||
includeTerminated: includeTerminated ? String(includeTerminated) : String(false) | ||
}); | ||
if (where) { | ||
if ("id" in where) { | ||
url = `${url}/${where.id}`; | ||
} | ||
} | ||
if (select?.length) { | ||
searchParams.set("fields", select.join(",")); | ||
} | ||
const response = await this._execute( | ||
`${url}?${searchParams.toString()}` | ||
); | ||
if (Array.isArray(response)) { | ||
return response.filter((data) => where && "name" in where ? data.name === where.name : true).map((data) => this._create(data)); | ||
} | ||
return this._create(response); | ||
} | ||
dropDatabase(name) { | ||
return Database.drop(this.connection, name); | ||
async update(...args) { | ||
return Workspace.update(this._api, ...args); | ||
} | ||
async showDatabasesInfo(extended) { | ||
const clauses = ["SHOW DATABASES"]; | ||
if (extended) clauses.push("EXTENDED"); | ||
const [rows] = await this.connection.client.query(clauses.join(" ")); | ||
return rows.map((row) => Database.normalizeInfo(row, extended)); | ||
async delete(...args) { | ||
return Workspace.delete(this._api, ...args); | ||
} | ||
async resume(...args) { | ||
return Workspace.resume(this._api, ...args); | ||
} | ||
async suspend(...args) { | ||
return Workspace.suspend(this._api, ...args); | ||
} | ||
async getState(...args) { | ||
return Workspace.getState(this._api, ...args); | ||
} | ||
}; | ||
// src/workspace-group/stage/index.ts | ||
var WorkspaceGroupStage = class _WorkspaceGroupStage extends APIManager { | ||
constructor(api, _workspaceGroupID, name, content, type, path, format, mimetype, size, writable, createdAt, modifiedAt) { | ||
super(api); | ||
this._workspaceGroupID = _workspaceGroupID; | ||
this.name = name; | ||
this.content = content; | ||
this.type = type; | ||
this.path = path; | ||
this.format = format; | ||
this.mimetype = mimetype; | ||
this.size = size; | ||
this.writable = writable; | ||
this.createdAt = createdAt; | ||
this.modifiedAt = modifiedAt; | ||
this._baseURL = _WorkspaceGroupStage.getBaseURL(this._workspaceGroupID, this.path); | ||
} | ||
_baseURL; | ||
static getBaseURL(workspaceGroupID, path) { | ||
return `/stage/${workspaceGroupID}/fs/${path}`; | ||
} | ||
static serializePath(path) { | ||
if (!path) return ""; | ||
return `/${encodeURIComponent(path.startsWith("/") ? path.substring(1) : path)}`; | ||
} | ||
static formatPath(id, path) { | ||
return this.getBaseURL(id, this.serializePath(path)); | ||
} | ||
static mergePaths(...paths) { | ||
return paths.filter(Boolean).join("").replaceAll("//", "/"); | ||
} | ||
static async get(api, id, path) { | ||
const response = await api.execute(this.formatPath(id, path)); | ||
if (!response.path) { | ||
throw new Error(`No stage found with the specified path: ${path}`); | ||
} | ||
return new _WorkspaceGroupStage( | ||
api, | ||
id, | ||
response.name, | ||
response.content, | ||
response.type, | ||
response.path, | ||
response.format, | ||
response.mimetype, | ||
response.size, | ||
response.writable, | ||
response.created ? new Date(response.created) : void 0, | ||
response.last_modified ? new Date(response.last_modified) : void 0 | ||
); | ||
} | ||
static async update(api, id, path, body) { | ||
const response = await api.execute(this.formatPath(id, path), { | ||
method: "PATCH", | ||
body: JSON.stringify({ | ||
...body, | ||
newPath: body.newPath || void 0 | ||
}) | ||
}); | ||
if (typeof response === "string") { | ||
throw new Error(response); | ||
} | ||
return response; | ||
} | ||
static async delete(api, id, path) { | ||
const response = await api.execute(this.formatPath(id, path), { | ||
method: "DELETE" | ||
}); | ||
if (typeof response === "string") { | ||
throw new Error(response); | ||
} | ||
return response; | ||
} | ||
static async createFolder(api, id, path, name) { | ||
const response = await api.execute( | ||
`${this.formatPath(id, path)}${encodeURIComponent(name)}/`, | ||
{ method: "PUT" } | ||
); | ||
if (typeof response === "string") { | ||
throw new Error(response); | ||
} | ||
return this.get(api, id, response.path); | ||
} | ||
// TODO: Complete this method | ||
static async uploadFile(api, id, path, file) { | ||
const formData = new FormData(); | ||
formData.append("file", file); | ||
const response = await api.execute(`${this.formatPath(id, path)}/${this.serializePath(file.name)}`, { | ||
method: "PUT", | ||
headers: { "Content-Type": "multipart/form-data" }, | ||
body: formData | ||
}); | ||
} | ||
async get(path) { | ||
const _path = _WorkspaceGroupStage.mergePaths(this.path, path); | ||
return _WorkspaceGroupStage.get(this._api, this._workspaceGroupID, _path); | ||
} | ||
async update(body, path) { | ||
const _path = _WorkspaceGroupStage.mergePaths(this.path, path); | ||
return _WorkspaceGroupStage.update(this._api, this._workspaceGroupID, _path, body); | ||
} | ||
async delete(path) { | ||
const _path = _WorkspaceGroupStage.mergePaths(this.path, path); | ||
return _WorkspaceGroupStage.delete(this._api, this._workspaceGroupID, _path); | ||
} | ||
async createFolder(name, path) { | ||
const _path = _WorkspaceGroupStage.mergePaths(this.path, path); | ||
return _WorkspaceGroupStage.createFolder(this._api, this._workspaceGroupID, _path, name); | ||
} | ||
async uploadFile(file, path) { | ||
const _path = _WorkspaceGroupStage.mergePaths(this.path, path); | ||
return _WorkspaceGroupStage.uploadFile(this._api, this._workspaceGroupID, _path, file); | ||
} | ||
}; | ||
// src/workspace-group/stage/manager.ts | ||
var WorkspaceGroupStageManager = class _WorkspaceGroupStageManager extends APIManager { | ||
constructor(api, _workspaceGroupID) { | ||
super(api); | ||
this._workspaceGroupID = _workspaceGroupID; | ||
this._baseURL = _WorkspaceGroupStageManager.getBaseURL(this._workspaceGroupID); | ||
} | ||
_baseURL; | ||
static getBaseURL(workspaceGroupID) { | ||
return `/stage/${workspaceGroupID}/fs`; | ||
} | ||
async get(...args) { | ||
return WorkspaceGroupStage.get(this._api, this._workspaceGroupID, ...args); | ||
} | ||
async update(...args) { | ||
return WorkspaceGroupStage.update(this._api, this._workspaceGroupID, ...args); | ||
} | ||
async delete(...args) { | ||
return WorkspaceGroupStage.delete(this._api, this._workspaceGroupID, ...args); | ||
} | ||
async createFolder(...args) { | ||
return WorkspaceGroupStage.createFolder(this._api, this._workspaceGroupID, ...args); | ||
} | ||
}; | ||
// src/workspace-group/storage/manager.ts | ||
var WorkspaceGroupStorageManager = class _WorkspaceGroupStorageManager extends APIManager { | ||
constructor(api, _workspaceGroupID) { | ||
super(api); | ||
this._workspaceGroupID = _workspaceGroupID; | ||
this._baseURL = _WorkspaceGroupStorageManager.getBaseURL(this._workspaceGroupID); | ||
} | ||
_baseURL; | ||
static getBaseURL(workspaceGroupID) { | ||
return `/workspaceGroups/${workspaceGroupID}/storage`; | ||
} | ||
async getStatus() { | ||
return this._execute("/DR/status"); | ||
} | ||
async getRegions() { | ||
const response = await this._execute("/DR/regions"); | ||
return response.map((data) => ({ id: data.regionID, name: data.region, provider: data.provider })); | ||
} | ||
}; | ||
// src/workspace-group/index.ts | ||
var updateWindowDaysMap = { | ||
0: "su", | ||
1: "mo", | ||
2: "tu", | ||
3: "we", | ||
4: "th", | ||
5: "fr", | ||
6: "sa" | ||
}; | ||
var WorkspaceGroup = class _WorkspaceGroup extends APIManager { | ||
constructor(api, _ai, _organization, id, name, regionID, state, smartDRStatus, allowAllTraffic, firewallRanges, updateWindow, createdAt, expiresAt, terminatedAt) { | ||
super(api); | ||
this._ai = _ai; | ||
this._organization = _organization; | ||
this.id = id; | ||
this.name = name; | ||
this.regionID = regionID; | ||
this.state = state; | ||
this.smartDRStatus = smartDRStatus; | ||
this.allowAllTraffic = allowAllTraffic; | ||
this.firewallRanges = firewallRanges; | ||
this.updateWindow = updateWindow; | ||
this.createdAt = createdAt; | ||
this.expiresAt = expiresAt; | ||
this.terminatedAt = terminatedAt; | ||
this._baseURL = _WorkspaceGroup.getBaseURL(this.id); | ||
this.stage = new WorkspaceGroupStageManager(this._api, this.id); | ||
this.storage = new WorkspaceGroupStorageManager(this._api, this.id); | ||
this.workspace = new WorkspaceManager(this._api, this._ai, this.id); | ||
} | ||
_baseURL; | ||
stage; | ||
storage; | ||
workspace; | ||
static getBaseURL(id) { | ||
return `/workspaceGroups/${id}`; | ||
} | ||
static serializeUpdateWindow(updateWindow) { | ||
const day = getKeyByValue(updateWindowDaysMap, updateWindow.day); | ||
if (!day) { | ||
throw new Error( | ||
`Day not found with the given name. Please provide a valid day from the following list: ${Object.values(updateWindowDaysMap).join(", ")}.` | ||
); | ||
} | ||
return { ...updateWindow, day: Number(day) }; | ||
} | ||
static async update(api, id, body) { | ||
const expiresAt = body.expiresAt ? body.expiresAt.toISOString().split(".")[0] + "Z" : void 0; | ||
const updateWindow = body.updateWindow ? _WorkspaceGroup.serializeUpdateWindow(body.updateWindow) : void 0; | ||
const response = await api.execute(this.getBaseURL(id), { | ||
method: "PATCH", | ||
body: JSON.stringify({ ...body, expiresAt, updateWindow }) | ||
}); | ||
return response.workspaceGroupID; | ||
} | ||
static async delete(api, id, force) { | ||
const params = new URLSearchParams({ force: force ? String(force) : String(false) }); | ||
const response = await api.execute( | ||
`${this.getBaseURL(id)}?${params.toString()}`, | ||
{ method: "DELETE" } | ||
); | ||
return response.workspaceGroupID; | ||
} | ||
async update(...args) { | ||
return _WorkspaceGroup.update(this._api, this.id, ...args); | ||
} | ||
async delete(...args) { | ||
return _WorkspaceGroup.delete(this._api, this.id, ...args); | ||
} | ||
async getPrivateConnections() { | ||
const response = await this._execute(`/privateConnections`); | ||
return response.map((data) => ({ | ||
...data, | ||
createdAt: new Date(data.createdAt), | ||
deletedAt: new Date(data.deletedAt), | ||
updatedAt: new Date(data.updatedAt), | ||
activeAt: new Date(data.activeAt) | ||
})); | ||
} | ||
async getMetrics() { | ||
const org = await this._organization.get(); | ||
return this._api.execute(`/organizations/${org.id}${_WorkspaceGroup.getBaseURL(this.id)}/metrics`, { | ||
version: 2 | ||
}); | ||
} | ||
}; | ||
// src/workspace-group/manager.ts | ||
var WorkspaceGroupManager = class extends APIManager { | ||
constructor(_api, _ai, _organization, _region) { | ||
super(_api); | ||
this._ai = _ai; | ||
this._organization = _organization; | ||
this._region = _region; | ||
} | ||
_baseURL = "/workspaceGroups"; | ||
_create(data) { | ||
return new WorkspaceGroup( | ||
this._api, | ||
this._ai, | ||
this._organization, | ||
data.workspaceGroupID, | ||
data.name, | ||
data.regionID, | ||
data.state, | ||
data.smartDRStatus, | ||
data.allowAllTraffic, | ||
data.firewallRanges, | ||
data.updateWindow ? { ...data.updateWindow, day: updateWindowDaysMap[data.updateWindow.day] } : void 0, | ||
new Date(data.createdAt), | ||
data.expiresAt ? new Date(data.expiresAt) : void 0, | ||
data.terminatedAt ? new Date(data.terminatedAt) : void 0 | ||
); | ||
} | ||
async create({ regionName, firewallRanges = [], ...body }) { | ||
const region = await this._region.get({ name: regionName }); | ||
if (!region) { | ||
throw new Error("Region not found with the given name. Please provide a valid region name."); | ||
} | ||
const updateWindow = body.updateWindow ? WorkspaceGroup.serializeUpdateWindow(body.updateWindow) : void 0; | ||
const response = await this._execute("", { | ||
method: "POST", | ||
body: JSON.stringify({ ...body, firewallRanges, updateWindow, regionID: region.id }) | ||
}); | ||
const newWorkspaceGroup = await this._execute(`/${response.workspaceGroupID}`); | ||
return { | ||
workspaceGroup: this._create(newWorkspaceGroup), | ||
adminPassword: body.adminPassword || response.adminPassword | ||
}; | ||
} | ||
async get({ where, select, includeTerminated } = {}) { | ||
let url = ""; | ||
const searchParams = new URLSearchParams({ | ||
includeTerminated: includeTerminated ? String(includeTerminated) : String(false) | ||
}); | ||
if (where) { | ||
if ("id" in where) { | ||
url = `${url}/${where.id}`; | ||
} | ||
} | ||
if (select?.length) { | ||
searchParams.set("fields", select.join(",")); | ||
} | ||
const response = await this._execute( | ||
`${url}?${searchParams.toString()}` | ||
); | ||
if (Array.isArray(response)) { | ||
return response.filter((data) => where && "name" in where ? data.name === where.name : true).map((data) => this._create(data)); | ||
} | ||
return this._create(response); | ||
} | ||
async update(...args) { | ||
return WorkspaceGroup.update(this._api, ...args); | ||
} | ||
async delete(...args) { | ||
return WorkspaceGroup.delete(this._api, ...args); | ||
} | ||
}; | ||
// src/index.ts | ||
@@ -537,7 +1563,23 @@ var import_mysql22 = require("mysql2"); | ||
_ai; | ||
_api; | ||
billing; | ||
job; | ||
organization; | ||
region; | ||
secret; | ||
team; | ||
workspaceGroup; | ||
constructor(config) { | ||
this._ai = config?.ai; | ||
this._api = new API(config?.apiKey); | ||
this.billing = new BillingManager(this._api); | ||
this.job = new JobManager(this._api); | ||
this.organization = new OrganizationManager(this._api); | ||
this.region = new RegionManager(this._api); | ||
this.secret = new SecretManager(this._api); | ||
this.team = new TeamManager(this._api); | ||
this.workspaceGroup = new WorkspaceGroupManager(this._api, this._ai, this.organization, this.region); | ||
} | ||
workspace(config) { | ||
return Workspace.connect({ ...config, ai: this._ai }); | ||
connect(config) { | ||
return WorkspaceConnection.create({ ...config, ai: this._ai }); | ||
} | ||
@@ -544,0 +1586,0 @@ }; |
{ | ||
"name": "@singlestore/client", | ||
"version": "0.0.35", | ||
"version": "0.0.36", | ||
"license": "Apache-2.0", | ||
@@ -33,2 +33,3 @@ "sideEffects": false, | ||
"@repo/typescript-config": "*", | ||
"@repo/utils": "*", | ||
"@types/node": "^22.2.0", | ||
@@ -35,0 +36,0 @@ "tsup": "^8.1.0", |
@@ -48,3 +48,3 @@ # SingleStore Client | ||
```ts | ||
const workspace = client.workspace({ | ||
const connection = client.connect({ | ||
host: "<DATABASE_HOST>", | ||
@@ -61,3 +61,3 @@ user: "<DATABASE_USER>", | ||
```ts | ||
const database = await workspace.createDatabase({ name: "my_database" }); | ||
const database = await connection.database.create({ name: "my_database" }); | ||
``` | ||
@@ -70,3 +70,3 @@ | ||
```ts | ||
const database = await workspace.database("my_database"); | ||
const database = await connection.database.use("my_database"); | ||
``` | ||
@@ -79,3 +79,3 @@ | ||
```ts | ||
const usersTable = await database.createTable({ | ||
const usersTable = await database.table.create({ | ||
name: "users", | ||
@@ -173,18 +173,12 @@ columns: { | ||
products: { | ||
name: "products"; | ||
columns: { | ||
id: number; | ||
name: string; | ||
description: string; | ||
price: number; | ||
category_id: number; | ||
description_v: string; | ||
}; | ||
id: number; | ||
name: string; | ||
description: string; | ||
price: number; | ||
category_id: number; | ||
description_v: string; | ||
}; | ||
categories: { | ||
name: "categories"; | ||
columns: { | ||
id: number; | ||
name: string; | ||
}; | ||
id: number; | ||
name: string; | ||
}; | ||
@@ -196,5 +190,3 @@ }; | ||
const workspace = client.workspace<{ | ||
databases: { store_database: StoreDatabase }; | ||
}>({ | ||
const connection = client.connect({ | ||
host: "<DATABASE_HOST>", | ||
@@ -205,5 +197,5 @@ user: "<DATABASE_USER>", | ||
const database = workspace.database("store_database"); | ||
const database = connection.database.use<StoreDatabase>("store_database"); | ||
const products = await database.table("products").find({ | ||
const products = await database.table.use("products").find({ | ||
select: ["id", "name", "description", "price", "category.name"], | ||
@@ -210,0 +202,0 @@ join: [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
509209
4084
6
212
3