@azure-tools/typespec-rust 0.22.0 → 0.23.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/dist/src/codegen/clients.js +180 -140
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/codeGenerator.d.ts.map +1 -1
- package/dist/src/codegen/codeGenerator.js +2 -0
- package/dist/src/codegen/codeGenerator.js.map +1 -1
- package/dist/src/codegen/context.d.ts +1 -1
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +28 -12
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/docTests.d.ts.map +1 -1
- package/dist/src/codegen/docTests.js +8 -3
- package/dist/src/codegen/docTests.js.map +1 -1
- package/dist/src/codegen/helpers.d.ts +5 -2
- package/dist/src/codegen/helpers.d.ts.map +1 -1
- package/dist/src/codegen/helpers.js +23 -15
- package/dist/src/codegen/helpers.js.map +1 -1
- package/dist/src/codegen/mod.d.ts.map +1 -1
- package/dist/src/codegen/mod.js +5 -3
- package/dist/src/codegen/mod.js.map +1 -1
- package/dist/src/codegen/unions.d.ts +13 -0
- package/dist/src/codegen/unions.d.ts.map +1 -0
- package/dist/src/codegen/unions.js +63 -0
- package/dist/src/codegen/unions.js.map +1 -0
- package/dist/src/codegen/use.d.ts.map +1 -1
- package/dist/src/codegen/use.js +1 -0
- package/dist/src/codegen/use.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +14 -5
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js +2 -2
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/crate.d.ts +2 -0
- package/dist/src/codemodel/crate.d.ts.map +1 -1
- package/dist/src/codemodel/crate.js +5 -0
- package/dist/src/codemodel/crate.js.map +1 -1
- package/dist/src/codemodel/types.d.ts +37 -1
- package/dist/src/codemodel/types.d.ts.map +1 -1
- package/dist/src/codemodel/types.js +18 -0
- package/dist/src/codemodel/types.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +2 -0
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/lib.d.ts +9 -9
- package/dist/src/lib.js +3 -3
- package/dist/src/lib.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +15 -0
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +173 -54
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/src/tcgcadapter/helpers.d.ts +0 -17
- package/dist/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/src/tcgcadapter/helpers.js +0 -70
- package/dist/src/tcgcadapter/helpers.js.map +1 -1
- package/dist/src/tcgcadapter/naming.d.ts +16 -0
- package/dist/src/tcgcadapter/naming.d.ts.map +1 -1
- package/dist/src/tcgcadapter/naming.js +36 -0
- package/dist/src/tcgcadapter/naming.js.map +1 -1
- package/package.json +7 -7
|
@@ -85,7 +85,7 @@ export function emitClients(crate) {
|
|
|
85
85
|
body += `${indent.push().get()}let ${client.constructable.endpoint ? 'mut ' : ''}${endpointParamName} = Url::parse(${endpointParamName})?;\n`;
|
|
86
86
|
body += `${indent.get()}${helpers.buildIfBlock(indent, {
|
|
87
87
|
condition: `!${endpointParamName}.scheme().starts_with("http")`,
|
|
88
|
-
body: (indent) => `${indent.get()}return Err(azure_core::Error::
|
|
88
|
+
body: (indent) => `${indent.get()}return Err(azure_core::Error::with_message(azure_core::error::ErrorKind::Other, format!("{${endpointParamName}} must use http(s)")));\n`,
|
|
89
89
|
})}`;
|
|
90
90
|
// construct the supplemental path and join it to the endpoint
|
|
91
91
|
if (client.constructable.endpoint) {
|
|
@@ -282,7 +282,9 @@ function getMethodOptions(crate) {
|
|
|
282
282
|
}
|
|
283
283
|
body += '}\n\n'; // end options
|
|
284
284
|
if (method.kind === 'pageable' || method.kind === 'lro') {
|
|
285
|
-
body += `impl ${helpers.getTypeDeclaration(method.options.type,
|
|
285
|
+
body += `impl ${helpers.getTypeDeclaration(method.options.type, 'anonymous')} {\n`;
|
|
286
|
+
const wrappedTypeName = helpers.wrapInBackTicks(helpers.getTypeDeclaration(method.options.type, 'omit'));
|
|
287
|
+
body += `${indent.get()}/// Transforms this [${wrappedTypeName}] into a new ${wrappedTypeName} that owns the underlying data, cloning it if necessary.\n`;
|
|
286
288
|
body += `${indent.get()}pub fn into_owned(self) -> ${method.options.type.name}<'static> {\n`;
|
|
287
289
|
body += `${indent.push().get()}${method.options.type.name} {\n`;
|
|
288
290
|
indent.push();
|
|
@@ -414,7 +416,7 @@ function getMethodParamsSig(method, use) {
|
|
|
414
416
|
paramsSig.push(`${param.name}: ${formatParamTypeName(param)}`);
|
|
415
417
|
}
|
|
416
418
|
}
|
|
417
|
-
paramsSig.push(`options: ${helpers.getTypeDeclaration(method.options,
|
|
419
|
+
paramsSig.push(`options: ${helpers.getTypeDeclaration(method.options, 'anonymous')}`);
|
|
418
420
|
}
|
|
419
421
|
return paramsSig.join(', ');
|
|
420
422
|
}
|
|
@@ -843,10 +845,20 @@ function applyHeaderParams(indent, use, method, paramGroups, inClosure) {
|
|
|
843
845
|
// we have some special handling for the header continuation token.
|
|
844
846
|
// if we have a token value, i.e. from the next page, then use that value.
|
|
845
847
|
// if not, then check if an optional token value was provided.
|
|
848
|
+
body += `${indent.get()}let ${headerParam.name} = ` + helpers.buildMatch(indent, headerParam.name, [
|
|
849
|
+
{
|
|
850
|
+
pattern: `PagerState::More(${headerParam.name})`,
|
|
851
|
+
body: (indent) => `${indent.get()}&Some(${headerParam.name})\n`,
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
pattern: 'PagerState::Initial',
|
|
855
|
+
body: (indent) => `${indent.get()}&options.${headerParam.name}\n`,
|
|
856
|
+
}
|
|
857
|
+
]) + ';\n';
|
|
846
858
|
body += indent.get() + helpers.buildIfBlock(indent, {
|
|
847
|
-
condition: `let Some(${headerParam.name}) = ${headerParam.name}
|
|
859
|
+
condition: `let Some(${headerParam.name}) = ${headerParam.name}`,
|
|
848
860
|
body: (indent) => `${indent.get()}request.insert_header("${headerParam.header}", ${headerParam.name});\n`,
|
|
849
|
-
});
|
|
861
|
+
}) + '\n';
|
|
850
862
|
continue;
|
|
851
863
|
}
|
|
852
864
|
if (isOptionalContentTypeHeader(headerParam)) {
|
|
@@ -939,17 +951,6 @@ function constructRequest(indent, use, method, paramGroups, inClosure, cloneUrl
|
|
|
939
951
|
}
|
|
940
952
|
return body;
|
|
941
953
|
}
|
|
942
|
-
/**
|
|
943
|
-
* Return an error if a local BufResponse variable "rsp" has a non-success status code.
|
|
944
|
-
* @param use the use statement builder currently in scope
|
|
945
|
-
* @param indent the indentation helper currently in scope
|
|
946
|
-
* @returns code to return an error if the status code of "rsp" doesn't indicate success
|
|
947
|
-
*/
|
|
948
|
-
function errIfNotSuccessResponse(use, indent) {
|
|
949
|
-
use.add('azure_core::http', 'check_success');
|
|
950
|
-
const body = `${indent.get()}let rsp = check_success(rsp).await?;\n`;
|
|
951
|
-
return body;
|
|
952
|
-
}
|
|
953
954
|
/**
|
|
954
955
|
* Returns 'mut ' if the Url local var needs to be mutable, else the empty string.
|
|
955
956
|
* @param paramGroups the param groups associated with the Url being constructed.
|
|
@@ -1011,7 +1012,7 @@ function emitEmptyPathParamCheck(indent, param) {
|
|
|
1011
1012
|
}
|
|
1012
1013
|
return helpers.buildIfBlock(indent, {
|
|
1013
1014
|
condition: `${param.name}${toString}.is_empty()`,
|
|
1014
|
-
body: (indent) => `${indent.get()}return Err(azure_core::Error::
|
|
1015
|
+
body: (indent) => `${indent.get()}return Err(azure_core::Error::with_message(azure_core::error::ErrorKind::Other, "parameter ${param.name} cannot be empty"));`,
|
|
1015
1016
|
});
|
|
1016
1017
|
}
|
|
1017
1018
|
/**
|
|
@@ -1032,8 +1033,7 @@ function getAsyncMethodBody(indent, use, client, method) {
|
|
|
1032
1033
|
body += `${indent.get()}let ${urlVarNeedsMut(paramGroups, method)}url = self.${getEndpointFieldName(client)}.clone();\n`;
|
|
1033
1034
|
body += constructUrl(indent, use, method, paramGroups);
|
|
1034
1035
|
body += constructRequest(indent, use, method, paramGroups, false);
|
|
1035
|
-
body += `${indent.get()}let rsp = self.pipeline.send(&ctx, &mut request).await?;\n`;
|
|
1036
|
-
body += errIfNotSuccessResponse(use, indent);
|
|
1036
|
+
body += `${indent.get()}let rsp = self.pipeline.send(&ctx, &mut request, ${getPipelineSendOptions(indent, use, method)}).await?;\n`;
|
|
1037
1037
|
let rspInto = 'rsp.into()';
|
|
1038
1038
|
if (method.returns.type.kind === 'bufResponse') {
|
|
1039
1039
|
rspInto = 'rsp';
|
|
@@ -1051,17 +1051,13 @@ function getAsyncMethodBody(indent, use, client, method) {
|
|
|
1051
1051
|
* @returns the contents of the method body
|
|
1052
1052
|
*/
|
|
1053
1053
|
function getPageableMethodBody(indent, use, client, method) {
|
|
1054
|
-
if (!method.strategy) {
|
|
1055
|
-
throw new CodegenError('InternalError', 'paged method with no strategy NYI');
|
|
1056
|
-
}
|
|
1057
|
-
const bodyFormat = helpers.convertResponseFormat(method.returns.type.type.format);
|
|
1058
1054
|
use.add('azure_core::http', 'Method', 'Request', 'Url');
|
|
1059
1055
|
use.add('azure_core::http::pager', 'PagerResult', 'PagerState');
|
|
1060
|
-
use.add('azure_core',
|
|
1056
|
+
use.add('azure_core', 'Result');
|
|
1061
1057
|
use.addForType(method.returns.type);
|
|
1062
1058
|
use.addForType(helpers.unwrapType(method.returns.type));
|
|
1063
1059
|
const paramGroups = getMethodParamGroup(method);
|
|
1064
|
-
const urlVar = 'first_url';
|
|
1060
|
+
const urlVar = method.strategy ? 'first_url' : 'url';
|
|
1065
1061
|
let body = checkEmptyRequiredPathParams(indent, paramGroups.path);
|
|
1066
1062
|
body += 'let options = options.unwrap_or_default().into_owned();\n';
|
|
1067
1063
|
body += `${indent.get()}let pipeline = self.pipeline.clone();\n`;
|
|
@@ -1070,67 +1066,77 @@ function getPageableMethodBody(indent, use, client, method) {
|
|
|
1070
1066
|
if (paramGroups.apiVersion) {
|
|
1071
1067
|
body += `${indent.get()}let ${paramGroups.apiVersion.name} = ${getHeaderPathQueryParamValue(use, paramGroups.apiVersion, true)}.clone();\n`;
|
|
1072
1068
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1069
|
+
// passed to constructRequest. we only need to
|
|
1070
|
+
// clone it for the non-continuation case.
|
|
1071
|
+
let cloneUrl = false;
|
|
1072
|
+
if (method.strategy) {
|
|
1073
|
+
switch (method.strategy.kind) {
|
|
1074
|
+
case 'continuationToken': {
|
|
1075
|
+
const reqTokenParam = method.strategy.requestToken.name;
|
|
1076
|
+
body += `${indent.get()}Ok(${method.returns.type.name}::from_callback(move |${reqTokenParam}: PagerState<String>| {\n`;
|
|
1077
|
+
body += `${indent.push().get()}let ${method.strategy.requestToken.kind === 'queryScalar' ? 'mut ' : ''}url = first_url.clone();\n`;
|
|
1078
|
+
if (method.strategy.requestToken.kind === 'queryScalar') {
|
|
1079
|
+
// if the url already contains the token query param,
|
|
1080
|
+
// e.g. we started on some page, then we need to remove
|
|
1081
|
+
// it before appending the token for the next page.
|
|
1082
|
+
const reqTokenValue = method.strategy.requestToken.key;
|
|
1083
|
+
body += `${indent.get()}${helpers.buildIfBlock(indent, {
|
|
1084
|
+
condition: `let PagerState::More(${reqTokenParam}) = ${reqTokenParam}`,
|
|
1085
|
+
body: (indent) => {
|
|
1086
|
+
let body = indent.get() + helpers.buildIfBlock(indent, {
|
|
1087
|
+
condition: `url.query_pairs().any(|(name, _)| name.eq("${reqTokenValue}"))`,
|
|
1088
|
+
body: (indent) => {
|
|
1089
|
+
let body = `${indent.get()}let mut new_url = url.clone();\n`;
|
|
1090
|
+
body += `${indent.get()}new_url.query_pairs_mut().clear().extend_pairs(url.query_pairs().filter(|(name, _)| name.ne("${reqTokenValue}")));\n`;
|
|
1091
|
+
body += `${indent.get()}url = new_url;\n`;
|
|
1092
|
+
return body;
|
|
1093
|
+
},
|
|
1094
|
+
}) + '\n';
|
|
1095
|
+
body += `${indent.get()}url.query_pairs_mut().append_pair("${reqTokenValue}", &${reqTokenParam});\n`;
|
|
1096
|
+
return body;
|
|
1097
|
+
}
|
|
1098
|
+
})}\n`;
|
|
1099
|
+
}
|
|
1100
|
+
break;
|
|
1099
1101
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
return
|
|
1102
|
+
case 'nextLink': {
|
|
1103
|
+
const nextLinkName = method.strategy.nextLinkPath[method.strategy.nextLinkPath.length - 1].name;
|
|
1104
|
+
body += `${indent.get()}Ok(${method.returns.type.name}::from_callback(move |${nextLinkName}: PagerState<Url>| {\n`;
|
|
1105
|
+
body += `${indent.push().get()}let url = ` + helpers.buildMatch(indent, nextLinkName, [{
|
|
1106
|
+
pattern: `PagerState::More(${nextLinkName})`,
|
|
1107
|
+
body: (indent) => {
|
|
1108
|
+
if (paramGroups.apiVersion && paramGroups.apiVersion.kind === 'queryScalar') {
|
|
1109
|
+
const apiVersionKey = `"${paramGroups.apiVersion.key}"`;
|
|
1110
|
+
// there are no APIs to set/update an existing query parameter.
|
|
1111
|
+
// so, we filter the existing query params to remove the api-version
|
|
1112
|
+
// query param. we then add back the filtered set and then add the
|
|
1113
|
+
// api-version as specified on the client.
|
|
1114
|
+
let setApiVerBody = `${indent.get()}let qp = ${nextLinkName}.query_pairs().filter(|(name, _)| name.ne(${apiVersionKey}));\n`;
|
|
1115
|
+
setApiVerBody += `${indent.get()}let mut ${nextLinkName} = ${nextLinkName}.clone();\n`;
|
|
1116
|
+
setApiVerBody += `${indent.get()}${nextLinkName}.query_pairs_mut().clear().extend_pairs(qp).append_pair(${apiVersionKey}, &${paramGroups.apiVersion.name});\n`;
|
|
1117
|
+
setApiVerBody += `${indent.get()}${nextLinkName}\n`;
|
|
1118
|
+
return setApiVerBody;
|
|
1119
|
+
}
|
|
1120
|
+
return `${indent.get()} ${nextLinkName}\n`;
|
|
1119
1121
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
break;
|
|
1122
|
+
}, {
|
|
1123
|
+
pattern: 'PagerState::Initial',
|
|
1124
|
+
body: (indent) => `${indent.get()}${urlVar}.clone()\n`
|
|
1125
|
+
}]);
|
|
1126
|
+
body += ';\n';
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1128
1129
|
}
|
|
1129
1130
|
}
|
|
1131
|
+
else {
|
|
1132
|
+
// no next link when there's no strategy
|
|
1133
|
+
body += `${indent.get()}Ok(Pager::from_callback(move |_: PagerState<Url>| {\n`;
|
|
1134
|
+
cloneUrl = true;
|
|
1135
|
+
}
|
|
1130
1136
|
// Pipeline::send() returns a BufResponse, so no reason to declare the type if not something else.
|
|
1131
1137
|
let rspType = '';
|
|
1132
1138
|
let rspInto = '';
|
|
1133
|
-
if (method.strategy.kind === 'continuationToken' && method.strategy.responseToken.kind === 'responseHeaderScalar') {
|
|
1139
|
+
if (method.strategy && method.strategy.kind === 'continuationToken' && method.strategy.responseToken.kind === 'responseHeaderScalar') {
|
|
1134
1140
|
// the continuation token comes from a response header. therefore,
|
|
1135
1141
|
// we need a Response<T> so we have access to the header trait.
|
|
1136
1142
|
use.addForType(method.returns.type.type);
|
|
@@ -1138,66 +1144,85 @@ function getPageableMethodBody(indent, use, client, method) {
|
|
|
1138
1144
|
rspType = `: ${rspTypeDecl}`;
|
|
1139
1145
|
rspInto = '.into()';
|
|
1140
1146
|
}
|
|
1141
|
-
body += constructRequest(indent, use, method, paramGroups, true);
|
|
1147
|
+
body += constructRequest(indent, use, method, paramGroups, true, cloneUrl);
|
|
1142
1148
|
body += `${indent.get()}let ctx = options.method_options.context.clone();\n`;
|
|
1143
1149
|
body += `${indent.get()}let pipeline = pipeline.clone();\n`;
|
|
1144
1150
|
body += `${indent.get()}async move {\n`;
|
|
1145
|
-
body += `${indent.push().get()}let rsp${rspType} = pipeline.send(&ctx, &mut request).await?${rspInto};\n`;
|
|
1146
|
-
if (rspType === '') {
|
|
1147
|
-
body += errIfNotSuccessResponse(use, indent);
|
|
1148
|
-
}
|
|
1151
|
+
body += `${indent.push().get()}let rsp${rspType} = pipeline.send(&ctx, &mut request, ${getPipelineSendOptions(indent, use, method)}).await?${rspInto};\n`;
|
|
1149
1152
|
// check if we need to extract the next link field from the response model
|
|
1150
|
-
if (method.strategy.kind === 'nextLink' || method.strategy.responseToken.kind === '
|
|
1151
|
-
|
|
1153
|
+
if (method.strategy && (method.strategy.kind === 'nextLink' || method.strategy.responseToken.kind === 'nextLink')) {
|
|
1154
|
+
const bodyFormat = helpers.convertResponseFormat(method.returns.type.type.format);
|
|
1155
|
+
use.add('azure_core', bodyFormat, 'http::BufResponse');
|
|
1152
1156
|
body += `${indent.get()}let (status, headers, body) = rsp.deconstruct();\n`;
|
|
1153
1157
|
body += `${indent.get()}let bytes = body.collect().await?;\n`;
|
|
1154
1158
|
const deserialize = bodyFormat === 'json' ? 'json::from_json' : 'xml::read_xml';
|
|
1155
1159
|
body += `${indent.get()}let res: ${helpers.getTypeDeclaration(helpers.unwrapType(method.returns.type))} = ${deserialize}(&bytes)?;\n`;
|
|
1156
1160
|
body += `${indent.get()}let rsp = BufResponse::from_bytes(status, headers, bytes).into();\n`;
|
|
1157
1161
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
break;
|
|
1169
|
-
case 'responseHeaderScalar':
|
|
1170
|
-
if (!method.responseHeaders) {
|
|
1171
|
-
throw new CodegenError('InternalError', `missing response headers trait for method ${method.name}`);
|
|
1172
|
-
}
|
|
1173
|
-
use.addForType(method.responseHeaders);
|
|
1174
|
-
srcNextPage = `rsp.${method.strategy.responseToken.name}()?`;
|
|
1175
|
-
break;
|
|
1162
|
+
if (method.strategy) {
|
|
1163
|
+
/** provides access to the next link field, handling nested fields as required */
|
|
1164
|
+
const buildNextLinkPath = function (nextLinkPath) {
|
|
1165
|
+
let fullPath = nextLinkPath[0].name;
|
|
1166
|
+
if (nextLinkPath.length > 1) {
|
|
1167
|
+
for (let i = 1; i < nextLinkPath.length; ++i) {
|
|
1168
|
+
const prev = nextLinkPath[i - 1];
|
|
1169
|
+
const cur = nextLinkPath[i];
|
|
1170
|
+
fullPath += `.and_then(|${prev.name}| ${prev.name}.${cur.name})`;
|
|
1171
|
+
}
|
|
1176
1172
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1173
|
+
return fullPath;
|
|
1174
|
+
};
|
|
1175
|
+
let srcNextPage;
|
|
1176
|
+
let nextPageValue;
|
|
1177
|
+
let continuation;
|
|
1178
|
+
switch (method.strategy.kind) {
|
|
1179
|
+
case 'continuationToken':
|
|
1180
|
+
switch (method.strategy.responseToken.kind) {
|
|
1181
|
+
case 'nextLink':
|
|
1182
|
+
nextPageValue = method.strategy.responseToken.nextLinkPath[method.strategy.responseToken.nextLinkPath.length - 1].name;
|
|
1183
|
+
srcNextPage = `res.${buildNextLinkPath(method.strategy.responseToken.nextLinkPath)}`;
|
|
1184
|
+
break;
|
|
1185
|
+
case 'responseHeaderScalar':
|
|
1186
|
+
if (!method.responseHeaders) {
|
|
1187
|
+
throw new CodegenError('InternalError', `missing response headers trait for method ${method.name}`);
|
|
1188
|
+
}
|
|
1189
|
+
nextPageValue = method.strategy.responseToken.name;
|
|
1190
|
+
use.addForType(method.responseHeaders);
|
|
1191
|
+
srcNextPage = `rsp.${method.strategy.responseToken.name}()?`;
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1194
|
+
continuation = nextPageValue;
|
|
1195
|
+
break;
|
|
1196
|
+
case 'nextLink': {
|
|
1197
|
+
const lastFieldName = method.strategy.nextLinkPath[method.strategy.nextLinkPath.length - 1].name;
|
|
1198
|
+
nextPageValue = lastFieldName;
|
|
1199
|
+
srcNextPage = `res.${buildNextLinkPath(method.strategy.nextLinkPath)}`;
|
|
1200
|
+
continuation = `${lastFieldName}.parse()?`;
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
// we need to handle the case where the next page value is the empty string,
|
|
1205
|
+
// so checking strictly for None(theNextLink) is insufficient.
|
|
1206
|
+
// the most common case for this is XML, e.g. an empty tag like <NextLink />
|
|
1207
|
+
body += `${indent.get()}Ok(${helpers.buildMatch(indent, srcNextPage, [{
|
|
1208
|
+
pattern: `Some(${nextPageValue}) if !${nextPageValue}.is_empty()`,
|
|
1209
|
+
body: (indent) => {
|
|
1210
|
+
return `${indent.get()}response: rsp, continuation: ${continuation}\n`;
|
|
1211
|
+
},
|
|
1212
|
+
returns: 'PagerResult::More',
|
|
1213
|
+
}, {
|
|
1214
|
+
pattern: '_',
|
|
1215
|
+
body: (indent) => {
|
|
1216
|
+
return `${indent.get()}response: rsp\n`;
|
|
1217
|
+
},
|
|
1218
|
+
returns: 'PagerResult::Done',
|
|
1219
|
+
}])}`;
|
|
1220
|
+
body += ')\n'; // end Ok
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
// non-continuation case, so we don't need to worry about next links, continuation tokens, etc...
|
|
1224
|
+
body += `${indent.get()}Ok(PagerResult::Done { response: rsp.into() })\n`;
|
|
1183
1225
|
}
|
|
1184
|
-
// we need to handle the case where the next page value is the empty string,
|
|
1185
|
-
// so checking strictly for None(theNextLink) is insufficient.
|
|
1186
|
-
// the most common case for this is XML, e.g. an empty tag like <NextLink />
|
|
1187
|
-
body += `${indent.get()}Ok(${helpers.buildMatch(indent, srcNextPage, [{
|
|
1188
|
-
pattern: `Some(${nextPageValue}) if !${nextPageValue}.is_empty()`,
|
|
1189
|
-
body: (indent) => {
|
|
1190
|
-
return `${indent.get()}response: rsp, continuation: ${continuation}`;
|
|
1191
|
-
},
|
|
1192
|
-
returns: 'PagerResult::More',
|
|
1193
|
-
}, {
|
|
1194
|
-
pattern: '_',
|
|
1195
|
-
body: (indent) => {
|
|
1196
|
-
return `${indent.get()}response: rsp`;
|
|
1197
|
-
},
|
|
1198
|
-
returns: 'PagerResult::Done',
|
|
1199
|
-
}])}`;
|
|
1200
|
-
body += ')\n'; // end Ok
|
|
1201
1226
|
body += `${indent.pop().get()}}\n`; // end async move
|
|
1202
1227
|
body += `${indent.pop().get()}}))`; // end Ok/Pager::from_callback
|
|
1203
1228
|
return body;
|
|
@@ -1223,40 +1248,39 @@ function getLroMethodBody(indent, use, client, method) {
|
|
|
1223
1248
|
let body = 'let options = options.unwrap_or_default().into_owned();\n';
|
|
1224
1249
|
body += `${indent.get()}let pipeline = self.pipeline.clone();\n`;
|
|
1225
1250
|
body += `${indent.get()}let ${urlVarNeedsMut(paramGroups, method)}${urlVar} = self.${getEndpointFieldName(client)}.clone();\n`;
|
|
1226
|
-
body +=
|
|
1251
|
+
body += constructUrl(indent, use, method, paramGroups, urlVar);
|
|
1227
1252
|
if (paramGroups.apiVersion) {
|
|
1228
|
-
body += `${indent.get()}let ${paramGroups.apiVersion.name} = ${getHeaderPathQueryParamValue(use, paramGroups.apiVersion, true)}.clone();\n
|
|
1253
|
+
body += `${indent.get()}let ${paramGroups.apiVersion.name} = ${getHeaderPathQueryParamValue(use, paramGroups.apiVersion, true)}.clone();\n`;
|
|
1229
1254
|
}
|
|
1230
1255
|
body += `${indent.get()}Ok(${method.returns.type.name}::from_callback(\n`;
|
|
1231
1256
|
body += `${indent.push().get()}move |next_link: PollerState<Url>| {\n`;
|
|
1232
1257
|
body += `${indent.push().get()}let (mut request, next_link) = ${helpers.buildMatch(indent, 'next_link', [{
|
|
1233
1258
|
pattern: `PollerState::More(next_link)`,
|
|
1234
1259
|
body: (indent) => {
|
|
1260
|
+
var _a;
|
|
1235
1261
|
let body = '';
|
|
1236
|
-
if (paramGroups.apiVersion) {
|
|
1237
|
-
body += `${indent.get()}let qp = next_link.query_pairs().filter(|(name, _)| name.ne("
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
if (paramGroups.apiVersion) {
|
|
1241
|
-
body += `${indent.get()}next_link.query_pairs_mut().clear().extend_pairs(qp).append_pair("api-version", &${paramGroups.apiVersion.name});\n\n`;
|
|
1262
|
+
if (((_a = paramGroups.apiVersion) === null || _a === void 0 ? void 0 : _a.kind) === 'queryScalar') {
|
|
1263
|
+
body += `${indent.get()}let qp = next_link.query_pairs().filter(|(name, _)| name.ne("${paramGroups.apiVersion.key}"));\n`;
|
|
1264
|
+
body += `${indent.get()}let mut next_link = next_link.clone();\n`;
|
|
1265
|
+
body += `${indent.get()}next_link.query_pairs_mut().clear().extend_pairs(qp).append_pair("${paramGroups.apiVersion.key}", &${paramGroups.apiVersion.name});\n`;
|
|
1242
1266
|
}
|
|
1243
|
-
body += `${indent.get()}let ${paramGroups.header.length > 0 ? 'mut ' : ''}request = Request::new(next_link.clone(), Method::Get)
|
|
1244
|
-
body +=
|
|
1267
|
+
body += `${indent.get()}let ${paramGroups.header.length > 0 ? 'mut ' : ''}request = Request::new(next_link.clone(), Method::Get);\n`;
|
|
1268
|
+
body += applyHeaderParams(indent, use, method, paramGroups, true);
|
|
1245
1269
|
body += `${indent.get()}(request, next_link)\n`;
|
|
1246
1270
|
return body;
|
|
1247
1271
|
},
|
|
1248
1272
|
}, {
|
|
1249
1273
|
pattern: 'PollerState::Initial',
|
|
1250
1274
|
body: (indent) => {
|
|
1251
|
-
let body =
|
|
1275
|
+
let body = constructRequest(indent, use, method, paramGroups, true, true, false);
|
|
1252
1276
|
body += `${indent.get()}(request, url.clone())\n`;
|
|
1253
1277
|
return body;
|
|
1254
1278
|
},
|
|
1255
|
-
}])};\n
|
|
1279
|
+
}])};\n`;
|
|
1256
1280
|
body += `${indent.get()}let ctx = options.method_options.context.clone();\n`;
|
|
1257
1281
|
body += `${indent.get()}let pipeline = pipeline.clone();\n`;
|
|
1258
1282
|
body += `${indent.get()}async move {\n`;
|
|
1259
|
-
body += `${indent.push().get()}let rsp = pipeline.send(&ctx, &mut request).await?;\n`;
|
|
1283
|
+
body += `${indent.push().get()}let rsp = pipeline.send(&ctx, &mut request, ${getPipelineSendOptions(indent, use, method)}).await?;\n`;
|
|
1260
1284
|
body += `${indent.get()}let (status, headers, body) = rsp.deconstruct();\n`;
|
|
1261
1285
|
body += `${indent.get()}let retry_after = get_retry_after(&headers, &[X_MS_RETRY_AFTER_MS, RETRY_AFTER_MS, RETRY_AFTER], &options.poller_options);\n`;
|
|
1262
1286
|
body += `${indent.get()}let bytes = body.collect().await?;\n`;
|
|
@@ -1439,4 +1463,20 @@ function nonCopyableType(type) {
|
|
|
1439
1463
|
function isClientMethodOptions(type) {
|
|
1440
1464
|
return type.kind === 'external' && type.name === 'ClientMethodOptions';
|
|
1441
1465
|
}
|
|
1466
|
+
function getPipelineSendOptions(indent, use, method) {
|
|
1467
|
+
let options = '';
|
|
1468
|
+
if (method.statusCodes.length != 0) {
|
|
1469
|
+
use.add("azure_core::http", "PipelineSendOptions");
|
|
1470
|
+
use.add("azure_core::error", "CheckSuccessOptions");
|
|
1471
|
+
options += `Some(PipelineSendOptions {\n`;
|
|
1472
|
+
indent.push();
|
|
1473
|
+
options += `${indent.get()}check_success: CheckSuccessOptions{ success_codes: &[${method.statusCodes.join(', ')}]},\n`;
|
|
1474
|
+
options += `${indent.get()}..Default::default()\n`;
|
|
1475
|
+
options += `${indent.pop().get()}})`;
|
|
1476
|
+
return options;
|
|
1477
|
+
}
|
|
1478
|
+
else {
|
|
1479
|
+
return 'None';
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1442
1482
|
//# sourceMappingURL=clients.js.map
|