@azure-tools/typespec-azure-resource-manager
Version:
TypeSpec Azure Resource Manager library
189 lines • 9.32 kB
TypeScript
import { ArrayModelType, Model, ModelProperty, Namespace, Program } from "@typespec/compiler";
import { ArmProviderNameValueDecorator, ArmResourceOperationsDecorator, ArmVirtualResourceDecorator, ExtensionResourceDecorator, IdentifiersDecorator, LocationResourceDecorator, ResourceBaseTypeDecorator, ResourceGroupResourceDecorator, SingletonDecorator, SubscriptionResourceDecorator, TenantResourceDecorator } from "../generated-defs/Azure.ResourceManager.js";
import { CustomAzureResourceDecorator } 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;
}
/** 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 base details for resolved resources */
export interface ResourceMetadata {
/** 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;
}
/** New details for a resolved resource */
export interface ResolvedResource extends ResourceMetadata {
/** The set of resolved operations for a resource. For most
resources there will be 1 returned record */
operations?: ResolvedOperations[];
}
export interface ResolvedResources {
resources?: ResolvedResource[];
unassociatedOperations?: ArmResourceOperation[];
}
export interface ResolvedOperationResourceInfo {
/** 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;
}
/** Resolved operations, including operations for non-arm resources */
export interface ResolvedOperations extends ResolvedOperationResourceInfo {
/** The lifecycle and action operations using this resourceInstancePath (or the parent path) */
operations: ArmResolvedOperationsForResource;
/** Other operations associated with this resource */
associatedOperations?: ArmResourceOperation[];
}
/** 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;
/**
* 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) => ResolvedResources | undefined, setResolvedResources: (program: Program, type: Namespace, value: ResolvedResources) => void;
export declare function resolveArmResources(program: Program): ResolvedResources;
export declare function getResourcePathElements(path: string, kind: ArmOperationKind): ResolvedOperationResourceInfo | undefined;
export declare function isResourceOperationMatch(source: {
resourceType: ResourceType;
resourceInstancePath: string;
}, target: {
resourceType: ResourceType;
resourceInstancePath: string;
}): boolean;
export declare function getUnassociatedOperations(program: Program): ArmResourceOperation[];
export declare function resolveArmResourceOperations(program: Program, resourceType: Model): ResolvedOperations[];
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): 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