@azure-tools/typespec-ts 0.46.1 → 0.47.0-alpha.20251208.1
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/CHANGELOG.md +15 -3
- package/LICENSE +21 -0
- package/dist/src/framework/hooks/sdkTypes.d.ts +7 -1
- package/dist/src/framework/hooks/sdkTypes.d.ts.map +1 -1
- package/dist/src/framework/hooks/sdkTypes.js +59 -1
- package/dist/src/framework/hooks/sdkTypes.js.map +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +20 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +18 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +137 -23
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +71 -24
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +2 -1
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +23 -0
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +57 -14
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/emitSamples.d.ts.map +1 -1
- package/dist/src/modular/emitSamples.js +53 -26
- package/dist/src/modular/emitSamples.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.js +73 -23
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +4 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +7 -4
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +7 -4
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +115 -23
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +3 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +7 -3
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts +4 -2
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.js +60 -17
- package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts +4 -2
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +61 -19
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/serializeUtils.d.ts +11 -0
- package/dist/src/modular/serialization/serializeUtils.d.ts.map +1 -1
- package/dist/src/modular/serialization/serializeUtils.js +15 -0
- package/dist/src/modular/serialization/serializeUtils.js.map +1 -1
- package/dist/src/modular/static-helpers-metadata.d.ts +17 -0
- package/dist/src/modular/static-helpers-metadata.d.ts.map +1 -1
- package/dist/src/modular/static-helpers-metadata.js +17 -0
- package/dist/src/modular/static-helpers-metadata.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +2 -0
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/namespaceUtils.d.ts.map +1 -1
- package/dist/src/utils/namespaceUtils.js +19 -4
- package/dist/src/utils/namespaceUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +1 -0
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +26 -0
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -11
- package/src/framework/hooks/sdkTypes.ts +102 -2
- package/src/index.ts +2 -0
- package/src/lib.ts +20 -1
- package/src/modular/buildClassicalClient.ts +182 -25
- package/src/modular/buildClientContext.ts +88 -31
- package/src/modular/buildRootIndex.ts +53 -1
- package/src/modular/emitModels.ts +72 -19
- package/src/modular/emitSamples.ts +86 -21
- package/src/modular/helpers/classicalOperationHelpers.ts +112 -30
- package/src/modular/helpers/clientHelpers.ts +8 -5
- package/src/modular/helpers/operationHelpers.ts +163 -43
- package/src/modular/helpers/typeHelpers.ts +19 -3
- package/src/modular/serialization/buildDeserializerFunction.ts +87 -35
- package/src/modular/serialization/buildSerializerFunction.ts +86 -36
- package/src/modular/serialization/serializeUtils.ts +37 -0
- package/src/modular/static-helpers-metadata.ts +18 -0
- package/src/transform/transfromRLCOptions.ts +2 -0
- package/src/utils/namespaceUtils.ts +19 -3
- package/src/utils/operationUtil.ts +35 -0
- package/static/static-helpers/serialization/check-prop-undefined.ts +17 -0
- package/static/static-helpers/simplePollerHelpers.ts +125 -0
|
@@ -2,6 +2,7 @@ import { FunctionDeclarationStructure, StructureKind } from "ts-morph";
|
|
|
2
2
|
import {
|
|
3
3
|
SdkArrayType,
|
|
4
4
|
SdkDictionaryType,
|
|
5
|
+
SdkModelPropertyType,
|
|
5
6
|
SdkModelType,
|
|
6
7
|
SdkType,
|
|
7
8
|
SdkUnionType,
|
|
@@ -40,17 +41,53 @@ import {
|
|
|
40
41
|
} from "../helpers/typeHelpers.js";
|
|
41
42
|
import { reportDiagnostic } from "../../lib.js";
|
|
42
43
|
import { NoTarget } from "@typespec/compiler";
|
|
44
|
+
import { useContext } from "../../contextManager.js";
|
|
45
|
+
|
|
46
|
+
export function buildPropertySerializer(
|
|
47
|
+
context: SdkContext,
|
|
48
|
+
property: SdkModelPropertyType,
|
|
49
|
+
options: ModelSerializeOptions = {
|
|
50
|
+
nameOnly: false,
|
|
51
|
+
skipDiscriminatedUnionSuffix: false
|
|
52
|
+
}
|
|
53
|
+
) {
|
|
54
|
+
const propertyContext =
|
|
55
|
+
useContext("sdkTypes").flattenProperties.get(property);
|
|
56
|
+
// only build de-serializer for flatten property
|
|
57
|
+
if (property.flatten !== true || !propertyContext) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const predefinedName = `_${normalizeName(
|
|
61
|
+
`${propertyContext.baseModel.name}_${property.name}`,
|
|
62
|
+
NameType.Method,
|
|
63
|
+
true
|
|
64
|
+
)}Serializer`;
|
|
65
|
+
return buildModelSerializer(context, property.type, {
|
|
66
|
+
...options,
|
|
67
|
+
flatten: {
|
|
68
|
+
baseModel: propertyContext.baseModel,
|
|
69
|
+
property
|
|
70
|
+
},
|
|
71
|
+
overrides: {
|
|
72
|
+
allOptional: property.optional,
|
|
73
|
+
propertyRenames: propertyContext.conflictMap
|
|
74
|
+
},
|
|
75
|
+
predefinedName
|
|
76
|
+
});
|
|
77
|
+
}
|
|
43
78
|
|
|
44
79
|
export function buildModelSerializer(
|
|
45
80
|
context: SdkContext,
|
|
46
81
|
type: SdkType,
|
|
47
|
-
|
|
48
|
-
|
|
82
|
+
options: ModelSerializeOptions = {
|
|
83
|
+
nameOnly: false,
|
|
84
|
+
skipDiscriminatedUnionSuffix: false
|
|
85
|
+
}
|
|
49
86
|
): FunctionDeclarationStructure | undefined | string {
|
|
50
|
-
// const modelTcgcType = getTcgcType(type) as SdkModelType;
|
|
51
87
|
if (!isSupportedSerializeType(type)) {
|
|
52
88
|
return undefined;
|
|
53
89
|
}
|
|
90
|
+
const { nameOnly } = options;
|
|
54
91
|
if (type.kind === "model" || type.kind === "union" || type.kind === "enum") {
|
|
55
92
|
if (
|
|
56
93
|
!type.usage ||
|
|
@@ -80,16 +117,13 @@ export function buildModelSerializer(
|
|
|
80
117
|
return buildPolymorphicSerializer(context, type, nameOnly);
|
|
81
118
|
}
|
|
82
119
|
|
|
83
|
-
if (isDiscriminatedUnion(type) && !
|
|
120
|
+
if (isDiscriminatedUnion(type) && !options.skipDiscriminatedUnionSuffix) {
|
|
84
121
|
return buildDiscriminatedUnionSerializer(context, type, nameOnly);
|
|
85
122
|
}
|
|
86
123
|
|
|
87
124
|
switch (type.kind) {
|
|
88
125
|
case "model":
|
|
89
|
-
return buildModelTypeSerializer(context, type,
|
|
90
|
-
nameOnly,
|
|
91
|
-
skipDiscriminatedUnionSuffix: skipDiscriminatedUnion
|
|
92
|
-
});
|
|
126
|
+
return buildModelTypeSerializer(context, type, options);
|
|
93
127
|
case "union": // for non-discriminated union, we just return whatever we get
|
|
94
128
|
return buildUnionSerializer(context, type, nameOnly);
|
|
95
129
|
case "dict":
|
|
@@ -227,6 +261,7 @@ function buildDiscriminatedUnionSerializer(
|
|
|
227
261
|
if (nameOnly) {
|
|
228
262
|
return resolveReference(refkey(type, "serializer"));
|
|
229
263
|
}
|
|
264
|
+
// Get the base serializer name and ensure reference tracking
|
|
230
265
|
const baseSerializerName = `${normalizeModelName(
|
|
231
266
|
context,
|
|
232
267
|
type,
|
|
@@ -248,12 +283,17 @@ function buildDiscriminatedUnionSerializer(
|
|
|
248
283
|
type.discriminatorProperty
|
|
249
284
|
);
|
|
250
285
|
const union = subType.discriminatedSubtypes ? "Union" : "";
|
|
251
|
-
const subTypeName =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
NameType.
|
|
255
|
-
|
|
286
|
+
const subTypeName = normalizeModelName(
|
|
287
|
+
context,
|
|
288
|
+
subType,
|
|
289
|
+
NameType.Interface,
|
|
290
|
+
!union
|
|
256
291
|
);
|
|
292
|
+
// Get the serializer name and ensure reference tracking
|
|
293
|
+
const subtypeSerializerName = buildModelSerializer(context, subType, {
|
|
294
|
+
nameOnly: true,
|
|
295
|
+
skipDiscriminatedUnionSuffix: false
|
|
296
|
+
}) as string;
|
|
257
297
|
|
|
258
298
|
const caseLabels = discriminatedValues.map((value) => `case "${value}":`);
|
|
259
299
|
cases.push(`
|
|
@@ -345,14 +385,18 @@ function buildModelTypeSerializer(
|
|
|
345
385
|
});
|
|
346
386
|
return ""; // Return empty string to continue processing
|
|
347
387
|
}
|
|
348
|
-
const serializerFunctionName =
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
388
|
+
const serializerFunctionName =
|
|
389
|
+
options.predefinedName ??
|
|
390
|
+
`${normalizeModelName(
|
|
391
|
+
context,
|
|
392
|
+
type,
|
|
393
|
+
NameType.Operation,
|
|
394
|
+
options.skipDiscriminatedUnionSuffix
|
|
395
|
+
)}Serializer`;
|
|
354
396
|
if (options.nameOnly) {
|
|
355
|
-
return
|
|
397
|
+
return options.flatten
|
|
398
|
+
? resolveReference(refkey(options.flatten.property, "serializer"))
|
|
399
|
+
: resolveReference(refkey(type, "serializer"));
|
|
356
400
|
}
|
|
357
401
|
const serializerFunction: FunctionDeclarationStructure = {
|
|
358
402
|
kind: StructureKind.Function,
|
|
@@ -361,7 +405,9 @@ function buildModelTypeSerializer(
|
|
|
361
405
|
parameters: [
|
|
362
406
|
{
|
|
363
407
|
name: "item",
|
|
364
|
-
type:
|
|
408
|
+
type: options.flatten
|
|
409
|
+
? resolveReference(refkey(options.flatten.baseModel))
|
|
410
|
+
: resolveReference(refkey(type))
|
|
365
411
|
}
|
|
366
412
|
],
|
|
367
413
|
returnType: "any",
|
|
@@ -435,7 +481,13 @@ function buildModelTypeSerializer(
|
|
|
435
481
|
type
|
|
436
482
|
);
|
|
437
483
|
|
|
438
|
-
const propertiesStr = getRequestModelMapping(
|
|
484
|
+
const propertiesStr = getRequestModelMapping(
|
|
485
|
+
context,
|
|
486
|
+
type,
|
|
487
|
+
"item",
|
|
488
|
+
options.overrides,
|
|
489
|
+
!options.flatten
|
|
490
|
+
);
|
|
439
491
|
|
|
440
492
|
if (additionalPropertiesSpread) {
|
|
441
493
|
propertiesStr.unshift(additionalPropertiesSpread);
|
|
@@ -470,8 +522,10 @@ function getAdditionalPropertiesStatement(
|
|
|
470
522
|
const deserializerFunction = buildModelSerializer(
|
|
471
523
|
context,
|
|
472
524
|
additionalPropertyType,
|
|
473
|
-
|
|
474
|
-
|
|
525
|
+
{
|
|
526
|
+
nameOnly: true,
|
|
527
|
+
skipDiscriminatedUnionSuffix: false
|
|
528
|
+
}
|
|
475
529
|
);
|
|
476
530
|
const params = [`item.${getAdditionalPropertiesName(context, type)} ?? {}`];
|
|
477
531
|
if (typeof deserializerFunction === "string") {
|
|
@@ -497,12 +551,10 @@ function buildDictTypeSerializer(
|
|
|
497
551
|
type: SdkDictionaryType,
|
|
498
552
|
nameOnly = false
|
|
499
553
|
): FunctionDeclarationStructure | undefined | string {
|
|
500
|
-
const valueSerializer = buildModelSerializer(
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
true
|
|
505
|
-
);
|
|
554
|
+
const valueSerializer = buildModelSerializer(context, type.valueType, {
|
|
555
|
+
nameOnly: true,
|
|
556
|
+
skipDiscriminatedUnionSuffix: false
|
|
557
|
+
});
|
|
506
558
|
if (!valueSerializer) {
|
|
507
559
|
return undefined;
|
|
508
560
|
}
|
|
@@ -555,12 +607,10 @@ function buildArrayTypeSerializer(
|
|
|
555
607
|
type: SdkArrayType,
|
|
556
608
|
nameOnly = false
|
|
557
609
|
): FunctionDeclarationStructure | undefined | string {
|
|
558
|
-
const valueSerializer = buildModelSerializer(
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
true
|
|
563
|
-
);
|
|
610
|
+
const valueSerializer = buildModelSerializer(context, type.valueType, {
|
|
611
|
+
nameOnly: true,
|
|
612
|
+
skipDiscriminatedUnionSuffix: false
|
|
613
|
+
});
|
|
564
614
|
if (!valueSerializer) {
|
|
565
615
|
return undefined;
|
|
566
616
|
}
|
|
@@ -182,4 +182,41 @@ export function isPolymorphicUnion(t: SdkType): boolean {
|
|
|
182
182
|
export interface ModelSerializeOptions {
|
|
183
183
|
nameOnly: boolean;
|
|
184
184
|
skipDiscriminatedUnionSuffix: boolean;
|
|
185
|
+
// Indicates if the serializer is being built for a property that is flattened.
|
|
186
|
+
flatten?: {
|
|
187
|
+
baseModel: SdkModelType;
|
|
188
|
+
property: SdkModelPropertyType;
|
|
189
|
+
};
|
|
190
|
+
// Indicates if any overrides should be applied when building the serializer/deserializer.
|
|
191
|
+
overrides?: ModelOverrideOptions;
|
|
192
|
+
// Predefined name to use for the serializer/deserializer instead of generating one.
|
|
193
|
+
predefinedName?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Options for overriding model information during serialization/deserialization.
|
|
197
|
+
export interface ModelOverrideOptions {
|
|
198
|
+
// If true, all properties will be treated as optional during serialization/deserialization.
|
|
199
|
+
allOptional?: boolean;
|
|
200
|
+
|
|
201
|
+
// The <Property, Client_Name> map for any renamed properties.
|
|
202
|
+
// Mainly because the original client name has collision with other property names during flattening.
|
|
203
|
+
propertyRenames?: Map<SdkModelPropertyType, string>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function getPropertyWithOverrides(
|
|
207
|
+
property: SdkModelPropertyType,
|
|
208
|
+
overrides?: ModelOverrideOptions
|
|
209
|
+
): SdkModelPropertyType {
|
|
210
|
+
if (!overrides) {
|
|
211
|
+
return property;
|
|
212
|
+
}
|
|
213
|
+
let updatedProperty = property;
|
|
214
|
+
if (overrides.allOptional) {
|
|
215
|
+
updatedProperty = { ...updatedProperty, optional: true };
|
|
216
|
+
}
|
|
217
|
+
const renamedClientName = overrides.propertyRenames?.get(property);
|
|
218
|
+
if (renamedClientName) {
|
|
219
|
+
updatedProperty = { ...updatedProperty, name: renamedClientName };
|
|
220
|
+
}
|
|
221
|
+
return updatedProperty;
|
|
185
222
|
}
|
|
@@ -33,6 +33,11 @@ export const SerializationHelpers = {
|
|
|
33
33
|
kind: "function",
|
|
34
34
|
name: "getBinaryResponse",
|
|
35
35
|
location: "serialization/get-binary-response.ts"
|
|
36
|
+
},
|
|
37
|
+
areAllPropsUndefined: {
|
|
38
|
+
kind: "function",
|
|
39
|
+
name: "areAllPropsUndefined",
|
|
40
|
+
location: "serialization/check-prop-undefined.ts"
|
|
36
41
|
}
|
|
37
42
|
} as const;
|
|
38
43
|
|
|
@@ -82,6 +87,19 @@ export const PollingHelpers = {
|
|
|
82
87
|
}
|
|
83
88
|
} as const;
|
|
84
89
|
|
|
90
|
+
export const SimplePollerHelpers = {
|
|
91
|
+
SimplePollerLike: {
|
|
92
|
+
kind: "interface",
|
|
93
|
+
name: "SimplePollerLike",
|
|
94
|
+
location: "simplePollerHelpers.ts"
|
|
95
|
+
},
|
|
96
|
+
getSimplePoller: {
|
|
97
|
+
kind: "function",
|
|
98
|
+
name: "getSimplePoller",
|
|
99
|
+
location: "simplePollerHelpers.ts"
|
|
100
|
+
}
|
|
101
|
+
} as const;
|
|
102
|
+
|
|
85
103
|
export const UrlTemplateHelpers = {
|
|
86
104
|
parseTemplate: {
|
|
87
105
|
kind: "function",
|
|
@@ -74,6 +74,7 @@ function extractRLCOptions(
|
|
|
74
74
|
const productDocLink = emitterOptions["product-doc-link"];
|
|
75
75
|
const isModularLibrary = emitterOptions["is-modular-library"];
|
|
76
76
|
const compatibilityMode = emitterOptions["compatibility-mode"];
|
|
77
|
+
const compatibilityLro = emitterOptions["compatibility-lro"];
|
|
77
78
|
const experimentalExtensibleEnums =
|
|
78
79
|
emitterOptions["experimental-extensible-enums"];
|
|
79
80
|
const ignorePropertyNameNormalize =
|
|
@@ -110,6 +111,7 @@ function extractRLCOptions(
|
|
|
110
111
|
productDocLink,
|
|
111
112
|
isModularLibrary,
|
|
112
113
|
compatibilityMode,
|
|
114
|
+
compatibilityLro,
|
|
113
115
|
experimentalExtensibleEnums,
|
|
114
116
|
ignorePropertyNameNormalize,
|
|
115
117
|
compatibilityQueryMultiFormat,
|
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
isGlobalNamespace,
|
|
4
4
|
isService,
|
|
5
5
|
Namespace,
|
|
6
|
+
NoTarget,
|
|
6
7
|
Operation
|
|
7
8
|
} from "@typespec/compiler";
|
|
9
|
+
import { reportDiagnostic } from "../lib.js";
|
|
8
10
|
import { SdkContext } from "./interfaces.js";
|
|
9
11
|
|
|
10
12
|
export function getModelNamespaceName(
|
|
@@ -68,14 +70,28 @@ export function getOperationNamespaceInterfaceName(
|
|
|
68
70
|
export function detectModelConflicts(dpgContext: SdkContext) {
|
|
69
71
|
const allModels = getAllModels(dpgContext);
|
|
70
72
|
const nameSet = new Set<string>();
|
|
73
|
+
const reported = new Set<string>();
|
|
74
|
+
let hasConflict = false;
|
|
71
75
|
for (const model of allModels) {
|
|
72
76
|
if (model.name === "") {
|
|
73
77
|
continue;
|
|
74
78
|
}
|
|
75
|
-
if (nameSet.has(model.name)) {
|
|
76
|
-
|
|
79
|
+
if (nameSet.has(model.name) && !reported.has(model.name)) {
|
|
80
|
+
reportDiagnostic(dpgContext.program, {
|
|
81
|
+
code: "detected-model-name-conflict",
|
|
82
|
+
format: {
|
|
83
|
+
modelName: model.name,
|
|
84
|
+
namespaces: allModels
|
|
85
|
+
.filter((m) => m.name === model.name)
|
|
86
|
+
.map((m) => m.namespace)
|
|
87
|
+
.join(" and ")
|
|
88
|
+
},
|
|
89
|
+
target: NoTarget
|
|
90
|
+
});
|
|
91
|
+
reported.add(model.name);
|
|
92
|
+
hasConflict = true;
|
|
77
93
|
}
|
|
78
94
|
nameSet.add(model.name);
|
|
79
95
|
}
|
|
80
|
-
return
|
|
96
|
+
return hasConflict;
|
|
81
97
|
}
|
|
@@ -679,6 +679,41 @@ export function getMethodHierarchiesMap(
|
|
|
679
679
|
return operationHierarchiesMap;
|
|
680
680
|
}
|
|
681
681
|
|
|
682
|
+
export function isTenantLevelOperation(
|
|
683
|
+
operation: ServiceOperation,
|
|
684
|
+
client: SdkClientType<SdkServiceOperation>
|
|
685
|
+
): boolean {
|
|
686
|
+
// Check if this operation has a subscriptionId path parameter
|
|
687
|
+
const subscriptionIdParam = operation.operation.parameters?.find(
|
|
688
|
+
(param) =>
|
|
689
|
+
param.name.toLowerCase() === "subscriptionid" && param.kind === "path"
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
if (subscriptionIdParam) {
|
|
693
|
+
// The operation has a client-level subscriptionId parameter, then it's not tenant-level
|
|
694
|
+
if (subscriptionIdParam.onClient) {
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
} else {
|
|
698
|
+
// Skip tenant-level internal ARM APIs
|
|
699
|
+
// Ref: https://armwiki.azurewebsites.net/rpaas/operations_auto_gen.html#special-cases
|
|
700
|
+
const pathLC = operation.operation.path.toLowerCase();
|
|
701
|
+
// Get the provider namespace from the client
|
|
702
|
+
const clientNamespaceLC = client.namespace.toLowerCase();
|
|
703
|
+
if (
|
|
704
|
+
operation.crossLanguageDefinitionId?.toLowerCase() ===
|
|
705
|
+
"azure.resourcemanager.operations.list" ||
|
|
706
|
+
pathLC.includes(`${clientNamespaceLC}/checknameavailability`)
|
|
707
|
+
) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// The operation has no subscriptionId parameter or has method-level subscriptionId parameter
|
|
713
|
+
// Considered as tenant-level
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
|
|
682
717
|
function resolveParameterNameConflict(
|
|
683
718
|
operationOrGroup: SdkServiceMethod<SdkHttpOperation>,
|
|
684
719
|
p: SdkMethodParameter | SdkHttpParameter | SdkBodyParameter
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if all specified properties of the item are undefined.
|
|
3
|
+
* @param item The object to check.
|
|
4
|
+
* @param properties The list of property names to check on the item.
|
|
5
|
+
* @returns True if all specified properties are undefined, otherwise false.
|
|
6
|
+
*/
|
|
7
|
+
export function areAllPropsUndefined(
|
|
8
|
+
item: Record<string, any>,
|
|
9
|
+
properties: string[]
|
|
10
|
+
): boolean {
|
|
11
|
+
for (const property of properties) {
|
|
12
|
+
if (item[property] !== undefined) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { PollerLike, OperationState, CancelOnProgress } from "@azure/core-lro";
|
|
2
|
+
import { AbortSignalLike } from "@azure/abort-controller";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A simple poller that can be used to poll a long running operation.
|
|
6
|
+
*/
|
|
7
|
+
export interface SimplePollerLike<
|
|
8
|
+
TState extends OperationState<TResult>,
|
|
9
|
+
TResult
|
|
10
|
+
> {
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the poller has finished polling.
|
|
13
|
+
*/
|
|
14
|
+
isDone(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the state of the operation.
|
|
17
|
+
*/
|
|
18
|
+
getOperationState(): TState;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the result value of the operation,
|
|
21
|
+
* regardless of the state of the poller.
|
|
22
|
+
* It can return undefined or an incomplete form of the final TResult value
|
|
23
|
+
* depending on the implementation.
|
|
24
|
+
*/
|
|
25
|
+
getResult(): TResult | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a promise that will resolve once a single polling request finishes.
|
|
28
|
+
* It does this by calling the update method of the Poller's operation.
|
|
29
|
+
*/
|
|
30
|
+
poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a promise that will resolve once the underlying operation is completed.
|
|
33
|
+
*/
|
|
34
|
+
pollUntilDone(pollOptions?: {
|
|
35
|
+
abortSignal?: AbortSignalLike;
|
|
36
|
+
}): Promise<TResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Invokes the provided callback after each polling is completed,
|
|
39
|
+
* sending the current state of the poller's operation.
|
|
40
|
+
*
|
|
41
|
+
* It returns a method that can be used to stop receiving updates on the given callback function.
|
|
42
|
+
*/
|
|
43
|
+
onProgress(callback: (state: TState) => void): CancelOnProgress;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns a promise that could be used for serialized version of the poller's operation
|
|
47
|
+
* by invoking the operation's serialize method.
|
|
48
|
+
*/
|
|
49
|
+
serialize(): Promise<string>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Wait the poller to be submitted.
|
|
53
|
+
*/
|
|
54
|
+
submitted(): Promise<void>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns a string representation of the poller's operation. Similar to serialize but returns a string.
|
|
58
|
+
* @deprecated Use serialize() instead.
|
|
59
|
+
*/
|
|
60
|
+
toString(): string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Stops the poller from continuing to poll. Please note this will only stop the client-side polling
|
|
64
|
+
* @deprecated Use abortSignal to stop polling instead.
|
|
65
|
+
*/
|
|
66
|
+
stopPolling(): void;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns true if the poller is stopped.
|
|
70
|
+
* @deprecated Use abortSignal status to track this instead.
|
|
71
|
+
*/
|
|
72
|
+
isStopped(): boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create the deprecated SimplePollerLike from PollerLike
|
|
77
|
+
* @param poller PollerLike to convert
|
|
78
|
+
* @returns SimplePollerLike
|
|
79
|
+
*/
|
|
80
|
+
export function getSimplePoller<TResult>(
|
|
81
|
+
poller: PollerLike<OperationState<TResult>, TResult>
|
|
82
|
+
): SimplePollerLike<OperationState<TResult>, TResult> {
|
|
83
|
+
const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {
|
|
84
|
+
isDone() {
|
|
85
|
+
return poller.isDone;
|
|
86
|
+
},
|
|
87
|
+
isStopped() {
|
|
88
|
+
throw new Error(
|
|
89
|
+
"isStopped is deprecated. Use abortSignal status to track this instead."
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
getOperationState() {
|
|
93
|
+
if (!poller.operationState) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState()."
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return poller.operationState;
|
|
99
|
+
},
|
|
100
|
+
getResult() {
|
|
101
|
+
return poller.result;
|
|
102
|
+
},
|
|
103
|
+
toString() {
|
|
104
|
+
if (!poller.operationState) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState()."
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return JSON.stringify({
|
|
110
|
+
state: poller.operationState
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
stopPolling() {
|
|
114
|
+
throw new Error(
|
|
115
|
+
"stopPolling is deprecated. Use abortSignal to stop polling instead."
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
onProgress: poller.onProgress,
|
|
119
|
+
poll: poller.poll,
|
|
120
|
+
pollUntilDone: poller.pollUntilDone,
|
|
121
|
+
serialize: poller.serialize,
|
|
122
|
+
submitted: poller.submitted
|
|
123
|
+
};
|
|
124
|
+
return simplePoller;
|
|
125
|
+
}
|