@azure-tools/typespec-azure-core 0.34.0-dev.0 → 0.34.0-dev.10
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.
- package/README.md +61 -0
- package/dist/src/decorators.d.ts +27 -4
- package/dist/src/decorators.d.ts.map +1 -1
- package/dist/src/decorators.js +200 -113
- package/dist/src/decorators.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +206 -912
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +124 -175
- package/dist/src/lib.js.map +1 -1
- package/dist/src/lro-helpers.d.ts +6 -0
- package/dist/src/lro-helpers.d.ts.map +1 -1
- package/dist/src/lro-helpers.js +103 -49
- package/dist/src/lro-helpers.js.map +1 -1
- package/dist/src/lro-info.d.ts +38 -0
- package/dist/src/lro-info.d.ts.map +1 -0
- package/dist/src/lro-info.js +299 -0
- package/dist/src/lro-info.js.map +1 -0
- package/dist/src/rules/api-version-parameter.d.ts +3 -1
- package/dist/src/rules/api-version-parameter.d.ts.map +1 -1
- package/dist/src/rules/api-version-parameter.js +11 -8
- package/dist/src/rules/api-version-parameter.js.map +1 -1
- package/dist/src/rules/auth-required.d.ts +3 -1
- package/dist/src/rules/auth-required.d.ts.map +1 -1
- package/dist/src/rules/auth-required.js +12 -10
- package/dist/src/rules/auth-required.js.map +1 -1
- package/dist/src/rules/byos.d.ts +3 -1
- package/dist/src/rules/byos.d.ts.map +1 -1
- package/dist/src/rules/byos.js +9 -7
- package/dist/src/rules/byos.js.map +1 -1
- package/dist/src/rules/casing.d.ts +3 -1
- package/dist/src/rules/casing.d.ts.map +1 -1
- package/dist/src/rules/casing.js +19 -22
- package/dist/src/rules/casing.js.map +1 -1
- package/dist/src/rules/extensible-enums.d.ts +3 -1
- package/dist/src/rules/extensible-enums.d.ts.map +1 -1
- package/dist/src/rules/extensible-enums.js +9 -6
- package/dist/src/rules/extensible-enums.js.map +1 -1
- package/dist/src/rules/known-encoding.d.ts +3 -1
- package/dist/src/rules/known-encoding.d.ts.map +1 -1
- package/dist/src/rules/known-encoding.js +9 -7
- package/dist/src/rules/known-encoding.js.map +1 -1
- package/dist/src/rules/lro-polling-operation.d.ts +3 -1
- package/dist/src/rules/lro-polling-operation.d.ts.map +1 -1
- package/dist/src/rules/lro-polling-operation.js +12 -9
- package/dist/src/rules/lro-polling-operation.js.map +1 -1
- package/dist/src/rules/no-error-status-codes.d.ts +3 -1
- package/dist/src/rules/no-error-status-codes.d.ts.map +1 -1
- package/dist/src/rules/no-error-status-codes.js +11 -9
- package/dist/src/rules/no-error-status-codes.js.map +1 -1
- package/dist/src/rules/no-explicit-routes-resource-ops.d.ts +3 -1
- package/dist/src/rules/no-explicit-routes-resource-ops.d.ts.map +1 -1
- package/dist/src/rules/no-explicit-routes-resource-ops.js +11 -7
- package/dist/src/rules/no-explicit-routes-resource-ops.js.map +1 -1
- package/dist/src/rules/no-fixed-enum-discriminator.d.ts +3 -1
- package/dist/src/rules/no-fixed-enum-discriminator.d.ts.map +1 -1
- package/dist/src/rules/no-fixed-enum-discriminator.js +10 -8
- package/dist/src/rules/no-fixed-enum-discriminator.js.map +1 -1
- package/dist/src/rules/no-nullable.d.ts +3 -1
- package/dist/src/rules/no-nullable.d.ts.map +1 -1
- package/dist/src/rules/no-nullable.js +8 -6
- package/dist/src/rules/no-nullable.js.map +1 -1
- package/dist/src/rules/no-offsetdatetime.d.ts +3 -1
- package/dist/src/rules/no-offsetdatetime.d.ts.map +1 -1
- package/dist/src/rules/no-offsetdatetime.js +17 -14
- package/dist/src/rules/no-offsetdatetime.js.map +1 -1
- package/dist/src/rules/no-operation-id.d.ts +3 -1
- package/dist/src/rules/no-operation-id.d.ts.map +1 -1
- package/dist/src/rules/no-operation-id.js +9 -6
- package/dist/src/rules/no-operation-id.js.map +1 -1
- package/dist/src/rules/no-order-by.d.ts +3 -1
- package/dist/src/rules/no-order-by.d.ts.map +1 -1
- package/dist/src/rules/no-order-by.js +10 -7
- package/dist/src/rules/no-order-by.js.map +1 -1
- package/dist/src/rules/no-response-body.d.ts +4 -1
- package/dist/src/rules/no-response-body.d.ts.map +1 -1
- package/dist/src/rules/no-response-body.js +13 -10
- package/dist/src/rules/no-response-body.js.map +1 -1
- package/dist/src/rules/no-rpc-path-params.d.ts +3 -1
- package/dist/src/rules/no-rpc-path-params.d.ts.map +1 -1
- package/dist/src/rules/no-rpc-path-params.js +10 -8
- package/dist/src/rules/no-rpc-path-params.js.map +1 -1
- package/dist/src/rules/prefer-csv-collection-format.d.ts +3 -1
- package/dist/src/rules/prefer-csv-collection-format.d.ts.map +1 -1
- package/dist/src/rules/prefer-csv-collection-format.js +11 -8
- package/dist/src/rules/prefer-csv-collection-format.js.map +1 -1
- package/dist/src/rules/prevent-format.d.ts +3 -1
- package/dist/src/rules/prevent-format.d.ts.map +1 -1
- package/dist/src/rules/prevent-format.js +18 -16
- package/dist/src/rules/prevent-format.js.map +1 -1
- package/dist/src/rules/prevent-multiple-discriminator.d.ts +3 -1
- package/dist/src/rules/prevent-multiple-discriminator.d.ts.map +1 -1
- package/dist/src/rules/prevent-multiple-discriminator.js +9 -7
- package/dist/src/rules/prevent-multiple-discriminator.js.map +1 -1
- package/dist/src/rules/prevent-rest-library.d.ts +3 -1
- package/dist/src/rules/prevent-rest-library.d.ts.map +1 -1
- package/dist/src/rules/prevent-rest-library.js +12 -10
- package/dist/src/rules/prevent-rest-library.js.map +1 -1
- package/dist/src/rules/prevent-unknown.d.ts +3 -1
- package/dist/src/rules/prevent-unknown.d.ts.map +1 -1
- package/dist/src/rules/prevent-unknown.js +11 -13
- package/dist/src/rules/prevent-unknown.js.map +1 -1
- package/dist/src/rules/property-naming.d.ts +4 -1
- package/dist/src/rules/property-naming.d.ts.map +1 -1
- package/dist/src/rules/property-naming.js +12 -10
- package/dist/src/rules/property-naming.js.map +1 -1
- package/dist/src/rules/record-types.d.ts +4 -1
- package/dist/src/rules/record-types.d.ts.map +1 -1
- package/dist/src/rules/record-types.js +20 -20
- package/dist/src/rules/record-types.js.map +1 -1
- package/dist/src/rules/request-body-array.d.ts +3 -1
- package/dist/src/rules/request-body-array.d.ts.map +1 -1
- package/dist/src/rules/request-body-array.js +12 -7
- package/dist/src/rules/request-body-array.js.map +1 -1
- package/dist/src/rules/require-docs.d.ts +3 -1
- package/dist/src/rules/require-docs.d.ts.map +1 -1
- package/dist/src/rules/require-docs.js +21 -24
- package/dist/src/rules/require-docs.js.map +1 -1
- package/dist/src/rules/require-key-visibility.d.ts +3 -1
- package/dist/src/rules/require-key-visibility.d.ts.map +1 -1
- package/dist/src/rules/require-key-visibility.js +10 -8
- package/dist/src/rules/require-key-visibility.js.map +1 -1
- package/dist/src/rules/response-schema-multi-status-code.d.ts +3 -1
- package/dist/src/rules/response-schema-multi-status-code.d.ts.map +1 -1
- package/dist/src/rules/response-schema-multi-status-code.js +12 -10
- package/dist/src/rules/response-schema-multi-status-code.js.map +1 -1
- package/dist/src/rules/rpc-operation-request-body.d.ts +4 -1
- package/dist/src/rules/rpc-operation-request-body.d.ts.map +1 -1
- package/dist/src/rules/rpc-operation-request-body.js +12 -9
- package/dist/src/rules/rpc-operation-request-body.js.map +1 -1
- package/dist/src/rules/use-standard-names.d.ts +9 -1
- package/dist/src/rules/use-standard-names.d.ts.map +1 -1
- package/dist/src/rules/use-standard-names.js +18 -10
- package/dist/src/rules/use-standard-names.js.map +1 -1
- package/dist/src/rules/use-standard-ops.d.ts +3 -1
- package/dist/src/rules/use-standard-ops.d.ts.map +1 -1
- package/dist/src/rules/use-standard-ops.js +23 -19
- package/dist/src/rules/use-standard-ops.js.map +1 -1
- package/dist/src/rules/utils.d.ts +0 -7
- package/dist/src/rules/utils.d.ts.map +1 -1
- package/dist/src/rules/utils.js +0 -9
- package/dist/src/rules/utils.js.map +1 -1
- package/dist/src/traits.d.ts.map +1 -1
- package/dist/src/traits.js +10 -1
- package/dist/src/traits.js.map +1 -1
- package/dist/src/utils.d.ts +7 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/src/{linter.d.ts → validate.d.ts} +1 -1
- package/dist/src/validate.d.ts.map +1 -0
- package/dist/src/validate.js +6 -0
- package/dist/src/validate.js.map +1 -0
- package/lib/decorators.tsp +30 -0
- package/lib/operations.tsp +11 -5
- package/lib/traits.tsp +7 -1
- package/package.json +4 -6
- package/dist/src/linter.d.ts.map +0 -1
- package/dist/src/linter.js +0 -71
- package/dist/src/linter.js.map +0 -1
package/README.md
CHANGED
|
@@ -17,7 +17,9 @@ npm install @azure-tools/typespec-azure-core
|
|
|
17
17
|
- [`@fixed`](#@fixed)
|
|
18
18
|
- [`@items`](#@items)
|
|
19
19
|
- [`@lroCanceled`](#@lrocanceled)
|
|
20
|
+
- [`@lroErrorResult`](#@lroerrorresult)
|
|
20
21
|
- [`@lroFailed`](#@lrofailed)
|
|
22
|
+
- [`@lroResult`](#@lroresult)
|
|
21
23
|
- [`@lroStatus`](#@lrostatus)
|
|
22
24
|
- [`@lroSucceeded`](#@lrosucceeded)
|
|
23
25
|
- [`@nextLink`](#@nextlink)
|
|
@@ -26,6 +28,7 @@ npm install @azure-tools/typespec-azure-core
|
|
|
26
28
|
- [`@pagedResult`](#@pagedresult)
|
|
27
29
|
- [`@pollingLocation`](#@pollinglocation)
|
|
28
30
|
- [`@pollingOperation`](#@pollingoperation)
|
|
31
|
+
- [`@pollingOperationParameter`](#@pollingoperationparameter)
|
|
29
32
|
|
|
30
33
|
#### `@finalLocation`
|
|
31
34
|
|
|
@@ -97,6 +100,7 @@ None
|
|
|
97
100
|
|
|
98
101
|
#### `@lroCanceled`
|
|
99
102
|
|
|
103
|
+
Used for custom StatusMonitor implementation.
|
|
100
104
|
Identifies an EnumMember as a long-running "Canceled" terminal state.
|
|
101
105
|
|
|
102
106
|
```typespec
|
|
@@ -111,8 +115,27 @@ Identifies an EnumMember as a long-running "Canceled" terminal state.
|
|
|
111
115
|
|
|
112
116
|
None
|
|
113
117
|
|
|
118
|
+
#### `@lroErrorResult`
|
|
119
|
+
|
|
120
|
+
Used for custom StatusMonitor implementation.
|
|
121
|
+
Identifies a model property of a StatusMonitor as containing the result
|
|
122
|
+
of a long-running operation that terminates unsuccessfully (Failed).
|
|
123
|
+
|
|
124
|
+
```typespec
|
|
125
|
+
@Azure.Core.lroErrorResult
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
##### Target
|
|
129
|
+
|
|
130
|
+
`ModelProperty`
|
|
131
|
+
|
|
132
|
+
##### Parameters
|
|
133
|
+
|
|
134
|
+
None
|
|
135
|
+
|
|
114
136
|
#### `@lroFailed`
|
|
115
137
|
|
|
138
|
+
Used for custom StatusMonitor implementation.
|
|
116
139
|
Identifies an enum member as a long-running "Failed" terminal state.
|
|
117
140
|
|
|
118
141
|
```typespec
|
|
@@ -127,8 +150,27 @@ Identifies an enum member as a long-running "Failed" terminal state.
|
|
|
127
150
|
|
|
128
151
|
None
|
|
129
152
|
|
|
153
|
+
#### `@lroResult`
|
|
154
|
+
|
|
155
|
+
Used for custom StatusMonitor implementation.
|
|
156
|
+
Identifies a model property of a StatusMonitor as containing the result
|
|
157
|
+
of a long-running operation that terminates successfully (Succeeded).
|
|
158
|
+
|
|
159
|
+
```typespec
|
|
160
|
+
@Azure.Core.lroResult
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
##### Target
|
|
164
|
+
|
|
165
|
+
`ModelProperty`
|
|
166
|
+
|
|
167
|
+
##### Parameters
|
|
168
|
+
|
|
169
|
+
None
|
|
170
|
+
|
|
130
171
|
#### `@lroStatus`
|
|
131
172
|
|
|
173
|
+
Used for custom StatusMonitor implementation.
|
|
132
174
|
Identifies an Enum or ModelProperty as containing long-running operation
|
|
133
175
|
status.
|
|
134
176
|
|
|
@@ -146,6 +188,7 @@ None
|
|
|
146
188
|
|
|
147
189
|
#### `@lroSucceeded`
|
|
148
190
|
|
|
191
|
+
Used for custom StatusMonitor implementation.
|
|
149
192
|
Identifies an EnumMember as a long-running "Succeeded" terminal state.
|
|
150
193
|
|
|
151
194
|
```typespec
|
|
@@ -266,6 +309,24 @@ Identifies that an operation is a polling operation for an LRO.
|
|
|
266
309
|
| linkedOperation | `Operation` | The linked Operation |
|
|
267
310
|
| parameters | `model {}` | Map of `RequestParameter<T>` and/or `ResponseProperty<T>` that will<br />be passed to the linked operation request. |
|
|
268
311
|
|
|
312
|
+
#### `@pollingOperationParameter`
|
|
313
|
+
|
|
314
|
+
Used to define how to call custom polling operations for long-running operations.
|
|
315
|
+
|
|
316
|
+
```typespec
|
|
317
|
+
@Azure.Core.pollingOperationParameter(targetParameter?: ModelProperty | string)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
##### Target
|
|
321
|
+
|
|
322
|
+
`ModelProperty`
|
|
323
|
+
|
|
324
|
+
##### Parameters
|
|
325
|
+
|
|
326
|
+
| Name | Type | Description |
|
|
327
|
+
| --------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
328
|
+
| targetParameter | `union ModelProperty \| string` | A reference to the polling operation parameter this parameter<br />provides a value for, or the name of that parameter. The default value is the name of<br />the decorated parameter or property. |
|
|
329
|
+
|
|
269
330
|
### Azure.Core.Foundations
|
|
270
331
|
|
|
271
332
|
- [`@omitKeyProperties`](#@omitkeyproperties)
|
package/dist/src/decorators.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { DecoratorContext, Diagnostic, Enum, EnumMember, Model, ModelProperty, Operation, Program, Scalar, Type } from "@typespec/compiler";
|
|
1
|
+
import { DecoratorContext, Diagnostic, Enum, EnumMember, Model, ModelProperty, Operation, Program, Scalar, StringLiteral, Type } from "@typespec/compiler";
|
|
2
|
+
import { OperationLink } from "./lro-helpers.js";
|
|
3
|
+
import { PropertyMap, ResultInfo } from "./lro-info.js";
|
|
2
4
|
export declare const namespace = "Azure.Core";
|
|
3
5
|
export declare const PollingOperationKey: string;
|
|
4
6
|
export declare const FinalOperationKey = "final";
|
|
@@ -8,9 +10,15 @@ export declare function $pagedResult(context: DecoratorContext, entity: Model):
|
|
|
8
10
|
export interface PagedResultMetadata {
|
|
9
11
|
modelType: Model;
|
|
10
12
|
itemsProperty?: ModelProperty;
|
|
13
|
+
/** @deprecated use itemsSegments */
|
|
11
14
|
itemsPath?: string;
|
|
15
|
+
/** Path to the items property. */
|
|
16
|
+
itemsSegments?: string[];
|
|
12
17
|
nextLinkProperty?: ModelProperty;
|
|
18
|
+
/** @deprecated use nextLinkSegments */
|
|
13
19
|
nextLinkPath?: string;
|
|
20
|
+
/** Path to the next link property. */
|
|
21
|
+
nextLinkSegments?: string[];
|
|
14
22
|
nextLinkOperation?: Operation;
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
@@ -34,9 +42,9 @@ export declare function getNextLink(program: Program, entity: Type): boolean | u
|
|
|
34
42
|
* additional states defined for the operation.
|
|
35
43
|
**/
|
|
36
44
|
export interface LongRunningStates {
|
|
37
|
-
succeededState: string;
|
|
38
|
-
failedState: string;
|
|
39
|
-
canceledState: string;
|
|
45
|
+
succeededState: string[];
|
|
46
|
+
failedState: string[];
|
|
47
|
+
canceledState: string[];
|
|
40
48
|
states: string[];
|
|
41
49
|
}
|
|
42
50
|
export declare function $lroStatus(context: DecoratorContext, entity: Enum | ModelProperty): void;
|
|
@@ -45,6 +53,18 @@ export declare function extractLroStates(program: Program, entity: Type): [LongR
|
|
|
45
53
|
* Returns the `LongRunningStates` associated with `entity`.
|
|
46
54
|
*/
|
|
47
55
|
export declare function getLongRunningStates(program: Program, entity: Enum | Model | Scalar | ModelProperty): LongRunningStates | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Return the property that contains the lro status
|
|
58
|
+
* @param program The program to process
|
|
59
|
+
* @param target The model to check for lro status
|
|
60
|
+
*/
|
|
61
|
+
export declare function getLroStatusProperty(program: Program, target: Model): ModelProperty | undefined;
|
|
62
|
+
export declare function $lroResult(context: DecoratorContext, entity: ModelProperty): void;
|
|
63
|
+
export declare function getLroResult(program: Program, entity: Model | ModelProperty, useDefault?: boolean): ModelProperty | undefined;
|
|
64
|
+
export declare function $lroErrorResult(context: DecoratorContext, entity: ModelProperty): void;
|
|
65
|
+
export declare function getLroErrorResult(program: Program, entity: Model | ModelProperty, useDefault?: boolean): ModelProperty | undefined;
|
|
66
|
+
export declare function $pollingOperationParameter(context: DecoratorContext, entity: ModelProperty, target?: ModelProperty | StringLiteral): void;
|
|
67
|
+
export declare function getPollingOperationParameter(program: Program, entity: ModelProperty): string | ModelProperty | undefined;
|
|
48
68
|
export declare function $lroSucceeded(context: DecoratorContext, entity: EnumMember): void;
|
|
49
69
|
/**
|
|
50
70
|
* Returns `true` if the enum member represents a "succeeded" state.
|
|
@@ -75,6 +95,9 @@ export interface OperationLinkMetadata {
|
|
|
75
95
|
parameters?: Type;
|
|
76
96
|
linkedOperation: Operation;
|
|
77
97
|
linkType: string;
|
|
98
|
+
link?: OperationLink;
|
|
99
|
+
parameterMap?: Map<string, PropertyMap>;
|
|
100
|
+
result?: ResultInfo;
|
|
78
101
|
}
|
|
79
102
|
export declare function $operationLink(context: DecoratorContext, entity: Operation, linkedOperation: Operation, linkType: string, parameters?: Model): void;
|
|
80
103
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,UAAU,EAOV,KAAK,EACL,aAAa,EACb,SAAS,EACT,OAAO,EACP,MAAM,EAEN,aAAa,EACb,IAAI,EACL,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACj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E,aAAa,GAAG,MAAM,GAAG,SAAS,CAI/F;AAID,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,QAEvF;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAI/F;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,KAAK,EACb,cAAc,EAAE,KAAK,QAsBtB;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,KAAK,EACb,cAAc,EAAE,KAAK,QAuBtB;AAID,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,IAAI,QAkDnB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAEnF;AAID,wBAAgB,WAAW,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,QAMvE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAa9C;AAID,wBAAgB,WAAW,CACzB,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,QAGb;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,QAkB/C"}
|
package/dist/src/decorators.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createDiagnostic, createStateSymbol, reportDiagnostic } from "./lib.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { filterModelProperties, getAllProperties } from "./utils.js";
|
|
3
|
+
import { createDiagnosticCollector, getKnownValues, getNamespaceFullName, getTypeName, isKey, isStringType, isTemplateDeclarationOrInstance, setTypeSpecNamespace, } from "@typespec/compiler";
|
|
4
|
+
import { getHttpOperation, getRoutePath } from "@typespec/http";
|
|
4
5
|
import { getResourceTypeKey, getSegment, isAutoRoute } from "@typespec/rest";
|
|
6
|
+
import { getLroOperationInfo } from "./lro-info.js";
|
|
5
7
|
export const namespace = "Azure.Core";
|
|
6
8
|
/*
|
|
7
9
|
* Constants for polling and final operation links
|
|
@@ -21,17 +23,20 @@ const pagedResultsKey = createStateSymbol("pagedResult");
|
|
|
21
23
|
export function $pagedResult(context, entity) {
|
|
22
24
|
context.program.stateMap(pagedResultsKey).set(entity, true);
|
|
23
25
|
}
|
|
24
|
-
function
|
|
26
|
+
function findPathToProperty(program, entity, condition, current = []) {
|
|
25
27
|
for (const prop of entity.properties.values()) {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
return
|
|
28
|
+
const match = condition(prop);
|
|
29
|
+
if (match) {
|
|
30
|
+
const segments = [...current, prop.name];
|
|
31
|
+
return {
|
|
32
|
+
property: prop,
|
|
33
|
+
path: segments.join("."),
|
|
34
|
+
segments,
|
|
35
|
+
};
|
|
30
36
|
}
|
|
31
37
|
else {
|
|
32
38
|
if (prop.type.kind === "Model") {
|
|
33
|
-
const
|
|
34
|
-
const items = _getItems(program, prop.type, currentPrefix);
|
|
39
|
+
const items = findPathToProperty(program, prop.type, condition, [...current, prop.name]);
|
|
35
40
|
if (items !== undefined) {
|
|
36
41
|
return items;
|
|
37
42
|
}
|
|
@@ -40,24 +45,11 @@ function _getItems(program, entity, prefix = "") {
|
|
|
40
45
|
}
|
|
41
46
|
return undefined;
|
|
42
47
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return [prop, currentPrefix];
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
if (prop.type.kind === "Model") {
|
|
52
|
-
const currentPrefix = prefix !== "" ? `${prefix}.${prop.name}` : `${prop.name}`;
|
|
53
|
-
const items = _getNextLink(program, prop.type, currentPrefix);
|
|
54
|
-
if (items !== undefined) {
|
|
55
|
-
return items;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
48
|
+
function _getItems(program, entity) {
|
|
49
|
+
return findPathToProperty(program, entity, (prop) => getItems(program, prop) !== undefined);
|
|
50
|
+
}
|
|
51
|
+
function _getNextLink(program, entity) {
|
|
52
|
+
return findPathToProperty(program, entity, (prop) => getNextLink(program, prop) !== undefined);
|
|
61
53
|
}
|
|
62
54
|
/**
|
|
63
55
|
* Find all named models that could have been the source of the given
|
|
@@ -90,13 +82,17 @@ export function getPagedResult(program, entity) {
|
|
|
90
82
|
metadata = { modelType: entity };
|
|
91
83
|
const items = _getItems(program, entity);
|
|
92
84
|
if (items !== undefined) {
|
|
93
|
-
metadata.itemsProperty = items
|
|
94
|
-
|
|
85
|
+
metadata.itemsProperty = items.property;
|
|
86
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
87
|
+
metadata.itemsPath = items.path;
|
|
88
|
+
metadata.itemsSegments = items.segments;
|
|
95
89
|
}
|
|
96
90
|
const nextLink = _getNextLink(program, entity);
|
|
97
91
|
if (nextLink !== undefined) {
|
|
98
|
-
metadata.nextLinkProperty = nextLink
|
|
99
|
-
|
|
92
|
+
metadata.nextLinkProperty = nextLink.property;
|
|
93
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
94
|
+
metadata.nextLinkPath = nextLink.path;
|
|
95
|
+
metadata.nextLinkSegments = nextLink.segments;
|
|
100
96
|
}
|
|
101
97
|
return metadata;
|
|
102
98
|
}
|
|
@@ -184,9 +180,9 @@ export function $lroStatus(context, entity) {
|
|
|
184
180
|
}
|
|
185
181
|
function storeLroState(program, states, name, enumMember) {
|
|
186
182
|
const expectedStates = [
|
|
187
|
-
["Succeeded", isLroSucceededState, () =>
|
|
188
|
-
["Failed", isLroFailedState, () =>
|
|
189
|
-
["Canceled", isLroCanceledState, () =>
|
|
183
|
+
["Succeeded", isLroSucceededState, () => states.succeededState.push(name)],
|
|
184
|
+
["Failed", isLroFailedState, () => states.failedState.push(name)],
|
|
185
|
+
["Canceled", isLroCanceledState, () => states.canceledState.push(name)],
|
|
190
186
|
];
|
|
191
187
|
states.states.push(name);
|
|
192
188
|
for (const [knownState, stateTest, setter] of expectedStates) {
|
|
@@ -197,7 +193,12 @@ function storeLroState(program, states, name, enumMember) {
|
|
|
197
193
|
}
|
|
198
194
|
}
|
|
199
195
|
export function extractLroStates(program, entity) {
|
|
200
|
-
const result = {
|
|
196
|
+
const result = {
|
|
197
|
+
states: [],
|
|
198
|
+
succeededState: [],
|
|
199
|
+
failedState: [],
|
|
200
|
+
canceledState: [],
|
|
201
|
+
};
|
|
201
202
|
const diagnostics = createDiagnosticCollector();
|
|
202
203
|
if (entity.kind === "ModelProperty") {
|
|
203
204
|
// Call the function recursively on the property type
|
|
@@ -236,10 +237,11 @@ export function extractLroStates(program, entity) {
|
|
|
236
237
|
}
|
|
237
238
|
// Make sure all terminal states have been identified
|
|
238
239
|
const missingStates = [];
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
if (result.succeededState.length < 1) {
|
|
241
|
+
missingStates.push("Succeeded");
|
|
242
|
+
}
|
|
243
|
+
if (result.failedState.length < 1) {
|
|
244
|
+
missingStates.push("Failed");
|
|
243
245
|
}
|
|
244
246
|
if (missingStates.length > 0) {
|
|
245
247
|
diagnostics.add(createDiagnostic({
|
|
@@ -266,6 +268,113 @@ export function getLongRunningStates(program, entity) {
|
|
|
266
268
|
// Otherwise just check the type itself
|
|
267
269
|
return program.stateMap(lroStatusKey).get(entity);
|
|
268
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Return the property that contains the lro status
|
|
273
|
+
* @param program The program to process
|
|
274
|
+
* @param target The model to check for lro status
|
|
275
|
+
*/
|
|
276
|
+
export function getLroStatusProperty(program, target) {
|
|
277
|
+
const props = getAllProperties(target);
|
|
278
|
+
for (const [_, prop] of props.entries()) {
|
|
279
|
+
let values = program.stateMap(lroStatusKey).get(prop);
|
|
280
|
+
if (values !== undefined)
|
|
281
|
+
return prop;
|
|
282
|
+
if (prop.type.kind === "Enum" || prop.type.kind === "Union") {
|
|
283
|
+
values = program.stateMap(lroStatusKey).get(prop.type);
|
|
284
|
+
if (values !== undefined)
|
|
285
|
+
return prop;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const statusProp = props.get("status");
|
|
289
|
+
if (statusProp) {
|
|
290
|
+
const [states, _] = extractLroStates(program, statusProp);
|
|
291
|
+
if (states !== undefined)
|
|
292
|
+
return statusProp;
|
|
293
|
+
}
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
//@lroResult
|
|
297
|
+
const lroResultKey = createStateSymbol("lroResult");
|
|
298
|
+
export function $lroResult(context, entity) {
|
|
299
|
+
const { program } = context;
|
|
300
|
+
if (entity.model) {
|
|
301
|
+
if (getLroResult(program, entity.model, false) !== undefined) {
|
|
302
|
+
reportDiagnostic(program, {
|
|
303
|
+
code: "lro-status-monitor-invalid-result-property",
|
|
304
|
+
target: entity.model,
|
|
305
|
+
format: { resultType: "result", decorator: "@lroResult" },
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
program.stateMap(lroResultKey).set(entity, true);
|
|
310
|
+
}
|
|
311
|
+
export function getLroResult(program, entity, useDefault = true) {
|
|
312
|
+
switch (entity.kind) {
|
|
313
|
+
case "ModelProperty":
|
|
314
|
+
return program.stateMap(lroResultKey).has(entity) ? entity : undefined;
|
|
315
|
+
case "Model":
|
|
316
|
+
let props = filterModelProperties(entity, (e) => getLroResult(program, e) !== undefined);
|
|
317
|
+
if (props.length > 0)
|
|
318
|
+
return props[0];
|
|
319
|
+
if (useDefault) {
|
|
320
|
+
props = filterModelProperties(entity, (p) => p.name.toLowerCase() === "result");
|
|
321
|
+
if (props.length === 1)
|
|
322
|
+
return props[0];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
//@lroErrorResult
|
|
328
|
+
const lroErrorResultKey = createStateSymbol("lroErrorResult");
|
|
329
|
+
export function $lroErrorResult(context, entity) {
|
|
330
|
+
const { program } = context;
|
|
331
|
+
if (entity.model) {
|
|
332
|
+
if (getLroErrorResult(program, entity.model, false) !== undefined) {
|
|
333
|
+
reportDiagnostic(program, {
|
|
334
|
+
code: "lro-status-monitor-invalid-result-property",
|
|
335
|
+
target: entity.model,
|
|
336
|
+
format: { resultType: "error", decorator: "@lroErrorResult" },
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
program.stateMap(lroErrorResultKey).set(entity, true);
|
|
341
|
+
}
|
|
342
|
+
export function getLroErrorResult(program, entity, useDefault = true) {
|
|
343
|
+
switch (entity.kind) {
|
|
344
|
+
case "ModelProperty":
|
|
345
|
+
return program.stateMap(lroErrorResultKey).has(entity) ? entity : undefined;
|
|
346
|
+
case "Model":
|
|
347
|
+
let props = filterModelProperties(entity, (e) => getLroErrorResult(program, e) !== undefined);
|
|
348
|
+
if (props.length > 0)
|
|
349
|
+
return props[0];
|
|
350
|
+
if (useDefault) {
|
|
351
|
+
props = filterModelProperties(entity, (p) => p.name.toLowerCase() === "error");
|
|
352
|
+
if (props.length === 1)
|
|
353
|
+
return props[0];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
//@pollingOperationParameter
|
|
359
|
+
const pollingParameterKey = createStateSymbol("pollingOperationParameter");
|
|
360
|
+
export function $pollingOperationParameter(context, entity, target) {
|
|
361
|
+
const { program } = context;
|
|
362
|
+
let storedValue;
|
|
363
|
+
switch (target === null || target === void 0 ? void 0 : target.kind) {
|
|
364
|
+
case "ModelProperty":
|
|
365
|
+
storedValue = target;
|
|
366
|
+
break;
|
|
367
|
+
case "String":
|
|
368
|
+
storedValue = target.value;
|
|
369
|
+
break;
|
|
370
|
+
default:
|
|
371
|
+
storedValue = undefined;
|
|
372
|
+
}
|
|
373
|
+
program.stateMap(pollingParameterKey).set(entity, storedValue !== null && storedValue !== void 0 ? storedValue : entity.name);
|
|
374
|
+
}
|
|
375
|
+
export function getPollingOperationParameter(program, entity) {
|
|
376
|
+
return program.stateMap(pollingParameterKey).get(entity);
|
|
377
|
+
}
|
|
269
378
|
// @lroSucceeded
|
|
270
379
|
const lroSucceededKey = createStateSymbol("lroSucceeded");
|
|
271
380
|
export function $lroSucceeded(context, entity) {
|
|
@@ -331,77 +440,11 @@ export function $omitKeyProperties(context, entity) {
|
|
|
331
440
|
}
|
|
332
441
|
const operationLinkKey = createStateSymbol("operationLink");
|
|
333
442
|
export function $operationLink(context, entity, linkedOperation, linkType, parameters) {
|
|
334
|
-
var _a
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const namespace = (_a = data.type.namespace) === null || _a === void 0 ? void 0 : _a.name;
|
|
340
|
-
const valid = namespace === "Core" &&
|
|
341
|
-
(typeName === "RequestParameter" || typeName === "ResponseProperty");
|
|
342
|
-
if (!valid) {
|
|
343
|
-
reportDiagnostic(context.program, {
|
|
344
|
-
code: "operation-link-parameter-invalid",
|
|
345
|
-
target: context.decoratorTarget,
|
|
346
|
-
format: {},
|
|
347
|
-
});
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
const targetProperty = data.type.templateMapper.args[0];
|
|
351
|
-
switch (targetProperty.kind) {
|
|
352
|
-
case "String":
|
|
353
|
-
const targetPropertyName = targetProperty.value;
|
|
354
|
-
if (typeName === "RequestParameter") {
|
|
355
|
-
const bodyType = getOperationParameters(context.program, entity)[0].body.type;
|
|
356
|
-
switch (bodyType.kind) {
|
|
357
|
-
case "Model":
|
|
358
|
-
if (!bodyType.properties.get(targetPropertyName)) {
|
|
359
|
-
reportDiagnostic(context.program, {
|
|
360
|
-
code: "request-parameter-invalid",
|
|
361
|
-
target: context.decoratorTarget,
|
|
362
|
-
format: { name: targetPropertyName },
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
break;
|
|
366
|
-
default:
|
|
367
|
-
reportDiagnostic(context.program, {
|
|
368
|
-
code: "request-parameter-invalid",
|
|
369
|
-
target: context.decoratorTarget,
|
|
370
|
-
format: { name: targetPropertyName },
|
|
371
|
-
});
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
else if (typeName === "ResponseProperty") {
|
|
376
|
-
const responses = getResponsesForOperation(context.program, entity)[0];
|
|
377
|
-
for (const response of responses) {
|
|
378
|
-
switch (response.type.kind) {
|
|
379
|
-
case "Model":
|
|
380
|
-
// error responses don't need the property
|
|
381
|
-
if (isErrorModel(context.program, response.type)) {
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
// however ALL non-error responses do need the property!
|
|
385
|
-
if (!((_b = response.type) === null || _b === void 0 ? void 0 : _b.properties.get(targetPropertyName))) {
|
|
386
|
-
reportDiagnostic(context.program, {
|
|
387
|
-
code: "response-property-invalid",
|
|
388
|
-
target: context.decoratorTarget,
|
|
389
|
-
format: { name: targetPropertyName },
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
break;
|
|
393
|
-
default:
|
|
394
|
-
reportDiagnostic(context.program, {
|
|
395
|
-
code: "response-property-invalid",
|
|
396
|
-
target: context.decoratorTarget,
|
|
397
|
-
format: { name: targetPropertyName },
|
|
398
|
-
});
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
443
|
+
var _a;
|
|
444
|
+
const { program } = context;
|
|
445
|
+
const [operationInfo, diagnostics] = getLroOperationInfo(program, entity, linkedOperation, parameters);
|
|
446
|
+
if (diagnostics.length > 0) {
|
|
447
|
+
program.reportDiagnostics(diagnostics);
|
|
405
448
|
}
|
|
406
449
|
// An operation may have many operationLinks, so treat them as a collection
|
|
407
450
|
let items = context.program.stateMap(operationLinkKey).get(entity);
|
|
@@ -412,6 +455,9 @@ export function $operationLink(context, entity, linkedOperation, linkType, param
|
|
|
412
455
|
parameters: parameters,
|
|
413
456
|
linkedOperation: linkedOperation,
|
|
414
457
|
linkType: linkType,
|
|
458
|
+
link: operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.getOperationLink(),
|
|
459
|
+
parameterMap: (_a = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.getInvocationInfo()) === null || _a === void 0 ? void 0 : _a.parameterMap,
|
|
460
|
+
result: operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.getResultInfo(),
|
|
415
461
|
});
|
|
416
462
|
context.program.stateMap(operationLinkKey).set(entity, items);
|
|
417
463
|
}
|
|
@@ -432,21 +478,62 @@ export function getOperationLinks(program, entity) {
|
|
|
432
478
|
return program.stateMap(operationLinkKey).get(entity);
|
|
433
479
|
}
|
|
434
480
|
export function $pollingOperation(context, target, linkedOperation, parameters) {
|
|
481
|
+
const { program } = context;
|
|
435
482
|
const isValidReturnType = target.returnType.kind === "Model" ||
|
|
436
483
|
(target.returnType.kind === "Union" &&
|
|
437
484
|
[...target.returnType.variants.values()].every((x) => x.type.kind === "Model"));
|
|
438
|
-
if (isValidReturnType) {
|
|
439
|
-
context.
|
|
485
|
+
if (!isValidReturnType) {
|
|
486
|
+
reportDiagnostic(context.program, {
|
|
487
|
+
code: "polling-operation-return-model",
|
|
488
|
+
target: target,
|
|
489
|
+
});
|
|
490
|
+
return;
|
|
440
491
|
}
|
|
441
|
-
|
|
492
|
+
context.call($operationLink, target, linkedOperation, PollingOperationKey, parameters);
|
|
493
|
+
const operationDetails = getOperationLink(program, target, PollingOperationKey);
|
|
494
|
+
if (operationDetails === undefined || operationDetails.result === undefined) {
|
|
442
495
|
reportDiagnostic(context.program, {
|
|
443
496
|
code: "polling-operation-return-model",
|
|
444
497
|
target: target,
|
|
445
498
|
});
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (operationDetails.result.statusMonitor === undefined) {
|
|
502
|
+
reportDiagnostic(context.program, {
|
|
503
|
+
code: "polling-operation-no-status-monitor",
|
|
504
|
+
target: linkedOperation,
|
|
505
|
+
});
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (operationDetails.result.statusMonitor.terminationInfo.succeededState.length < 1) {
|
|
509
|
+
reportDiagnostic(context.program, {
|
|
510
|
+
code: "polling-operation-no-lro-success",
|
|
511
|
+
target: operationDetails.result.statusMonitor.type,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
if (operationDetails.result.statusMonitor.terminationInfo.failedState.length < 1) {
|
|
515
|
+
reportDiagnostic(context.program, {
|
|
516
|
+
code: "polling-operation-no-lro-failure",
|
|
517
|
+
target: operationDetails.result.statusMonitor.type,
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (operationDetails.parameterMap === undefined && operationDetails.link === undefined) {
|
|
521
|
+
reportDiagnostic(context.program, {
|
|
522
|
+
code: "polling-operation-no-ref-or-link",
|
|
523
|
+
target: target,
|
|
524
|
+
});
|
|
446
525
|
}
|
|
447
526
|
}
|
|
448
527
|
export function $finalOperation(context, entity, linkedOperation, parameters) {
|
|
528
|
+
const { program } = context;
|
|
449
529
|
context.call($operationLink, entity, linkedOperation, FinalOperationKey, parameters);
|
|
530
|
+
const operationDetails = getOperationLink(program, entity, FinalOperationKey);
|
|
531
|
+
if (operationDetails === undefined || operationDetails.result === undefined) {
|
|
532
|
+
reportDiagnostic(context.program, {
|
|
533
|
+
code: "invalid-final-operation",
|
|
534
|
+
target: entity,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
450
537
|
}
|
|
451
538
|
export function $nextPageOperation(context, entity, linkedOperation, parameters) {
|
|
452
539
|
context.call($operationLink, entity, linkedOperation, "nextPage", parameters);
|