keq 1.6.5 → 1.6.6

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
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.6.6](https://www.github.com/keq-request/keq/compare/v1.6.5...v1.6.6) (2021-12-13)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * response cannot call .text, .json, .formData and .blob together ([fa1605a](https://www.github.com/keq-request/keq/commit/fa1605a911b05ac7ce3ecdb9f6d7805b4ced36f2))
11
+
5
12
  ### [1.6.5](https://www.github.com/keq-request/keq/compare/v1.6.4...v1.6.5) (2021-12-13)
6
13
 
7
14
 
package/es/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "keq",
3
3
  "main": "lib/index.js",
4
4
  "module": "es/index.js",
5
- "version": "1.6.5",
5
+ "version": "1.6.6",
6
6
  "license": "MIT",
7
7
  "types": "lib/index.d.ts",
8
8
  "scripts": {
package/es/src/keq.js CHANGED
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as url from 'url';
11
11
  import fetch, { Headers } from 'cross-fetch';
12
12
  import * as clone from 'clone';
13
- import * as R from 'ramda';
14
13
  import { Exception, FileExpectedException, OverwriteArrayBodyException, UnknowContentTypeException, } from "./exception";
15
14
  import { isFormData, isFile, isBrowser, encodeBase64, sleep, inferContentTypeByBody, fixContentType, getBoundaryByContentType, parseFormData, serializeBody, } from "./util";
16
15
  import { matchHost, matchMiddleware, compose } from "./middleware";
17
- import { FormData } from "./polyfill";
16
+ import { FormData, Response } from "./polyfill";
18
17
  import { compile } from 'path-to-regexp';
19
18
  export class Keq {
20
19
  constructor(urlObj, method, middlewares) {
@@ -245,36 +244,33 @@ export class Keq {
245
244
  fetchOptions.headers.delete('content-type');
246
245
  }
247
246
  const res = yield ctx.options.fetchAPI(uri, fetchOptions);
247
+ function resFromData() {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ const str = yield this.text();
250
+ const contentType = this.headers.get('content-type');
251
+ if (!contentType)
252
+ throw new Exception('Cannot parse form-data body without content-type');
253
+ const boundary = getBoundaryByContentType(contentType);
254
+ return parseFormData(str, boundary);
255
+ });
256
+ }
248
257
  if (!isBrowser()) {
249
258
  // node-fetch does not implement Response.formData()
250
- res.formData = function () {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- const str = yield this.text();
253
- const contentType = this.headers.get('content-type');
254
- if (!contentType)
255
- throw new Exception('Cannot parse form-data body without content-type');
256
- const boundary = getBoundaryByContentType(contentType);
257
- return parseFormData(str, boundary);
258
- });
259
- };
259
+ res.formData = resFromData.bind(res);
260
260
  }
261
- const cache = {};
261
+ let cache;
262
262
  ctx.res = new Proxy(res, {
263
263
  get(target, property) {
264
264
  if (!(typeof property === 'string' && ['json', 'formData', 'text', 'blob'].includes(property))) {
265
265
  return target[property];
266
266
  }
267
- return () => {
268
- if (!(property in cache))
269
- cache[property] = target[property]();
270
- return cache[property].then(data => {
271
- if (!isBrowser() && data instanceof Buffer)
272
- return Buffer.from(data);
273
- else if (isBrowser() && data instanceof Blob)
274
- return data.slice();
275
- return R.clone(data);
276
- });
277
- };
267
+ return () => __awaiter(this, void 0, void 0, function* () {
268
+ if (!cache)
269
+ cache = yield target.arrayBuffer();
270
+ const res = new Response(cache, { headers: target.headers });
271
+ res.formData = resFromData.bind(res);
272
+ return yield res[property]();
273
+ });
278
274
  },
279
275
  });
280
276
  if (ctx.options.resolveWithFullResponse) {
package/lib/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "keq",
3
3
  "main": "lib/index.js",
4
4
  "module": "es/index.js",
5
- "version": "1.6.5",
5
+ "version": "1.6.6",
6
6
  "license": "MIT",
7
7
  "types": "lib/index.d.ts",
8
8
  "scripts": {
package/lib/src/keq.js CHANGED
@@ -13,7 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  if (v !== undefined) module.exports = v;
14
14
  }
15
15
  else if (typeof define === "function" && define.amd) {
16
- define(["require", "exports", "url", "cross-fetch", "clone", "ramda", "./exception", "./util", "./middleware", "./polyfill", "path-to-regexp"], factory);
16
+ define(["require", "exports", "url", "cross-fetch", "clone", "./exception", "./util", "./middleware", "./polyfill", "path-to-regexp"], factory);
17
17
  }
18
18
  })(function (require, exports) {
19
19
  "use strict";
@@ -22,7 +22,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  const url = require("url");
23
23
  const cross_fetch_1 = require("cross-fetch");
24
24
  const clone = require("clone");
25
- const R = require("ramda");
26
25
  const exception_1 = require("./exception");
27
26
  const util_1 = require("./util");
28
27
  const middleware_1 = require("./middleware");
@@ -257,36 +256,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
257
256
  fetchOptions.headers.delete('content-type');
258
257
  }
259
258
  const res = yield ctx.options.fetchAPI(uri, fetchOptions);
259
+ function resFromData() {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ const str = yield this.text();
262
+ const contentType = this.headers.get('content-type');
263
+ if (!contentType)
264
+ throw new exception_1.Exception('Cannot parse form-data body without content-type');
265
+ const boundary = (0, util_1.getBoundaryByContentType)(contentType);
266
+ return (0, util_1.parseFormData)(str, boundary);
267
+ });
268
+ }
260
269
  if (!(0, util_1.isBrowser)()) {
261
270
  // node-fetch does not implement Response.formData()
262
- res.formData = function () {
263
- return __awaiter(this, void 0, void 0, function* () {
264
- const str = yield this.text();
265
- const contentType = this.headers.get('content-type');
266
- if (!contentType)
267
- throw new exception_1.Exception('Cannot parse form-data body without content-type');
268
- const boundary = (0, util_1.getBoundaryByContentType)(contentType);
269
- return (0, util_1.parseFormData)(str, boundary);
270
- });
271
- };
271
+ res.formData = resFromData.bind(res);
272
272
  }
273
- const cache = {};
273
+ let cache;
274
274
  ctx.res = new Proxy(res, {
275
275
  get(target, property) {
276
276
  if (!(typeof property === 'string' && ['json', 'formData', 'text', 'blob'].includes(property))) {
277
277
  return target[property];
278
278
  }
279
- return () => {
280
- if (!(property in cache))
281
- cache[property] = target[property]();
282
- return cache[property].then(data => {
283
- if (!(0, util_1.isBrowser)() && data instanceof Buffer)
284
- return Buffer.from(data);
285
- else if ((0, util_1.isBrowser)() && data instanceof Blob)
286
- return data.slice();
287
- return R.clone(data);
288
- });
289
- };
279
+ return () => __awaiter(this, void 0, void 0, function* () {
280
+ if (!cache)
281
+ cache = yield target.arrayBuffer();
282
+ const res = new polyfill_1.Response(cache, { headers: target.headers });
283
+ res.formData = resFromData.bind(res);
284
+ return yield res[property]();
285
+ });
290
286
  },
291
287
  });
292
288
  if (ctx.options.resolveWithFullResponse) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "keq",
3
3
  "main": "lib/index.js",
4
4
  "module": "es/index.js",
5
- "version": "1.6.5",
5
+ "version": "1.6.6",
6
6
  "license": "MIT",
7
7
  "types": "lib/index.d.ts",
8
8
  "scripts": {