ibm-cloud-sdk-core 3.2.0 → 3.2.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.2.1](https://github.com/IBM/node-sdk-core/compare/v3.2.0...v3.2.1) (2022-10-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * allow for synchronous building of file requests ([#211](https://github.com/IBM/node-sdk-core/issues/211)) ([dcce4ea](https://github.com/IBM/node-sdk-core/commit/dcce4ea78189e4619cde2d736436a30128cf4b59))
7
+
1
8
  # [3.2.0](https://github.com/IBM/node-sdk-core/compare/v3.1.0...v3.2.0) (2022-10-12)
2
9
 
3
10
 
@@ -130,29 +130,27 @@ export class RequestWrapper {
130
130
  const multipartForm = new FormData();
131
131
  // Form params
132
132
  if (formData) {
133
- Object.keys(formData).forEach((key) => {
134
- const values = Array.isArray(formData[key]) ? formData[key] : [formData[key]];
133
+ for (const key of Object.keys(formData)) { // eslint-disable-line
134
+ let values = Array.isArray(formData[key]) ? formData[key] : [formData[key]];
135
135
  // Skip keys with undefined/null values or empty object value
136
- values
137
- .filter((v) => v != null && !isEmptyObject(v))
138
- .forEach((value) => __awaiter(this, void 0, void 0, function* () {
139
- // Special case of empty file object
140
- if (Object.prototype.hasOwnProperty.call(value, 'contentType') &&
141
- !Object.prototype.hasOwnProperty.call(value, 'data')) {
142
- return;
143
- }
144
- if (isFileWithMetadata(value)) {
145
- const fileObj = yield buildRequestFileObject(value);
146
- multipartForm.append(key, fileObj.value, fileObj.options);
147
- }
148
- else {
149
- if (typeof value === 'object' && !isFileData(value)) {
150
- value = JSON.stringify(value);
136
+ values = values.filter((v) => v != null && !isEmptyObject(v));
137
+ for (let value of values) { // eslint-disable-line
138
+ // Ignore special case of empty file object
139
+ if (!Object.prototype.hasOwnProperty.call(value, 'contentType') ||
140
+ Object.prototype.hasOwnProperty.call(value, 'data')) {
141
+ if (isFileWithMetadata(value)) {
142
+ const fileObj = yield buildRequestFileObject(value); // eslint-disable-line
143
+ multipartForm.append(key, fileObj.value, fileObj.options);
144
+ }
145
+ else {
146
+ if (typeof value === 'object' && !isFileData(value)) {
147
+ value = JSON.stringify(value);
148
+ }
149
+ multipartForm.append(key, value);
151
150
  }
152
- multipartForm.append(key, value);
153
151
  }
154
- }));
155
- });
152
+ }
153
+ }
156
154
  }
157
155
  // Path params
158
156
  url = parsePath(url, path);
@@ -175,50 +175,50 @@ var RequestWrapper = /** @class */ (function () {
175
175
  */
176
176
  RequestWrapper.prototype.sendRequest = function (parameters) {
177
177
  return __awaiter(this, void 0, void 0, function () {
178
- var options, path, body, form, formData, qs, method, serviceUrl, headers, url, multipartForm, data, requestParams;
178
+ var options, path, body, form, formData, qs, method, serviceUrl, headers, url, multipartForm, _i, _a, key, values, _b, values_1, value, fileObj, data, requestParams;
179
179
  var _this = this;
180
- return __generator(this, function (_a) {
181
- switch (_a.label) {
180
+ return __generator(this, function (_c) {
181
+ switch (_c.label) {
182
182
  case 0:
183
183
  options = extend_1.default(true, {}, parameters.defaultOptions, parameters.options);
184
184
  path = options.path, body = options.body, form = options.form, formData = options.formData, qs = options.qs, method = options.method, serviceUrl = options.serviceUrl;
185
185
  headers = options.headers, url = options.url;
186
186
  multipartForm = new form_data_1.default();
187
- // Form params
188
- if (formData) {
189
- Object.keys(formData).forEach(function (key) {
190
- var values = Array.isArray(formData[key]) ? formData[key] : [formData[key]];
191
- // Skip keys with undefined/null values or empty object value
192
- values
193
- .filter(function (v) { return v != null && !helper_1.isEmptyObject(v); })
194
- .forEach(function (value) { return __awaiter(_this, void 0, void 0, function () {
195
- var fileObj;
196
- return __generator(this, function (_a) {
197
- switch (_a.label) {
198
- case 0:
199
- // Special case of empty file object
200
- if (Object.prototype.hasOwnProperty.call(value, 'contentType') &&
201
- !Object.prototype.hasOwnProperty.call(value, 'data')) {
202
- return [2 /*return*/];
203
- }
204
- if (!helper_1.isFileWithMetadata(value)) return [3 /*break*/, 2];
205
- return [4 /*yield*/, helper_1.buildRequestFileObject(value)];
206
- case 1:
207
- fileObj = _a.sent();
208
- multipartForm.append(key, fileObj.value, fileObj.options);
209
- return [3 /*break*/, 3];
210
- case 2:
211
- if (typeof value === 'object' && !helper_1.isFileData(value)) {
212
- value = JSON.stringify(value);
213
- }
214
- multipartForm.append(key, value);
215
- _a.label = 3;
216
- case 3: return [2 /*return*/];
217
- }
218
- });
219
- }); });
220
- });
187
+ if (!formData) return [3 /*break*/, 7];
188
+ _i = 0, _a = Object.keys(formData);
189
+ _c.label = 1;
190
+ case 1:
191
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
192
+ key = _a[_i];
193
+ values = Array.isArray(formData[key]) ? formData[key] : [formData[key]];
194
+ // Skip keys with undefined/null values or empty object value
195
+ values = values.filter(function (v) { return v != null && !helper_1.isEmptyObject(v); });
196
+ _b = 0, values_1 = values;
197
+ _c.label = 2;
198
+ case 2:
199
+ if (!(_b < values_1.length)) return [3 /*break*/, 6];
200
+ value = values_1[_b];
201
+ if (!(!Object.prototype.hasOwnProperty.call(value, 'contentType') ||
202
+ Object.prototype.hasOwnProperty.call(value, 'data'))) return [3 /*break*/, 5];
203
+ if (!helper_1.isFileWithMetadata(value)) return [3 /*break*/, 4];
204
+ return [4 /*yield*/, helper_1.buildRequestFileObject(value)];
205
+ case 3:
206
+ fileObj = _c.sent();
207
+ multipartForm.append(key, fileObj.value, fileObj.options);
208
+ return [3 /*break*/, 5];
209
+ case 4:
210
+ if (typeof value === 'object' && !helper_1.isFileData(value)) {
211
+ value = JSON.stringify(value);
221
212
  }
213
+ multipartForm.append(key, value);
214
+ _c.label = 5;
215
+ case 5:
216
+ _b++;
217
+ return [3 /*break*/, 2];
218
+ case 6:
219
+ _i++;
220
+ return [3 /*break*/, 1];
221
+ case 7:
222
222
  // Path params
223
223
  url = parsePath(url, path);
224
224
  // Headers
@@ -248,12 +248,12 @@ var RequestWrapper = /** @class */ (function () {
248
248
  }
249
249
  // accept gzip encoded responses if Accept-Encoding is not already set
250
250
  headers['Accept-Encoding'] = headers['Accept-Encoding'] || 'gzip';
251
- if (!this.compressRequestData) return [3 /*break*/, 2];
251
+ if (!this.compressRequestData) return [3 /*break*/, 9];
252
252
  return [4 /*yield*/, this.gzipRequestBody(data, headers)];
253
- case 1:
254
- data = _a.sent();
255
- _a.label = 2;
256
- case 2:
253
+ case 8:
254
+ data = _c.sent();
255
+ _c.label = 9;
256
+ case 9:
257
257
  requestParams = {
258
258
  url: url,
259
259
  method: method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
5
5
  "main": "index.js",
6
6
  "typings": "./es/index.d.ts",