swagger-client 3.13.6 → 3.15.0

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.
@@ -0,0 +1,5 @@
1
+ var foldFormDataToRequest = function foldFormDataToRequest(formdata, request) {
2
+ request.body = formdata;
3
+ };
4
+
5
+ export default foldFormDataToRequest;
@@ -0,0 +1,26 @@
1
+ import _objectSpread from "@babel/runtime-corejs3/helpers/objectSpread2";
2
+ import { Readable } from 'stream';
3
+ import { Encoder } from 'form-data-encoder';
4
+ /**
5
+ * formdata-node works in node-fetch@2.x via form-data-encoder only.
6
+ * FormData instance is converted to Encoder instance which gets converted
7
+ * to Readable Stream.
8
+ *
9
+ * TODO(vladimir.gorej@gmail.com): this can be removed when migrated to node-fetch@3.x
10
+ */
11
+
12
+ var foldFormDataToRequest = function foldFormDataToRequest(formdata, request) {
13
+ var encoder = new Encoder(formdata);
14
+ var readableStream = Readable.from(encoder); // get rid of previous headers
15
+
16
+ delete request.headers['content-type'];
17
+ delete request.headers['Content-Type']; // set computed headers
18
+
19
+ request.headers = _objectSpread(_objectSpread({}, request.headers), encoder.headers); // set FormData instance to request for debugging purposes
20
+
21
+ request.formdata = formdata; // assign readable stream as request body
22
+
23
+ request.body = readableStream;
24
+ };
25
+
26
+ export default foldFormDataToRequest;
@@ -20,8 +20,9 @@ import jsYaml from 'js-yaml';
20
20
  import pick from 'lodash/pick';
21
21
  import isFunction from 'lodash/isFunction';
22
22
  import { Buffer } from 'buffer';
23
- import FormData from './internal/form-data-monkey-patch';
24
- import { encodeDisallowedCharacters } from './execute/oas3/style-serializer'; // For testing
23
+ import { FormData } from 'formdata-node';
24
+ import { encodeDisallowedCharacters } from '../execute/oas3/style-serializer';
25
+ import foldFormDataToRequest from './fold-formdata-to-request.node'; // For testing
25
26
 
