npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@microsoft/vscode-azureresources-api

v2.3.2

Published

Type declarations and client library for the Azure Resources extension API

Downloads

7,422

Readme

VS Code Azure Resources API

Provides typings and utilities for the VS Code Azure Resources API. This API is used to integrate "client" Azure extensions into views provided by the Azure Resources "host" extension for VS Code.

Overview

The Azure Resources extension for VS Code contributes the Azure resources view and the Workspace resources view. The Azure view lets users browse and work with supported resources in Azure. The Workspace resources view is home to development related resources like an emulated database, or a functions project detected in an open workspace folder.

In the past, each supported Azure resource had a dedicated view in the Azure view container. In the updated design, the Azure resources and Workspace resources views contain all resources. To facilitate this design, each Azure product extension contributes to a single host extension.

The Azure Resources extension provides small generic features for all Azure resource types. Users can then install Azure product extensions to enable rich, product-specific features.

The Azure Resources extension exposes an API which enables any number of client extensions to contribute UI and functionality to the Azure and Workspace resources views.

Capabilities

Tree views

The Azure Resources extension contributes two extendable views. The Resources view, and the Workspace view. In the Resources view, clients can customize resource tree items, and have full control over resource tree item children.

For the Workspace view, clients can contribute root level tree items to the view. Clients have full control over these tree items and their children.

Create Resource command

API Overview

Branch data provider

The VS Code API provides a TreeDataProvider interface for controlling tree views. In order to make the Azure trees extensible, the host extension splits tree views into "branches", where each branch is controlled by a branch data provider. Clients can register a BranchDataProvider for a resource type. The registered branch data provider is then responsible for providing the tree items for that branch in the tree view. BranchDataProvider is an extension of VS Code's TreeDataProvider.

Note: clients registering resource providers must declare that they do so in their extension manifest. See Extension Manifest

/**
 * The base interface for visualizers of Azure and workspace resources.
 */
export interface BranchDataProvider<TResource extends ResourceBase, TModel extends ResourceModelBase> extends vscode.TreeDataProvider<TModel> {
    /**
     * Get the children of `element`.
     *
     * @param element The element from which the provider gets children. Unlike a traditional tree data provider, this will never be `undefined`.
     *
     * @return Children of `element`.
     */
    getChildren(element: TModel): vscode.ProviderResult<TModel[]>;

    /**
     * Called to get the provider's model element for a specific resource.
     *
     * @remarks getChildren() assumes that the provider passes a known (TModel) model item, or undefined when getting the "root" children.
     *          However, branch data providers have no "root" so this function is called for each matching resource to obtain a starting branch item.
     *
     * @returns The provider's model element for `resource`.
     */
    getResourceItem(element: TResource): TModel | Thenable<TModel>;
}

Resource provider

Clients register resource providers to add resources to a view. Currently the API is limited to registering Workspace resource providers because a default Azure resource provider is built into the Azure Resources extension.

Note: clients registering resource providers must declare that they do so in their extension manifest. See Extension Manifest

/**
 * The base interface for providers of Azure and workspace resources.
 */
export interface ResourceProvider<TResourceSource, TResource extends ResourceBase> {
    /**
     * Fired when the provider's resources have changed.
     */
    readonly onDidChangeResource?: vscode.Event<TResource | undefined>;

    /**
     * Called to supply the resources used as the basis for the resource views.
     *
     * @param source The source from which resources should be generated.
     *
     * @returns The resources to be displayed in the resource view.
     */
    getResources(source: TResourceSource): vscode.ProviderResult<TResource[]>;
}

Extension manifest

Client extensions define an x-azResources object on inside of contributes in the extension manifest package.json file.

This object informs the host extension when to activate the client extension and what contributions the client extension makes to the shared views.

azure?: {
    /**
     * List of Azure resource types this extension registers a BranchDataProvider for.
     */
    branches: {
        /**
         * The resource type the BranchDataProvider is registered for.
         */
        type: AzExtResourceType
    }[];
};

/**
 * List of Workspace resource types this extension registers a BranchDataProvider for.
 */
workspace?: {
    branches: {
        /**
         * The resource type the BranchDataProvider is registered for.
         */
        type: string;
    }[];

    /**
     * Whether this extension registers a WorkspaceResourceProvider.
     */
    resources?: boolean;
};

/**
 * Commands to add to the "Create Resource..." quick pick prompt.
 */
commands?: {
    command: string;
    title: string;
    detail: string;
    type?: string; // Optional: resource type associated with the command. Used to show an icon next to the command.
}[];

