Skip to content

Commit 8f38f32

Browse files
authored
feat: provide getLibraries and getColumns API for Rest (#1450)
1 parent 470e22f commit 8f38f32

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

client/src/components/APIProvider.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import { authentication } from "vscode";
4+
5+
import { profileConfig } from "../commands/profile";
6+
import { SASAuthProvider } from "./AuthProvider";
7+
import { ConnectionType } from "./profile";
8+
9+
/* only Rest APIs for now */
10+
11+
const apis = {};
12+
13+
export const registerAPI = (name: string, fn) => {
14+
apis[name] = fn;
15+
};
16+
17+
export const getRestAPIs = async (accessToken: string) => {
18+
const activeProfile = profileConfig.getProfileByName(
19+
profileConfig.getActiveProfile(),
20+
);
21+
if (!activeProfile || activeProfile.connectionType !== ConnectionType.Rest) {
22+
return;
23+
}
24+
const session = await authentication.getSession(SASAuthProvider.id, [], {
25+
silent: true,
26+
});
27+
if (session.accessToken !== accessToken) {
28+
return;
29+
}
30+
31+
return apis;
32+
};

client/src/components/LibraryNavigator/LibraryDataProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424

2525
import { Writable } from "stream";
2626

27+
import { registerAPI } from "../APIProvider";
2728
import { SubscriptionProvider } from "../SubscriptionProvider";
2829
import LibraryModel from "./LibraryModel";
2930
import { Icons, Messages, WorkLibraryId } from "./const";
@@ -62,6 +63,9 @@ class LibraryDataProvider
6263
this.selector(),
6364
this,
6465
);
66+
registerAPI("getColumns", model.fetchColumns.bind(model));
67+
registerAPI("getTables", model.getTables.bind(model));
68+
registerAPI("getLibraries", model.getLibraries.bind(model));
6569
}
6670

6771
public getSubscriptions(): Disposable[] {

client/src/components/LibraryNavigator/LibraryModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class LibraryModel {
137137
return await this.getTables(item);
138138
}
139139

140-
private async getLibraries(): Promise<LibraryItem[]> {
140+
public async getLibraries(): Promise<LibraryItem[]> {
141141
await this.libraryAdapter.setup();
142142

143143
let offset = 0;
@@ -159,7 +159,7 @@ class LibraryModel {
159159
return this.processItems(items, "library", undefined);
160160
}
161161

162-
private async getTables(item: LibraryItem): Promise<LibraryItem[]> {
162+
public async getTables(item: LibraryItem): Promise<LibraryItem[]> {
163163
await this.libraryAdapter.setup();
164164

165165
let offset = 0;

client/src/node/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
updateProfile,
3333
} from "../commands/profile";
3434
import { run, runRegion, runSelected } from "../commands/run";
35+
import { getRestAPIs } from "../components/APIProvider";
3536
import { SASAuthProvider } from "../components/AuthProvider";
3637
import { installCAs } from "../components/CAHelper";
3738
import ContentNavigator from "../components/ContentNavigator";
@@ -61,7 +62,7 @@ let client: LanguageClient;
6162

6263
export let extensionContext: ExtensionContext | undefined;
6364

64-
export function activate(context: ExtensionContext): void {
65+
export function activate(context: ExtensionContext) {
6566
// The server is implemented in node
6667
extensionContext = context;
6768
const serverModule = context.asAbsolutePath(
@@ -212,6 +213,10 @@ export function activate(context: ExtensionContext): void {
212213
profileConfig.migrateLegacyProfiles();
213214
triggerProfileUpdate();
214215
updateViewSettings();
216+
217+
return {
218+
getRestAPIs,
219+
};
215220
}
216221

217222
function updateViewSettings(): void {

0 commit comments

Comments
 (0)