26
27
  export var self = {
27
28
  serializeRes: serializeRes,
@@ -97,10 +98,10 @@ function _http() {
97
98
 
98
99
  case 12:
99
100
  // for content-type=multipart\/form-data remove content-type from request before fetch
100
- // so that correct one with `boundary` is set
101
- contentType = request.headers['content-type'] || request.headers['Content-Type'];
101
+ // so that correct one with `boundary` is set when request body is different than boundary encoded string
102
+ contentType = request.headers['content-type'] || request.headers['Content-Type']; // TODO(vladimir.gorej@gmail.com): assertion of FormData instance can be removed when migrated to node-fetch@2.x
102
103
 
103
- if (/multipart\/form-data/i.test(contentType)) {
104
+ if (/multipart\/form-data/i.test(contentType) && request.body instanceof FormData) {
104
105
  delete request.headers['content-type'];
105
106
  delete request.headers['Content-Type'];
106
107
  } // eslint-disable-next-line no-undef
@@ -196,7 +197,7 @@ function parseBody(body, contentType) {
196
197
  return JSON.parse(body);
197
198
  }
198
199
 
199
- return jsYaml.safeLoad(body);
200
+ return jsYaml.load(body);
200
201
  } // Serialize the response, returns a promise with headers and the body part of the hash
201
202
 
202
203
 
@@ -577,7 +578,8 @@ export function mergeInQueryOrForm() {
577
578
  var contentType = req.headers['content-type'] || req.headers['Content-Type'];
578
579
 
579
580
  if (hasFile || /multipart\/form-data/i.test(contentType)) {
580
- req.body = buildFormData(req.form);
581
+ var formdata = buildFormData(req.form);
582
+ foldFormDataToRequest(formdata, req);
581
583
  } else {
582
584
  req.body = encodeFormOrQuery(form);
583
585
  }
package/es/index.js CHANGED
@@ -78,7 +78,8 @@ Swagger.prototype = {
78
78
  allowMetaPatches: this.allowMetaPatches,
79
79
  useCircularStructures: this.useCircularStructures,
80
80
  requestInterceptor: this.requestInterceptor || null,
81
- responseInterceptor: this.responseInterceptor || null
81
+ responseInterceptor: this.responseInterceptor || null,
82
+ skipNormalization: this.skipNormalization || false
82
83
  }, options)).then(function (obj) {
83
84
  _this2.originalSpec = _this2.spec;
84
85
  _this2.spec = obj.spec;
@@ -6,7 +6,9 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
6
6
  import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
7
7
  import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
8
8
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
9
- import { fetch } from 'cross-fetch';
9
+ import 'cross-fetch/polyfill';
10
+ /* global fetch */
11
+
10
12
  import jsYaml from 'js-yaml';
11
13
  import qs from 'querystring-browser';
12
14
  import url from 'url';
@@ -391,7 +393,7 @@ function fetchJSON(docPath) {
391
393
  }).then(function (res) {
392
394
  return res.text();
393
395
  }).then(function (text) {
394
- return jsYaml.safeLoad(text);
396
+ return jsYaml.load(text);
395
397
  });
396
398
  }
397
399
  /**
@@ -530,7 +532,7 @@ function pointerAlreadyInPath(pointer, basePath, parent, specmap) {
530
532
 
531
533
  var rootDoc = specmap.contextTree.get([]).baseDoc;
532
534
 
533
- if (basePath == rootDoc && pointerIsAParent(safeParentPointer, pointer)) {
535
+ if (basePath === rootDoc && pointerIsAParent(safeParentPointer, pointer)) {
534
536
  // eslint-disable-line
535
537
  return true;
536
538
  } // Case 2: indirect cycle
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+
6
+ const foldFormDataToRequest = (formdata, request) => {
7
+ request.body = formdata;
8
+ };
9
+
10
+ var _default = foldFormDataToRequest;
11
+ exports.default = _default;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+
6
+ var _stream = require("stream");
7
+
8
+ var _formDataEncoder = require("form-data-encoder");
9
+
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
+
14
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+
16
+ /**
17
+ * formdata-node works in node-fetch@2.x via form-data-encoder only.
18
+ * FormData instance is converted to Encoder instance which gets converted
19
+ * to Readable Stream.
20
+ *
21
+ * TODO(vladimir.gorej@gmail.com): this can be removed when migrated to node-fetch@3.x
22
+ */
23
+ const foldFormDataToRequest = (formdata, request) => {
24
+ const encoder = new _formDataEncoder.Encoder(formdata);
25
+
26
+ const readableStream = _stream.Readable.from(encoder); // get rid of previous headers
27
+
28
+
29
+ delete request.headers['content-type'];
30
+ delete request.headers['Content-Type']; // set computed headers
31
+
32
+ request.headers = _objectSpread(_objectSpread({}, request.headers), encoder.headers); // set FormData instance to request for debugging purposes
33
+
34
+ request.formdata = formdata; // assign readable stream as request body
35
+
36
+ request.body = readableStream;
37
+ };
38
+
39
+ var _default = foldFormDataToRequest;
40
+ exports.default = _default;
@@ -22,9 +22,11 @@ var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
22
22
 
23
23
  var _buffer = require("buffer");
24
24
 
25
- var _formDataMonkeyPatch = _interopRequireDefault(require("./internal/form-data-monkey-patch"));
25
+ var _formdataNode = require("formdata-node");
26
26
 
27
- var _styleSerializer = require("./execute/oas3/style-serializer");
27
+ var _styleSerializer = require("../execute/oas3/style-serializer");
28
+
29
+ var _foldFormdataToRequest = _interopRequireDefault(require("./fold-formdata-to-request.node"));
28
30
 
29
31
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
32
 
@@ -68,12 +70,12 @@ async function http(url, request = {}) {
68
70
  if (request.requestInterceptor) {
69
71
  request = (await request.requestInterceptor(request)) || request;
70
72
  } // for content-type=multipart\/form-data remove content-type from request before fetch
71
- // so that correct one with `boundary` is set
73
+ // so that correct one with `boundary` is set when request body is different than boundary encoded string
72
74
 
73
75
 
74
- const contentType = request.headers['content-type'] || request.headers['Content-Type'];
76
+ const contentType = request.headers['content-type'] || request.headers['Content-Type']; // TODO(vladimir.gorej@gmail.com): assertion of FormData instance can be removed when migrated to node-fetch@2.x
75
77
 
76
- if (/multipart\/form-data/i.test(contentType)) {
78
+ if (/multipart\/form-data/i.test(contentType) && request.body instanceof _formdataNode.FormData) {
77
79
  delete request.headers['content-type'];
78
80
  delete request.headers['Content-Type'];
79
81
  } // eslint-disable-next-line no-undef
@@ -123,7 +125,7 @@ function parseBody(body, contentType) {
123
125
  return JSON.parse(body);
124
126
  }
125
127
 
126
- return _jsYaml.default.safeLoad(body);
128
+ return _jsYaml.default.load(body);
127
129
  } // Serialize the response, returns a promise with headers and the body part of the hash
128
130
 
129
131
 
@@ -370,7 +372,7 @@ function buildFormData(reqForm) {
370
372
  }
371
373
 
372
374
  return formData;
373
- }, new _formDataMonkeyPatch.default());
375
+ }, new _formdataNode.FormData());
374
376
  } // Encodes an object using appropriate serializer.
