@azure/provisioning-core

中文文档
1.0.0-alpha.20261107.1发布于 2026/11/08TypeScriptES Module近 30 天下载 3322

Core primitives for the Azure Provisioning library

原始使用文档
文档目录6 节
  1. Major features
  2. Resource authoring
  3. Functions and expressions
  4. Serialization and restoration
  5. Bicep generation
  6. Related packages

@azure/provisioning-core

The runtime for authoring Azure infrastructure in TypeScript: resource trees, symbolic expressions, shared configuration, and JSON and Bicep serialization. Creating or editing these objects changes a deployment definition, not live Azure resources.

Start with Getting started for a walkthrough using core and service classes such as StorageAccount and KeyVault.

Major features

Resource authoring

A deployment definition is a tree of ProvisioningComponent objects. Stack, Resource, and concrete resource classes such as StorageAccount are direct or indirect subclasses of it. Each building block links to its source implementation:

  • ProvisioningComponent - the base class for tree nodes, providing parent-child tracking, inherited deployment context, traversal, and transformations. You can create your own subclass to group related resources, apply shared configuration, and expose resource handles as a reusable component. The component itself does not declare an Azure resource.
  • Stack - the root component of a definition, holding resources and deployment inputs and outputs.
  • Resource - the base for service classes and generic ARM declarations, including existing references, conditions, and dependencies. Writable properties can be edited after construction and before serialization; read-only properties remain available as references.
  • ResourceGroup - a built-in Azure resource that also provides a parent context for its resources.
  • Deployment context - carries inherited location, tags, and naming policy through the component tree. The nearest ancestor supplies location and policy; ancestor tags are merged with nearer values taking precedence.
  • Naming - generates omitted resource names through a configurable policy, using resource naming rules that describe Azure length, character, and uniqueness requirements. These rules guide name generation; explicit names are used unchanged.
  • Parameters - inputs supplied at deployment, with optional defaults and constraints.
  • Variables - named values or expressions shared within the definition.
  • Outputs - values returned by the deployment, such as a resource ID.
  • Resource queries - find authored objects by type or literal name so they can be inspected and edited without querying Azure.

Read more

Functions and expressions

Connect resource settings to parameters, calculations, and other resources even when their values are not yet known. Core preserves these relationships as deployment-time expressions rather than evaluating them in JavaScript.

  • Function helpers - fn builds symbolic operations such as concatenation, comparisons, and resource-ID calculations.
  • Expression types - Expression<T> and ExpressionOrValue<T> describe symbolic and literal values; generated input/view types use core's typing contracts to support nested authoring.
  • Resource property expressions - use resource properties as deployment-time expressions to connect resources, such as passing one resource's ID to another resource's input.

Read more

Deploy-time discriminators

Use asDiscriminator when a deployment expression must fill a literal discriminator. In this example, kindParam is an Expression<"cache">, and widget.properties.primaryRule accepts either a cache rule with cacheKind and days or a redirect rule. The helper selects the cache variant while preserving its property checks.

import { asDiscriminator } from "@azure/provisioning-core";

widget.properties.primaryRule = {
  kind: asDiscriminator(kindParam),
  cacheKind: "long",
  days: 7,
};

Prefer a literal discriminator when possible. This helper is a type assertion, not runtime validation.

Serialization and restoration

serialize converts the tree, values, and references into a JSON-compatible document. deserialize reconstructs supported resource objects so they can be queried, edited, and serialized again. Three pieces support this round trip:

  • Serialization AST - defines the cross-language JSON format for exchanging provisioning definitions between TypeScript and .NET, so both sides interpret resource declarations, values, and references consistently.
  • Runtime shapes - retain client-to-ARM property mappings, nested types, and encoding metadata after TypeScript erasure, guiding value conversion in both directions.
  • Resource registration - resolves registered classes and shapes by resource type, API version, and variant. Load the relevant service packages before restoration so their registrations are available.

Imported scopes resolve to known parent relationships where possible. Otherwise, their expressions are preserved for round-tripping and explicit Bicep rendering without inferring a deployment destination. This does not add explicit scope authoring for new resources.

Read more

Bicep generation

The internal renderBicepFiles API generates Bicep files from authored Stacks.

import { renderBicepFiles } from "@azure/provisioning-core/internal";

for (const file of renderBicepFiles(stack)) {
  console.log(file.path);
  console.log(file.contents);
}

The renderer accepts one Stack or an array of Stacks and returns paths and source text without writing files or deploying resources. Restore saved JSON with deserialize() before rendering it.

See Bicep generation for file layout and cross-file references, and Bicep scopes for deployment scope rules.

For how service classes, their types, and runtime metadata are produced, see Service package anatomy and the TypeSpec emitter overview.

版本与发布记录

@azure/provisioning-core 共发布 20 个版本,首次发布于 2026/09/28;过去 12 个月发布了 20 个版本。

版本发布日期距今
1.0.0-alpha.20261107.1latest2026/11/08今天
1.0.0-alpha.20261106.12026/11/071 天前
1.0.0-alpha.20261105.12026/11/062 天前
1.0.0-alpha.20261104.12026/11/053 天前
1.0.0-alpha.20261103.12026/11/044 天前
1.0.0-alpha.20261102.22026/11/035 天前

其他发布通道:dev → 0.1.0-alpha.20261014.1,beta → 1.0.0-beta.2。

关于 @azure/provisioning-core 的常见问题

@azure/provisioning-core 是什么?

Core primitives for the Azure Provisioning library

如何安装 @azure/provisioning-core?

在项目目录运行 npm install @azure/provisioning-core,或使用 pnpm add / yarn add / bun add。

@azure/provisioning-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azure/provisioning-core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@azure/provisioning-core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@azure/provisioning-core 可以商用吗?

@azure/provisioning-core 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@azure/provisioning-core 的下载量有多少?

根据 npm 官方下载统计,@azure/provisioning-core 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,322 次,日均约 111 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azure/provisioning-core 还在维护吗?

最新版本 1.0.0-alpha.20261107.1 发布于 2026/11/08(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/09/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。