Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial migration to v1.5 #2095

Merged
merged 14 commits into from
Jan 17, 2023
44 changes: 37 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 29 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,42 @@
],
"contributes": {
"x-azResources": {
"activation": {
"onResolve": [
"microsoft.documentdb/databaseaccounts",
"microsoft.dbforpostgresql/servers",
"microsoft.dbforpostgresql/flexibleservers"
"azure": {
"branches": [
{
"type": "AzureCosmosDb"
},
{
"type": "PostgresqlServersStandard"
},
{
"type": "PostgresqlServersFlexible"
}
]
},
"workspace": {
"branches": [
{
"type": "ms-azuretools.vscode-cosmosdb"
}
],
"resources": true
},
"commands": [
{
"command": "azureDatabases.createServer",
"title": "Create Database Server...",
"type": "microsoft.documentdb/databaseaccounts",
"detail": "SQL or NoSQL databases for your web apps."
}
]
],
"activation": {
"onResolve": [
"microsoft.documentdb/databaseaccounts",
"microsoft.dbforpostgresql/servers",
"microsoft.dbforpostgresql/flexibleservers"
]
}
},
"languages": [
{
Expand Down Expand Up @@ -475,7 +496,7 @@
"view/item/context": [
{
"command": "azureDatabases.createServer",
"when": "view == azureResourceGroups && viewItem =~ /azureResourceTypeGroup.*(microsoft.documentdb/databaseaccounts|microsoft.dbforpostgresql/(servers|flexibleservers))/",
"when": "view == azureResourceGroups && viewItem =~ /(AzureCosmosDb|PostgreSqlServers(Standard|Flexible))/i && viewItem =~ /azureResourceTypeGroup/i",
"group": "1@1"
},
{
Expand Down Expand Up @@ -1034,7 +1055,7 @@
"@azure/arm-postgresql-flexible": "^5.0.0",
"@azure/cosmos": "^3.6.3",
"@microsoft/vscode-azext-azureutils": "^0.3.4",
"@microsoft/vscode-azext-utils": "^0.3.15",
"@microsoft/vscode-azext-utils": "^0.4.0",
"antlr4ts": "^0.4.1-alpha.0",
"bson": "^1.1.3",
"fs-extra": "^8.0.0",
Expand Down
72 changes: 2 additions & 70 deletions src/DatabasesFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzExtItemQuery, AzExtItemUriParts, AzExtTreeFileSystem, AzExtTreeItem, DialogResponses, IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { Collection, Db } from "mongodb";
import { basename, dirname } from 'path';
import { AzExtTreeFileSystem, AzExtTreeItem, DialogResponses, IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { FileStat, FileType, MessageItem, Uri, workspace } from "vscode";
import { FileChangeType } from "vscode-languageclient";
import { ext } from "./extensionVariables";
import { MongoCollectionTreeItem } from "./mongo/tree/MongoCollectionTreeItem";
import { MongoDatabaseTreeItem } from "./mongo/tree/MongoDatabaseTreeItem";
import { localize } from "./utils/localize";
import { getWorkspaceSetting, updateGlobalSetting } from "./utils/settingUtils";
import { getNodeEditorLabel } from "./utils/vscodeUtils";

export interface IEditableTreeItem extends AzExtTreeItem {
id: string;
filePath: string;
cTime: number;
mTime: number;
Expand Down Expand Up @@ -77,69 +74,4 @@ export class DatabasesFileSystem extends AzExtTreeFileSystem<IEditableTreeItem>
node.mTime = Date.now();
this.fireSoon({ type: FileChangeType.Changed, item: node });
}

protected getUriParts(node: IEditableTreeItem): AzExtItemUriParts {
const uriParts: AzExtItemUriParts = super.getUriParts(node);
if (node instanceof MongoCollectionTreeItem && node.findArgs) {
addFindArgsToQuery(uriParts.query, node.findArgs);
}
return uriParts;
}

protected async findItem(context: IActionContext, query: AzExtItemQuery): Promise<IEditableTreeItem | undefined> {
let node: IEditableTreeItem | undefined = query.id.includes('cosmosDBAttachedAccounts') ?
await ext.rgApi.workspaceResourceTree.findTreeItem(query.id, context) :
await ext.rgApi.appResourceTree.findTreeItem(query.id, context);

if (!node) {
const parentId: string = dirname(query.id);
const parentNode: IEditableTreeItem | undefined = parentId.includes('cosmosDBAttachedAccounts') ?
await ext.rgApi.workspaceResourceTree.findTreeItem(parentId, context) :
await ext.rgApi.appResourceTree.findTreeItem(parentId, context);
if (parentNode instanceof MongoDatabaseTreeItem) {
const db: Db = await parentNode.connectToDb();
const collectionName: string = basename(query.id);
const collection: Collection = db.collection(collectionName);
node = new MongoCollectionTreeItem(parentNode, collection);
}
}

if (node && node instanceof MongoCollectionTreeItem) {
const findArgs: {}[] | undefined = getFindArgsFromQuery(query);
if (findArgs) {
return new MongoCollectionTreeItem(node.parent, node.collection, findArgs);
}
}
return node;
}
}

function addFindArgsToQuery(query: AzExtItemQuery, commandArgs: {}[]): void {
let count: number = 0;
for (const arg of commandArgs) {
const key: string = getFindArgKey(count);
query[key] = JSON.stringify(arg);
count += 1;
}
}

function getFindArgsFromQuery(query: AzExtItemQuery): {}[] | undefined {
const result: {}[] = [];
let count: number = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
const key: string = getFindArgKey(count);
const value: string | string[] | undefined = query[key];
if (typeof value === 'string') {
result.push(JSON.parse(value));
} else if (!value) {
break;
}
count += 1;
}
return result.length > 0 ? result : undefined;
}

function getFindArgKey(count: number): string {
return 'arg' + String(count);
}
20 changes: 10 additions & 10 deletions src/docdb/registerDocDBCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzExtTreeItem, IActionContext, ITreeItemPickerContext, registerCommand } from "@microsoft/vscode-azext-utils";
import { AzExtTreeItem, IActionContext, ITreeItemPickerContext, registerCommandWithTreeNodeUnwrapping } from "@microsoft/vscode-azext-utils";
import { commands } from "vscode";
import { doubleClickDebounceDelay, sqlFilter } from "../constants";
import { ext } from "../extensionVariables";
Expand All @@ -16,41 +16,41 @@ import { DocDBStoredProceduresTreeItem } from "./tree/DocDBStoredProceduresTreeI
import { DocDBStoredProcedureTreeItem } from "./tree/DocDBStoredProcedureTreeItem";

export function registerDocDBCommands(): void {
registerCommand('cosmosDB.createDocDBDatabase', createDocDBDatabase);
registerCommand('cosmosDB.createDocDBCollection', createDocDBCollection);
registerCommand('cosmosDB.createDocDBDocument', async (context: IActionContext, node?: DocDBDocumentsTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBDatabase', createDocDBDatabase);
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBCollection', createDocDBCollection);
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBDocument', async (context: IActionContext, node?: DocDBDocumentsTreeItem) => {
if (!node) {
node = await pickDocDBAccount<DocDBDocumentsTreeItem>(context, DocDBDocumentsTreeItem.contextValue);
}
const documentNode = <DocDBDocumentTreeItem>await node.createChild(context);
await commands.executeCommand("cosmosDB.openDocument", documentNode);

});
registerCommand('cosmosDB.createDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProceduresTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProceduresTreeItem) => {
if (!node) {
node = await pickDocDBAccount<DocDBStoredProceduresTreeItem>(context, DocDBStoredProceduresTreeItem.contextValue);
}
const childNode = await node.createChild(context);
await commands.executeCommand("cosmosDB.openStoredProcedure", childNode);

});
registerCommand('cosmosDB.deleteDocDBDatabase', deleteDocDBDatabase);
registerCommand('cosmosDB.deleteDocDBCollection', deleteDocDBCollection);
registerCommand('cosmosDB.openStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBDatabase', deleteDocDBDatabase);
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBCollection', deleteDocDBCollection);
registerCommandWithTreeNodeUnwrapping('cosmosDB.openStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
if (!node) {
node = await pickDocDBAccount<DocDBStoredProcedureTreeItem>(context, DocDBStoredProcedureTreeItem.contextValue);
}
await ext.fileSystem.showTextDocument(node);
}, doubleClickDebounceDelay);
registerCommand('cosmosDB.deleteDocDBDocument', async (context: IActionContext, node?: DocDBDocumentTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBDocument', async (context: IActionContext, node?: DocDBDocumentTreeItem) => {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
node = await pickDocDBAccount<DocDBDocumentTreeItem>(context, DocDBDocumentTreeItem.contextValue);
}
await node.deleteTreeItem(context);
});
registerCommand('cosmosDB.deleteDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
Expand Down
Loading