View definition of AzExtResourceType

The contribution object from the Azure Functions extension is shown below as an example.

This extension declares that it registers a BranchDataProvider for the FunctionApp resource type in the Azure resources view, and a BranchDataProvider for the func resource type in the Workspace resources view. It also registers a WorkspaceResourceProvider. Finally, it contributes a command to the "Create Resource..." quick pick prompt for creating a Function App.

{
    "contributes": {
        "x-azResources": {
            "azure": {
                "branches": [
                    // extension registers a BranchDataProvider for Function Apps
                    {
                        "type": "FunctionApp"
                    }
                ]
            },
            "workspace": {
                "branches": [
                    // extension registers a BranchDataProvider for workspace resources of type "func"
                    {
                        "type": "func"
                    }
                ],
                // extension registers a WorkspaceResourceProvider
                "resources": true
            },
            "commands": [
                // extension contributes a command to the "Create Resource..." quick pick prompt
                {
                    "command": "azureFunctions.createFunctionApp",
                    "title": "%azureFunctions.createFunctionApp%",
                    "detail": "%azureFunctions.createFunctionAppDetail%"
                }
            ],
        },
        // other extension contributions
    }
}
"x-azResources": {
    "azure": {
        "branches": [
            {
                "type": "FunctionApp"
            }
        ]
    },
    "workspace": {
        "branches": [
            {
                "type": "func"
            }
        ],
        "resources": true
    },
    "commands": [
        {
            "command": "azureFunctions.createFunctionApp",
            "title": "%azureFunctions.createFunctionApp%",
            "detail": "%azureFunctions.createFunctionAppDetail%"
        }
    ]
}

Getting started

On activation, client extensions can fetch an instance of the Azure Resources API using the getAzureResourcesExtensionApi utility provided by the @microsoft/vscode-azureresources-api package.

import { getAzureResourcesExtensionApi } from '@microsoft/vscode-azureresources-api';

export async function activate(context: vscode.ExtensionContext): Promise<void> {
    const azureResourcesApi = await getAzureResourcesExtensionApi(context, '2.0.0');
    // ...register providers
}

Contributing to the Workspace resources view

view/title commands

Client extensions are encouraged to make commands accessible via the workspace view/title menu. Commands should be grouped by extension into submenus. Submenu icons and titles should be the same as the client extension's icon and title. This is to prevent the view/title menu from becoming too cluttered.

Group workspace view/title commands into submenus

Here's an example of how the Azure Functions extension contributes commands to the workspace view/title menu. See the Azure Functions package.json for reference.

"submenus": [
    // define the submenu
    {
        "id": "azureFunctions.submenus.workspaceActions",
        "icon": "resources/azure-functions.png",
        "label": "Azure Functions"
    }
],
"menus": {
    // add commands to the submenu
    "azureFunctions.submenus.workspaceActions": [
        {
            "command": "azureFunctions.createFunction",
            "group": "1_projects@1"
        },
        {
            "command": "azureFunctions.createNewProject",
            "group": "1_projects@2"
        },
        {
            "command": "azureFunctions.deploy",
            "group": "2_deploy@1"
        },
        {
            "command": "azureFunctions.createFunctionApp",
            "group": "3_create@1"
        },
        {
            "command": "azureFunctions.createFunctionAppAdvanced",
            "group": "3_create@2"
        }
    ],
    // add the submenu to the workspace view/title menu
    "view/title": [
        {
            "submenu": "azureFunctions.submenus.workspaceActions",
            "when": "view == azureWorkspace",
            "group": "navigation@1"
        }
    ],
}

Extension dependencies

Client extensions must declare the Azure Resources extension as an extension dependency in their extension manifest package.json file.

"extensionDependencies": [
    "ms-azuretools.vscode-azureresources"
]

Example extensions

The following extensions are integrated with the Azure Resources API v2. They are great examples of how to use the API.

API Reference

See vscode-azureresources-api.d.ts for the full API definition.

Terms

  • Host extension: Azure Resources extension which exposes the Azure Resources API
  • Host API: Azure Resources API exposed by the host extension
  • Client extension: Extension which consumes the Azure Resources API
  • Azure resources view: Unified view of Azure resources contributed owned by the Azure Resources extension
  • Workspace resources view: Unified view of workspace resources contributed by client extensions
  • Azure resource: A resource that can be represented in the Azure resources view.
  • Workspace resource: Any resource that is located on the local machine, or in the opened workspace.