@webqit/webflo 0.11.39 → 0.11.41

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.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/docker/Dockerfile +43 -0
  3. package/docker/README.md +91 -0
  4. package/docker/package.json +3 -0
  5. package/package.json +2 -3
  6. package/src/Context.js +3 -3
  7. package/src/config-pi/deployment/Layout.js +0 -1
  8. package/src/config-pi/deployment/Origins.js +7 -0
  9. package/src/config-pi/deployment/{Virtualization.js → Proxy.js} +3 -3
  10. package/src/config-pi/deployment/index.js +2 -2
  11. package/src/config-pi/runtime/Server.js +2 -2
  12. package/src/deployment-pi/origins/index.js +3 -2
  13. package/src/runtime-pi/{RuntimeClient.js → Application.js} +2 -2
  14. package/src/runtime-pi/HttpEvent.js +106 -0
  15. package/src/runtime-pi/Router.js +2 -3
  16. package/src/runtime-pi/Runtime.js +3 -3
  17. package/src/runtime-pi/client/{RuntimeClient.js → Application.js} +12 -4
  18. package/src/runtime-pi/client/Router.js +4 -3
  19. package/src/runtime-pi/client/Runtime.js +37 -59
  20. package/src/runtime-pi/client/Url.js +3 -3
  21. package/src/runtime-pi/client/Workport.js +1 -1
  22. package/src/runtime-pi/client/{Storage.js → createStorage.js} +3 -3
  23. package/src/runtime-pi/client/generate.js +5 -3
  24. package/src/runtime-pi/client/index.js +4 -4
  25. package/src/runtime-pi/client/worker/{WorkerClient.js → Application.js} +12 -8
  26. package/src/runtime-pi/client/worker/{Worker.js → Runtime.js} +25 -27
  27. package/src/runtime-pi/client/worker/index.js +6 -6
  28. package/src/runtime-pi/server/{RuntimeClient.js → Application.js} +8 -8
  29. package/src/runtime-pi/server/Router.js +3 -2
  30. package/src/runtime-pi/server/Runtime.js +50 -107
  31. package/src/runtime-pi/server/index.js +4 -4
  32. package/src/runtime-pi/util-http.js +70 -0
  33. package/src/runtime-pi/util-url.js +147 -0
  34. package/src/runtime-pi/xFormData.js +10 -46
  35. package/src/runtime-pi/xHeaders.js +2 -11
  36. package/src/runtime-pi/xRequest.js +29 -42
  37. package/src/runtime-pi/xRequestHeaders.js +20 -23
  38. package/src/runtime-pi/xResponse.js +19 -15
  39. package/src/runtime-pi/xResponseHeaders.js +41 -43
  40. package/src/runtime-pi/xURL.js +71 -77
  41. package/src/runtime-pi/xfetch.js +15 -6
  42. package/src/runtime-pi/xxHttpMessage.js +102 -0
  43. package/src/runtime-pi/client/whatwag.js +0 -27
  44. package/src/runtime-pi/server/whatwag.js +0 -35
  45. package/src/runtime-pi/util.js +0 -162
  46. package/src/runtime-pi/xHttpEvent.js +0 -101
  47. package/src/runtime-pi/xHttpMessage.js +0 -171
@@ -2,59 +2,23 @@
2
2
  /**
3
3
  * @imports
4
4
  */
5
- import { _isTypeObject, _isNumeric } from '@webqit/util/js/index.js';
6
- import { _before } from '@webqit/util/str/index.js';
7
- import { wwwFormSet, wwwFormPathSerializeCallback } from './util.js';
5
+ import { formData } from './util-http.js';
8
6
 
9
7
  /**
10
8
  * The _Headers Mixin
11
9
  */
