@azure-tools/typespec-azure-resource-manager 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +346 -0
  3. package/dist/src/common-types.d.ts +8 -0
  4. package/dist/src/common-types.d.ts.map +1 -0
  5. package/dist/src/common-types.js +14 -0
  6. package/dist/src/common-types.js.map +1 -0
  7. package/dist/src/index.d.ts +7 -0
  8. package/dist/src/index.d.ts.map +1 -0
  9. package/dist/src/index.js +7 -0
  10. package/dist/src/index.js.map +1 -0
  11. package/dist/src/internal.d.ts +44 -0
  12. package/dist/src/internal.d.ts.map +1 -0
  13. package/dist/src/internal.js +142 -0
  14. package/dist/src/internal.js.map +1 -0
  15. package/dist/src/lib.d.ts +615 -0
  16. package/dist/src/lib.d.ts.map +1 -0
  17. package/dist/src/lib.js +250 -0
  18. package/dist/src/lib.js.map +1 -0
  19. package/dist/src/linter.d.ts +3 -0
  20. package/dist/src/linter.d.ts.map +1 -0
  21. package/dist/src/linter.js +42 -0
  22. package/dist/src/linter.js.map +1 -0
  23. package/dist/src/namespace.d.ts +16 -0
  24. package/dist/src/namespace.d.ts.map +1 -0
  25. package/dist/src/namespace.js +106 -0
  26. package/dist/src/namespace.js.map +1 -0
  27. package/dist/src/operations.d.ts +36 -0
  28. package/dist/src/operations.d.ts.map +1 -0
  29. package/dist/src/operations.js +186 -0
  30. package/dist/src/operations.js.map +1 -0
  31. package/dist/src/resource.d.ts +81 -0
  32. package/dist/src/resource.d.ts.map +1 -0
  33. package/dist/src/resource.js +358 -0
  34. package/dist/src/resource.js.map +1 -0
  35. package/dist/src/rules/arm-resource-action-no-segment.d.ts +2 -0
  36. package/dist/src/rules/arm-resource-action-no-segment.d.ts.map +1 -0
  37. package/dist/src/rules/arm-resource-action-no-segment.js +31 -0
  38. package/dist/src/rules/arm-resource-action-no-segment.js.map +1 -0
  39. package/dist/src/rules/arm-resource-invalid-chars.d.ts +2 -0
  40. package/dist/src/rules/arm-resource-invalid-chars.d.ts.map +1 -0
  41. package/dist/src/rules/arm-resource-invalid-chars.js +61 -0
  42. package/dist/src/rules/arm-resource-invalid-chars.js.map +1 -0
  43. package/dist/src/rules/arm-resource-invalid-version-format.d.ts +2 -0
  44. package/dist/src/rules/arm-resource-invalid-version-format.d.ts.map +1 -0
  45. package/dist/src/rules/arm-resource-invalid-version-format.js +48 -0
  46. package/dist/src/rules/arm-resource-invalid-version-format.js.map +1 -0
  47. package/dist/src/rules/arm-resource-operations.d.ts +2 -0
  48. package/dist/src/rules/arm-resource-operations.d.ts.map +1 -0
  49. package/dist/src/rules/arm-resource-operations.js +70 -0
  50. package/dist/src/rules/arm-resource-operations.js.map +1 -0
  51. package/dist/src/rules/arm-resource-properties.d.ts +2 -0
  52. package/dist/src/rules/arm-resource-properties.d.ts.map +1 -0
  53. package/dist/src/rules/arm-resource-properties.js +55 -0
  54. package/dist/src/rules/arm-resource-properties.js.map +1 -0
  55. package/dist/src/rules/arm-resource-provisioning-state-rule.d.ts +2 -0
  56. package/dist/src/rules/arm-resource-provisioning-state-rule.d.ts.map +1 -0
  57. package/dist/src/rules/arm-resource-provisioning-state-rule.js +62 -0
  58. package/dist/src/rules/arm-resource-provisioning-state-rule.js.map +1 -0
  59. package/dist/src/rules/beyond-nesting-levels.d.ts +5 -0
  60. package/dist/src/rules/beyond-nesting-levels.d.ts.map +1 -0
  61. package/dist/src/rules/beyond-nesting-levels.js +37 -0
  62. package/dist/src/rules/beyond-nesting-levels.js.map +1 -0
  63. package/dist/src/rules/core-operations.d.ts +2 -0
  64. package/dist/src/rules/core-operations.d.ts.map +1 -0
  65. package/dist/src/rules/core-operations.js +181 -0
  66. package/dist/src/rules/core-operations.js.map +1 -0
  67. package/dist/src/rules/delete-operation.d.ts +5 -0
  68. package/dist/src/rules/delete-operation.d.ts.map +1 -0
  69. package/dist/src/rules/delete-operation.js +28 -0
  70. package/dist/src/rules/delete-operation.js.map +1 -0
  71. package/dist/src/rules/envelope-properties.d.ts +5 -0
  72. package/dist/src/rules/envelope-properties.d.ts.map +1 -0
  73. package/dist/src/rules/envelope-properties.js +62 -0
  74. package/dist/src/rules/envelope-properties.js.map +1 -0
  75. package/dist/src/rules/list-operation.d.ts +5 -0
  76. package/dist/src/rules/list-operation.d.ts.map +1 -0
  77. package/dist/src/rules/list-operation.js +35 -0
  78. package/dist/src/rules/list-operation.js.map +1 -0
  79. package/dist/src/rules/no-response-body.d.ts +5 -0
  80. package/dist/src/rules/no-response-body.d.ts.map +1 -0
  81. package/dist/src/rules/no-response-body.js +27 -0
  82. package/dist/src/rules/no-response-body.js.map +1 -0
  83. package/dist/src/rules/operations-interface-missing.d.ts +5 -0
  84. package/dist/src/rules/operations-interface-missing.d.ts.map +1 -0
  85. package/dist/src/rules/operations-interface-missing.js +37 -0
  86. package/dist/src/rules/operations-interface-missing.js.map +1 -0
  87. package/dist/src/rules/resource-name.d.ts +5 -0
  88. package/dist/src/rules/resource-name.d.ts.map +1 -0
  89. package/dist/src/rules/resource-name.js +47 -0
  90. package/dist/src/rules/resource-name.js.map +1 -0
  91. package/dist/src/rules/retry-after.d.ts +5 -0
  92. package/dist/src/rules/retry-after.d.ts.map +1 -0
  93. package/dist/src/rules/retry-after.js +31 -0
  94. package/dist/src/rules/retry-after.js.map +1 -0
  95. package/dist/src/rules/unsupported-types.d.ts +5 -0
  96. package/dist/src/rules/unsupported-types.d.ts.map +1 -0
  97. package/dist/src/rules/unsupported-types.js +39 -0
  98. package/dist/src/rules/unsupported-types.js.map +1 -0
  99. package/dist/src/rules/utils.d.ts +18 -0
  100. package/dist/src/rules/utils.d.ts.map +1 -0
  101. package/dist/src/rules/utils.js +77 -0
  102. package/dist/src/rules/utils.js.map +1 -0
  103. package/dist/src/testing/index.d.ts +3 -0
  104. package/dist/src/testing/index.d.ts.map +1 -0
  105. package/dist/src/testing/index.js +24 -0
  106. package/dist/src/testing/index.js.map +1 -0
  107. package/lib/arm.foundations.tsp +465 -0
  108. package/lib/arm.tsp +31 -0
  109. package/lib/decorators.tsp +87 -0
  110. package/lib/interfaces.tsp +287 -0
  111. package/lib/models.tsp +203 -0
  112. package/lib/operations.tsp +260 -0
  113. package/lib/parameters.tsp +126 -0
  114. package/lib/responses.tsp +47 -0
  115. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md ADDED