375
377
 
376
378
 
@@ -420,7 +422,8 @@ function mergeInQueryOrForm(req = {}) {
420
422
  const contentType = req.headers['content-type'] || req.headers['Content-Type'];
421
423
 
422
424
  if (hasFile || /multipart\/form-data/i.test(contentType)) {
423
- req.body = buildFormData(req.form);
425
+ const formdata = buildFormData(req.form);
426
+ (0, _foldFormdataToRequest.default)(formdata, req);
424
427
  } else {
425
428
  req.body = encodeFormOrQuery(form);
426
429
  }
package/lib/index.js CHANGED
@@ -98,7 +98,8 @@ Swagger.prototype = {
98
98
  allowMetaPatches: this.allowMetaPatches,
99
99
  useCircularStructures: this.useCircularStructures,
100
100
  requestInterceptor: this.requestInterceptor || null,
101
- responseInterceptor: this.responseInterceptor || null
101
+ responseInterceptor: this.responseInterceptor || null,
102
+ skipNormalization: this.skipNormalization || false
102
103
  }, options)).then(obj => {
103
104
  this.originalSpec = this.spec;
104
105
  this.spec = obj.spec;
@@ -3,7 +3,7 @@
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
5
 
6
- var _crossFetch = require("cross-fetch");
6
+ require("cross-fetch/polyfill");
7
7
 
8
8
  var _jsYaml = _interopRequireDefault(require("js-yaml"));
9
9
 
@@ -21,6 +21,7 @@ var _constants = require("../../constants");
21
21
 
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
24
+ /* global fetch */
24
25
  const ABSOLUTE_URL_REGEXP = new RegExp('^([a-z]+://|//)', 'i');
25
26
  const JSONRefError = (0, _createError.default)('JSONRefError', function cb(message, extra, oriError) {
26
27
  this.originalError = oriError;
@@ -341,12 +342,12 @@ function getDoc(docPath) {
341
342
 
342
343
 
343
344
  function fetchJSON(docPath) {
344
- return (0, _crossFetch.fetch)(docPath, {
345
+ return fetch(docPath, {
345
346
  headers: {
346
347
  Accept: _constants.ACCEPT_HEADER_VALUE_FOR_DOCUMENTS
347
348
  },
348
349
  loadSpec: true
349
- }).then(res => res.text()).then(text => _jsYaml.default.safeLoad(text));
350
+ }).then(res => res.text()).then(text => _jsYaml.default.load(text));
350
351
  }
351
352
  /**
352
353
  * Extracts a pointer from an object.
@@ -474,7 +475,7 @@ function pointerAlreadyInPath(pointer, basePath, parent, specmap) {
474
475
 
475
476
  const rootDoc = specmap.contextTree.get([]).baseDoc;
476
477
 
477
- if (basePath == rootDoc && pointerIsAParent(safeParentPointer, pointer)) {
478
+ if (basePath === rootDoc && pointerIsAParent(safeParentPointer, pointer)) {
478
479
  // eslint-disable-line
479
480
  return true;
480
481
  } // Case 2: indirect cycle
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "swagger-client",
3
- "version": "3.13.6",
3
+ "version": "3.15.0",
4
4
  "description": "SwaggerJS - a collection of interfaces for OAI specs",
5
+ "browser": {
6
+ "./src/http/fold-formdata-to-request.node.js": "./src/http/fold-formdata-to-request.browser.js",
7
+ "./lib/http/fold-formdata-to-request.node.js": "./lib/http/fold-formdata-to-request.browser.js",
8
+ "./es/http/fold-formdata-to-request.node.js": "./es/http/fold-formdata-to-request.browser.js"
9
+ },
5
10
  "main": "lib/commonjs.js",
6
11
  "module": "es/index.js",
7
12
  "jsnext:main": "es/index.js",
@@ -41,7 +46,7 @@
41
46
  "test:unit:coverage": "cross-env BABEL_ENV=commonjs jest --runInBand --config ./config/jest/jest.unit.coverage.config.js",
42
47
  "test:unit:watch": "cross-env BABEL_ENV=commonjs jest --runInBand --watch --config ./config/jest/jest.unit.config.js",
43
48
  "test:artifact": "run-s test:artifact:umd:browser test:artifact:es test:artifact:commonjs",
44
- "test:artifact:umd:browser": "npm run build:umd:browser && cross-env BABEL_ENV=commonjs jest --config ./config/jest/jest.artifact-umd-browser.config.js",
49
+ "test:artifact:umd:browser": "npm run build:umd:browser && cross-env BABEL_ENV=browser jest --config ./config/jest/jest.artifact-umd-browser.config.js",
45
50
  "test:artifact:es": "npm run build:es && cross-env BABEL_ENV=commonjs jest --config ./config/jest/jest.artifact-es.config.js",
46
51
  "test:artifact:commonjs": "npm run build:commonjs && cross-env BABEL_ENV=commonjs jest --config ./config/jest/jest.artifact-commonjs.config.js",
47
52
  "deps:license": "license-checker --production --csv --out $npm_package_config_deps_check_dir/licenses.csv && license-checker --development --csv --out $npm_package_config_deps_check_dir/licenses-dev.csv",
@@ -60,20 +65,20 @@
60
65
  ],
61
66
  "license": "Apache-2.0",
62
67
  "devDependencies": {
63
- "@babel/cli": "=7.14.5",
64
- "@babel/core": "=7.14.6",
68
+ "@babel/cli": "=7.14.8",
69
+ "@babel/core": "=7.15.0",
65
70
  "@babel/plugin-proposal-class-properties": "=7.14.5",
66
71
  "@babel/plugin-proposal-object-rest-spread": "=7.14.7",
67
- "@babel/plugin-transform-runtime": "=7.14.5",
68
- "@babel/preset-env": "=7.14.7",
72
+ "@babel/plugin-transform-runtime": "=7.15.0",
73
+ "@babel/preset-env": "=7.15.0",
69
74
  "@babel/register": "=7.14.5",
70
75
  "@char0n/npm-audit": "gist:2964395223d7943c10396f59df9a8ea0",
71
- "@commitlint/cli": "^12.0.0",
72
- "@commitlint/config-conventional": "^12.0.0",
76
+ "@commitlint/cli": "^13.1.0",
77
+ "@commitlint/config-conventional": "^13.1.0",
73
78
  "babel-loader": "=8.2.2",
74
79
  "babel-plugin-lodash": "=3.3.4",
75
80
  "cross-env": "=7.0.3",
76
- "eslint": "=7.30.0",
81
+ "eslint": "=7.32.0",
77
82
  "eslint-config-airbnb-base": "=14.2.1",
78
83
  "eslint-config-prettier": "=8.3.0",
79
84
  "eslint-plugin-import": "=2.23.4",
@@ -81,13 +86,13 @@
81
86
  "expect": "=27.0.6",
82
87
  "fetch-mock": "=9.11.0",
83
88
  "glob": "=7.1.7",
84
- "husky": "=6.0.0",
89
+ "husky": "^7.0.1",
85
90
  "inspectpack": "=4.7.1",
86
91
  "install": "=0.13.0",
87
92
  "jest": "^27.0.1",
88
93
  "json-loader": "=0.5.7",
89
94
  "license-checker": "=25.0.1",
90
- "lint-staged": "=11.0.0",
95
+ "lint-staged": "=11.1.2",
91
96
  "lodash-webpack-plugin": "=0.11.6",
92
97
  "nock": "=13.1.1",
93
98
  "node-fetch": "=2.6.1",
@@ -95,7 +100,7 @@
95
100
  "prettier": "^2.3.0",
96
101
  "rimraf": "=3.0.2",
97
102
  "terser-webpack-plugin": "^5.0.3",
98
- "webpack": "=5.43.0",
103
+ "webpack": "=5.49.0",
99
104
  "webpack-bundle-size-analyzer": "=3.1.0",
100
105
  "webpack-cli": "=4.7.2",
101
106
  "webpack-stats-plugin": "=1.0.3",
@@ -109,8 +114,9 @@
109
114
  "cross-fetch": "^3.1.4",
110
115
  "deep-extend": "~0.6.0",
111
116
  "fast-json-patch": "^3.0.0-1",
112
- "isomorphic-form-data": "~2.0.0",
113
- "js-yaml": "^3.14.0",
117
+ "form-data-encoder": "^1.0.1",
118
+ "formdata-node": "^3.6.2",
119
+ "js-yaml": "^4.1.0",
114
120
  "lodash": "^4.17.19",
115
121
  "qs": "^6.9.4",
116
122
  "querystring-browser": "^1.0.4",
@@ -1,104 +0,0 @@
1
- import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime-corejs3/helpers/createClass";
3
- import _get from "@babel/runtime-corejs3/helpers/get";
4
- import _getPrototypeOf from "@babel/runtime-corejs3/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime-corejs3/helpers/inherits";
6
- import _createSuper from "@babel/runtime-corejs3/helpers/createSuper";
7
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
8
- import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
9
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
10
- import isFunction from 'lodash/isFunction';
11
- import IsomorphicFormData from 'isomorphic-form-data'; // patches FormData type by mutating it.
12
- // patch :: FormData -> PatchedFormData
13
-
14
- export var patch = function patch(FormData) {
15
- var createEntry = function createEntry(field, value) {
16
- return {
17
- name: field,
18
- value: value
19
- };
20
- };
21
- /** We return original type if prototype already contains one of methods we're trying to patch.
22
- * Reasoning: if one of the methods already exists, it would access data in other
23
- * property than our `_entryList`. That could potentially create nasty
24
- * hardly detectable bugs if `form-data` library implements only couple of
25
- * methods that it misses, instead of implementing all of them.
26
- * Current solution will fail the tests to let us know that form-data library
27
- * already implements some of the methods that we try to monkey-patch, and our
28
- * monkey-patch code should then compensate the library changes easily.
29
- */
30
-
31
-
32
- if (isFunction(FormData.prototype.set) || isFunction(FormData.prototype.get) || isFunction(FormData.prototype.getAll) || isFunction(FormData.prototype.has)) {
33
- return FormData;
34
- }
35
-
36
- var PatchedFormData = /*#__PURE__*/function (_FormData) {
37
- _inherits(PatchedFormData, _FormData);
38
-
39
- var _super = _createSuper(PatchedFormData);
40
-
41
- function PatchedFormData(form) {
42
- var _this;
43
-
44
- _classCallCheck(this, PatchedFormData);
45
-
46
- _this = _super.call(this, form);
47
- _this.entryList = [];
48
- return _this;
49
- }
50
-
51
- _createClass(PatchedFormData, [{
52
- key: "append",
53
- value: function append(field, value, options) {
54
- this.entryList.push(createEntry(field, value));
55
- return _get(_getPrototypeOf(PatchedFormData.prototype), "append", this).call(this, field, value, options);
56
- }
57
- }, {
58
- key: "set",
59
- value: function set(field, value) {
60
- var _context;
61
-
62
- var newEntry = createEntry(field, value);
63
- this.entryList = _filterInstanceProperty(_context = this.entryList).call(_context, function (entry) {
64
- return entry.name !== field;
65
- });
66
- this.entryList.push(newEntry);
67
- }
68
- }, {
69
- key: "get",
70
- value: function get(field) {
71
- var _context2;
72
-
73
- var foundEntry = _findInstanceProperty(_context2 = this.entryList).call(_context2, function (entry) {
74
- return entry.name === field;
75
- });
76
-
77
- return foundEntry === undefined ? null : foundEntry;
78
- }
79
- }, {
80
- key: "getAll",
81
- value: function getAll(field) {
82
- var _context3, _context4;
83
-
84
- return _mapInstanceProperty(_context3 = _filterInstanceProperty(_context4 = this.entryList).call(_context4, function (entry) {
85
- return entry.name === field;
86
- })).call(_context3, function (entry) {
87
- return entry.value;
88
- });
89
- }
90
- }, {
91
- key: "has",
92
- value: function has(field) {
93
- return this.entryList.some(function (entry) {
94
- return entry.name === field;
95
- });
96
- }
97
- }]);
98
-
99
- return PatchedFormData;
100
- }(FormData);
101
-
102
- return PatchedFormData;
103
- };
104
- export default patch(IsomorphicFormData);
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.default = exports.patch = void 0;
5
-
6
- var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
7
-
8
- var _isomorphicFormData = _interopRequireDefault(require("isomorphic-form-data"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- // patches FormData type by mutating it.
13
- // patch :: FormData -> PatchedFormData
14
- const patch = FormData => {
15
- const createEntry = (field, value) => ({
16
- name: field,
17
- value
18
- });
19
- /** We return original type if prototype already contains one of methods we're trying to patch.
20
- * Reasoning: if one of the methods already exists, it would access data in other
21
- * property than our `_entryList`. That could potentially create nasty
22
- * hardly detectable bugs if `form-data` library implements only couple of
23
- * methods that it misses, instead of implementing all of them.
24
- * Current solution will fail the tests to let us know that form-data library
25
- * already implements some of the methods that we try to monkey-patch, and our
26
- * monkey-patch code should then compensate the library changes easily.
27
- */
28
-
29
-
30
- if ((0, _isFunction.default)(FormData.prototype.set) || (0, _isFunction.default)(FormData.prototype.get) || (0, _isFunction.default)(FormData.prototype.getAll) || (0, _isFunction.default)(FormData.prototype.has)) {
31
- return FormData;
32
- }
33
-
34
- class PatchedFormData extends FormData {
35
- constructor(form) {
36
- super(form);
37
- this.entryList = [];
38
- }
39
-
40
- append(field, value, options) {
41
- this.entryList.push(createEntry(field, value));
42
- return super.append(field, value, options);
43
- }
44
-
45
- set(field, value) {
46
- const newEntry = createEntry(field, value);
47
- this.entryList = this.entryList.filter(entry => entry.name !== field);
48
- this.entryList.push(newEntry);
49
- }
50
-
51
- get(field) {
52
- const foundEntry = this.entryList.find(entry => entry.name === field);
53
- return foundEntry === undefined ? null : foundEntry;
54
- }
55
-
56
- getAll(field) {
57
- return this.entryList.filter(entry => entry.name === field).map(entry => entry.value);
58
- }
59
-
60
- has(field) {
61
- return this.entryList.some(entry => entry.name === field);
62
- }
63
-
64
- }
65
-
66
- return PatchedFormData;
67
- };
68
-
69
- exports.patch = patch;
70
-
71
- var _default = patch(_isomorphicFormData.default);
72
-
73
- exports.default = _default;