feat(dolt): add database-aware version control workspace
This commit is contained in:
1 parent
3e6e43c57c
commit
cf1476a6dc
29 files changed
+5411
-6
No files matched your search
@@ -122,6 +122,16 @@ export function isDoltDriverProfile(driverProfile?: string): boolean {
|
||||
return driverProfile?.toLowerCase() === DOLT_DRIVER_PROFILE;
|
||||
}
|
||||
|
||||
export function doltWorkspaceTarget(database: string, source: "connection" | "database") {
|
||||
const separator = database.indexOf("/");
|
||||
if (separator <= 0) return { database };
|
||||
const baseDatabase = database.slice(0, separator);
|
||||
const branch = database.slice(separator + 1);
|
||||
// Connection-level navigation uses the database's default branch. A tree
|
||||
// database entry may explicitly address a Dolt db/branch revision database.
|
||||
return source === "database" && branch ? { database: baseDatabase, branch } : { database: baseDatabase };
|
||||
}
|
||||
|
||||
type DoltConnectionConfig = Pick<ConnectionConfig, "driver_profile"> & Partial<Pick<ConnectionConfig, "external_config">>;
|
||||
|
||||
function externalConfigRecord(value: unknown): Record<string, unknown> {
|
||||
@@ -174,6 +184,14 @@ export function doltSqlRoutineSignatures(driverProfile?: string): Map<string, st
|
||||
|
||||
export const DOLT_DRIVER_PROFILE_EXTENSION: DriverProfileExtensionDefinition = {
|
||||
id: DOLT_DRIVER_PROFILE,
|
||||
databaseWorkspace: {
|
||||
mode: "dolt-version-control",
|
||||
menuLabelKey: "doltVersionControl.open",
|
||||
tabTitleKey: "doltVersionControl.title",
|
||||
tabScope: "connection",
|
||||
entryScopes: ["connection", "database"],
|
||||
resolveTarget: doltWorkspaceTarget,
|
||||
},
|
||||
objectTreeProfile: doltObjectTreeProfileForConnection,
|
||||
completionTableMetadata: (tableName) =>
|
||||
tableName.toLowerCase().startsWith("dolt")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DOLT_DRIVER_PROFILE_EXTENSION } from "@/lib/database/doltProfile";
|
||||
import type { SqlCompletionObject, SqlCompletionTable, SqlStatementKind } from "@/lib/sql/sqlCompletion";
|
||||
import type { ConnectionConfig, TableNameFilter, TreeNodeType } from "@/types/database";
|
||||
import type { ConnectionConfig, QueryTab, TableNameFilter, TreeNodeType } from "@/types/database";
|
||||
|
||||
export type DriverProfileObjectTreeProfile = {
|
||||
cacheKey: string;
|
||||
@@ -22,6 +22,25 @@ export type DriverProfileSqlCompletionContext = {
|
||||
|
||||
export type DriverProfileCompletionTableMetadata = Pick<SqlCompletionTable, "detail" | "boost">;
|
||||
|
||||
export type DriverProfileWorkspaceTarget = {
|
||||
database: string;
|
||||
branch?: string;
|
||||
};
|
||||
|
||||
export type DriverProfileWorkspaceScope = "database" | "connection";
|
||||
|
||||
export type DriverProfileDatabaseWorkspace = {
|
||||
mode: QueryTab["mode"];
|
||||
menuLabelKey: string;
|
||||
tabTitleKey: string;
|
||||
/** Determines whether tabs are reused per connection or per database. */
|
||||
tabScope: DriverProfileWorkspaceScope;
|
||||
/** Tree levels whose context menu exposes the workspace entry. */
|
||||
entryScopes: readonly DriverProfileWorkspaceScope[];
|
||||
/** Maps a tree database name to the context opened by the workspace. */
|
||||
resolveTarget?: (database: string, source: DriverProfileWorkspaceScope) => DriverProfileWorkspaceTarget;
|
||||
};
|
||||
|
||||
export type DriverProfileExtensionDefinition = {
|
||||
id: string;
|
||||
objectTreeProfile?: (config: ConnectionConfig) => DriverProfileObjectTreeProfile | undefined;
|
||||
@@ -30,6 +49,7 @@ export type DriverProfileExtensionDefinition = {
|
||||
completionTables?: (context: DriverProfileSqlCompletionContext) => SqlCompletionTable[];
|
||||
sqlBuiltinTerms?: () => string;
|
||||
routineSignatures?: () => Map<string, string[]>;
|
||||
databaseWorkspace?: DriverProfileDatabaseWorkspace;
|
||||
};
|
||||
|
||||
export const DRIVER_PROFILE_EXTENSIONS = [DOLT_DRIVER_PROFILE_EXTENSION] as const satisfies readonly DriverProfileExtensionDefinition[];
|
||||
@@ -69,3 +89,7 @@ export function driverProfileSqlBuiltinTerms(driverProfile?: string): string {
|
||||
export function driverProfileRoutineSignatures(driverProfile?: string): Map<string, string[]> {
|
||||
return driverProfileExtension(driverProfile)?.routineSignatures?.() ?? new Map();
|
||||
}
|
||||
|
||||
export function driverProfileDatabaseWorkspace(driverProfile?: string): DriverProfileDatabaseWorkspace | undefined {
|
||||
return driverProfileExtension(driverProfile)?.databaseWorkspace;
|
||||
}
|
||||
Reference in new issue
Block a user