Refresh tree after adding or removing project (#7)

* refresh tree after adding or removing project

* Always check if client is defined

* fix lint errors

* remove extra nodejs versions from pipeline
This commit is contained in:
Alex Weininger 2021-04-30 02:53:24 -07:00 committed by GitHub
parent 070d0b1a58
commit 354b635701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 171 additions and 132 deletions

View file

@ -8,13 +8,35 @@
"plugins": [ "plugins": [
"@typescript-eslint" "@typescript-eslint"
], ],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": { "rules": {
"@typescript-eslint/naming-convention": "off", "@typescript-eslint/naming-convention": "off",
"@typescript-eslint/semi": "warn", "@typescript-eslint/semi": "warn",
"curly": "warn", "curly": "warn",
"eqeqeq": "warn", "eqeqeq": "warn",
"no-throw-literal": "warn", "no-throw-literal": "warn",
"semi": "off" "semi": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"no-unused-vars": "off",
"no-useless-escape": "off",
"no-inner-declarations": "off",
"no-case-declarations": "off",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off"
}, },
"ignorePatterns": [ "ignorePatterns": [
"**/*.d.ts" "**/*.d.ts"

View file

@ -16,7 +16,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [10.x, 12.x, 14.x, 15.x] node-version: [12.x, 14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps: steps:

View file

@ -1,14 +1,12 @@
import { Client, Collection, CreatedCollection, CreatedRule, DatabaseClient, Rule, SDK } from "../appwrite"; import { Client, Collection, CreatedCollection, CreatedRule, DatabaseClient, Rule } from "../appwrite";
import { CreateRuleWizardContext } from "../ui/createRuleWizard"; import { AppwriteSDK } from '../constants';
import AppwriteCall from "../utils/AppwriteCall"; import AppwriteCall from "../utils/AppwriteCall";
const sdk: SDK = require("node-appwrite");
export class Database { export class Database {
private readonly database: DatabaseClient; private readonly database: DatabaseClient;
constructor(client: Client) { constructor(client: Client) {
this.database = new sdk.Database(client); this.database = new AppwriteSDK.Database(client);
} }
public async getCollection(collectionId: string): Promise<Collection | undefined> { public async getCollection(collectionId: string): Promise<Collection | undefined> {

View file

@ -1,12 +1,11 @@
import { MarkdownString } from 'vscode'; import { MarkdownString } from 'vscode';
import { AppwriteHealth, Client, HealthClient, SDK } from "../appwrite"; import { AppwriteHealth, Client, HealthClient } from "../appwrite";
const sdk: SDK = require("node-appwrite"); import { AppwriteSDK } from '../constants';
export class Health { export class Health {
private readonly health: HealthClient; private readonly health: HealthClient;
constructor(client: Client) { constructor(client: Client) {
this.health = new sdk.Health(client); this.health = new AppwriteSDK.Health(client);
} }
/** /**

View file

@ -1,14 +1,12 @@
import { Client, Collection, CreatedCollection, CreatedRule, DatabaseClient, File, FilesList, Rule, SDK, StorageClient } from "../appwrite"; import { Client, FilesList, StorageClient } from "../appwrite";
import { CreateRuleWizardContext } from "../ui/createRuleWizard"; import { AppwriteSDK } from '../constants';
import AppwriteCall from "../utils/AppwriteCall"; import AppwriteCall from "../utils/AppwriteCall";
const sdk: SDK = require("node-appwrite");
export class Storage { export class Storage {
private readonly storage: StorageClient; private readonly storage: StorageClient;
constructor(client: Client) { constructor(client: Client) {
this.storage = new sdk.Storage(client); this.storage = new AppwriteSDK.Storage(client);
} }
public async listFiles(): Promise<FilesList | undefined> { public async listFiles(): Promise<FilesList | undefined> {

View file

@ -1,14 +1,13 @@
import { window } from "vscode"; import { window } from "vscode";
import { Client, Log, SDK, User, UsersClient } from "../appwrite"; import { Client, Log, User, UsersClient } from "../appwrite";
import { ext } from "../extensionVariables"; import { AppwriteSDK } from "../constants";
import AppwriteCall from "../utils/AppwriteCall"; import AppwriteCall from "../utils/AppwriteCall";
const sdk: SDK = require("node-appwrite");
export class Users { export class Users {
private readonly users: UsersClient; private readonly users: UsersClient;
constructor(client: Client) { constructor(client: Client) {
this.users = new sdk.Users(client); this.users = new AppwriteSDK.Users(client);
} }
public async createNewUser(context: CreateUserContext): Promise<void> { public async createNewUser(context: CreateUserContext): Promise<void> {
await AppwriteCall<User, void>(this.users.create(context.email, context.password, context.name), (user) => { await AppwriteCall<User, void>(this.users.create(context.email, context.password, context.name), (user) => {
@ -23,7 +22,7 @@ export class Users {
} }
public async getLogs(userId: string): Promise<Log[]> { public async getLogs(userId: string): Promise<Log[]> {
return await AppwriteCall<Log[], Log[]>(this.users.getLogs(userId)) ?? []; return (await AppwriteCall<Log[], Log[]>(this.users.getLogs(userId))) ?? [];
} }
} }

View file

@ -1,21 +1,20 @@
import { Client, SDK } from "./appwrite"; import { Client } from "./appwrite";
import { Database } from "./appwrite/Database"; import { Database } from "./appwrite/Database";
import { Health } from "./appwrite/Health"; import { Health } from "./appwrite/Health";
import { Storage } from "./appwrite/Storage"; import { Storage } from "./appwrite/Storage";
import { Users } from "./appwrite/Users"; import { Users } from "./appwrite/Users";
import { AppwriteSDK } from "./constants";
import { AppwriteProjectConfiguration } from "./settings"; import { AppwriteProjectConfiguration } from "./settings";
const sdk: SDK = require("node-appwrite");
export let client: Client; export let client: Client;
export let clientConfig: { endpoint: string; projectId: string; secret: string }; export let clientConfig: { endpoint: string; projectId: string; secret: string };
export let usersClient: Users; export let usersClient: Users | undefined;
export let healthClient: Health; export let healthClient: Health | undefined;
export let databaseClient: Database; export let databaseClient: Database | undefined;
export let storageClient: Storage; export let storageClient: Storage | undefined;
export function initAppwriteClient({ endpoint, projectId, secret }: AppwriteProjectConfiguration) { function initAppwriteClient({ endpoint, projectId, secret }: AppwriteProjectConfiguration) {
client = new sdk.Client(); client = new AppwriteSDK.Client();
clientConfig = { endpoint, projectId, secret }; clientConfig = { endpoint, projectId, secret };
client.setEndpoint(endpoint).setProject(projectId).setKey(secret); client.setEndpoint(endpoint).setProject(projectId).setKey(secret);
@ -26,3 +25,15 @@ export function initAppwriteClient({ endpoint, projectId, secret }: AppwriteProj
return client; return client;
} }
export function createAppwriteClient(config?: AppwriteProjectConfiguration): void {
if (config) {
initAppwriteClient(config);
return;
}
usersClient = undefined;
healthClient = undefined;
databaseClient = undefined;
storageClient = undefined;
}

View file

@ -1,13 +1,13 @@
import { initAppwriteClient } from "../client"; import { createAppwriteClient } from "../client";
import { addProjectConfiguration } from '../settings'; import { addProjectConfiguration } from '../settings';
import { addProjectWizard } from "../ui/AddProjectWizard"; import { addProjectWizard } from "../ui/AddProjectWizard";
import { refreshTree } from '../utils/refreshTree'; import { refreshTree } from '../utils/refreshTree';
export async function connectAppwrite() { export async function connectAppwrite(): Promise<void> {
const projectConfiguration = await addProjectWizard(); const projectConfiguration = await addProjectWizard();
if (projectConfiguration) { if (projectConfiguration) {
addProjectConfiguration(projectConfiguration); addProjectConfiguration(projectConfiguration);
initAppwriteClient(projectConfiguration); createAppwriteClient(projectConfiguration);
refreshTree(); refreshTree();
} }
} }

View file

@ -1,9 +1,13 @@
import { window } from 'vscode'; import { window } from "vscode";
import { databaseClient } from '../../client'; import { databaseClient } from "../../client";
export async function createCollection(): Promise<void> { export async function createCollection(): Promise<void> {
if (!databaseClient) {
return;
}
const name = await window.showInputBox({ const name = await window.showInputBox({
prompt: 'Collection name' prompt: "Collection name",
}); });
if (name && name.length > 0) { if (name && name.length > 0) {

View file

@ -5,6 +5,11 @@ import { createRuleWizard } from "../../ui/createRuleWizard";
import { refreshTree } from '../../utils/refreshTree'; import { refreshTree } from '../../utils/refreshTree';
export async function createRule(rulesTreeItem: RulesTreeItem): Promise<void> { export async function createRule(rulesTreeItem: RulesTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const ruleContext = await createRuleWizard(); const ruleContext = await createRuleWizard();
const collection = rulesTreeItem.parent.collection; const collection = rulesTreeItem.parent.collection;

View file

@ -4,6 +4,9 @@ import { CollectionTreeItem } from "../../tree/database/CollectionTreeItem";
import { confirmDialog } from "../../ui/confirmDialog"; import { confirmDialog } from "../../ui/confirmDialog";
export async function deleteCollection(collectionTreeItem: CollectionTreeItem): Promise<void> { export async function deleteCollection(collectionTreeItem: CollectionTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const collection = collectionTreeItem.collection; const collection = collectionTreeItem.collection;
try { try {
const shouldDelete = await confirmDialog(`Delete collection "${collection.name}"?`); const shouldDelete = await confirmDialog(`Delete collection "${collection.name}"?`);

View file

@ -4,13 +4,16 @@ import { DocumentTreeItem } from "../../tree/database/DocumentTreeItem";
import { confirmDialog } from "../../ui/confirmDialog"; import { confirmDialog } from "../../ui/confirmDialog";
export async function deleteDocument(documentTreeItem: DocumentTreeItem): Promise<void> { export async function deleteDocument(documentTreeItem: DocumentTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const document = documentTreeItem.document; const document = documentTreeItem.document;
const collection = documentTreeItem.parent.parent.collection; const collection = documentTreeItem.parent.parent.collection;
try { try {
const shouldDelete = await confirmDialog(`Delete document "${document["$id"]}" from ${collection.name}?`); const shouldDelete = await confirmDialog(`Delete document "${document["$id"]}" from ${collection.name}?`);
if (shouldDelete) { if (shouldDelete) {
await databaseClient.deleteDocument(collection.$id, document["$id"]); await databaseClient.deleteDocument(collection.$id, document["$id"]);
documentTreeItem.parent.window.showInformationMessage(`Deleted document "${document["$id"]}" from ${collection.name}.`); window.showInformationMessage(`Deleted document "${document["$id"]}" from ${collection.name}.`);
} }
} catch (e) { } catch (e) {
window.showErrorMessage(e); window.showErrorMessage(e);

View file

@ -1,8 +1,6 @@
import { window } from "vscode"; import { window } from "vscode";
import { databaseClient } from '../../../client'; import { databaseClient } from "../../../client";
import { CollapsableTreeItem } from '../../../tree/CollapsableTreeItem';
import { PermissionsTreeItem } from "../../../tree/database/settings/PermissionsTreeItem"; import { PermissionsTreeItem } from "../../../tree/database/settings/PermissionsTreeItem";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export type CreatePermissionWizardContext = { export type CreatePermissionWizardContext = {
kind: "read" | "write"; kind: "read" | "write";
@ -25,7 +23,9 @@ export async function createPermissionWizard(kind?: "read" | "write"): Promise<C
} }
export async function createPermission(treeItem: PermissionsTreeItem): Promise<void> { export async function createPermission(treeItem: PermissionsTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const collection = treeItem.parent.collection; const collection = treeItem.parent.collection;
const context = await createPermissionWizard(undefined); const context = await createPermissionWizard(undefined);
@ -37,7 +37,7 @@ export async function createPermission(treeItem: PermissionsTreeItem): Promise<v
const read = Array.from(collection.$permissions.read); const read = Array.from(collection.$permissions.read);
const write = Array.from(collection.$permissions.write); const write = Array.from(collection.$permissions.write);
if (context.kind === 'read') { if (context.kind === "read") {
read.push(context.permission); read.push(context.permission);
} else { } else {
write.push(context.permission); write.push(context.permission);

View file

@ -2,6 +2,9 @@ import { databaseClient } from "../../../client";
import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem"; import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export async function deletePermission(treeItem: PermissionTreeItem): Promise<void> { export async function deletePermission(treeItem: PermissionTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const collection = treeItem.parent.parent.collection; const collection = treeItem.parent.parent.collection;
const kind = treeItem.kind; const kind = treeItem.kind;

View file

@ -1,8 +1,11 @@
import { window } from 'vscode'; import { window } from "vscode";
import { databaseClient } from '../../../client'; import { databaseClient } from "../../../client";
import { PermissionTreeItem } from '../../../tree/database/settings/PermissionTreeItem'; import { PermissionTreeItem } from "../../../tree/database/settings/PermissionTreeItem";
export async function editPermission(treeItem: PermissionTreeItem): Promise<void> { export async function editPermission(treeItem: PermissionTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const editedPermission = await window.showInputBox({ const editedPermission = await window.showInputBox({
value: treeItem.permission, value: treeItem.permission,
}); });

View file

@ -1,5 +1,5 @@
import { CollectionTreeItem } from "../../tree/database/CollectionTreeItem"; import { CollectionTreeItem } from "../../tree/database/CollectionTreeItem";
export async function refreshCollection(collectionTreeItem: CollectionTreeItem) { export async function refreshCollection(collectionTreeItem: CollectionTreeItem): Promise<void> {
await collectionTreeItem.refresh(); await collectionTreeItem.refresh();
} }

View file

@ -3,6 +3,9 @@ import { RuleTreeItem } from '../../tree/database/settings/RuleTreeItem';
import { refreshTree } from '../../utils/refreshTree'; import { refreshTree } from '../../utils/refreshTree';
export async function removeRule(ruleItem: RuleTreeItem): Promise<void> { export async function removeRule(ruleItem: RuleTreeItem): Promise<void> {
if (!databaseClient) {
return;
}
const rule = ruleItem.rule; const rule = ruleItem.rule;
const collection = ruleItem.parent.parent.collection; const collection = ruleItem.parent.parent.collection;
await databaseClient.removeRule(collection, rule); await databaseClient.removeRule(collection, rule);

View file

@ -1,12 +1,12 @@
import { window } from "vscode"; import { window } from "vscode";
import { initAppwriteClient } from "../../client"; import { createAppwriteClient } from '../../client';
import { addProjectWizard } from "../../ui/AddProjectWizard"; import { addProjectWizard } from "../../ui/AddProjectWizard";
export async function addProject() { export async function addProject(): Promise<void> {
const projectConfiguration = await addProjectWizard(); const projectConfiguration = await addProjectWizard();
if (projectConfiguration) { if (projectConfiguration) {
initAppwriteClient(projectConfiguration); createAppwriteClient(projectConfiguration);
} }
window.showInformationMessage("Connected to Appwrite project."); window.showInformationMessage("Connected to Appwrite project.");

View file

@ -1,11 +1,8 @@
import { window } from "vscode"; import { removeProjectConfig } from "../../settings";
import { initAppwriteClient } from "../../client"; import { ProjectTreeItem } from "../../tree/projects/ProjectTreeItem";
import { removeProjectConfig } from '../../settings';
import { ProjectTreeItem } from '../../tree/projects/ProjectTreeItem';
import { addProjectWizard } from "../../ui/AddProjectWizard";
export async function removeProject(project: ProjectTreeItem | string) { export async function removeProject(project: ProjectTreeItem | string): Promise<void> {
if (typeof project === 'string') { if (typeof project === "string") {
await removeProjectConfig(project); await removeProjectConfig(project);
return; return;
} }

View file

@ -1,9 +1,7 @@
import { window } from "vscode";
import { initAppwriteClient } from "../../client";
import { setActiveProjectId } from '../../settings'; import { setActiveProjectId } from '../../settings';
import { ProjectTreeItem } from "../../tree/projects/ProjectTreeItem"; import { ProjectTreeItem } from "../../tree/projects/ProjectTreeItem";
export async function setActiveProject(treeItem: ProjectTreeItem) { export async function setActiveProject(treeItem: ProjectTreeItem): Promise<void> {
if (treeItem === undefined) { if (treeItem === undefined) {
return; return;
} }

View file

@ -1,5 +1,5 @@
import { commands, ExtensionContext } from "vscode"; import { commands, ExtensionContext } from "vscode";
import { AppwriteTree, ext } from "../extensionVariables"; import { AppwriteTree } from "../extensionVariables";
import { refreshAllViews, refreshTree } from "../utils/refreshTree"; import { refreshAllViews, refreshTree } from "../utils/refreshTree";
import { connectAppwrite } from "./connectAppwrite"; import { connectAppwrite } from "./connectAppwrite";
import { createCollection } from "./database/createCollection"; import { createCollection } from "./database/createCollection";
@ -24,7 +24,7 @@ import { refreshUsersList } from "./users/refreshUsersList";
import { viewUserPrefs } from "./users/viewUserPrefs"; import { viewUserPrefs } from "./users/viewUserPrefs";
import { editPermission } from "./database/permissions/editPermission"; import { editPermission } from "./database/permissions/editPermission";
import { setActiveProject } from "./project/setActiveProject"; import { setActiveProject } from "./project/setActiveProject";
import { removeProject } from './project/removeProject'; import { removeProject } from "./project/removeProject";
class CommandRegistrar { class CommandRegistrar {
constructor(private readonly context: ExtensionContext) {} constructor(private readonly context: ExtensionContext) {}
@ -57,7 +57,7 @@ export function registerCommands(context: ExtensionContext): void {
}; };
/** General **/ /** General **/
registerCommand("Connect", connectAppwrite); registerCommand("Connect", connectAppwrite, "all");
/** Users **/ /** Users **/
registerCommand("openUserInConsole", openUserInConsole); registerCommand("openUserInConsole", openUserInConsole);
@ -86,11 +86,11 @@ export function registerCommands(context: ExtensionContext): void {
registerCommand("editPermission", editPermission, "database"); registerCommand("editPermission", editPermission, "database");
/** Health **/ /** Health **/
registerCommand("refreshHealth", () => {}, "health"); registerCommand("refreshHealth", undefined, "health");
registerCommand("openHealthDocumentation", () => openDocumentation("health")); registerCommand("openHealthDocumentation", () => openDocumentation("health"));
/** Storage **/ /** Storage **/
registerCommand("refreshStorage", () => {}, "storage"); registerCommand("refreshStorage", undefined, "storage");
registerCommand("openStorageDocumentation", () => openDocumentation("storage")); registerCommand("openStorageDocumentation", () => openDocumentation("storage"));
/** Projects **/ /** Projects **/

View file

@ -3,6 +3,9 @@ import { usersClient } from '../../client';
import { ext } from '../../extensionVariables'; import { ext } from '../../extensionVariables';
export async function createUser(): Promise<void> { export async function createUser(): Promise<void> {
if (!usersClient) {
return;
}
const email = await window.showInputBox({ const email = await window.showInputBox({
ignoreFocusOut: true, ignoreFocusOut: true,
placeHolder: "jane.doe@hotmail.com", placeHolder: "jane.doe@hotmail.com",

View file

@ -5,6 +5,9 @@ import { DialogResponses } from "../../ui/DialogResponses";
import { refreshTree } from "../../utils/refreshTree"; import { refreshTree } from "../../utils/refreshTree";
export async function deleteUser(userTreeItem: UserTreeItem): Promise<void> { export async function deleteUser(userTreeItem: UserTreeItem): Promise<void> {
if (!usersClient) {
return;
}
const user = userTreeItem.user; const user = userTreeItem.user;
const userId = user.$id; const userId = user.$id;
const shouldDeleteUser = await window.showWarningMessage( const shouldDeleteUser = await window.showWarningMessage(

View file

@ -3,6 +3,9 @@ import { UserTreeItem } from "../../tree/users/UserTreeItem";
import { openReadOnlyJson } from '../../ui/openReadonlyContent'; import { openReadOnlyJson } from '../../ui/openReadonlyContent';
export async function getUserLogs(treeItem: UserTreeItem): Promise<void> { export async function getUserLogs(treeItem: UserTreeItem): Promise<void> {
if (!usersClient) {
return;
}
const userId = treeItem.user.$id; const userId = treeItem.user.$id;
const logs = await usersClient.getLogs(userId); const logs = await usersClient.getLogs(userId);

View file

@ -12,7 +12,7 @@ function getUserUrl(userId: string, endpoint: string, projectId: string): string
return `${getConsoleUrlFromEndpoint(endpoint)}/users/user?id=${userId}&project=${projectId}`; return `${getConsoleUrlFromEndpoint(endpoint)}/users/user?id=${userId}&project=${projectId}`;
} }
export async function openUserInConsole(item: UserTreeItem) { export async function openUserInConsole(item: UserTreeItem): Promise<void> {
const url = getUserUrl(item.user.$id, clientConfig.endpoint, clientConfig.projectId); const url = getUserUrl(item.user.$id, clientConfig.endpoint, clientConfig.projectId);
await commands.executeCommand("vscode.open", Uri.parse(url)); await commands.executeCommand("vscode.open", Uri.parse(url));

View file

@ -1,5 +1,5 @@
import { ext } from "../../extensionVariables"; import { ext } from "../../extensionVariables";
export async function refreshUsersList() { export async function refreshUsersList(): Promise<void> {
ext.tree?.users?.refresh(); ext.tree?.users?.refresh();
} }

View file

@ -2,7 +2,7 @@ import { UserPrefsTreeItem } from "../../tree/users/properties/UserPrefsTreeItem
import { UserTreeItem } from '../../tree/users/UserTreeItem'; import { UserTreeItem } from '../../tree/users/UserTreeItem';
import { openReadOnlyJson } from "../../ui/openReadonlyContent"; import { openReadOnlyJson } from "../../ui/openReadonlyContent";
export async function viewUserPrefs(item: UserPrefsTreeItem | UserTreeItem) { export async function viewUserPrefs(item: UserPrefsTreeItem | UserTreeItem): Promise<void> {
const userItem = item instanceof UserPrefsTreeItem ? item.parent : item; const userItem = item instanceof UserPrefsTreeItem ? item.parent : item;
const prefs = userItem.user.prefs; const prefs = userItem.user.prefs;

View file

@ -1,3 +1,4 @@
import type { SDK } from './appwrite'; import type { SDK } from './appwrite';
// eslint-disable-next-line @typescript-eslint/no-var-requires
export const AppwriteSDK: SDK = require('node-appwrite') as SDK; export const AppwriteSDK: SDK = require('node-appwrite') as SDK;

View file

@ -1,12 +1,11 @@
import * as vscode from "vscode"; import * as vscode from "vscode";
import { workspace } from 'vscode'; import { createAppwriteClient } from "./client";
import { initAppwriteClient } from "./client";
import { registerCommands } from "./commands/registerCommands"; import { registerCommands } from "./commands/registerCommands";
import { ext } from "./extensionVariables"; import { ext } from "./extensionVariables";
import { getActiveProjectConfiguration, getActiveProjectId, getDefaultProject } from "./settings"; import { getActiveProjectConfiguration } from "./settings";
import { DatabaseTreeItemProvider } from "./tree/database/DatabaseTreeItemProvider"; import { DatabaseTreeItemProvider } from "./tree/database/DatabaseTreeItemProvider";
import { HealthTreeItemProvider } from "./tree/health/HealthTreeItemProvider"; import { HealthTreeItemProvider } from "./tree/health/HealthTreeItemProvider";
import { ProjectsTreeItemProvider } from './tree/projects/ProjectsTreeItemProvider'; import { ProjectsTreeItemProvider } from "./tree/projects/ProjectsTreeItemProvider";
import { StorageTreeItemProvider } from "./tree/storage/StorageTreeItemProvider"; import { StorageTreeItemProvider } from "./tree/storage/StorageTreeItemProvider";
import { UserTreeItemProvider } from "./tree/users/UserTreeItemProvider"; import { UserTreeItemProvider } from "./tree/users/UserTreeItemProvider";
import { createAppwriteOutputChannel } from "./ui/AppwriteOutputChannel"; import { createAppwriteOutputChannel } from "./ui/AppwriteOutputChannel";
@ -25,9 +24,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
vscode.window.registerTreeDataProvider("Projects", projectsTreeItemProvider); vscode.window.registerTreeDataProvider("Projects", projectsTreeItemProvider);
const activeProject = await getActiveProjectConfiguration(); const activeProject = await getActiveProjectConfiguration();
if (activeProject) { createAppwriteClient(activeProject);
initAppwriteClient(activeProject);
}
ext.context = context; ext.context = context;
ext.outputChannel = createAppwriteOutputChannel("Appwrite", "appwrite"); ext.outputChannel = createAppwriteOutputChannel("Appwrite", "appwrite");
@ -37,10 +34,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
health: healthTreeItemProvider, health: healthTreeItemProvider,
database: databaseTreeItemProvider, database: databaseTreeItemProvider,
storage: storageTreeItemProvider, storage: storageTreeItemProvider,
projects: projectsTreeItemProvider projects: projectsTreeItemProvider,
}; };
registerCommands(context); registerCommands(context);
} }
export function deactivate() {}

View file

@ -1,4 +1,4 @@
import { ExtensionContext, OutputChannel } from "vscode"; import { ExtensionContext } from "vscode";
import { DatabaseTreeItemProvider } from './tree/database/DatabaseTreeItemProvider'; import { DatabaseTreeItemProvider } from './tree/database/DatabaseTreeItemProvider';
import { HealthTreeItemProvider } from './tree/health/HealthTreeItemProvider'; import { HealthTreeItemProvider } from './tree/health/HealthTreeItemProvider';
import { ProjectsTreeItemProvider } from './tree/projects/ProjectsTreeItemProvider'; import { ProjectsTreeItemProvider } from './tree/projects/ProjectsTreeItemProvider';

View file

@ -1,5 +1,5 @@
import { workspace } from "vscode"; import { workspace } from "vscode";
import { initAppwriteClient } from "./client"; import { createAppwriteClient } from "./client";
export type AppwriteProjectConfiguration = { export type AppwriteProjectConfiguration = {
nickname?: string; nickname?: string;
@ -64,9 +64,7 @@ export async function setActiveProjectId(projectId: string): Promise<void> {
const configuration = workspace.getConfiguration("appwrite"); const configuration = workspace.getConfiguration("appwrite");
await configuration.update("activeProjectId", projectId, true); await configuration.update("activeProjectId", projectId, true);
const active = await getActiveProjectConfiguration(); const active = await getActiveProjectConfiguration();
if (active) { createAppwriteClient(active);
initAppwriteClient(active);
}
} }
export async function updateActiveProjectId(): Promise<void> { export async function updateActiveProjectId(): Promise<void> {
@ -75,17 +73,12 @@ export async function updateActiveProjectId(): Promise<void> {
const configuration = workspace.getConfiguration("appwrite"); const configuration = workspace.getConfiguration("appwrite");
await configuration.update("activeProjectId", projects[0].projectId, true); await configuration.update("activeProjectId", projects[0].projectId, true);
const active = await getActiveProjectConfiguration(); const active = await getActiveProjectConfiguration();
if (active) { createAppwriteClient(active);
initAppwriteClient(active);
}
} }
} }
export async function removeProjectConfig(projectId: string): Promise<void> { export async function removeProjectConfig(projectId: string): Promise<void> {
const projects = await getAppwriteProjects(); const projects = await getAppwriteProjects();
const activeProjectId = await getActiveProjectId();
const updatedProjects = projects.filter((project) => project.projectId !== projectId); const updatedProjects = projects.filter((project) => project.projectId !== projectId);
const configuration = workspace.getConfiguration("appwrite"); const configuration = workspace.getConfiguration("appwrite");
await configuration.update("projects", updatedProjects, true); await configuration.update("projects", updatedProjects, true);

View file

@ -1,6 +1,5 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { TreeItem, TreeItemCollapsibleState } from "vscode";
import { AppwriteTreeItemBase } from "../ui/AppwriteTreeItemBase"; import { AppwriteTreeItemBase } from "../ui/AppwriteTreeItemBase";
import { ChildTreeItem } from "./ChildTreeItem";
export class CollapsableTreeItem<Parent> extends AppwriteTreeItemBase<Parent> { export class CollapsableTreeItem<Parent> extends AppwriteTreeItemBase<Parent> {
constructor(parent: Parent, item: Partial<TreeItem> & { label: string }, private readonly children: TreeItem[], public readonly brand?: string) { constructor(parent: Parent, item: Partial<TreeItem> & { label: string }, private readonly children: TreeItem[], public readonly brand?: string) {

View file

@ -1,11 +1,11 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { Collection } from "../../appwrite"; import { Collection } from "../../appwrite";
import { databaseClient } from '../../client'; import { databaseClient } from "../../client";
import { AppwriteTreeItemBase } from '../../ui/AppwriteTreeItemBase'; import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase";
import { DatabaseTreeItemProvider } from './DatabaseTreeItemProvider'; import { DatabaseTreeItemProvider } from "./DatabaseTreeItemProvider";
import { DocumentsTreeItem } from './DocumentsTreeItem'; import { DocumentsTreeItem } from "./DocumentsTreeItem";
import { PermissionsTreeItem } from './settings/PermissionsTreeItem'; import { PermissionsTreeItem } from "./settings/PermissionsTreeItem";
import { RulesTreeItem } from './settings/RulesTreeItem'; import { RulesTreeItem } from "./settings/RulesTreeItem";
export class CollectionTreeItem extends AppwriteTreeItemBase { export class CollectionTreeItem extends AppwriteTreeItemBase {
constructor(public collection: Collection, public readonly provider: DatabaseTreeItemProvider) { constructor(public collection: Collection, public readonly provider: DatabaseTreeItemProvider) {
@ -17,7 +17,10 @@ export class CollectionTreeItem extends AppwriteTreeItemBase {
} }
public async refresh(): Promise<void> { public async refresh(): Promise<void> {
this.collection = await databaseClient.getCollection(this.collection.$id) ?? this.collection; if (!databaseClient) {
return;
}
this.collection = (await databaseClient.getCollection(this.collection.$id)) ?? this.collection;
this.provider.refreshChild(this); this.provider.refreshChild(this);
} }
@ -25,5 +28,5 @@ export class CollectionTreeItem extends AppwriteTreeItemBase {
contextValue = "collection"; contextValue = "collection";
iconPath = new ThemeIcon('folder'); iconPath = new ThemeIcon("folder");
} }

View file

@ -1,7 +1,7 @@
import * as vscode from "vscode"; import * as vscode from "vscode";
import { client } from "../../client"; import { client } from "../../client";
import AppwriteCall from "../../utils/AppwriteCall"; import AppwriteCall from "../../utils/AppwriteCall";
import { Collection, CollectionsList, DocumentsList } from "../../appwrite"; import { Collection, CollectionsList } from "../../appwrite";
import { CollectionTreeItem } from "./CollectionTreeItem"; import { CollectionTreeItem } from "./CollectionTreeItem";
import { AppwriteSDK } from "../../constants"; import { AppwriteSDK } from "../../constants";
import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase"; import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase";
@ -14,8 +14,6 @@ export class DatabaseTreeItemProvider implements vscode.TreeDataProvider<vscode.
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event; readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void { refresh(): void {
ext.outputChannel?.appendLine('refresh database'); ext.outputChannel?.appendLine('refresh database');
this._onDidChangeTreeData.fire(); this._onDidChangeTreeData.fire();
@ -39,7 +37,7 @@ export class DatabaseTreeItemProvider implements vscode.TreeDataProvider<vscode.
return parent.getChildren?.() ?? []; return parent.getChildren?.() ?? [];
} }
let databaseSdk = new AppwriteSDK.Database(client); const databaseSdk = new AppwriteSDK.Database(client);
const collectionsList = await AppwriteCall<CollectionsList, CollectionsList>(databaseSdk.listCollections()); const collectionsList = await AppwriteCall<CollectionsList, CollectionsList>(databaseSdk.listCollections());
if (collectionsList) { if (collectionsList) {

View file

@ -3,6 +3,7 @@ import { ChildTreeItem } from '../ChildTreeItem';
import { DocumentsTreeItem } from './DocumentsTreeItem'; import { DocumentsTreeItem } from './DocumentsTreeItem';
export class DocumentTreeItem extends ChildTreeItem<DocumentsTreeItem> { export class DocumentTreeItem extends ChildTreeItem<DocumentsTreeItem> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(parent: DocumentsTreeItem, public readonly document: Record<string, any>) { constructor(parent: DocumentsTreeItem, public readonly document: Record<string, any>) {
super(parent, { super(parent, {
label: document['$id'], label: document['$id'],

View file

@ -9,13 +9,12 @@ import { CollectionTreeItem } from "./CollectionTreeItem";
import { DocumentTreeItem } from "./DocumentTreeItem"; import { DocumentTreeItem } from "./DocumentTreeItem";
export class DocumentsTreeItem extends AppwriteTreeItemBase<CollectionTreeItem> { export class DocumentsTreeItem extends AppwriteTreeItemBase<CollectionTreeItem> {
window: any;
constructor(parent: CollectionTreeItem) { constructor(parent: CollectionTreeItem) {
super(parent, "Documents"); super(parent, "Documents");
} }
public async getChildren(): Promise<TreeItem[]> { public async getChildren(): Promise<TreeItem[]> {
let databaseSdk = new AppwriteSDK.Database(client); const databaseSdk = new AppwriteSDK.Database(client);
const documentList = await AppwriteCall<DocumentsList>(databaseSdk.listDocuments(this.parent.collection.$id)); const documentList = await AppwriteCall<DocumentsList>(databaseSdk.listDocuments(this.parent.collection.$id));
if (documentList === undefined) { if (documentList === undefined) {
return []; return [];

View file

@ -1,4 +1,3 @@
import { AppwriteTreeItemBase } from "../../../ui/AppwriteTreeItemBase";
import { ChildTreeItem } from "../../ChildTreeItem"; import { ChildTreeItem } from "../../ChildTreeItem";
import { PermissionsTreeItem } from "./PermissionsTreeItem"; import { PermissionsTreeItem } from "./PermissionsTreeItem";

View file

@ -1,4 +1,3 @@
import { TreeItem } from "vscode";
import { Rule } from "../../../appwrite"; import { Rule } from "../../../appwrite";
import { ChildTreeItem } from "../../ChildTreeItem"; import { ChildTreeItem } from "../../ChildTreeItem";
import { RulesTreeItem } from "./RulesTreeItem"; import { RulesTreeItem } from "./RulesTreeItem";

View file

@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { MarkdownString } from 'vscode'; import { MarkdownString } from 'vscode';
export class HealthTreeItem extends vscode.TreeItem { export class HealthTreeItem extends vscode.TreeItem {
constructor(public readonly label: string, status: any, tooltip?: string | MarkdownString | undefined) { constructor(public readonly label: string, status: "check" | "error" | any, tooltip?: string | MarkdownString | undefined) {
super(label); super(label);
console.log(status); console.log(status);
this.label = label; this.label = label;

View file

@ -3,15 +3,12 @@ import { healthClient } from "../../client";
import { ext } from "../../extensionVariables"; import { ext } from "../../extensionVariables";
import { HealthTreeItem } from "./HealthTreeItem"; import { HealthTreeItem } from "./HealthTreeItem";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
import * as relativeTime from "dayjs/plugin/relativeTime";
import * as localizedFormat from "dayjs/plugin/localizedFormat"; import * as localizedFormat from "dayjs/plugin/localizedFormat";
import { healthTooltips } from "../../appwrite/Health"; import { healthTooltips } from "../../appwrite/Health";
import { AppwriteHealth } from "../../appwrite"; import { AppwriteHealth } from "../../appwrite";
// dayjs.extend(relativeTime); // dayjs.extend(relativeTime);
dayjs.extend(localizedFormat); dayjs.extend(localizedFormat);
type PartialRecord<K extends string | number | symbol, T> = { [P in K]?: T };
export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> { export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
private _onDidChangeTreeData: vscode.EventEmitter<HealthTreeItem | undefined | void> = new vscode.EventEmitter< private _onDidChangeTreeData: vscode.EventEmitter<HealthTreeItem | undefined | void> = new vscode.EventEmitter<
HealthTreeItem | undefined | void HealthTreeItem | undefined | void
@ -21,8 +18,6 @@ export class HealthTreeItemProvider implements vscode.TreeDataProvider<vscode.Tr
readonly onDidChangeTreeData: vscode.Event<HealthTreeItem | undefined | void> = this._onDidChangeTreeData.event; readonly onDidChangeTreeData: vscode.Event<HealthTreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void { refresh(): void {
this._onDidChangeTreeData.fire(); this._onDidChangeTreeData.fire();
} }

View file

@ -1,6 +1,6 @@
import * as vscode from "vscode"; import * as vscode from "vscode";
import { getActiveProjectId, getAppwriteProjects } from '../../settings'; import { getActiveProjectId, getAppwriteProjects } from "../../settings";
import { ProjectTreeItem } from './ProjectTreeItem'; import { ProjectTreeItem } from "./ProjectTreeItem";
export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> { export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
private _onDidChangeTreeData: vscode.EventEmitter<vscode.TreeItem | undefined | void> = new vscode.EventEmitter< private _onDidChangeTreeData: vscode.EventEmitter<vscode.TreeItem | undefined | void> = new vscode.EventEmitter<
@ -9,7 +9,13 @@ export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event; readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {} constructor() {
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("appwrite")) {
this.refresh();
}
});
}
refresh(): void { refresh(): void {
this._onDidChangeTreeData.fire(); this._onDidChangeTreeData.fire();
@ -19,7 +25,7 @@ export class ProjectsTreeItemProvider implements vscode.TreeDataProvider<vscode.
return element; return element;
} }
async getChildren(element?: vscode.TreeItem): Promise<vscode.TreeItem[]> { async getChildren(_element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
const configs = await getAppwriteProjects(); const configs = await getAppwriteProjects();
if (configs === undefined || configs.length === 0) { if (configs === undefined || configs.length === 0) {
return []; return [];

View file

@ -9,8 +9,6 @@ export class StorageTreeItemProvider implements vscode.TreeDataProvider<vscode.T
readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event; readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void { refresh(): void {
this._onDidChangeTreeData.fire(); this._onDidChangeTreeData.fire();
} }
@ -19,7 +17,7 @@ export class StorageTreeItemProvider implements vscode.TreeDataProvider<vscode.T
return element; return element;
} }
async getChildren(element?: vscode.TreeItem): Promise<vscode.TreeItem[]> { async getChildren(_element?: vscode.TreeItem): Promise<vscode.TreeItem[]> {
if (storageClient === undefined) { if (storageClient === undefined) {
return []; return [];
} }

View file

@ -6,6 +6,7 @@ import { ThemeIcon } from "vscode";
import { UserPrefsTreeItem } from "./properties/UserPrefsTreeItem"; import { UserPrefsTreeItem } from "./properties/UserPrefsTreeItem";
import { ChildTreeItem } from "../ChildTreeItem"; import { ChildTreeItem } from "../ChildTreeItem";
import { UserTreeItem } from "./UserTreeItem"; import { UserTreeItem } from "./UserTreeItem";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sdk = require("node-appwrite"); const sdk = require("node-appwrite");
export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> { export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
@ -15,8 +16,6 @@ export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.Tree
readonly onDidChangeTreeData: vscode.Event<UserTreeItem | undefined | void> = this._onDidChangeTreeData.event; readonly onDidChangeTreeData: vscode.Event<UserTreeItem | undefined | void> = this._onDidChangeTreeData.event;
constructor() {}
refresh(): void { refresh(): void {
this._onDidChangeTreeData.fire(); this._onDidChangeTreeData.fire();
} }
@ -63,10 +62,10 @@ export class UserTreeItemProvider implements vscode.TreeDataProvider<vscode.Tree
return Promise.resolve(items); return Promise.resolve(items);
} }
let usersSdk = new sdk.Users(client); const usersSdk = new sdk.Users(client);
const usersList = await AppwriteCall<UsersList, UsersList>(usersSdk.list()); const usersList = await AppwriteCall<UsersList, UsersList>(usersSdk.list());
if (usersList) { if (usersList) {
const userTreeItems = usersList.users.map((user: any) => new UserTreeItem(user)) ?? []; const userTreeItems = usersList.users.map((user: User) => new UserTreeItem(user)) ?? [];
const headerItem: vscode.TreeItem = { const headerItem: vscode.TreeItem = {
label: `Total users: ${usersList.sum}`, label: `Total users: ${usersList.sum}`,
}; };

View file

@ -6,7 +6,7 @@
import { OutputChannel, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode"; import { OutputChannel, ViewColumn, window, workspace, WorkspaceConfiguration } from "vscode";
// tslint:disable-next-line: export-name // tslint:disable-next-line: export-name
export function createAppwriteOutputChannel(name: string, extensionPrefix: string) { export function createAppwriteOutputChannel(name: string, extensionPrefix: string): AppwriteOutputChannel {
return new AppwriteOutputChannel(name, extensionPrefix); return new AppwriteOutputChannel(name, extensionPrefix);
} }
@ -50,8 +50,8 @@ export class AppwriteOutputChannel {
public show(preserveFocus?: boolean | undefined): void; public show(preserveFocus?: boolean | undefined): void;
public show(column?: ViewColumn | undefined, preserveFocus?: boolean | undefined): void; public show(column?: ViewColumn | undefined, preserveFocus?: boolean | undefined): void;
// tslint:disable-next-line: no-any // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
public show(_column?: any, preserveFocus?: boolean | undefined): void { public show(_column?: unknown, preserveFocus?: boolean | undefined): void {
this._outputChannel.show(preserveFocus); this._outputChannel.show(preserveFocus);
} }

View file

@ -1,4 +1,4 @@
import { TreeDataProvider, TreeItem } from "vscode"; import { TreeItem } from "vscode";
export abstract class AppwriteTreeItemBase<Parent = void> extends TreeItem { export abstract class AppwriteTreeItemBase<Parent = void> extends TreeItem {
constructor(public readonly parent: Parent, label: string) { constructor(public readonly parent: Parent, label: string) {

View file

@ -93,7 +93,7 @@ export abstract class BaseEditor<ContextT> implements vscode.Disposable {
} }
private async updateEditor(data: string, textEditor?: vscode.TextEditor): Promise<void> { private async updateEditor(data: string, textEditor?: vscode.TextEditor): Promise<void> {
if (!!textEditor) { if (textEditor) {
await BaseEditor.writeToEditor(textEditor, data); await BaseEditor.writeToEditor(textEditor, data);
this.ignoreSave = true; this.ignoreSave = true;
try { try {

View file

@ -1,5 +1,4 @@
import { QuickPickItem, window } from "vscode"; import { QuickPickItem, window } from "vscode";
import { AppwriteProjectConfiguration } from "../settings";
export type CreateRuleWizardContext = { export type CreateRuleWizardContext = {
label: string; label: string;

View file

@ -8,8 +8,8 @@ export function refreshTree(...trees: (keyof AppwriteTree)[]): void {
export function refreshAllViews(): void { export function refreshAllViews(): void {
if (ext.tree) { if (ext.tree) {
Object.keys(ext.tree).forEach((tree) => { for (const tree in ext.tree) {
refreshTree(tree as keyof AppwriteTree); refreshTree(tree as keyof AppwriteTree);
}); }
} }
} }