@azure-tools/typespec-azure-resource-manager
Version:
TypeSpec Azure Resource Manager library
235 lines • 11.7 kB
TypeScript
import { ArrayModelType, Model, ModelProperty, Namespace, Operation, Program } from "@typespec/compiler";
import { ArmProviderNameValueDecorator, ArmResourceOperationsDecorator, ArmVirtualResourceDecorator, ExtensionResourceDecorator, IdentifiersDecorator, LocationResourceDecorator, ResourceBaseTypeDecorator, ResourceGroupResourceDecorator, SingletonDecorator, SubscriptionResourceDecorator, TenantResourceDecorator } from "../generated-defs/Azure.ResourceManager.js";
import { ArmExternalTypeDecorator, CustomAzureResourceDecorator, CustomResourceOptions } from "../generated-defs/Azure.ResourceManager.Legacy.js";
import { ArmOperationKind, ArmResolvedOperationsForResource, ArmResourceOperation, ArmResourceOperations } from "./operations.js";
export type ArmResourceKind = "Tracked" | "Proxy" | "Extension" | "Virtual" | "Custom" | "BuiltIn";
/**
* The base details for all kinds of resources
*
* @interface
*/
export interface ArmResourceDetailsBase {
/**
* The name of the resource.
*/
name: string;
/** The category of resource */
kind: ArmResourceKind;
/** The RP namespace */
armProviderNamespace: string;
/** The name parameter for the resource */
keyName: string;
/** The type name / collection name of the resource */
collectionName: string;
/** A reference to the TypeSpec type */
typespecType: Model;
}
export declare const isArmExternalType: (program: Program, type: Model) => boolean | undefined, setArmExternalType: (program: Program, type: Model, value: boolean) => void;
export declare const $armExternalType: ArmExternalTypeDecorator;
/** Details for RP resources */
export interface ArmResourceDetails extends ArmResourceDetailsBase {
/** The set of lifecycle operations and actions for the resource */
operations: ArmResourceOperations;
/** RPaaS-specific value for resource type */
resourceTypePath?: string;
}
/** Representation of a resource used but not provided by the RP */
export interface ArmVirtualResourceDetails {
/** The base kind for resources not provided by RPs */
kind: "Virtual";
/** The provider namespace for the provider of this resource */
provider?: string;
}
/** New details for a resolved resource */
export interface ResourceModel {
/** The model type for the resource */
type: Model;
/** The kind of resource (extension | tracked | proxy | custom | virtual | built-in) */
kind: ArmResourceKind;
/** The provider namespace */
providerNamespace: string;
/** The set of resolved operations for a resource. For most
resources there will be 1 returned record */
resources?: ResolvedResource[];
}
export interface Provider {
/** The set of resources in this provider */
resources?: ResolvedResource[];
/** non-resource operations in this provider */
providerOperations?: ArmResourceOperation[];
}
export interface ResourcePathInfo {
/** The resource type (The actual resource type string will be "${provider}/${types.join("/")}) */
resourceType: ResourceType;
/** The path to the instance of a resource */
resourceInstancePath: string;
}
export interface ResolvedResourceInfo {
/** The resource type (The actual resource type string will be "${provider}/${types.join("/")}) */
resourceType: ResourceType;
/** The path to the instance of a resource */
resourceInstancePath: string;
/** The name of the resource at this instance path */
resourceName: string;
}
interface ResolvedResourceOperations {
operations: ArmResolvedOperationsForResource;
/** Other operations associated with this resource */
associatedOperations?: ArmResourceOperation[];
/** The name of the resource at this instance path */
resourceName: string;
/** The resource type (The actual resource type string will be "${provider}/${types.join("/")}) */
resourceType: ResourceType;
/** The path to the instance of a resource */
resourceInstancePath: string;
/** The parent of this resource */
parent?: ResolvedResource;
/** The scope of this resource */
scope?: string;
}
/** Resolved operations, including operations for non-arm resources */
export interface ResolvedResource {
/** The model type for the resource */
type: Model;
/** The kind of resource (extension | tracked | proxy | custom | virtual | built-in) */
kind: "Tracked" | "Proxy" | "Extension" | "Other";
/** The provider namespace */
providerNamespace: string;
/** The lifecycle and action operations using this resourceInstancePath (or the parent path) */
operations: ArmResolvedOperationsForResource;
/** Other operations associated with this resource */
associatedOperations?: ArmResourceOperation[];
/** The name of the resource at this instance path */
resourceName: string;
/** The resource type (The actual resource type string will be "${provider}/${types.join("/")}) */
resourceType: ResourceType;
/** The path to the instance of a resource */
resourceInstancePath: string;
/** The parent of this resource */
parent?: ResolvedResource;
/** The scope of this resource */
scope?: string | ResolvedResource;
}
/** Description of the resource type */
export interface ResourceType {
/** The provider namespace */
provider: string;
/** The type of the resource, including all ancestor types (in order) */
types: string[];
}
/**
* Marks the given resource as an external resource
* @param context The decorator context
* @param entity The resource model
* @param propertiesType The type of the resource properties
*/
export declare const $armVirtualResource: ArmVirtualResourceDecorator;
export declare const $customAzureResource: CustomAzureResourceDecorator;
/**
* Determine if the given model is an external resource.
* @param program The program to process.
* @param target The model to check.
* @returns true if the model or any model it extends is marked as a resource, otherwise false.
*/
export declare function isArmVirtualResource(program: Program, target: Model): boolean;
/**
*
* @param program The program to process.
* @param target The model to get details for
* @returns The resource details if the model is an external resource, otherwise undefined.
*/
export declare function getArmVirtualResourceDetails(program: Program, target: Model, visited?: Set<Model>): ArmVirtualResourceDetails | undefined;
declare const getCustomResourceOptions: (program: Program, type: Model) => CustomResourceOptions | undefined;
export { getCustomResourceOptions };
/**
* Determine if the given model is a custom resource.
* @param program The program to process.
* @param target The model to check.
* @returns true if the model or any model it extends is marked as a resource, otherwise false.
*/
export declare function isCustomAzureResource(program: Program, target: Model): boolean;
/**
* This function returns fully-resolved details about all ARM resources
* registered in the TypeSpec document including operations and their details.
*
* It should only be called after the full TypeSpec document has been compiled
* so that operation route details are certain to be present.
*/
export declare function getArmResources(program: Program): ArmResourceDetails[];
export declare const getResolvedResources: (program: Program, type: Namespace) => Provider | undefined, setResolvedResources: (program: Program, type: Namespace, value: Provider) => void;
export declare function getPublicResourceKind(typespecType: Model): "Tracked" | "Proxy" | "Extension" | "Other" | undefined;
export declare function resolveArmResources(program: Program): Provider;
export declare function getResourcePathElements(path: string, kind: ArmOperationKind): ResourcePathInfo | undefined;
export declare function isResourceOperationMatch(source: {
resourceType: ResourceType;
resourceInstancePath: string;
resourceName?: string;
}, target: {
resourceType: ResourceType;
resourceInstancePath: string;
resourceName?: string;
}): boolean;
export declare function getUnassociatedOperations(program: Program): ArmResourceOperation[];
export declare function getResourceOperation(program: Program, operation: Operation): ArmResourceOperation | undefined;
export declare function resolveArmResourceOperations(program: Program, resourceType: Model): ResolvedResourceOperations[];
export { getArmResource } from "./private.decorators.js";
export declare function getArmResourceInfo(program: Program, resourceType: Model): ArmResourceDetails | undefined;
export declare function getArmResourceKind(resourceType: Model): ArmResourceKind | undefined;
/**
* This decorator is used to identify interfaces containing resource operations.
* When applied, it marks the interface with the `@autoRoute` decorator so that
* all of its contained operations will have their routes generated
* automatically.
*
* It also adds a `@tag` decorator bearing the name of the interface so that all
* of the operations will be grouped based on the interface name in generated
* clients.
*/
export declare const $armResourceOperations: ArmResourceOperationsDecorator;
/**
* This decorator is used to mark a resource type as a "singleton", a type with
* only one instance. The standard set of resource operations can be applied to
* such a resource type, they will generate the correct routes and parameter
* lists.
*/
export declare const $singleton: SingletonDecorator;
export declare function isSingletonResource(program: Program, resourceType: Model): boolean;
export declare function getSingletonResourceKey(program: Program, resourceType: Model): string | undefined;
export declare enum ResourceBaseType {
Tenant = "Tenant",
Subscription = "Subscription",
Location = "Location",
ResourceGroup = "ResourceGroup",
Extension = "Extension",
BuiltIn = "BuiltIn",
BuiltInSubscription = "BuiltInSubscription",
BuiltInResourceGroup = "BuiltInResourceGroup"
}
export declare const $resourceBaseType: ResourceBaseTypeDecorator;
export declare const $tenantResource: TenantResourceDecorator;
export declare const $subscriptionResource: SubscriptionResourceDecorator;
export declare const $locationResource: LocationResourceDecorator;
export declare const $resourceGroupResource: ResourceGroupResourceDecorator;
export declare const $extensionResource: ExtensionResourceDecorator;
export declare const $armProviderNameValue: ArmProviderNameValueDecorator;
export declare const $identifiers: IdentifiersDecorator;
/**
* This function returns identifiers using the '@identifiers' decorator
*
* @param program The program to process.
* @param entity The array model type to check.
* @returns returns list of arm identifiers for the given array model type if any or undefined.
*/
export declare function getArmIdentifiers(program: Program, entity: ModelProperty | Model): string[] | undefined;
/**
* This function returns identifiers using the '@key' decorator.
*
* @param program The program to process.
* @param entity The array model type to check.
* @returns returns list of arm identifiers for the given array model type if any or undefined.
*/
export declare function getArmKeyIdentifiers(program: Program, entity: ArrayModelType): string[] | undefined;
export declare function setResourceBaseType(program: Program, resource: Model, type: string): void;
export declare function getResourceBaseType(program: Program, resource: Model): ResourceBaseType;
export declare function resolveResourceBaseType(type?: string | undefined): ResourceBaseType;
//# sourceMappingURL=resource.d.ts.map