12
- const xFormData = whatwagFormData => class extends whatwagFormData {
10
+ export default class xFormData extends FormData {
13
11
 
14
- tee(callback = null) {
15
- const formData1 = new this.constructor, formData2 = new this.constructor;
16
- for (var [ name, value ] of this.entries()) {
17
- const formDataType = formDataType(value);
18
- if ((callback && callback(value, name, formDataType)) || (!callback && !formDataType)) {
19
- formData1.append(name, value);
20
- } else {
21
- formData2.append(name, value);
22
- }
23
- }
24
- return [ formData1, formData2 ];
12
+ json(data = {}) {
13
+ const result = formData.call(this, ...arguments);
14
+ return result[0];
25
15
  }
26
16
 
27
- json(data = {}, callback = null) {
28
- if (arguments.length) {
29
- Object.keys(data).forEach(key => {
30
- wwwFormPathSerializeCallback(key, data[key], (_wwwFormPath, _value) => {
31
- if (!callback || callback(_wwwFormPath, _value, _isTypeObject(_value))) {
32
- this.append(_wwwFormPath, _value);
33
- }
34
- }, value => !formDataType(value));
35
- });
36
- return;
37
- }
38
- var jsonBuild; // We'll dynamically determine if this should be an array or an object
39
- for (var [ name, value ] of this.entries()) {
40
- if (!jsonBuild) {
41
- jsonBuild = _isNumeric(_before(name, '[')) ? [] : {};
42
- }
43
- wwwFormSet(jsonBuild, name, value);
17
+ static compat(formData) {
18
+ if (formData instanceof this) return formData;
19
+ if (formData instanceof FormData) {
20
+ return Object.setPrototypeOf(formData, new this);
44
21
  }
45
- return jsonBuild;
46
22
  }
47
23
 
48
- }
49
-
50
- export default xFormData;
51
-
52
- export const formDataType = (value, list = null) => {
53
- if (!_isTypeObject(value)) {
54
- return;
55
- }
56
- const toStringTag = value[Symbol.toStringTag];
57
- return (list || [
58
- 'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer', 'Blob', 'File', 'FormData', 'Stream'
59
- ]).reduce((_toStringTag, type) => _toStringTag || (toStringTag === type ? type : null), null);
60
- };
24
+ }
@@ -1,22 +1,15 @@
1
1
 
2
- /**
3
- * @imports
4
- */
5
- import { _after, _beforeLast } from "@webqit/util/str/index.js";
6
- import { _isString, _getType, _isObject, _isFunction } from "@webqit/util/js/index.js";
7
- import { _isTypeObject } from '@webqit/util/js/index.js';
8
-
9
2
  /**
10
3
  * The xHeaders Mixin
11
4
  */
12
- const xHeaders = whatwagHeaders => class extends whatwagHeaders {
5
+ export default class xHeaders extends Headers {
13
6
 
14
7
  // construct
15
8
  constructor(definition = {}) {
16
9
  const cookies = definition.cookies;
17
10
  delete definition.cookies;
18
11
  // -----------------
19
- if (definition instanceof whatwagHeaders) {
12
+ if (definition instanceof Headers) {
20
13
  // It's another Headers instance
21
14
  super(definition);
22
15
  } else {
@@ -140,8 +133,6 @@ const xHeaders = whatwagHeaders => class extends whatwagHeaders {
140
133
 
141
134
  }
142
135
 
143
- export default xHeaders;
144
-
145
136
  function getAllPropertyDescriptors(obj) {
146
137
  if (!obj) {
147
138
  return Object.create(null);
@@ -2,46 +2,47 @@
2
2
  /**
3
3
  * @imports
4
4
  */
5
- import xHttpMessage, { encodeBody } from './xHttpMessage.js';
5
+ import { formatMessage } from './util-http.js';
6
+ import mxHttpMessage from './xxHttpMessage.js';
7
+ import xRequestHeaders from './xRequestHeaders.js';
6
8
 
7
9
  /**
8
10
  * The xRequest Mixin
9
11
  */
10
- const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHttpMessage(whatwagRequest, Headers, FormData) {
12
+ export default class xRequest extends mxHttpMessage(Request, xRequestHeaders) {
11
13
 
12
14
  constructor(input, init = {}) {
13
- init = { ...init };
14
- let bodyAttrs = {};
15
- if ((input instanceof whatwagRequest)) {
15
+ let meta = {};
16
+ if ((input instanceof Request)) {
16
17
  // On method change...
17
18
  if (init.method && input.method !== init.method.toUpperCase() && [ 'GET', 'HEAD' ].includes(init.method.toUpperCase())) {
18
19
  // Body must not be inherited.
19
20
  input = input.url;
21
+ init = { ...init };
20
22
  // We should now simply copy attributes
21
23
  [ 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity' ].forEach(attr => {
22
- if (!(attr in init)) {
23
- init[attr] = input[attr];
24
- }
24
+ if (!(attr in init)) { init[attr] = input[attr]; }
25
25
  });
26
- } else {
27
- // Inherit bodyAttrs
28
- bodyAttrs = input.bodyAttrs || {};
29
26
  }
30
27
  }
31
- // Init can contain "already-parsed request content"
32
- if (('body' in init)) {
33
- bodyAttrs = encodeBody(init.body, FormData, Blob);
34
- init.body = bodyAttrs.body;
35
- }
36
28
  let isNavigateMode;
37
- if (init.mode === 'navigate') {
38
- isNavigateMode = true;
39
- init = { ...init };
40
- delete init.mode;
29
+ if (!(init instanceof Request)) {
30
+ // Init can contain "already-parsed request content"
31
+ if (('body' in init) && !(init.headers instanceof Headers)) {
32
+ const [ body, headers, type ] = formatMessage(init.body);
33
+ meta = { type, body: init.body };
34
+ init = { ...init, body, headers: { ...headers, ...(init.headers || {}), } };
35
+ }
36
+ if (init.mode === 'navigate') {
37
+ isNavigateMode = true;
38
+ init = { ...init };
39
+ delete init.mode;
40
+ }
41
41
  }
42
- super(input, init, bodyAttrs);
42
+ // ---------------
43
+ super(input, init, meta);
44
+ // ---------------
43
45
  if (isNavigateMode) {
44
- // Through the backdoor
45
46
  this.attrs.mode = 'navigate';
46
47
  }
47
48
  }
@@ -50,16 +51,11 @@ const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHtt
50
51
  return 'mode' in this.attrs ? this.attrs.mode : super.mode;
51
52
  }
52
53
 
53
- get cache() {
54
- return 'cache' in this.attrs ? this.attrs.cache : super.cache;
55
- }
56
-
57
- get destination() {
58
- return 'destination' in this.attrs ? this.attrs.destination : super.destination;
59
- }
60
-
61
- get referrer() {
62
- return 'referrer' in this.attrs ? this.attrs.referrer : super.referrer;
54
+ static compat(request) {
55
+ if (request instanceof this) return request;
56
+ if (request instanceof Request) {
57
+ return Object.setPrototypeOf(request, new this);
58
+ }
63
59
  }
64
60
 
65
61
  static async rip(request) {
@@ -72,13 +68,4 @@ const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHtt
72
68
  return [ request.url, requestInit ];
73
69
  }
74
70
 
75
- static compat(request) {
76
- if (request instanceof this) return request;
77
- if (request instanceof whatwagRequest) {
78
- return Object.setPrototypeOf(request, new this);
79
- }
80
- }
81
-
82
- };
83
-
84
- export default xRequest;
71
+ }
@@ -4,34 +4,14 @@
4
4
  */
5
5
  import { _after } from "@webqit/util/str/index.js";
6
6
  import { _from as _arrFrom } from "@webqit/util/arr/index.js";
7
- import { _getType, _isObject } from "@webqit/util/js/index.js";
8
- import { wwwFormUnserialize } from './util.js';
7
+ import { params } from './util-url.js';
9
8
  import xHeaders from './xHeaders.js';
10
9
  import xCookies from './Cookies.js';
11
10
 
12
- /**
13
- * Cookies
14
- */
15
- class Cookies extends xCookies {
16
-
17
- parse(str) {
18
- return wwwFormUnserialize(str, {}, ';');
19
- }
20
-
21
- parseEntry(str) {
22
- return str.trim().split('=');
23
- }
24
-
25
- stringifyEntry(cookieBody) {
26
- return cookieBody;
27
- }
28
-
29
- }
30
-
31
11
  /**
32
12
  * The xHeaders Mixin
33
13
  */
34
- const xRequestHeaders = NativeHeaders => class extends xHeaders(NativeHeaders) {
14
+ export default class xRequestHeaders extends xHeaders {
35
15
 
36
16
  get cookieHeaderName() {
37
17
  return 'Cookie';
@@ -109,4 +89,21 @@ const xRequestHeaders = NativeHeaders => class extends xHeaders(NativeHeaders) {
109
89
 
110
90
  }
111
91
 
112
- export default xRequestHeaders;
92
+ /**
93
+ * Cookies
94
+ */
95
+ class Cookies extends xCookies {
96
+
97
+ parse(str) {
98
+ return params.parse(str, ';');
99
+ }
100
+
101
+ parseEntry(str) {
102
+ return str.trim().split('=');
103
+ }
104
+
105
+ stringifyEntry(cookieBody) {
106
+ return cookieBody;
107
+ }
108
+
109
+ }
@@ -2,31 +2,37 @@
2
2
  /**
3
3
  * @imports
4
4
  */
5
- import xHttpMessage, { encodeBody } from './xHttpMessage.js';
5
+ import { formatMessage } from './util-http.js';
6
+ import mxHttpMessage from './xxHttpMessage.js';
7
+ import xResponseHeaders from './xResponseHeaders.js';
6
8
 
7
9
  /**
8
10
  * The xResponse Mixin
9
11
  */
10
- const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xHttpMessage(whatwagResponse, Headers, FormData) {
12
+ export default class xResponse extends mxHttpMessage(Response, xResponseHeaders) {
11
13
 
12
14
  // construct
13
- constructor(body = null, init = {}) {
14
- let bodyAttrs = {}, isResponseInput;
15
+ constructor(body = undefined, init = {}) {
16
+ let meta = {}, isResponseInput;
15
17
  if (arguments.length) {
16
- if (body instanceof whatwagResponse) {
18
+ if (body instanceof Response) {
17
19
  isResponseInput = body;
18
20
  // Inherit init
19
21
  init = { status: body.status, statusText: body.statusText, headers: body.headers, ...init };
20
22
  if (body.status === 0) delete init.status;
21
- // Inherit bodyAttrs and body
22
- bodyAttrs = body.bodyAttrs || {};
23
+ // Inherit meta and body
24
+ meta = body.meta || {};
23
25
  body = body.body;
24
- } else {
25
- bodyAttrs = encodeBody(body, FormData, Blob);
26
- body = bodyAttrs.body;
26
+ } else if (!(init.headers instanceof Headers)) {
27
+ let headers, type, _body = body;
28
+ [ body, headers, type ] = formatMessage(body);
29
+ meta = { type, body: _body };
30
+ init = { ...init, headers: { ...headers, ...(init.headers || {}), } };
27
31
  }
28
32
  }
29
- super(body, init, bodyAttrs);
33
+ // ---------------
34
+ super(body, init, meta);
35
+ // ---------------
30
36
  if (isResponseInput) {
31
37
  // Through the backdoor
32
38
  this.attrs.url = isResponseInput.url;
@@ -59,11 +65,9 @@ const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xH
59
65
 
60
66
  static compat(response) {
61
67
  if (response instanceof this) return response;
62
- if (response instanceof whatwagResponse) {
68
+ if (response instanceof Response) {
63
69
  return Object.setPrototypeOf(response, new this);
64
70
  }
65
71
  }
66
72
 
67
- };
68
-
69
- export default xResponse;
73
+ }
@@ -4,53 +4,13 @@
4
4
  */
5
5
  import { _after, _beforeLast } from "@webqit/util/str/index.js";
6
6
  import { _isString, _getType, _isObject } from "@webqit/util/js/index.js";
7
- import _Headers from './xHeaders.js';
7
+ import xHeaders from './xHeaders.js';
8
8
  import xCookies from './Cookies.js';
9
9
 
10
- /**
11
- * Cookies
12
- */
13
- class Cookies extends xCookies {
14
-
15
- parse(cookieStr) {
16
- const obj = {};
17
- cookieStr && cookieStr.split(',').forEach(str => {
18
- let [ cookieName, definition ] = this.parseEntry(str);
19
- obj[cookieName] = definition;
20
- });
21
- return obj;
22
- }
23
-
24
- parseEntry(str) {
25
- let [ cookieDefinition, attrsStr ] = str.split(';');
26
- let [ cookieName, cookieValue ] = cookieDefinition.trim().split('=');
27
- let attrs = { value: cookieValue, };
28
- attrsStr && (attrsStr || '').split(/\;/g).map(attrStr => attrStr.trim().split('=')).forEach(attrsArr => {
29
- attrs[attrsArr[0][0].toLowerCase() + attrsArr[0].substring(1).replace('-', '')] = attrsArr.length === 1 ? true : attrsArr[1];
30
- });
31
- return [ cookieName, attrs ];
32
- }
33
-
34
- stringifyEntry(cookieBody) {
35
- if (_isObject(cookieBody)) {
36
- let attrsArr = [ cookieBody.value ];
37
- for (let attrName in cookieBody) {
38
- if (attrName === 'value') continue;
39
- let _attrName = attrName[0].toUpperCase() + attrName.substring(1);
40
- if (_attrName === 'MaxAge') { _attrName = 'Max-Age' };
41
- attrsArr.push(cookieBody[attrName] === true ? _attrName : `${_attrName}=${cookieBody[attrName]}`);
42
- }
43
- cookieBody = attrsArr.join(';');
44
- }
45
- return cookieBody;
46
- }
47
-
48
- }
49
-
50
10
  /**
51
11
  * The _Headers Mixin
52
12
  */
53
- const _ResponseHeaders = NativeHeaders => class extends _Headers(NativeHeaders) {
13
+ export default class xResponseHeaders extends xHeaders {
54
14
 
55
15
  get cookieHeaderName() {
56
16
  return 'Set-Cookie';
@@ -116,4 +76,42 @@ const _ResponseHeaders = NativeHeaders => class extends _Headers(NativeHeaders)
116
76
 
117
77
  }
118
78
 
119
- export default _ResponseHeaders;
79
+ /**
80
+ * Cookies
81
+ */
82
+ class Cookies extends xCookies {
83
+
84
+ parse(cookieStr) {
85
+ const obj = {};
86
+ cookieStr && cookieStr.split(',').forEach(str => {
87
+ let [ cookieName, definition ] = this.parseEntry(str);
88
+ obj[cookieName] = definition;
89
+ });
90
+ return obj;
91
+ }
92
+
93
+ parseEntry(str) {
94
+ let [ cookieDefinition, attrsStr ] = str.split(';');
95
+ let [ cookieName, cookieValue ] = cookieDefinition.trim().split('=');
96
+ let attrs = { value: cookieValue, };
97
+ attrsStr && (attrsStr || '').split(/\;/g).map(attrStr => attrStr.trim().split('=')).forEach(attrsArr => {
98
+ attrs[attrsArr[0][0].toLowerCase() + attrsArr[0].substring(1).replace('-', '')] = attrsArr.length === 1 ? true : attrsArr[1];
99
+ });
100
+ return [ cookieName, attrs ];
101
+ }
102
+
103
+ stringifyEntry(cookieBody) {
104
+ if (_isObject(cookieBody)) {
105
+ let attrsArr = [ cookieBody.value ];
106
+ for (let attrName in cookieBody) {
107
+ if (attrName === 'value') continue;
108
+ let _attrName = attrName[0].toUpperCase() + attrName.substring(1);
109
+ if (_attrName === 'MaxAge') { _attrName = 'Max-Age' };
110
+ attrsArr.push(cookieBody[attrName] === true ? _attrName : `${_attrName}=${cookieBody[attrName]}`);
111
+ }
112
+ cookieBody = attrsArr.join(';');
113
+ }
114
+ return cookieBody;
115
+ }
116
+
117
+ }
@@ -2,94 +2,89 @@
2
2
  /**
3
3
  * @imports
4
4
  */
5
- import _isArray from '@webqit/util/js/isArray.js';
6
- import _isObject from '@webqit/util/js/isObject.js';
7
- import { wwwFormUnserialize, wwwFormSerialize } from './util.js';
5
+ import { _isObject, _isArray } from '@webqit/util/js/index.js';
6
+ import { params } from './util-url.js';
8
7
 
9
8
  /**
10
9
  * ---------------------------
11
10
  * The xURL Mixin
12
11
  * ---------------------------
13
12
  */
14
- const xURL = whatwagURL => {
15
- const URL = class extends whatwagURL {
16
-
17
- // constructor
18
- constructor(...args) {
19
- super(...args);
20
- var query = wwwFormUnserialize(this.search);
21
- const updateSearch = query => {
22
- // "query" was updated. So we update "search"
23
- var search = wwwFormSerialize(query);
24
- search = search ? '?' + search : '';
25
- if (search !== this.search) {
26
- this.search = search;
13
+ export default class xURL extends URL {
14
+
15
+ // constructor
16
+ constructor(...args) {
17
+ super(...args);
18
+ var query = params.parse(this.search);
19
+ const updateSearch = query => {
20
+ // "query" was updated. So we update "search"
21
+ var search = params.stringify(query);
22
+ search = search ? '?' + search : '';
23
+ if (search !== this.search) {
24
+ this.search = search;
25
+ }
26
+ };
27
+ this.__query = {
28
+ value: query,
29
+ proxy: new Proxy(query, {
30
+ set(t, n, v) {
31
+ t[n] = v;
32
+ updateSearch(t);
33
+ return true;
34
+ },
35
+ deleteProperty(t, n) {
36
+ delete t[n];
37
+ updateSearch(t);
38
+ return true;
27
39
  }
28
- };
29
- this.__query = {
30
- value: query,
31
- proxy: new Proxy(query, {
32
- set(t, n, v) {
33
- t[n] = v;
34
- updateSearch(t);
35
- return true;
36
- },
37
- deleteProperty(t, n) {
38
- delete t[n];
39
- updateSearch(t);
40
- return true;
41
- }
42
- })
43
- };
44
- }
40
+ })
41
+ };
42
+ }
45
43
 
46
- // Set search
47
- set search(value) {
48
- super.search = value;
49
- // "search" was updated. So we update "query"
50
- var query = wwwFormUnserialize(value);
51
- if (!_strictEven(query, this.query)) {
52
- this.query = query;
53
- }
44
+ // Set search
45
+ set search(value) {
46
+ super.search = value;
47
+ // "search" was updated. So we update "query"
48
+ var query = params.parse(value);
49
+ if (!_strictEven(query, this.query)) {
50
+ this.query = query;
54
51
  }
52
+ }
55
53
 
56
- // Get search
57
- get search() {
58
- return super.search;
59
- }
54
+ // Get search
55
+ get search() {
56
+ return super.search;
57
+ }
60
58
 
61
- // Get query
62
- get query() {
63
- return this.__query.proxy;
64
- }
59
+ // Get query
60
+ get query() {
61
+ return this.__query.proxy;
62
+ }
65
63
 
66
- };
67
- // ----------
68
- URL.Observable = class extends URL {
69
-
70
- constructor() {
71
- super(...arguments);
72
- const { Observer } = WebQit;
73
- Observer.accessorize(this, [
74
- 'protocol',
75
- 'username',
76
- 'password',
77
- 'host',
78
- 'hostname',
79
- 'port',
80
- 'origin',
81
- 'pathname',
82
- 'search',
83
- 'query',
84
- 'hash',
85
- 'href',
86
- ]);
87
- }
88
-
89
- };
90
- // ----------
91
- return URL;
92
- }
64
+ };
65
+ // ----------
66
+ xURL.Observable = class extends xURL {
67
+
68
+ constructor() {
69
+ super(...arguments);
70
+ const { Observer } = WebQit;
71
+ Observer.accessorize(this, [
72
+ 'protocol',
73
+ 'username',
74
+ 'password',
75
+ 'host',
76
+ 'hostname',
77
+ 'port',
78
+ 'origin',
79
+ 'pathname',
80
+ 'search',
81
+ 'query',
82
+ 'hash',
83
+ 'href',
84
+ ]);
85
+ }
86
+
87
+ };
93
88
 
94
89
  /**
95
90
  * ---------------------------
@@ -108,4 +103,3 @@ var _strictEven = (a, b) => {
108
103
  return a === b;
109
104
  };
110
105
 
111
- export default xURL;
@@ -1,14 +1,23 @@
1
1
 
2
+ /**
3
+ * @imports
4
+ */
5
+ import { formatMessage } from './util-http.js';
6
+
2
7
  /**
3
8
  * The xfetch Mixin
4
9
  */
5
- const xfetch = (whatwagFetch, xRequest = null) => {
6
- return (url, init = {}) => {
7
- if (init.body && (typeof init.body === 'object') && xRequest) {
8
- return whatwagFetch(new xRequest(url, init));
9
- }
10
- return whatwagFetch(url, init);
10
+ const xfetch = async (url, init = {}) => {
11
+ if (init.body) {
12
+ const [ body, headers ] = formatMessage(init.body);
13
+ init = { ...init, body, headers: { ...headers, ...(init.headers || {}), } };
14
+ }
15
+ let response = await fetch(url, init), encoding;
16
+ if (init.decompress === false && (encoding = response.headers.get('Content-Encoding'))) {
17
+ let recompressedBody = response.body.pipeThrough(new CompressionStream(encoding));
18
+ response = new Response(recompressedBody, response);
11
19
  }
20
+ return response;
12
21
  };
13
22
 
14
23
  export default xfetch;