@@ -0,0 +1,346 @@
1
+ # TypeSpec Azure Resource Manager Library
2
+
3
+ This is a library that provides model types and interfaces which can be used to define an Azure Resource Manager service API.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Getting Started](#getting-started)
8
+ - [Creating a project with `tsp init`](#creating-a-project-with-typespec-init)
9
+ - [Creating a project manually](#creating-a-project-manually)
10
+ - [Concepts](#concepts)
11
+ - [Defining the Service](#defining-the-service)
12
+ - [Defining Resource Types](#defining-resource-types)
13
+ - [Generating an OpenAPI Specification](#generating-an-openapi-specification)
14
+ - [A Complete Example](#a-complete-example)
15
+
16
+ ## Getting Started
17
+
18
+ To author an Azure Resource Manager service definition, you will first need to create a TypeSpec project for your service.
19
+ The easiest way to do that is to follow the instructions on this page:
20
+
21
+ https://github.com/Azure/typespec-azure/blob/main/packages/typespec-providerhub-templates/README.md#getting-started
22
+
23
+ ## Concepts
24
+
25
+ Before using this library, you should familiarize yourself with the TypeSpec language and tools. You can do this by reading the [TypeSpec tutorial](https://github.com/microsoft/typespec/blob/main/docs/tutorial.md).
26
+
27
+ ### Defining the Service
28
+
29
+ To define an Azure Resource Manager service, the first thing you will need to do is define the service namespace and decorate it with the `serviceTitle`, `serviceVersion` and `armProviderNamespace` decorators:
30
+
31
+ ```typespec
32
+ @armProviderNamespace
33
+ @service({title: "<service name>", version: "<service version>"})
34
+ namespace <mynamespace>;
35
+ ```
36
+
37
+ For example:
38
+
39
+ ```typespec
40
+ @armProviderNamespace
41
+ @service({
42
+ title: "Contoso User Service",
43
+ version: "2020-10-01-preview",
44
+ })
45
+ namespace Contoso.Users;
46
+ ```
47
+
48
+ ### The `using` keyword
49
+
50
+ Just after the `namespace` declaration, you will also need to include a few `using` statements to pull in symbols from the namespaces of libraries you will for your specification.
51
+
52
+ For example, these lines pull in symbols from the `@typespec/rest` and `@azure-tools/typespec-azure-resource-manager`:
53
+
54
+ ```
55
+ using TypeSpec.Http;
56
+ using TypeSpec.Rest;
57
+ using Azure.ResourceManager;
58
+ ```
59
+
60
+ ### Defining Resource Types
61
+
62
+ A resource provider is composed of resources. The TypeSpec Azure Resource Manager library makes it much easier to define the structure and endpoints of such resources.
63
+
64
+ There are three essential components of a resource defined with TypeSpec:
65
+
66
+ - A model type representing the resource, derived from one of the [base resource types](#base-resource-types)
67
+ - A model type defining the properties of the resource type
68
+ - An interface that defines the operations that can be performed on the resource type, usually a combination of [standard resource operations](#standard-resource-operations) and [custom actions](#custom-actions)
69
+
70
+ Read the [TypeSpec tutorial](https://github.com/Microsoft/typespec/blob/main/docs/tutorial.md) to learn the basics about TypeSpec model types and interfaces.
71
+
72
+ #### 1. **Define a model representing the `properties` of the ARM resource**
73
+
74
+ Each resource type must have a properties type which defines its custom properties. This type will be exposed as the `properties` property of the resource type.
75
+
76
+ ```typespec
77
+ @doc("The properties of UserResource")
78
+ model UserResourceProperties {
79
+ @doc("The user's full name")
80
+ fullName: string;
81
+
82
+ @doc("The user's email address.")
83
+ emailAddress: string;
84
+ }
85
+ ```
86
+
87
+ #### 2. **Define a model representing the resource type**
88
+
89
+ Resource types are defined as plain models which pull in a standard resource type using the `is` keyword.
90
+
91
+ You define a resource type, you need the following:
92
+
93
+ - A `name` property which is marked with the following decorators
94
+ - `@key`: Specifies the parameter name for this resource type in the service URI hierarchy
95
+ - `@segment`: Specifies the name of the resource "collection", the URI segment that comes just before the parameter name which identifies the resource type
96
+ - A second model type which defines the resource type's custom properties as we described in step 1
97
+
98
+ Here we define a tracked resource called `UserResource`:
99
+
100
+ ```typespec
101
+ @doc("A UserResource")
102
+ model UserResource is TrackedResource<UserResourceProperties> {
103
+ @key("userName")
104
+ @segment("users")
105
+ name: string;
106
+ }
107
+ ```
108
+
109
+ #### 3. **Define an interface with operations for the resource type**
110
+
111
+ ```typespec
112
+ @armResourceOperations
113
+ interface Users extends TrackedResourceOperations<UserResource> {}
114
+ ```
115
+
116
+ This will now produce all the endpoints(`get`, `post`, `put`, `patch` and `delete`, listByResourceGroup, listBySubscription) for a resource called `UserResources` and the `operations` endpoint for the service:
117
+
118
+ | Method & Path | Description |
119
+ | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
120
+ | `GET /providers/Contoso.Users/operations` | List all operations for your service |
121
+ | `GET /subscriptions/{subscriptionId}/providers/Contoso.Users/users` | list all UserResource by subscription |
122
+ | `GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Contoso.Users/users` | list all UserResource by resource group |
123
+ | `GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Contoso.Users/users/{userName}` | get item |
124
+ | `PUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Contoso.Users/users/{userName}` | insert item |
125
+ | `PATCH /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Contoso.Users/users/{userName}` | patch item |
126
+ | `DELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Contoso.Users/users/{userName}` | delete item |
127
+
128
+ #### Base Resource Types
129
+
130
+ Here are the base resource types you can use when defining your own ARM resources:
131
+
132
+ | Name | Description |
133
+ | ------------------------------ | -------------------------------------------------------------------------------------- |
134
+ | TrackedResource<TProperties> | Defines a normal ARM resource where `TProperties` is the model of the `properties` |
135
+ | ProxyResource<TProperties> | Defines a proxy ARM resource where `TProperties` is the model of the `properties` |
136
+ | ExtensionResource<TProperties> | Defines an extension ARM resource where `TProperties` is the model of the `properties` |
137
+
138
+ ### Defining Child Resource Types
139
+
140
+ You can create parent/child relationships between resource types by using the `@parentResource` decorator when defining a resource type.
141
+
142
+ For example, here's how you could create a new `AddressResource` resource under the `UserResource` defined above:
143
+
144
+ ```typespec
145
+ @doc("An address resource belonging to a user resource.")
146
+ @parentResource(UserResource)
147
+ model AddressResource is ProxyResource<AddressResourceProperties> {
148
+ @key("addressName")
149
+ @segment("addresses")
150
+ name: string;
151
+ }
152
+
153
+ @doc("The properties of AddressResource")
154
+ model AddressResourceProperties {
155
+ @doc("The street address.")
156
+ streetAddress: string;
157
+
158
+ @doc("The city of the address.")
159
+ city: string;
160
+
161
+ @doc("The state of the address.")
162
+ state: string;
163
+
164
+ @doc("The zip code of the address.")
165
+ zip: int32;
166
+ }
167
+
168
+ @armResourceOperations
169
+ interface Addresses extends ProxyResourceOperations<AddressResource> {}
170
+ ```
171
+
172
+ ### Defining Custom Actions
173
+
174
+ Some resources will provide more than the standard CRUD operations and will need to define a custom action endpoint. Additional resource operations can be added to the `interface` where you pulled in standard resource operations.
175
+
176
+ For example, to add an additional `POST` action called `/notify` to the standard operations of `UserResource`:
177
+
178
+ ```typespec
179
+ @doc("The details of a user notification.")
180
+ model NotificationDetails {
181
+ @doc("The notification message.")
182
+ message: string;
183
+
184
+ @doc("If true, the notification is urgent.")
185
+ urgent: boolean;
186
+ }
187
+
188
+ @armResourceOperations
189
+ interface Users extends TrackedResourceOperations<UserResource, UserResourceProperties> {
190
+ @post
191
+ @doc("Send a notification to the user")
192
+ @segment("notify")
193
+ NotifyUser(
194
+ ...ResourceInstanceParameters<UserResource>,
195
+ @body notification: NotificationDetails
196
+ ): ArmResponse<string> | ErrorResponse;
197
+ }
198
+ ```
199
+
200
+ #### ARM Response Types
201
+
202
+ Custom operations in ARM still need to respect the correct response schema. This library provides standard ARM response types to help with reusability and compliance.
203
+
204
+ | Model | Code | Description |
205
+ | ----------------------------- | ---- | --------------------------------------------- |
206
+ | `ArmResponse<T>` | 200 | Base Arm 200 response. |
207
+ | `ArmCreatedResponse<T>` | 201 | Resource created response |
208
+ | `ArmDeletedResponse` | 200 | Resource deleted response |
209
+ | `ArmDeleteAcceptedResponse` | 202 | Resource deletion in progress response |
210
+ | `ArmDeletedNoContentResponse` | 204 | Resource deleted response |
211
+ | `Page<T>` | 200 | Return a list of resource with ARM pagination |
212
+ | `ErrorResponse<T>` | x | Error response |
213
+
214
+ #### Common Operation Parameters
215
+
216
+ There are a number of model types which specify common parameters which are used in resource type operations:
217
+
218
+ | Model | In | Description |
219
+ | ---------------------------- | ------------ | ------------------------------------------------------------------ |
220
+ | `ApiVersionParameter` | query | `api-version` parameter |
221
+ | `SubscriptionIdParameter` | path | Subscription ID path parameter |
222
+ | `ResourceGroupNameParameter` | path | Resource Group Name path parameter |
223
+ | `CommonResourceParameters` | path & query | Group of Api version, Subscription ID and Resource group parameter |
224
+ | `ResourceUriParameter` | path | Resource uri path parameter |
225
+ | `OperationIdParameter` | path | Operation Id path parameter |
226
+
227
+ ## Generating an OpenAPI Specification
228
+
229
+ To generate an OpenAPI v2 (Swagger) specification from the service definition, run the following command inside of the project folder:
230
+
231
+ ```
232
+ tsp compile . --emit @azure-tools/typespec-autorest
233
+ ```
234
+
235
+ This will create a file in the `tsp-output` subfolder called `openapi.json`.
236
+
237
+ ## A Complete Example
238
+
239
+ Here's a complete example `main.tsp` file based on all of the snippets in this README:
240
+
241
+ ```typespec
242
+ import "@typespec/http";
243
+ import "@typespec/rest";
244
+ import "@typespec/versioning";
245
+ import "@azure-tools/typespec-providerhub";
246
+ import "@azure-tools/typespec-azure-core";
247
+ import "@azure-tools/typespec-azure-resource-manager";
248
+
249
+ using TypeSpec.Http;
250
+ using TypeSpec.Rest;
251
+ using TypeSpec.Versioning;
252
+ using Azure.Core;
253
+ using Azure.ResourceManager;
254
+
255
+ @armProviderNamespace
256
+ @service({
257
+ title: "ContosoProviderHubClient",
258
+ version: "2021-01-01-preview",
259
+ })
260
+ @doc("Contoso Resource Provider management API.")
261
+ @versionedDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
262
+ namespace Microsoft.ContosoProviderHub;
263
+
264
+ interface Operations extends Azure.ResourceManager.Operations {}
265
+
266
+ @lroStatus
267
+ enum ProvisioningState {
268
+ ...ResourceProvisioningState,
269
+ Provisioning,
270
+ Updating,
271
+ Deleting,
272
+ Accepted,
273
+ }
274
+
275
+ @doc("The properties of UserResource")
276
+ model UserResourceProperties {
277
+ @doc("The user's full name")
278
+ fullName: string;
279
+
280
+ @doc("The user's email address.")
281
+ emailAddress: string;
282
+
283
+ @doc("The status of the last operation.")
284
+ provisioningState?: ProvisioningState;
285
+ }
286
+
287
+ @doc("A UserResource")
288
+ model UserResource is TrackedResource<UserResourceProperties> {
289
+ @key("userName")
290
+ @segment("users")
291
+ @doc("Address name")
292
+ @path
293
+ name: string;
294
+ }
295
+
296
+ @doc("The details of a user notification.")
297
+ model NotificationDetails {
298
+ @doc("The notification message.")
299
+ message: string;
300
+
301
+ @doc("If true, the notification is urgent.")
302
+ urgent: boolean;
303
+ }
304
+
305
+ @armResourceOperations
306
+ interface Users extends TrackedResourceOperations<UserResource, UserResourceProperties> {
307
+ @post
308
+ @doc("Send a notification to the user")
309
+ @segment("notify")
310
+ notifyUser(
311
+ ...ResourceInstanceParameters<UserResource>,
312
+ @body notification: NotificationDetails
313
+ ): ArmResponse<string> | ErrorResponse;
314
+ }
315
+
316
+ @doc("An address resource belonging to a user resource.")
317
+ @parentResource(UserResource)
318
+ model AddressResource is ProxyResource<AddressResourceProperties> {
319
+ @doc("Address name")
320
+ @key("addressName")
321
+ @segment("addresses")
322
+ @path
323
+ name: string;
324
+ }
325
+
326
+ @doc("The properties of AddressResource")
327
+ model AddressResourceProperties {
328
+ @doc("The street address.")
329
+ streetAddress: string;
330
+
331
+ @doc("The city of the address.")
332
+ city: string;
333
+
334
+ @doc("The state of the address.")
335
+ state: string;
336
+
337
+ @doc("The zip code of the address.")
338
+ zip: int32;
339
+
340
+ @doc("The status of the last operation.")
341
+ provisioningState?: ProvisioningState;
342
+ }
343
+
344
+ @armResourceOperations
345
+ interface Addresses extends ProxyResourceOperations<AddressResource> {}
346
+ ```
@@ -0,0 +1,8 @@
1
+ import { Type } from "@typespec/compiler";
2
+ /**
3
+ * Check if a given model or model property is an ARM common type.
4
+ * @param {Type} entity - The entity to be checked.
5
+ * @return {boolean} - A boolean value indicating whether an entity is an ARM common type.
6
+ */
7
+ export declare function isArmCommonType(entity: Type): boolean;
8
+ //# sourceMappingURL=common-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-types.d.ts","sourceRoot":"","sources":["../../src/common-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAQrD"}
@@ -0,0 +1,14 @@
1
+ import { isTypeSpecValueTypeOf } from "@typespec/compiler";
2
+ /**
3
+ * Check if a given model or model property is an ARM common type.
4
+ * @param {Type} entity - The entity to be checked.
5
+ * @return {boolean} - A boolean value indicating whether an entity is an ARM common type.
6
+ */
7
+ export function isArmCommonType(entity) {
8
+ const commonDecorators = ["$armCommonDefinition", "$armCommonParameter"];
9
+ if (isTypeSpecValueTypeOf(entity, ["Model", "ModelProperty"])) {
10
+ return commonDecorators.some((commonDecorator) => entity.decorators.some((d) => d.decorator.name === commonDecorator));
11
+ }
12
+ return false;
13
+ }
14
+ //# sourceMappingURL=common-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-types.js","sourceRoot":"","sources":["../../src/common-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAQ,MAAM,oBAAoB,CAAC;AAEjE;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAY;IAC1C,MAAM,gBAAgB,GAAG,CAAC,sBAAsB,EAAE,qBAAqB,CAAC,CAAC;IACzE,IAAI,qBAAqB,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE;QAC7D,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE,CAC/C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,KAAK,eAAe,CAAC,CACpE,CAAC;KACH;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const namespace = "Azure.ResourceManager";
2
+ export * from "./common-types.js";
3
+ export * from "./linter.js";
4
+ export * from "./namespace.js";
5
+ export * from "./operations.js";
6
+ export * from "./resource.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,0BAA0B,CAAC;AAEjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,7 @@
1
+ export const namespace = "Azure.ResourceManager";
2
+ export * from "./common-types.js";
3
+ export * from "./linter.js";
4
+ export * from "./namespace.js";
5
+ export * from "./operations.js";
6
+ export * from "./resource.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAEjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,44 @@
1
+ export declare const namespace = "Azure.ResourceManager.Foundations";
2
+ import { DecoratorContext, Interface, Program, Type } from "@typespec/compiler";
3
+ /**
4
+ * Using ARM common definition for a Model
5
+ * @param {DecoratorContext} context DecoratorContext object
6
+ * @param {Type} entity Decorator target type. Must be `Model`
7
+ * @param {string?} definitionName Optional definition name
8
+ * @param {string?} version Optional version
9
+ * @param {string?} referenceFile Optional common file path
10
+ * @returns {void}
11
+ */
12
+ export declare function $armCommonDefinition(context: DecoratorContext, entity: Type, definitionName?: string, version?: string, referenceFile?: string): void;
13
+ /**
14
+ * Refer an model property to be a common ARM parameter
15
+ * @param {DecoratorContext} context DecoratorContext object
16
+ * @param {Type} entity Decorator target type. Must be `Model`
17
+ * @param {string?} definitionName Optional definition name
18
+ * @param {string?} version Optional version
19
+ * @param {string?} referenceFile Optional common file path
20
+ * @returns void
21
+ */
22
+ export declare function $armCommonParameter(context: DecoratorContext, entity: Type, parameterName?: string, version?: string, referenceFile?: string): void;
23
+ /**
24
+ * This decorator dynamically assigns the serviceNamespace from the containing
25
+ * namespace to the string literal value of the path parameter to which this
26
+ * decorator is applied. Its purpose is to dynamically insert the provider
27
+ * namespace (e.g. 'Microsoft.CodeSigning') into the path parameter list.
28
+ * @param {DecoratorContext} context DecoratorContext
29
+ * @param {Type} target Target of this decorator. Must be a string `ModelProperty`.
30
+ * @param {Type} resourceType Must be a `Model`.
31
+ */
32
+ export declare function $assignProviderNameValue(context: DecoratorContext, target: Type, resourceType: Type): void;
33
+ /**
34
+ * Update the ARM provider namespace for a given entity.
35
+ * @param {DecoratorContext} context DecoratorContext
36
+ * @param {Type} entity Entity to set namespace. Must be a `Operation`.
37
+ * @returns
38
+ */
39
+ export declare function $armUpdateProviderNamespace(context: DecoratorContext, entity: Type): void;
40
+ /**
41
+ * Check if an interface is extending the Azure.ResourceManager.Operations interface.
42
+ */
43
+ export declare function isArmOperationsListInterface(program: Program, type: Interface): boolean;
44
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,sCAAsC,CAAC;AAG7D,OAAO,EACL,gBAAgB,EAChB,SAAS,EAGT,OAAO,EAEP,IAAI,EAGL,MAAM,oBAAoB,CAAC;AAS5B;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,IAAI,EACZ,cAAc,CAAC,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GACrB,IAAI,CAqBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,IAAI,EACZ,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GACrB,IAAI,CAqBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,IAAI,EACZ,YAAY,EAAE,IAAI,GACjB,IAAI,CAoBN;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,QA4BlF;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAWvF"}
@@ -0,0 +1,142 @@
1
+ export const namespace = "Azure.ResourceManager.Foundations";
2
+ import { $useRef } from "@azure-tools/typespec-autorest";
3
+ import { validateDecoratorParamType, validateDecoratorTarget, } from "@typespec/compiler";
4
+ import { getSegment } from "@typespec/rest";
5
+ import { reportDiagnostic } from "./lib.js";
6
+ import { getArmProviderNamespace } from "./namespace.js";
7
+ function getArmTypesPath(program) {
8
+ return program.getOption("arm-types-path") || "../../../../../common-types/resource-management";
9
+ }
10
+ /**
11
+ * Using ARM common definition for a Model
12
+ * @param {DecoratorContext} context DecoratorContext object
13
+ * @param {Type} entity Decorator target type. Must be `Model`
14
+ * @param {string?} definitionName Optional definition name
15
+ * @param {string?} version Optional version
16
+ * @param {string?} referenceFile Optional common file path
17
+ * @returns {void}
18
+ */
19
+ export function $armCommonDefinition(context, entity, definitionName, version, referenceFile) {
20
+ if (!validateDecoratorTarget(context, entity, "@armCommonDefinition", "Model")) {
21
+ return;
22
+ }
23
+ // Use the name of the model type if not specified
24
+ if (!definitionName) {
25
+ definitionName = entity.name;
26
+ }
27
+ const basePath = getArmTypesPath(context.program).trim();
28
+ // for backward compatibility, skip if we are trying to access a non-default file and emit the type
29
+ if ((version || referenceFile) && basePath.endsWith(".json"))
30
+ return;
31
+ if (!version)
32
+ version = "v3";
33
+ if (!referenceFile)
34
+ referenceFile = "types.json";
35
+ const path = basePath.endsWith(".json")
36
+ ? `${basePath}#/definitions/${definitionName}`
37
+ : `${basePath}/${version}/${referenceFile}#/definitions/${definitionName}`;
38
+ context.call($useRef, entity, path);
39
+ }
40
+ /**
41
+ * Refer an model property to be a common ARM parameter
42
+ * @param {DecoratorContext} context DecoratorContext object
43
+ * @param {Type} entity Decorator target type. Must be `Model`
44
+ * @param {string?} definitionName Optional definition name
45
+ * @param {string?} version Optional version
46
+ * @param {string?} referenceFile Optional common file path
47
+ * @returns void
48
+ */
49
+ export function $armCommonParameter(context, entity, parameterName, version, referenceFile) {
50
+ if (!validateDecoratorTarget(context, entity, "@armCommonParameter", "ModelProperty")) {
51
+ return;
52
+ }
53
+ // Use the name of the model type if not specified
54
+ if (!parameterName) {
55
+ parameterName = entity.name;
56
+ }
57
+ const basePath = getArmTypesPath(context.program).trim();
58
+ // for backward compatibility, skip if we are trying to access a non-default file and emit the type
59
+ if ((version || referenceFile) && basePath.endsWith(".json"))
60
+ return;
61
+ if (!version)
62
+ version = "v3";
63
+ if (!referenceFile)
64
+ referenceFile = "types.json";
65
+ const path = basePath.endsWith(".json")
66
+ ? `${basePath}#/parameters/${parameterName}`
67
+ : `${basePath}/${version}/${referenceFile}#/parameters/${parameterName}`;
68
+ context.call($useRef, entity, path);
69
+ }
70
+ /**
71
+ * This decorator dynamically assigns the serviceNamespace from the containing
72
+ * namespace to the string literal value of the path parameter to which this
73
+ * decorator is applied. Its purpose is to dynamically insert the provider
74
+ * namespace (e.g. 'Microsoft.CodeSigning') into the path parameter list.
75
+ * @param {DecoratorContext} context DecoratorContext
76
+ * @param {Type} target Target of this decorator. Must be a string `ModelProperty`.
77
+ * @param {Type} resourceType Must be a `Model`.
78
+ */
79
+ export function $assignProviderNameValue(context, target, resourceType) {
80
+ const { program } = context;
81
+ // If the resource type is a template parameter, this must be a templated type
82
+ if (resourceType.kind === "TemplateParameter") {
83
+ return;
84
+ }
85
+ if (!validateDecoratorTarget(context, target, "@assignProviderNameValue", "ModelProperty") ||
86
+ !validateDecoratorParamType(program, target, target.type, "String") ||
87
+ !validateDecoratorParamType(program, target, resourceType, "Model")) {
88
+ return;
89
+ }
90
+ const armProviderNamespace = getArmProviderNamespace(program, resourceType);
91
+ if (armProviderNamespace) {
92
+ target.type.value = armProviderNamespace;
93
+ }
94
+ }
95
+ /**
96
+ * Update the ARM provider namespace for a given entity.
97
+ * @param {DecoratorContext} context DecoratorContext
98
+ * @param {Type} entity Entity to set namespace. Must be a `Operation`.
99
+ * @returns
100
+ */
101
+ export function $armUpdateProviderNamespace(context, entity) {
102
+ const { program } = context;
103
+ if (!validateDecoratorTarget(context, entity, "@armUpdateProviderNamespace", "Operation")) {
104
+ return;
105
+ }
106
+ const operation = entity;
107
+ const opInterface = operation.interface;
108
+ if (opInterface && opInterface.namespace) {
109
+ const armProviderNamespace = getArmProviderNamespace(program, opInterface.namespace);
110
+ if (armProviderNamespace) {
111
+ // Set the namespace constant on the 'provider' parameter
112
+ const providerParam = operation.parameters.properties.get("provider");
113
+ if (providerParam) {
114
+ if (providerParam.type.kind !== "String") {
115
+ reportDiagnostic(program, {
116
+ code: "decorator-param-wrong-type",
117
+ messageId: "armUpdateProviderNamespace",
118
+ target: providerParam,
119
+ });
120
+ return;
121
+ }
122
+ providerParam.type.value = armProviderNamespace;
123
+ }
124
+ }
125
+ }
126
+ }
127
+ /**
128
+ * Check if an interface is extending the Azure.ResourceManager.Operations interface.
129
+ */
130
+ export function isArmOperationsListInterface(program, type) {
131
+ if (type.name !== "Operations") {
132
+ return false;
133
+ }
134
+ const listOperation = type.operations.get("list");
135
+ if (listOperation) {
136
+ if (getSegment(program, listOperation) === "operations") {
137
+ return true;
138
+ }
139
+ }
140
+ return false;
141
+ }
142
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAE7D,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAQL,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,g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