@singlestore/client
Advanced tools
Comparing version 0.0.25 to 0.0.26
import * as _singlestore_ai from '@singlestore/ai'; | ||
import { AI } from '@singlestore/ai'; | ||
import { AnyAI } from '@singlestore/ai'; | ||
import * as mysql2_promise from 'mysql2/promise'; | ||
@@ -121,3 +121,3 @@ import { PoolOptions, Pool, ResultSetHeader, RowDataPacket } from 'mysql2/promise'; | ||
} | ||
interface TableSchema<T extends TableType = TableType> { | ||
interface TableSchema<T extends TableType> { | ||
name: string; | ||
@@ -131,6 +131,6 @@ columns: { | ||
} | ||
interface TableInfo<T extends string = string> { | ||
interface TableInfo<T extends string> { | ||
name: T; | ||
} | ||
interface TableInfoExtended<T extends string = string> extends TableInfo<T> { | ||
interface TableInfoExtended<T extends string> extends TableInfo<T> { | ||
tableType: string; | ||
@@ -140,6 +140,6 @@ distributed: boolean; | ||
} | ||
type ColumnName<T extends TableType = TableType> = Extract<keyof T["columns"], string>; | ||
type TableColumnName<T extends TableType> = Extract<keyof T["columns"], string>; | ||
type VectorScoreKey = "v_score"; | ||
type ExtractAICreateChatCompletionsOptions<U extends AI | undefined> = U extends AI ? Parameters<U["chatCompletions"]["create"]>[1] : never; | ||
declare class Table<T extends TableType = TableType, U extends AI | undefined = undefined> { | ||
type ExtractAICreateChatCompletionsOptions<U extends AnyAI | undefined> = U extends AnyAI ? Parameters<U["chatCompletions"]["create"]>[1] : never; | ||
declare class Table<T extends TableType = TableType, U extends AnyAI | undefined = undefined> { | ||
private _connection; | ||
@@ -153,12 +153,12 @@ databaseName: string; | ||
private get ai(); | ||
static normalizeInfo<T extends string = string, U extends boolean = boolean>(info: any, extended?: U): U extends true ? TableInfoExtended<T> : TableInfo<T>; | ||
static normalizeInfo<T extends string, U extends boolean>(info: any, extended?: U): U extends true ? TableInfoExtended<T> : TableInfo<T>; | ||
static schemaToClauses(schema: TableSchema<any>): string; | ||
static create<T extends TableType = TableType, U extends AI | undefined = undefined>(connection: Connection, databaseName: string, schema: TableSchema<T>, ai?: U): Promise<Table<T, U>>; | ||
static create<T extends TableType = TableType, U extends AnyAI | undefined = undefined>(connection: Connection, databaseName: string, schema: TableSchema<T>, ai?: U): Promise<Table<T, U>>; | ||
static drop(connection: Connection, databaseName: string, name: string): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
showInfo<T extends boolean>(extended?: T): Promise<T extends true ? TableInfoExtended<string> : TableInfo<string>>; | ||
drop(): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
column(name: ColumnName<T> | (string & {})): Column; | ||
column(name: TableColumnName<T> | (string & {})): Column; | ||
showColumnsInfo(): Promise<ColumnInfo<Extract<keyof T["columns"], string>>[]>; | ||
addColumn(schema: ColumnSchema): Promise<Column>; | ||
dropColumn(name: ColumnName<T> | (string & {})): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
dropColumn(name: TableColumnName<T> | (string & {})): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
truncate(): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
@@ -172,23 +172,20 @@ rename(newName: string): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
prompt: string; | ||
vectorColumn: ColumnName<T>; | ||
vectorColumn: TableColumnName<T>; | ||
}, ...QueryBuilderArgs<T["columns"]>]>(...args: A): Promise<(ExtractQueryColumns<T["columns"], ExtractQueryOptions<A extends [any, ...infer _A] ? _A extends QueryBuilderArgs<T["columns"]> ? _A : never : never>> & { | ||
v_score: number; | ||
} & RowDataPacket)[]>; | ||
createChatCompletion<K extends ExtractAICreateChatCompletionsOptions<U>>(...args: [search: { | ||
prompt: string; | ||
vectorColumn: ColumnName<T>; | ||
template?: string; | ||
} & K, ...QueryBuilderArgs<T["columns"]>]): Promise<_singlestore_ai.CreateChatCompletionResult<Omit<{ | ||
prompt: string; | ||
vectorColumn: ColumnName<T>; | ||
template?: string; | ||
} & K, "systemRole" | "prompt" | "vectorColumn" | "template"> & { | ||
systemRole: string; | ||
}>>; | ||
createChatCompletion<K extends ExtractAICreateChatCompletionsOptions<U>>(...args: [ | ||
search: { | ||
prompt: string; | ||
vectorColumn: TableColumnName<T>; | ||
template?: string; | ||
} & K, | ||
...QueryBuilderArgs<T["columns"]> | ||
]): Promise<_singlestore_ai.ChatCompletionStream | _singlestore_ai.ChatCompletion>; | ||
} | ||
interface DatabaseType { | ||
tables: Record<string, TableType>; | ||
interface DatabaseType<T extends Record<string, TableType> = Record<string, TableType>> { | ||
tables: T; | ||
} | ||
interface DatabaseSchema<T extends DatabaseType = DatabaseType> { | ||
interface DatabaseSchema<T extends DatabaseType> { | ||
name: string; | ||
@@ -202,3 +199,3 @@ tables?: { | ||
} | ||
interface DatabaseInfoExtended<T extends string = string> extends DatabaseInfo<T> { | ||
interface DatabaseInfoExtended<T extends string> extends DatabaseInfo<T> { | ||
commits: number; | ||
@@ -224,4 +221,5 @@ role: string; | ||
}; | ||
type TableName<T extends DatabaseType = DatabaseType> = Extract<keyof T["tables"], string>; | ||
declare class Database<T extends DatabaseType = DatabaseType, U extends AI | undefined = undefined> { | ||
type AnyDatabase = Database<DatabaseType<any>, AnyAI | undefined>; | ||
type DatabaseTableName<T extends DatabaseType> = Extract<keyof T["tables"], string>; | ||
declare class Database<T extends DatabaseType = DatabaseType, U extends AnyAI | undefined = undefined> { | ||
private _connection; | ||
@@ -232,4 +230,4 @@ name: string; | ||
constructor(_connection: Connection, name: string, workspaceName?: string | undefined, _ai?: U | undefined); | ||
static normalizeInfo<T extends string = string, U extends boolean = boolean>(info: any, extended?: U): U extends true ? DatabaseInfoExtended<T> : DatabaseInfo<T>; | ||
static create<T extends DatabaseType = DatabaseType, U extends AI | undefined = undefined>(connection: Connection, schema: DatabaseSchema<T>, workspaceName?: string, ai?: U): Promise<Database<T, U>>; | ||
static normalizeInfo<T extends string, U extends boolean>(info: any, extended?: U): U extends true ? DatabaseInfoExtended<T> : DatabaseInfo<T>; | ||
static create<T extends DatabaseType = DatabaseType, U extends AnyAI | undefined = undefined>(connection: Connection, schema: DatabaseSchema<T>, workspaceName?: string, ai?: U): Promise<Database<T, U>>; | ||
static drop(connection: Connection, name: string): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
@@ -264,6 +262,6 @@ showInfo<T extends boolean>(extended?: T): Promise<T extends true ? DatabaseInfoExtended<string> : DatabaseInfo<string>>; | ||
drop(): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
table<N, K extends TableName<T> | (string & {}) = TableName<T> | (string & {})>(name: K): Table<N extends TableType ? N : T["tables"][K] extends TableType ? T["tables"][K] : TableType, U>; | ||
table<N, K extends DatabaseTableName<T> | (string & {}) = DatabaseTableName<T> | (string & {})>(name: K): Table<N extends TableType ? N : T["tables"][K] extends TableType ? T["tables"][K] : TableType, U>; | ||
showTablesInfo<U extends boolean>(extended?: U): Promise<(U extends true ? TableInfoExtended<Extract<keyof T["tables"], string>> : TableInfo<Extract<keyof T["tables"], string>>)[]>; | ||
createTable<T extends TableType = TableType>(schema: TableSchema<T>): Promise<Table<T, U>>; | ||
dropTable(name: TableName<T> | (string & {})): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
dropTable(name: DatabaseTableName<T> | (string & {})): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>; | ||
query<T extends any[]>(statement: string): Promise<T>; | ||
@@ -275,3 +273,3 @@ } | ||
} | ||
interface WorkspaceSchema<T extends WorkspaceType = WorkspaceType> { | ||
interface WorkspaceSchema<T extends WorkspaceType> { | ||
name: string; | ||
@@ -282,8 +280,8 @@ databases: { | ||
} | ||
interface ConnectWorkspaceConfig<T extends WorkspaceType = WorkspaceType, U extends AI | undefined = undefined> extends ConnectionConfig { | ||
interface ConnectWorkspaceConfig<T extends WorkspaceType, U extends AnyAI | undefined> extends ConnectionConfig { | ||
name?: WorkspaceSchema<T>["name"]; | ||
ai?: U; | ||
} | ||
type DatabaseName<T extends WorkspaceType = WorkspaceType> = Extract<keyof T["databases"], string>; | ||
declare class Workspace<T extends WorkspaceType = WorkspaceType, U extends AI | undefined = undefined> { | ||
type WorkspaceDatabaseName<T extends WorkspaceType> = Extract<keyof T["databases"], string>; | ||
declare class Workspace<T extends WorkspaceType = WorkspaceType, U extends AnyAI | undefined = undefined> { | ||
connection: Connection; | ||
@@ -293,20 +291,20 @@ name?: string | undefined; | ||
constructor(connection: Connection, name?: string | undefined, _ai?: U | undefined); | ||
static connect<T extends WorkspaceType = WorkspaceType, U extends AI | undefined = undefined>({ ai, name, ...config }: ConnectWorkspaceConfig<T, U>): Workspace<T, U>; | ||
database<N, K extends DatabaseName<T> | (string & {}) = DatabaseName<T> | (string & {})>(name: K): Database<N extends DatabaseType ? N : T["databases"][K] extends DatabaseType ? T["databases"][K] : DatabaseType, U>; | ||
static connect<T extends WorkspaceType = WorkspaceType, U extends AnyAI | undefined = undefined>({ ai, name, ...config }: ConnectWorkspaceConfig<T, U>): Workspace<T, U>; | ||
database<N, K extends WorkspaceDatabaseName<T> | (string & {}) = WorkspaceDatabaseName<T> | (string & {})>(name: K): Database<N extends DatabaseType<Record<string, TableType>> ? N : T["databases"][K] extends DatabaseType<Record<string, TableType>> ? T["databases"][K] : DatabaseType<Record<string, TableType>>, U>; | ||
createDatabase<T extends DatabaseType = DatabaseType>(schema: DatabaseSchema<T>): Promise<Database<T, U>>; | ||
dropDatabase(name: DatabaseName<T> | (string & {})): Promise<[mysql2.ResultSetHeader, mysql2.FieldPacket[]]>; | ||
dropDatabase(name: WorkspaceDatabaseName<T> | (string & {})): Promise<[mysql2.ResultSetHeader, mysql2.FieldPacket[]]>; | ||
showDatabasesInfo<U extends boolean>(extended?: U): Promise<(U extends true ? DatabaseInfoExtended<Extract<keyof T["databases"], string>> : DatabaseInfo<Extract<keyof T["databases"], string>>)[]>; | ||
} | ||
interface SingleStoreClientConfig { | ||
ai?: AI; | ||
interface SingleStoreClientConfig<T extends AnyAI | undefined> { | ||
ai?: T; | ||
} | ||
interface WorkspaceConfig<T extends WorkspaceType = WorkspaceType, U extends AI | undefined = undefined> extends Omit<ConnectWorkspaceConfig<T, U>, "ai"> { | ||
interface WorkspaceConfig<T extends WorkspaceType, U extends AnyAI | undefined> extends Omit<ConnectWorkspaceConfig<T, U>, "ai"> { | ||
} | ||
declare class SingleStoreClient<T extends SingleStoreClientConfig = SingleStoreClientConfig> { | ||
_ai: T["ai"] extends AI ? T["ai"] : undefined; | ||
constructor(config?: T); | ||
workspace<U extends WorkspaceType = WorkspaceType>(config: WorkspaceConfig<U, T["ai"]>): Workspace<U, T["ai"]>; | ||
declare class SingleStoreClient<T extends AnyAI | undefined = undefined> { | ||
private _ai; | ||
constructor(config?: SingleStoreClientConfig<T>); | ||
workspace<U extends WorkspaceType = WorkspaceType>(config: WorkspaceConfig<U, T>): Workspace<U, T>; | ||
} | ||
export { Column, type ColumnInfo, type ColumnSchema, type ColumnType, type ConnectWorkspaceConfig, Connection, type ConnectionConfig, Database, type DatabaseInfo, type DatabaseInfoExtended, type DatabaseSchema, type DatabaseTablesToRecords, type DatabaseType, QueryBuilder, type QueryBuilderArgs, type QueryFilters, QueryFiltersBuilder, type QueryOptions, QueryOptionsBuilder, type QuerySchema, SingleStoreClient, type SingleStoreClientConfig, Table, type TableInfo, type TableInfoExtended, type TableSchema, type TableType, Workspace, type WorkspaceConfig, type WorkspaceSchema, type WorkspaceType, queryOptionKeys }; | ||
export { type AnyDatabase, 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, QueryBuilder, type QueryBuilderArgs, type QueryFilters, QueryFiltersBuilder, type QueryOptions, QueryOptionsBuilder, type QuerySchema, SingleStoreClient, type SingleStoreClientConfig, Table, type TableColumnName, type TableInfo, type TableInfoExtended, type TableSchema, type TableType, Workspace, type WorkspaceConfig, type WorkspaceDatabaseName, type WorkspaceSchema, type WorkspaceType, queryOptionKeys }; |
@@ -262,3 +262,3 @@ "use strict"; | ||
if (!this._ai) { | ||
throw new Error("AI instance is undefined. Ensure ai is properly initialized before accessing."); | ||
throw new Error("AnyAI instance is undefined. Ensure ai is properly initialized before accessing."); | ||
} | ||
@@ -342,2 +342,3 @@ return this._ai; | ||
} | ||
// TODO: Add joins support | ||
async select(...args) { | ||
@@ -344,0 +345,0 @@ const { columns, clause, values } = new QueryBuilder(...args); |
{ | ||
"name": "@singlestore/client", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
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
149645
1284