@azure-tools/typespec-ts 0.28.0 → 0.29.0-alpha.20240531.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 +12 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -18
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +14 -4
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +9 -2
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +2 -0
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +3 -0
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +80 -83
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildLroFiles.d.ts +24 -0
- package/dist/src/modular/buildLroFiles.d.ts.map +1 -0
- package/dist/src/modular/buildLroFiles.js +399 -0
- package/dist/src/modular/buildLroFiles.js.map +1 -0
- package/dist/src/modular/buildOperations.d.ts +6 -0
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +64 -5
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildPagingFiles.js +3 -3
- package/dist/src/modular/buildPagingFiles.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts +0 -3
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +0 -399
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +20 -0
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +4 -3
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +2 -0
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +73 -11
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +5 -5
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +171 -55
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +6 -1
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/interfaces.d.ts +5 -0
- package/dist/src/modular/interfaces.d.ts.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +9 -1
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +1 -1
- package/dist/src/transform/transformParameters.js +2 -2
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.js +1 -1
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.js +2 -2
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +23 -31
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +8 -1
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +12 -2
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +88 -49
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -18
- package/src/index.ts +36 -22
- package/src/lib.ts +10 -2
- package/src/modular/buildClassicalClient.ts +2 -0
- package/src/modular/buildClassicalOperationGroups.ts +4 -0
- package/src/modular/buildCodeModel.ts +100 -155
- package/src/modular/buildLroFiles.ts +433 -0
- package/src/modular/buildOperations.ts +91 -10
- package/src/modular/buildPagingFiles.ts +4 -4
- package/src/modular/buildProjectFiles.ts +0 -471
- package/src/modular/buildRootIndex.ts +49 -0
- package/src/modular/buildSubpathIndex.ts +4 -4
- package/src/modular/emitModels.ts +102 -15
- package/src/modular/helpers/operationHelpers.ts +207 -72
- package/src/modular/helpers/typeHelpers.ts +6 -2
- package/src/modular/interfaces.ts +6 -0
- package/src/modular/modularCodeModel.ts +10 -1
- package/src/transform/transformHelperFunctionDetails.ts +1 -1
- package/src/transform/transformParameters.ts +2 -2
- package/src/transform/transformPaths.ts +1 -1
- package/src/transform/transformResponses.ts +2 -2
- package/src/transform/transformSchemas.ts +22 -33
- package/src/transform/transfromRLCOptions.ts +10 -1
- package/src/utils/modelUtils.ts +107 -46
|
@@ -7,19 +7,37 @@ import { getImportSpecifier } from "@azure-tools/rlc-common";
|
|
|
7
7
|
function isAzureCoreErrorSdkType(t) {
|
|
8
8
|
return (t.name &&
|
|
9
9
|
["error", "errormodel", "innererror", "errorresponse"].includes(t.name.toLowerCase()) &&
|
|
10
|
-
t.
|
|
10
|
+
t.coreTypeInfo === "ErrorType");
|
|
11
|
+
}
|
|
12
|
+
function isAzureCoreLroSdkType(t) {
|
|
13
|
+
return (t.name &&
|
|
14
|
+
["operationstate"].includes(t.name.toLowerCase()) &&
|
|
15
|
+
t.coreTypeInfo === "LroType");
|
|
16
|
+
}
|
|
17
|
+
function isAnonymousModel(t) {
|
|
18
|
+
return t.type === "model" && t.name === "";
|
|
19
|
+
}
|
|
20
|
+
export function isModelWithAdditionalProperties(t) {
|
|
21
|
+
return t.type === "dict" && t.name !== "Record";
|
|
11
22
|
}
|
|
12
23
|
function getCoreClientErrorType(name, coreClientTypes) {
|
|
13
24
|
const coreClientType = name === "Error" ? "ErrorModel" : name;
|
|
14
25
|
coreClientTypes.add(coreClientType);
|
|
15
26
|
return coreClientType;
|
|
16
27
|
}
|
|
28
|
+
function getCoreLroType(name, coreLroTypes) {
|
|
29
|
+
const coreLroType = name === "OperationState" ? "CoreOperationStatus" : name;
|
|
30
|
+
coreLroTypes.add(coreLroType);
|
|
31
|
+
return coreLroType;
|
|
32
|
+
}
|
|
17
33
|
// ====== TYPE EXTRACTION ======
|
|
18
34
|
function extractModels(codeModel) {
|
|
19
35
|
var _a;
|
|
20
|
-
const models = codeModel.types.filter((t) => (t.type === "model" || t.type === "enum") &&
|
|
36
|
+
const models = codeModel.types.filter((t) => ((t.type === "model" || t.type === "enum") &&
|
|
21
37
|
!isAzureCoreErrorSdkType(t) &&
|
|
22
|
-
!(t
|
|
38
|
+
!isAzureCoreLroSdkType(t) &&
|
|
39
|
+
!isAnonymousModel(t)) ||
|
|
40
|
+
isModelWithAdditionalProperties(t));
|
|
23
41
|
for (const model of codeModel.types) {
|
|
24
42
|
if (model.type === "combined" && model.nullable) {
|
|
25
43
|
for (const unionModel of (_a = model.types) !== null && _a !== void 0 ? _a : []) {
|
|
@@ -37,7 +55,10 @@ function extractModels(codeModel) {
|
|
|
37
55
|
* 2. alias from unions, where we also need to use typescript union to combine all the union variants
|
|
38
56
|
*/
|
|
39
57
|
export function extractAliases(codeModel) {
|
|
40
|
-
const models = codeModel.types.filter((t) => (t.type === "model" || t.type === "combined") &&
|
|
58
|
+
const models = codeModel.types.filter((t) => ((t.type === "model" || t.type === "combined") &&
|
|
59
|
+
t.alias &&
|
|
60
|
+
t.aliasType) ||
|
|
61
|
+
(isModelWithAdditionalProperties(t) && t.alias && t.aliasType));
|
|
41
62
|
return models;
|
|
42
63
|
}
|
|
43
64
|
// ====== TYPE BUILDERS ======
|
|
@@ -82,9 +103,10 @@ export function buildModelInterface(model, cache) {
|
|
|
82
103
|
const propertyMetadata = getType(p.type, p.format);
|
|
83
104
|
let propertyTypeName = propertyMetadata.name;
|
|
84
105
|
if (isAzureCoreErrorSdkType(p.type)) {
|
|
85
|
-
propertyTypeName =
|
|
86
|
-
|
|
87
|
-
|
|
106
|
+
propertyTypeName = getCoreClientErrorType(propertyTypeName, cache.coreClientTypes);
|
|
107
|
+
}
|
|
108
|
+
if (isAzureCoreLroSdkType(p.type)) {
|
|
109
|
+
propertyTypeName = getCoreLroType(propertyTypeName, cache.coreLroTypes);
|
|
88
110
|
}
|
|
89
111
|
return {
|
|
90
112
|
name: `"${p.clientName}"`,
|
|
@@ -105,6 +127,7 @@ export function buildModels(subClient, codeModel) {
|
|
|
105
127
|
var _a, _b;
|
|
106
128
|
// We are generating both models and enums here
|
|
107
129
|
const coreClientTypes = new Set();
|
|
130
|
+
const coreLroTypes = new Set();
|
|
108
131
|
// filter out the models/enums that are anonymous
|
|
109
132
|
const models = extractModels(codeModel).filter((m) => !!m.name);
|
|
110
133
|
const aliases = extractAliases(codeModel);
|
|
@@ -124,10 +147,14 @@ export function buildModels(subClient, codeModel) {
|
|
|
124
147
|
modelsFile.addTypeAlias(enumAlias);
|
|
125
148
|
}
|
|
126
149
|
else {
|
|
127
|
-
const modelInterface = buildModelInterface(model, {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
const modelInterface = buildModelInterface(model, {
|
|
151
|
+
coreClientTypes,
|
|
152
|
+
coreLroTypes
|
|
153
|
+
});
|
|
154
|
+
(_b = model.parents) === null || _b === void 0 ? void 0 : _b.forEach((p) => { var _a; return modelInterface.extends.push((_a = p.alias) !== null && _a !== void 0 ? _a : getType(p, p.format).name); });
|
|
155
|
+
if (isModelWithAdditionalProperties(model)) {
|
|
156
|
+
addExtendedDictInfo(model, modelInterface, codeModel.modularOptions.compatibilityMode);
|
|
157
|
+
}
|
|
131
158
|
modelsFile.addInterface(modelInterface);
|
|
132
159
|
}
|
|
133
160
|
}
|
|
@@ -139,11 +166,46 @@ export function buildModels(subClient, codeModel) {
|
|
|
139
166
|
}
|
|
140
167
|
]);
|
|
141
168
|
}
|
|
169
|
+
if (coreLroTypes.size > 0) {
|
|
170
|
+
modelsFile.addImportDeclarations([
|
|
171
|
+
{
|
|
172
|
+
moduleSpecifier: getImportSpecifier("azureCoreLro", codeModel.runtimeImports),
|
|
173
|
+
namedImports: Array.from(coreLroTypes).map((t) => t === "CoreOperationStatus"
|
|
174
|
+
? "OperationStatus as CoreOperationStatus"
|
|
175
|
+
: t)
|
|
176
|
+
}
|
|
177
|
+
]);
|
|
178
|
+
}
|
|
142
179
|
aliases.forEach((alias) => {
|
|
143
180
|
modelsFile.addTypeAlias(buildModelTypeAlias(alias));
|
|
144
181
|
});
|
|
145
182
|
return modelsFile;
|
|
146
183
|
}
|
|
184
|
+
function addExtendedDictInfo(model, modelInterface, compatibilityMode = false) {
|
|
185
|
+
var _a, _b, _c, _d, _e;
|
|
186
|
+
if ((model.properties &&
|
|
187
|
+
model.properties.length > 0 &&
|
|
188
|
+
model.elementType &&
|
|
189
|
+
((_a = model.properties) === null || _a === void 0 ? void 0 : _a.every((p) => {
|
|
190
|
+
var _a;
|
|
191
|
+
return (_a = getType(model.elementType)) === null || _a === void 0 ? void 0 : _a.name.includes(getType(p.type).name);
|
|
192
|
+
}))) ||
|
|
193
|
+
(((_b = model.properties) === null || _b === void 0 ? void 0 : _b.length) === 0 && model.elementType)) {
|
|
194
|
+
modelInterface.extends.push(`Record<string, ${(_c = getType(model.elementType).name) !== null && _c !== void 0 ? _c : "any"}>`);
|
|
195
|
+
}
|
|
196
|
+
else if (compatibilityMode) {
|
|
197
|
+
modelInterface.extends.push(`Record<string, any>`);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
(_d = modelInterface.properties) === null || _d === void 0 ? void 0 : _d.push({
|
|
201
|
+
name: "additionalProperties",
|
|
202
|
+
docs: ["Additional properties"],
|
|
203
|
+
hasQuestionToken: true,
|
|
204
|
+
isReadonly: false,
|
|
205
|
+
type: `Record<string, ${(_e = getType(model.elementType).name) !== null && _e !== void 0 ? _e : "any"}>`
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
147
209
|
export function buildModelTypeAlias(model) {
|
|
148
210
|
return {
|
|
149
211
|
name: model.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitModels.js","sourceRoot":"","sources":["../../../src/modular/emitModels.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,0BAA0B;AAE1B,SAAS,uBAAuB,CAAC,CAAO;IACtC,OAAO,CACL,CAAC,CAAC,IAAI;QACN,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,QAAQ,CAC7D,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CACrB;QACD,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"emitModels.js","sourceRoot":"","sources":["../../../src/modular/emitModels.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,0BAA0B;AAE1B,SAAS,uBAAuB,CAAC,CAAO;IACtC,OAAO,CACL,CAAC,CAAC,IAAI;QACN,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,QAAQ,CAC7D,CAAC,CAAC,IAAI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pD,cAAc,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACtC,qBAAqB,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC;IACD,gBAAgB,CAAC,qBAAqB,CAAC;QACrC;YACE,eAAe,EAAE,kBAAkB,CACjC,YAAY,EACZ,SAAS,CAAC,cAAc,CACzB;YACD,YAAY,EAAE,CAAC,kBAAkB,CAAC;SACnC;KACF,CAAC,CAAC;IAEH,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;IACrC,gBAAgB;SACb,qBAAqB,EAAE;SACvB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QACb,OAAO,CACL,EAAE,CAAC,yBAAyB,EAAE;YAC9B,CAAC,EAAE,CAAC,uBAAuB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC9C,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACV,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,uBAAuB,EAAE,GAAG,KAAK,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACL,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -38,11 +38,11 @@ export declare function deserializeResponseValue(type: Type, restValue: string,
|
|
|
38
38
|
* deserialized correctly
|
|
39
39
|
*/
|
|
40
40
|
export declare function serializeRequestValue(type: Type, clientValue: string, runtimeImports: RuntimeImports, required: boolean, typeStack?: Type[], format?: string): string;
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function
|
|
43
|
-
export declare function
|
|
44
|
-
export declare function
|
|
45
|
-
export declare function
|
|
41
|
+
export declare function isLroAndPagingOperation(op: Operation): boolean;
|
|
42
|
+
export declare function isLroOnlyOperation(op: Operation): boolean;
|
|
43
|
+
export declare function hasPagingOnlyOperation(client: Client, needRLC?: boolean): boolean;
|
|
44
|
+
export declare function hasPagingOnlyOperation(codeModel: ModularCodeModel, needRLC?: boolean): boolean;
|
|
45
|
+
export declare function isPagingOnlyOperation(op: Operation): boolean;
|
|
46
46
|
export declare function getAllProperties(type: Type, parents?: Type[]): Property[];
|
|
47
47
|
export declare function getAllAncestors(type: Type): Type[];
|
|
48
48
|
//# sourceMappingURL=operationHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operationHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/operationHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,YAAY,EAEb,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACL,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,OAAO,IAAI,cAAc,EAK1B,MAAM,yBAAyB,CAAC;AAiBjC,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"operationHelpers.d.ts","sourceRoot":"","sources":["../../../../src/modular/helpers/operationHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,YAAY,EAEb,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACL,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,OAAO,IAAI,cAAc,EAK1B,MAAM,yBAAyB,CAAC;AAiBjC,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AA+BzE,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,cAAc,GAC7B,YAAY,CAAC,4BAA4B,CAAC,CAoC5C;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,SAAS,EACpB,aA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E,SAAS,GAAG,OAAO,CAE9D;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAEzD;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC;AACX,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,gBAAgB,EAC3B,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC;AAoBX,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAE5D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,CAczE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAOlD"}
|
|
@@ -19,6 +19,13 @@ function getRLCResponseType(rlcResponse) {
|
|
|
19
19
|
return (_a = resp.predefinedName) !== null && _a !== void 0 ? _a : getResponseTypeName(baseResponseName);
|
|
20
20
|
}).join(" | ");
|
|
21
21
|
}
|
|
22
|
+
function getRLCLroLogicalResponse(rlcResponse) {
|
|
23
|
+
var _a;
|
|
24
|
+
const logicalResponse = ((_a = rlcResponse === null || rlcResponse === void 0 ? void 0 : rlcResponse.responses) !== null && _a !== void 0 ? _a : []).filter((r) => r.predefinedName && r.predefinedName.endsWith(`LogicalResponse`));
|
|
25
|
+
return logicalResponse.length > 0
|
|
26
|
+
? logicalResponse[0].predefinedName
|
|
27
|
+
: "any";
|
|
28
|
+
}
|
|
22
29
|
export function getSendPrivateFunction(dpgContext, operation, clientType, runtimeImports) {
|
|
23
30
|
var _a;
|
|
24
31
|
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
@@ -50,10 +57,16 @@ export function getDeserializePrivateFunction(operation, needSubClient, needUnex
|
|
|
50
57
|
type: getRLCResponseType(operation.rlcResponse)
|
|
51
58
|
}
|
|
52
59
|
];
|
|
60
|
+
// TODO: Support LRO + paging operation
|
|
61
|
+
// https://github.com/Azure/autorest.typescript/issues/2313
|
|
62
|
+
const isLroOnly = isLroOnlyOperation(operation);
|
|
53
63
|
// TODO: Support operation overloads
|
|
54
64
|
const response = operation.responses[0];
|
|
55
65
|
let returnType;
|
|
56
|
-
if (
|
|
66
|
+
if (isLroOnly && operation.method.toLowerCase() !== "patch") {
|
|
67
|
+
returnType = buildLroReturnType(operation);
|
|
68
|
+
}
|
|
69
|
+
else if ((_a = response === null || response === void 0 ? void 0 : response.type) === null || _a === void 0 ? void 0 : _a.type) {
|
|
57
70
|
returnType = buildType(response.type.name, response.type, response.type.format);
|
|
58
71
|
}
|
|
59
72
|
else {
|
|
@@ -84,21 +97,52 @@ export function getDeserializePrivateFunction(operation, needSubClient, needUnex
|
|
|
84
97
|
addImportToSpecifier("restClient", runtimeImports, "createRestError");
|
|
85
98
|
}
|
|
86
99
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
let deserializedType = isLroOnly
|
|
101
|
+
? (_b = operation === null || operation === void 0 ? void 0 : operation.lroMetadata) === null || _b === void 0 ? void 0 : _b.finalResult
|
|
102
|
+
: response.type;
|
|
103
|
+
let hasLroSubPath = ((_c = operation === null || operation === void 0 ? void 0 : operation.lroMetadata) === null || _c === void 0 ? void 0 : _c.finalResultPath) !== undefined;
|
|
104
|
+
let deserializedRoot = hasLroSubPath
|
|
105
|
+
? `result.body.${(_d = operation === null || operation === void 0 ? void 0 : operation.lroMetadata) === null || _d === void 0 ? void 0 : _d.finalResultPath}`
|
|
106
|
+
: "result.body";
|
|
107
|
+
// TODO: Hard-coded for LRO PATCH case for now
|
|
108
|
+
// https://github.com/Azure/autorest.typescript/issues/2314
|
|
109
|
+
if (isLroOnly && operation.method.toLowerCase() === "patch") {
|
|
110
|
+
deserializedType = response.type;
|
|
111
|
+
hasLroSubPath = false;
|
|
112
|
+
deserializedRoot = "result.body";
|
|
113
|
+
}
|
|
114
|
+
if (isLroOnly) {
|
|
115
|
+
const lroLogicalResponse = getRLCLroLogicalResponse(operation.rlcResponse);
|
|
116
|
+
statements.push(`result = result as ${lroLogicalResponse};`);
|
|
117
|
+
if (hasLroSubPath) {
|
|
118
|
+
statements.push(`if(${deserializedRoot.split(".").join("?.")} === undefined) {
|
|
119
|
+
throw createRestError(\`Expected a result in the response at position "${deserializedRoot}"\`, result);
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const allParents = deserializedType ? getAllAncestors(deserializedType) : [];
|
|
125
|
+
const properties = deserializedType
|
|
126
|
+
? getAllProperties(deserializedType, allParents)
|
|
127
|
+
: [];
|
|
128
|
+
if ((deserializedType === null || deserializedType === void 0 ? void 0 : deserializedType.type) === "any" ||
|
|
129
|
+
(deserializedType === null || deserializedType === void 0 ? void 0 : deserializedType.type) === "dict" ||
|
|
130
|
+
((deserializedType === null || deserializedType === void 0 ? void 0 : deserializedType.type) === "model" &&
|
|
131
|
+
allParents.some((p) => p.type === "dict")) ||
|
|
90
132
|
response.isBinaryPayload ||
|
|
91
|
-
(
|
|
133
|
+
(deserializedType === null || deserializedType === void 0 ? void 0 : deserializedType.aliasType)) {
|
|
92
134
|
statements.push(`return result.body`);
|
|
93
135
|
}
|
|
94
|
-
else if (properties.length > 0) {
|
|
95
|
-
statements.push(`return {`, getResponseMapping(
|
|
136
|
+
else if (deserializedType && properties.length > 0) {
|
|
137
|
+
statements.push(`return {`, getResponseMapping(deserializedType, deserializedRoot, runtimeImports).join(","), `}`);
|
|
96
138
|
}
|
|
97
|
-
else if (returnType.type === "void") {
|
|
139
|
+
else if (returnType.type === "void" || deserializedType === undefined) {
|
|
98
140
|
statements.push(`return;`);
|
|
99
141
|
}
|
|
100
142
|
else {
|
|
101
|
-
statements.push(`return ${deserializeResponseValue(
|
|
143
|
+
statements.push(`return ${deserializeResponseValue(deserializedType, deserializedRoot, runtimeImports, deserializedType.nullable !== undefined
|
|
144
|
+
? !deserializedType.nullable
|
|
145
|
+
: false, [deserializedType], deserializedType.format)}`);
|
|
102
146
|
}
|
|
103
147
|
return {
|
|
104
148
|
...functionStatement,
|
|
@@ -140,17 +184,25 @@ function getOperationSignatureParameters(operation, clientType) {
|
|
|
140
184
|
*/
|
|
141
185
|
export function getOperationFunction(operation, clientType) {
|
|
142
186
|
var _a, _b;
|
|
187
|
+
if (isPagingOnlyOperation(operation)) {
|
|
188
|
+
// Case 1: paging-only operation
|
|
189
|
+
return getPagingOnlyOperationFunction(operation, clientType);
|
|
190
|
+
}
|
|
191
|
+
else if (isLroOnlyOperation(operation)) {
|
|
192
|
+
// Case 2: lro-only operation
|
|
193
|
+
return getLroOnlyOperationFunction(operation, clientType);
|
|
194
|
+
}
|
|
195
|
+
else if (isLroAndPagingOperation(operation)) {
|
|
196
|
+
// Case 3: both paging + lro operation is not supported yet so handle them as normal operation and customization may be needed
|
|
197
|
+
// https://github.com/Azure/autorest.typescript/issues/2313
|
|
198
|
+
}
|
|
143
199
|
// Extract required parameters
|
|
144
200
|
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
145
|
-
const isPaging = isPagingOperation(operation);
|
|
146
201
|
// TODO: Support operation overloads
|
|
147
202
|
const response = operation.responses[0];
|
|
148
203
|
let returnType = { name: "", type: "void" };
|
|
149
204
|
if ((_a = response.type) === null || _a === void 0 ? void 0 : _a.type) {
|
|
150
|
-
|
|
151
|
-
if (isPaging) {
|
|
152
|
-
type = (_b = extractPagingType(type, operation.itemName)) !== null && _b !== void 0 ? _b : type;
|
|
153
|
-
}
|
|
205
|
+
const type = (_b = extractPagingType(response.type, operation.itemName)) !== null && _b !== void 0 ? _b : response.type;
|
|
154
206
|
returnType = buildType(type.name, type, type.format);
|
|
155
207
|
}
|
|
156
208
|
const { name, fixme = [] } = getOperationName(operation);
|
|
@@ -159,37 +211,101 @@ export function getOperationFunction(operation, clientType) {
|
|
|
159
211
|
...getDocsFromDescription(operation.description),
|
|
160
212
|
...getFixmeForMultilineDocs(fixme)
|
|
161
213
|
],
|
|
162
|
-
isAsync:
|
|
214
|
+
isAsync: true,
|
|
163
215
|
isExported: true,
|
|
164
216
|
name,
|
|
165
217
|
propertyName: operation.name,
|
|
166
218
|
parameters,
|
|
167
|
-
returnType:
|
|
168
|
-
? `PagedAsyncIterableIterator<${returnType.type}>`
|
|
169
|
-
: `Promise<${returnType.type}>`
|
|
219
|
+
returnType: `Promise<${returnType.type}>`
|
|
170
220
|
};
|
|
171
221
|
const statements = [];
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
222
|
+
statements.push(`const result = await _${name}Send(${parameters
|
|
223
|
+
.map((p) => p.name)
|
|
224
|
+
.join(", ")});`);
|
|
225
|
+
statements.push(`return _${name}Deserialize(result);`);
|
|
226
|
+
return {
|
|
227
|
+
...functionStatement,
|
|
228
|
+
statements
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function getLroOnlyOperationFunction(operation, clientType) {
|
|
232
|
+
// Extract required parameters
|
|
233
|
+
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
234
|
+
const returnType = buildLroReturnType(operation);
|
|
235
|
+
const { name, fixme = [] } = getOperationName(operation);
|
|
236
|
+
const functionStatement = {
|
|
237
|
+
docs: [
|
|
238
|
+
...getDocsFromDescription(operation.description),
|
|
239
|
+
...getFixmeForMultilineDocs(fixme)
|
|
240
|
+
],
|
|
241
|
+
isAsync: false,
|
|
242
|
+
isExported: true,
|
|
243
|
+
name,
|
|
244
|
+
propertyName: operation.name,
|
|
245
|
+
parameters,
|
|
246
|
+
returnType: `PollerLike<OperationState<${returnType.type}>, ${returnType.type}>`
|
|
247
|
+
};
|
|
248
|
+
const statements = [];
|
|
249
|
+
statements.push(`
|
|
250
|
+
return getLongRunningPoller(context, _${name}Deserialize, {
|
|
251
|
+
updateIntervalInMs: options?.updateIntervalInMs,
|
|
252
|
+
abortSignal: options?.abortSignal,
|
|
253
|
+
getInitialResponse: () => _${name}Send(${parameters
|
|
254
|
+
.map((p) => p.name)
|
|
255
|
+
.join(", ")})
|
|
256
|
+
}) as PollerLike<OperationState<${returnType.type}>, ${returnType.type}>;
|
|
257
|
+
`);
|
|
258
|
+
return {
|
|
259
|
+
...functionStatement,
|
|
260
|
+
statements
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function buildLroReturnType(operation) {
|
|
264
|
+
const metadata = operation.lroMetadata;
|
|
265
|
+
if (metadata !== undefined && metadata.finalResult !== undefined) {
|
|
266
|
+
const type = metadata.finalResult;
|
|
267
|
+
return buildType(type.name, type, type.format);
|
|
186
268
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
269
|
+
return { name: "", type: "void" };
|
|
270
|
+
}
|
|
271
|
+
function getPagingOnlyOperationFunction(operation, clientType) {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
// Extract required parameters
|
|
274
|
+
const parameters = getOperationSignatureParameters(operation, clientType);
|
|
275
|
+
// TODO: Support operation overloads
|
|
276
|
+
const response = operation.responses[0];
|
|
277
|
+
let returnType = { name: "", type: "void" };
|
|
278
|
+
if ((_a = response.type) === null || _a === void 0 ? void 0 : _a.type) {
|
|
279
|
+
const type = (_b = extractPagingType(response.type, operation.itemName)) !== null && _b !== void 0 ? _b : response.type;
|
|
280
|
+
returnType = buildType(type.name, type, type.format);
|
|
192
281
|
}
|
|
282
|
+
const { name, fixme = [] } = getOperationName(operation);
|
|
283
|
+
const functionStatement = {
|
|
284
|
+
docs: [
|
|
285
|
+
...getDocsFromDescription(operation.description),
|
|
286
|
+
...getFixmeForMultilineDocs(fixme)
|
|
287
|
+
],
|
|
288
|
+
isAsync: false,
|
|
289
|
+
isExported: true,
|
|
290
|
+
name,
|
|
291
|
+
propertyName: operation.name,
|
|
292
|
+
parameters,
|
|
293
|
+
returnType: `PagedAsyncIterableIterator<${returnType.type}>`
|
|
294
|
+
};
|
|
295
|
+
const statements = [];
|
|
296
|
+
const options = [];
|
|
297
|
+
if (operation.itemName) {
|
|
298
|
+
options.push(`itemName: "${operation.itemName}"`);
|
|
299
|
+
}
|
|
300
|
+
if (operation.continuationTokenName) {
|
|
301
|
+
options.push(`nextLinkName: "${operation.continuationTokenName}"`);
|
|
302
|
+
}
|
|
303
|
+
statements.push(`return buildPagedAsyncIterator(
|
|
304
|
+
context,
|
|
305
|
+
() => _${name}Send(${parameters.map((p) => p.name).join(", ")}),
|
|
306
|
+
_${name}Deserialize,
|
|
307
|
+
${options.length > 0 ? `{${options.join(", ")}}` : ``}
|
|
308
|
+
);`);
|
|
193
309
|
return {
|
|
194
310
|
...functionStatement,
|
|
195
311
|
statements
|
|
@@ -291,7 +407,10 @@ function buildBodyParameter(bodyParameter, runtimeImports) {
|
|
|
291
407
|
if (!bodyParameter) {
|
|
292
408
|
return "";
|
|
293
409
|
}
|
|
294
|
-
|
|
410
|
+
const allParents = getAllAncestors(bodyParameter.type);
|
|
411
|
+
if (bodyParameter.type.type === "model" &&
|
|
412
|
+
!bodyParameter.type.aliasType &&
|
|
413
|
+
!allParents.some((p) => p.type === "dict")) {
|
|
295
414
|
const bodyParts = getRequestModelMapping(bodyParameter.type, bodyParameter.clientName, runtimeImports, [bodyParameter.type]);
|
|
296
415
|
if (bodyParameter && bodyParts.length > 0) {
|
|
297
416
|
const optionalBody = bodyParameter.optional
|
|
@@ -303,8 +422,10 @@ function buildBodyParameter(bodyParameter, runtimeImports) {
|
|
|
303
422
|
return `\nbody: ${bodyParameter.clientName},`;
|
|
304
423
|
}
|
|
305
424
|
}
|
|
306
|
-
else if (bodyParameter.type.type === "model" &&
|
|
307
|
-
bodyParameter.type.aliasType
|
|
425
|
+
else if ((bodyParameter.type.type === "model" &&
|
|
426
|
+
(bodyParameter.type.aliasType ||
|
|
427
|
+
allParents.some((p) => p.type === "dict"))) ||
|
|
428
|
+
bodyParameter.type.type === "dict") {
|
|
308
429
|
return `\nbody: ${bodyParameter.clientName},`;
|
|
309
430
|
}
|
|
310
431
|
if (bodyParameter.type.type === "list") {
|
|
@@ -498,7 +619,7 @@ export function getRequestModelMapping(modelPropertyType, propertyPath = "body",
|
|
|
498
619
|
const propertyFullName = `${propertyPath}.${property.clientName}`;
|
|
499
620
|
if (property.type.type === "model") {
|
|
500
621
|
let definition;
|
|
501
|
-
if (property.type.
|
|
622
|
+
if (property.type.coreTypeInfo === "ErrorType") {
|
|
502
623
|
definition = `"${property.restApiName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${propertyFullName}`;
|
|
503
624
|
}
|
|
504
625
|
else if (typeStack.includes(property.type)) {
|
|
@@ -552,7 +673,7 @@ export function getResponseMapping(type, propertyPath = "result.body", runtimeIm
|
|
|
552
673
|
const propertyFullName = `${propertyPath}.${property.restApiName}`;
|
|
553
674
|
if (property.type.type === "model") {
|
|
554
675
|
let definition;
|
|
555
|
-
if (property.type.
|
|
676
|
+
if (property.type.coreTypeInfo === "ErrorType") {
|
|
556
677
|
definition = `"${property.clientName}": ${getNullableCheck(propertyFullName, property.type)} ${!property.optional ? "" : `!${propertyFullName} ? undefined :`} ${propertyFullName}`;
|
|
557
678
|
}
|
|
558
679
|
else if (typeStack.includes(property.type)) {
|
|
@@ -743,18 +864,13 @@ function needsDeserialize(type) {
|
|
|
743
864
|
(type === null || type === void 0 ? void 0 : type.type) === "list" ||
|
|
744
865
|
(type === null || type === void 0 ? void 0 : type.type) === "byte-array");
|
|
745
866
|
}
|
|
746
|
-
export function
|
|
747
|
-
|
|
748
|
-
return ((_a = codeModel.clients) !== null && _a !== void 0 ? _a : []).some((c) => {
|
|
749
|
-
var _a;
|
|
750
|
-
return (needRLC ? c.rlcHelperDetails.hasLongRunning : false) ||
|
|
751
|
-
((_a = c.operationGroups) !== null && _a !== void 0 ? _a : []).some((og) => { var _a; return ((_a = og.operations) !== null && _a !== void 0 ? _a : []).some(isLROOperation); });
|
|
752
|
-
});
|
|
867
|
+
export function isLroAndPagingOperation(op) {
|
|
868
|
+
return op.discriminator === "lropaging";
|
|
753
869
|
}
|
|
754
|
-
export function
|
|
755
|
-
return op.discriminator === "lro"
|
|
870
|
+
export function isLroOnlyOperation(op) {
|
|
871
|
+
return op.discriminator === "lro";
|
|
756
872
|
}
|
|
757
|
-
export function
|
|
873
|
+
export function hasPagingOnlyOperation(clientOrCodeModel, needRLC = false) {
|
|
758
874
|
let clients = [];
|
|
759
875
|
if (clientOrCodeModel === null || clientOrCodeModel === void 0 ? void 0 : clientOrCodeModel.operationGroups) {
|
|
760
876
|
clients = [clientOrCodeModel];
|
|
@@ -765,11 +881,11 @@ export function hasPagingOperation(clientOrCodeModel, needRLC = false) {
|
|
|
765
881
|
return clients.some((c) => {
|
|
766
882
|
var _a;
|
|
767
883
|
return (needRLC ? c.rlcHelperDetails.hasPaging : false) ||
|
|
768
|
-
((_a = c.operationGroups) !== null && _a !== void 0 ? _a : []).some((og) => { var _a; return ((_a = og.operations) !== null && _a !== void 0 ? _a : []).some(
|
|
884
|
+
((_a = c.operationGroups) !== null && _a !== void 0 ? _a : []).some((og) => { var _a; return ((_a = og.operations) !== null && _a !== void 0 ? _a : []).some(isPagingOnlyOperation); });
|
|
769
885
|
});
|
|
770
886
|
}
|
|
771
|
-
export function
|
|
772
|
-
return op.discriminator === "paging"
|
|
887
|
+
export function isPagingOnlyOperation(op) {
|
|
888
|
+
return op.discriminator === "paging";
|
|
773
889
|
}
|
|
774
890
|
export function getAllProperties(type, parents) {
|
|
775
891
|
var _a;
|